读见

用「混沌循环」强化 Claude Docs 上线:数十亿次请求中仅出现 60 次服务器错误 / claude.dev 博客

原题Using a "chaos loop" to harden the Claude Docs launch: 60 server errors across billions of requests / claude.dev Blog

约 9 分钟约 2,113 字原文英文已翻译

读前速览

5 个要点

Anthropic 使用 Claude Code 搭建「混沌循环」,通过合成负载测试和自动修复来强化 Claude Docs 上线表现:处理 20 亿次请求、创建 460 万份文档,仅出现 60 次服务器错误。

  1. Claude Code 驱动了一个自我改进的混沌循环,在合成负载下自动测试并修复 Claude Docs 服务。

    该循环由 Claude 担任协调者,指挥子智能体读取遥测数据、提出修复方案,并将更改部署到预发布环境;对于可逆更改,无需人工介入即可持续改进。

  2. 上线期间,该服务处理 20 亿次请求,仅出现 60 次服务器错误,可靠性表现出色。

    Docs 服务仅运行在 50 个内存优化型 Pod 上,第一周就处理了 460 万份文档,且没有回滚,展现了自动化测试方法的成效。

  3. 内存优化将所需基础设施从 500 多个 Pod 降至约 50 个。

    Claude 发现每次按键都会将文档复制到多个数据结构中,因此采用写时复制优化,大幅降低了内存使用量:每份文档从 3GB 降至 180MB。

  4. 该方法利用了 Claude 保持长期目标能力的提升,避免在长时间测试周期中出现「目标偏移」。

    较新的前沿模型在多轮迭代中能持续专注于避免崩溃这一目标,无需反复重申目标,因此可以自主运行数周。

  5. 人工监督仅限于数据库架构修改等不可逆更改。

    对于难以撤销的更改,Claude 会暂停并提供选项;对于可逆修复,则会自动处理,从而在确保安全的同时尽量减少人工参与。

完整摘要

在公开上线 Claude Docs 之前,Anthropic 运行了一套「混沌循环」:Claude Code 驱动预发布集群,在每天超过 100 万份文档的合成负载下运行,故意破坏组件,并自动提出和部署修复方案。该循环由 Claude 协调多个子智能体,读取遥测数据、识别问题并实施更改,同时确保文档即时加载、编辑内容持久保存等不变条件。经过 3 周迭代,服务仅运行在 50 个内存优化型 Pod 上,就能处理数百万份文档;在 20 亿次请求中仅出现 60 次服务器错误。这种方法利用了 Claude 保持长期目标能力的提升;对于修改数据库架构等不可逆更改,则只需少量人工介入。

目录 · 8 节

查看原文

Claude Docs 面向公众开放前三周,它还只是一个运行在单个节点上的概念验证版本,由 Anthropic 内部几千人使用。我们正全力赶在一个雄心勃勃的发布日期前完成准备,而我们自己的估算显示,头几天内就会有数百万份文档。Three weeks before Claude Docs opened to the public, it was running as a proof of concept on a single node, used by a few thousand people inside Anthropic. We were racing toward an ambitious launch date, and our own estimate said we'd see millions of docs within the first few days.

我们于9月16日上线。截至9月22日,用户已创建超过460万份文档。在20亿次请求中,我们只遇到60次服务器错误,而且从未需要回滚。整个 Docs 服务仅运行在约50个内存优化型 Pod 上。We launched on September 16. By September 22, people had created over 4.6 million docs. Across 2 billion requests we saw only 60 server errors, and we never had to roll back. The whole Docs service ran on about 50 memory-optimized pods.

我们通过两个决定实现了这一点:Two decisions got us there:

  • 一次达到发布规模的混沌测试循环。我们在预发布环境搭建了一个测试框架,让 Claude 连续运行两周,试图弄垮服务。它对基础设施的每个部分都进行了负载测试,并修复了所有出故障的部分。
    A chaos loop at launch scale. We set up a test harness on our staging environment where Claude ran constantly for two weeks to try and break the service. It load tested every part of our infrastructure and fixed whatever fell over.
  • 提高对 Claude 的可读性。只有当我们的系统每次迭代都能生成准确的遥测数据时,Claude 才能有效地完成修复闭环。我们很早就决定避开那些会以代码难以控制的方式使用内存或 CPU 的运行时(例如带垃圾回收机制的运行时)。当某个遥测信号令人担忧时,Claude 可以轻松追溯到其中的 bug 或某项具体的设计决策。
    Improving legibility to Claude. Claude could only close the loop effectively on fixes if our system produced accurate telemetry every iteration. We made a call early to avoid any runtime that uses memory or CPU in ways our code can't easily control (e.g. runtimes with garbage collection). When a telemetry signal looked concerning, Claude could easily trace it to a bug or a specific design decision.

但说实话,这之所以能奏效,只是因为我们的前沿模型最近进步很大(我用的是一个内部研究模型,大致相当于 Claude Fable 5.2)。根据我们的经验,它们现在能够在这样的运行过程中连续数周专注于同一个目标,这帮助我们在紧迫的时间安排下达到了发布所需的规模。But honestly, this only worked because our frontier models have gotten much better recently (I used an internal research model roughly comparable to Claude Fable 5.2). In our experience, they can now stick with one goal through a run like this for weeks, which is what helped us hit launch scale in a tight timeline.

混乱循环THE CHAOS LOOP

在一台机器上有几千名内部用户,并不能告诉我们这项服务能否经受住上线考验,而且显然我们也没有上线流量可供测试。A few thousand internal users on one machine told us nothing about whether the service would survive launch, and we obviously didn't have launch traffic to test with.

我们需要真实证据来决定推广速度。因此,9 月 4 日,也就是上线前约两周,我让 Claude 驱动一个与生产环境镜像一致的预发布集群,以每天超过一百万份合成文档的规模运行,并故意破坏核心组件。然后……我就让它一直运行下去了(本文末尾列出了全部费用)。We wanted real evidence to decide how fast we could roll out. So on September 4, about two weeks before launch, I had Claude drive a staging cluster that mirrored production at over a million synthetic docs a day and break core components on purpose. And then... I just left it running (I've included the full cost at the end of this article).

我的设置相当简单。这个循环就是 Claude Code 中一个一直运行着的会话:选择一个场景、运行测试框架、查看遥测数据、提出修复方案、部署到预发布环境,然后重复。这个会话充当协调器,把大部分工作交给子代理。在最忙的一周里,通常会同时运行大约 11 个子代理,峰值时达到 30 个。协调器还通过 Slack MCP 与我们内部的 Claude Tag(测试版)变体交流,向 Anthropic 其他扩展过类似服务的基础设施团队取经。他们的代理会检查我们的扩展方案,看看是否存在他们之前遇到过的问题。My setup was pretty simple. The loop was a session in Claude Code that I left running: pick a scenario, run the harness, read the telemetry, propose a fix, ship it to staging, repeat. That session acted as a coordinator and handed most of the work to sub-agents. In the busiest week, that usually meant about 11 sub-agents running at a time, and 30 at the peak. The coordinator also talked to our internal variant of Claude Tag (beta) via the Slack MCP to learn from other infrastructure teams at Anthropic who had scaled similar services. Their agents checked our scaling approach for pitfalls they’d already hit.

有意思的部分,是挑选那些我觉得有些杞人忧天的情境:The fun part was picking scenarios I thought were paranoid:

  • 单日新创建 1000 万份文档
    10M new docs created in a single day
  • 22,000 个实时连接同时重新连接
    22,000 live connections reconnecting at once
  • 一份热门文档有数百名查看者、服务器在文档仍在加载时被终止,以及数据库陷入停滞
    One hot doc with hundreds of viewers, a server killed while it was still loading a doc, and the database stalling

每次迭代看起来都一样。我们的测试框架会选取一项功能(例如创建文档),并将其推至饱和状态。随后,Claude 使用 Datadog MCP 读取遥测数据,并给出一份简短的选项清单和一项建议。Each iteration looked the same. Our testing harness selected a feature like document creation and pushed creation to saturation. Claude then read telemetry using the Datadog MCP and came back with a short menu of options and a recommendation.

如果这项建议很容易撤销,Claude 就会编写并部署更改到预发布环境,然后重新运行测试。我们对服务执行的每项操作都有遥测数据。例如,每条数据库查询都会报告其名称,以及扫描的行数和返回的行数,因此 Claude 可以发现有问题的查询并重写它。If the recommendation was easy to undo, Claude wrote and deployed the change to staging and reran the test. We had telemetry on every operation the service ran. Every database query, for example, reported its name and how many rows it scanned versus how many it returned, so Claude could spot a bad query and rewrite it.

A loop of eight steps, with a legend marking the steps Claude does and the ones you do. Top row, left to right: the harness adds load, Claude reads the telemetry, Claude proposes options, and you pick one. Bottom row, right to left: Claude writes the change, Claude reviews it in a separate session, you approve, and Claude deploys to staging, which leads back to the harness. Inside the loop: opens instantly, and check that no confirmed edit was lost.
FIG 1One iteration of the loop, with two decisions made by a person

循环开始前,我告诉 Claude 哪些决策需要经过我的批准;基本上,所有难以撤销的事情都包括在内,比如更改数据库 schema 或键的布局,或者更改文档的存储和物化方式。Before the loop started, I told Claude which decisions needed my approval; basically anything hard to undo, like changing the database schema or key layout, or changing how a doc is stored and materialized.

Claude 遇到这类情况时,会停下来问我,通常还会给出一个建议,而我最后也会采纳。架构变更就是我希望事先征求意见的典型情况:通常有几种合理的方案,而中途改变方向往往很麻烦。When Claude ran into one of those, it stopped and asked me, usually with a recommendation that I ended up approving. Schema changes were the classic case where I wanted to be consulted: there are usually a few reasonable answers, and changing directions is often painful.

在整个测试过程中,Claude 必须遵守两个不变量:And during the whole testing process, Claude had to conform to two invariants:

  1. 文档必须几乎瞬间打开(即使是有很长历史记录的文档)
    Docs had to open almost instantly (even ones with a long history)
  2. 服务器确认编辑后,测试必须证明该编辑仍然存在。
    Once the server acknowledged an edit, tests had to show the edit was still there

让 Claude 看懂这项服务MAKING THE SERVICE LEGIBLE TO CLAUDE

我的同事 Felix Rieseberg 最近写了一篇教程,介绍如何更大胆地使用模型。他的核心观点是,向 Claude 提示时要提高“高度”:说出你想要的结果,而不是逐项布置具体任务。My colleague Felix Rieseberg recently wrote a tutorial on being more ambitious with models. His main idea is to raise the "altitude" you prompt Claude at: ask for the outcome you want, not the individual task.

所以,你不再让 Claude 修复单个崩溃,而是让它让你的应用不再崩溃。(我们自己的应用还没完全达到这个目标,但我们正是通过这种方式取得实质性进展。)不过,要让它在这个层面开展工作,你得先设置好代码,让 Claude 能自行获取崩溃报告,并运行一个测试框架来复现每次崩溃并验证修复效果。So instead of asking Claude to fix individual crashes, you ask it to make your app crash-free. (Our own apps aren't all the way there yet, but this is how we're making real progress.) To work at that altitude, though, you have to set up your code so Claude can pull crash reports on its own and run a harness that reproduces each crash and checks the fix.

对我们而言,最终成果是一个能够应对上线的服务。为此,我们做了两件事,尽可能让 Claude 理解这个服务:For us, the outcome was a service that could handle launch. To get there, we did two things to make the service as legible to Claude as we could:

  • 一个诊断循环。Claude 每次迭代都会读取遥测数据,并补充它认为缺失的内容。
    A diagnostic loop. Claude read the telemetry on every iteration and added whatever it thought was missing.
  • 清晰透明的技术选型。我们选择了运行时和依赖项,确保 Claude 测量的任何数值都能追溯到我们编写的代码。
    Legible technology choices. We picked a runtime and dependencies so any number Claude measured traced back to code we wrote.

诊断循环A diagnostic loop

每次迭代,Claude 都会读取遥测数据,并补上它认为缺少的部分。手动编写遥测代码很繁琐,因此实际上,大多数遥测代码都是出了问题之后才补上的。现在 Claude 会在开发过程中顺手把它们写好。Every iteration, Claude read the telemetry and added whatever it thought was missing. Writing telemetry by hand is tedious, so in practice most telemetry would go in after something broke. Now Claude just writes it as it goes.

记忆就是最好的例子。Memory is the best example.

在测试框架运行初期,有一份大型文档在其 Pod 上占用了约 3 GB 内存(看到这个数字可不是什么愉快的事)。Claude 最初尝试通过缩小我们其中一个缓存来解决问题,这样服务器就会更早淘汰文档。下一次测试框架运行时发现,内存实际上占用在某个依赖项内部的另一个独立缓存中,因此 Claude 撤回了这项改动。Early in the harness run, one large doc was using about 3 GB on its pod (not a fun number to see). Claude’s first stab at fixing it was to shrink one of our caches so our server would evict docs sooner. The next harness run showed the memory was actually in a separate cache inside one of our dependencies, so Claude dropped the change.

之后,Claude 通过更细致的内存分析不断缩小排查范围。最终发现,每次按键都会将文档复制到多个不同的数据结构中,每次因此增加几 MB 的内存占用。Claude 将这些结构改为写时复制,这样它们现在共享同一个引用,而不再各自保存一份副本。From there Claude kept narrowing it down with finer-grained memory profiling. Eventually it found that every keystroke was copying the doc into several different data structures, adding a few MB each time. Claude switched those structures to copy-on-write, so they now share one reference instead of each holding its own copy.

经过大约三天的反复迭代,那份文档的大小最终稳定在约 180 MB,我们对上线所需资源的估算也从 500 多个内存优化型 Pod 降到了约 50 个。After about three days of iterating, that doc topped out around 180 MB, and our estimate of what we’d need for launch dropped from more than 500 memory-optimized pods to about 50.

Claude adds telemetry as it goes. A loop of six steps: the harness stresses the service, the service reports telemetry, and Claude reads it and traces it to a cause. Then Claude adds what's missing, which is highlighted, Claude fixes it or drops a wrong guess, and Claude deploys and reruns, with hard-to-undo changes going to you first, which leads back to the harness.
FIG 2The diagnostic loop

清晰易懂的技术选择Legible technology choices

我们对服务的运行时和依赖项要求很严格。我们希望 Claude 测得的任何数字都能追溯到我们编写的代码。We were picky about the service’s runtime and dependencies. We wanted any number Claude measured to trace back to code we wrote.

这是因为我们的模型在信号干净时最适合采用爬山法优化。我们原以为垃圾回收器会引入噪声,因为内存占用和延迟会随着回收器的调度而变化。This is because our models hill climb best with a clean signal. We expected a garbage collector to add noise, because memory and latency shift on the collector’s schedule.

有两个选择最有帮助。Two choices helped the most.

  1. 我们用 Rust 编写了这个服务。由于没有垃圾回收器,文档的所有内存都存放在我们定义的结构体中,因此当内存占用增长时,Claude 可以指出具体是哪一处造成的,修改它,并在下一轮检查内存是否下降。Anthropic 也有很棒的 Go 工具链,而且我们并没有对两种语言进行对比测试,所以这只是我们使用 Rust 的体验。让我很满意的是,考虑到我过去使用 Go 的经历,我几乎不必操心代码处理完数据后,内存还会继续被占用多久。
    We wrote the service in Rust. With no garbage collector, all of a doc’s memory sits in structures we defined, so when it grew, Claude could point to the one responsible, change it, and see whether memory came down on the next iteration. We have great Go tooling at Anthropic too, and we didn’t bake off the two languages, so this is our experience with Rust. What I did appreciate, coming from past work in Go, was how little I had to think about memory sticking around after my code was done with it.
  2. 我们还尽量减少了依赖。每个库都会引入我们没有编写、也难以全面了解的数据结构。对于少数确实需要的库,我们将其代码直接纳入项目,以便自行阅读和衡量。
    We also kept dependencies to a minimum. Every library brings data structures we didn’t write and can’t easily account for. For the few we really needed, we vendored the code so we could read and measure it ourselves.

Rust 对人类来说很难写,而几年前这一点会对选择产生很大影响。Claude 能很好地编写 Rust 和大多数其他语言,所以现在这方面的影响小得多。Rust is hard for people to write, and a few years ago that would have weighed heavily on the choice. Claude writes it and most other languages fine, so that matters a lot less now.

We wanted every number to trace back to code we wrote, so we used Rust and kept dependencies to a minimum. Two lanes. What we chose: Rust and few dependencies, so memory sits in our own structures, then Claude finds the cause, then fixes are easy to check. What we avoided, a bet and not a test: garbage collection and libraries we didn't write, then memory we can't account for, then a noisier signal that is harder to trace to our code.
FIG 3Legible technology choices: memory our code can explain, and memory it can't

发布周LAUNCH WEEK

该服务在上线规模下保持稳定。首批 100 万份文档在约 30 小时内涌现;到 9 月 22 日,数量已超过 460 万份。9 月份我们在生产环境发布了 629 次,从未回滚过一次。The service held at launch scale. The first million docs showed up in about 30 hours, and we were past 4.6 million by September 22. We rolled prod 629 times in September and never once rolled back.

上线周有种奇怪的熟悉感。Claude 很擅长设想服务可能出现故障的各种方式,并且在上线前很久就为其中大多数情况做好了准备。我们在预发布环境演练过的十种情形中,有七种后来确实在生产环境发生了。那时,测试框架已经让预发布环境经历过其中的大部分情况,而 Claude 也已将修复方案部署到线上,只是由运行时标志控制。基础设施的某个部分遇到压力时,我们通常只需切换一个标志。Launch week felt weirdly familiar. Claude is great at imagining ways a service can fail and had planned for most of them well before launch. Seven of the ten scenarios we’d rehearsed on staging actually happened in prod. By then the harness had already put staging through most of it, and Claude had shipped the fixes behind runtime flags. When part of the infra ran into pressure, we usually just flipped a flag.

为什么现在这样行得通WHY THIS WORKS NOW

几个月前,这大概还行不通。较早的模型很擅长通过 MCP 服务器读取遥测数据,但在漫长循环中迭代十几或二十次后,它们就会开始忘记我们要优化的目标,而我最终不得不重新说明目标。Anthropic 的其他员工把这种现象称为目标漂移。A few months ago this probably wouldn’t have worked. Older models were fine at reading telemetry through an MCP server, but ten or twenty iterations into a long loop, they’d start forgetting what we were optimizing for, and I’d end up restating the goal. Other Anthropic employees have called this goal drift.

我们的新一代前沿模型专为长时间运行的任务打造。Claude 在多次上下文压缩过程中始终牢记我们的所有不变量,我从未需要重复说明。Our newer frontier models are built for long-running work. Claude held all of our invariants across many compactions, and I never had to repeat them.

做这件事的不止我们。Vercel 也通过一个与我们的做法非常相似的监督式智能体循环,将 Turborepo 的速度提升了高达 96%。We're not the only ones doing this, either. Vercel made Turborepo up to 96% faster with a supervised agent loop a lot like ours.

它花了多少钱WHAT IT COST

按 Claude Fable 5.2 的 API 标价(截至 2026 年 11 月)计算,从 8 月底到发布当天,我大约花了 12.5 万美元用于推理。几年前,我猜这种规模的工作大概需要一个工程师团队花六个月左右才能完成。At Claude Fable 5.2's API list price (as of November 2026), I used roughly $125,000 of inference from the end of August to launch day. A couple of years ago, work on this scale I'd guess would have taken a team of engineers about six months.

其中大部分时间都花在阅读遥测数据、撰写提案、生成修复方案和审查代码上。Most of that went to reading telemetry, writing proposals, generating fixes, and reviewing code.

关于费用有几点说明:A couple of things about the cost:

  • 我们的上线规模尤其庞大。很大一部分资金都投入到了只有达到这种规模才有意义的基础设施中,而分析这些基础设施也需要更多推理。Claude 必须更深入地思考不断增多的服务如何协同运作,以及它们可能出现故障的各种方式。
    Our launch was particularly massive. A good chunk of the money went into infrastructure that only makes sense at that scale, and that infrastructure took more inference to reason about. Claude had to think a lot harder about how a growing set of services fit together and all the ways they could fail.
  • 我还花了很多 token 才摸清整个流程。尝试配置时,循环一直不停地运行。以我现在掌握的信息来看,我觉得我们本可以少花一半左右。
    I also burned a lot of tokens figuring out the process. The loop ran nonstop while I was experimenting with the setup. Knowing what I know now, I think we could have spent about half as much.

试试看TRYING THIS OUT

这对规模小得多的服务也适用,而且成本应该低得多。This works for much smaller services too, and it should cost a lot less.

为了粗略估算,我计算了一套典型小团队技术栈的成本:几台配置还算不错的 Kubernetes 节点,以及一个 Postgres 实例。然后,我梳理了从八月底到正式上线期间完成的改动,并去掉了这套配置不需要的工作:To get a rough number, I priced out a classic small team stack: a couple of reasonably sized Kubernetes nodes and a Postgres instance. Then I went through the changes I landed between the end of August and launch day and removed the work that setup wouldn’t need:

  • 与我们的其他内部服务相集成
    Fitting in with our other internal services
  • 与规模化工作交织进行的客户和产品工作
    Client and product work that was intermixed with the scale work
  • 在多个 Pod 上运行
    Running across many pods
  • 精细化速率限制
    Fine-grained rate limiting

大约三分之一的改动被保留了。About a third of the changes were left.

如果把我们的支出缩减到三分之一,并剔除我还在摸索配置时犯下的错误,我会估计像这样为期两周的推广,按相同的标价,价值在 3,000 到 10,000 美元之间(我实际上还没做过,所以这只是个粗略估计)。Scaling our spend down to that third and taking out the mistakes I made while I was still figuring out the setup, I’d put a two week push like this one at $3,000 to $10,000 at the same list price (I haven’t actually run this, so it’s only a rough sense).

以下步骤假设由一名工程师使用 Claude Code、一个预发布环境和一个可观测性服务提供商来完成。协调器和子代理有助于加快进程,但如果你发现它们每小时消耗的 token 太多,改用单个代理也应该能很好地完成任务。如果你想试试:The steps below assume one engineer with Claude Code, a staging environment, and an observability provider. The coordinator and sub-agents helped speed up the process, but if you find they’re burning too many tokens per hour, going back to a single agent should also work quite well. If you want to try it:

  1. 让 Claude 访问你的遥测数据。大多数可观测性服务提供商都有一个 Claude 可以使用的 MCP 服务器。
    Give Claude access to your telemetry. Most observability providers have an MCP server that Claude can use.
  2. 让 Claude 编写一个负载测试脚本,向服务的预发布环境副本施加相当于真实流量十倍的压力,并故意制造故障。可以先从终止一个实例、让数据库陷入停滞,以及在流量激增期间进行部署开始。然后让 Claude 不断修复出现的各种问题。
    Have Claude write a load script that throws ten times your real traffic at the staging copy of the service and breaks things on purpose. Killing an instance, stalling the database, and deploying in the middle of a spike are good places to start. Then let Claude keep fixing whatever falls over.
  3. 选择技术栈时,尽量选择 Claude 最容易衡量的方案。对我们来说,那就是 Rust,并尽可能减少依赖项。
    When you’re picking your stack, lean toward whatever Claude can measure most easily. For us that was Rust and as few dependencies as possible.
  4. 开始之前,写下你最重要的技术不变量,并把它们交给 Claude。
    Before you start, write down your most important technical invariants and give them to Claude.
  5. 对于任何难以撤销的操作,让 Claude 先停下来,给你几个选项,并明确推荐其中一个。
    For anything that’s hard to undo, have Claude stop and give you a few options with a clear recommendation.

衷心感谢 Docs 团队,他们在同样的三周内提交了数千项编辑器修复;也感谢平台和存储团队,他们构建了这一切赖以运行的基础。Huge thanks to the Docs team, who landed thousands of editor fixes in the same three weeks, and to the platform and storage teams who built everything this sits on.

延伸阅读。我们如何在两周内让 claude.ai 快 3 倍(claude.dev)· 每项任务一个任务框架:Claude Code 中的动态工作流(claude.dev),探讨目标偏移。Further reading. How we made claude.ai 3x faster in two weeks (claude.dev) · A harness for every task: dynamic workflows in Claude Code (claude.dev), on goal drift.

值得记下

  1. 第三方平台,例如编程智能体和工作流自动化工具,可以让其终端客户支付 Claude API 的使用费用,而无需共享 API 密钥。
  2. 我们于 9 月 16 日上线。截至 9 月 22 日,用户已创建超过 460 万份文档。在 20 亿次请求中,我们仅遇到 60 次服务器错误,而且从未需要回滚。
  3. 整个 Docs 服务运行在约 50 个内存优化型 Pod 上。
  4. Claude 在多次上下文压缩后仍记住了所有不变条件,我从来不必重复说明。