Wink Pings

98% tests passed, but real traffic only matched a quarter: How Anthropic closed the gap in its Rust migration

Anthropic had Claude agents migrate the Messages API from Python to Rust, cutting CPU per request by about 70%. The first version was written in a week; validation was harder: the old API became the test for the new API. 98% of tests passed, but on real traffic only about a quarter of inputs matched.

Anthropic had Claude agents migrate the Messages API from Python to Rust. According to rari's breakdown of the paper on X, CPU per request dropped by about 70%. Claude took about a week to write the first version. The harder part came later: proving it could really replace the old implementation.

This tweet breaks the migration method into six steps, called shadow migration. The core idea is not complicated: the old API is the test for the new API.

1. The old API is the test
The Rust API passed about 98% of tests. On real traffic, only about a quarter of inputs matched. Green tests said the rewrite was done; real traffic said a quarter. That's the gap.

2. Run the model only once
Claude's replies vary, so the model is run only once. The same reply is replayed separately against Python and Rust, then outputs are compared. This rules out model sampling differences and tests only implementation differences.

3. Fingerprint every diff
Each diff records the step, fragment, first differing byte, and lengths on both sides. It does not record text. One bug leaves one fingerprint. This lets similar issues be aggregated without humans scanning logs.

4. One bug type, one agent
A script groups diffs every 10 to 30 minutes. A coordinator agent assigns each new type to a corresponding worker agent. The bug-fixing agent does not need to understand the whole migration; it only handles one fingerprint.

5. Fast loop first, then real traffic
In the sandbox, checking one input takes less than a second. Fixes are reviewed, merged, and then real traffic confirms the fingerprint disappears. The fast loop handles convergence; real traffic exposes inputs the tests didn't cover.

6. Corrections become rules
An agent turned about 60 review comments into CLAUDE.md rules. One of those rules then found seven places where guesses had been made during porting. The rules stay in the repo and can be used for the next migration.

Result: CPU dropped by about 70%. Test pass rate was 98%, and real traffic covered a quarter. The old API checks the new API, closing the gap. rari packaged the six steps into a prompt and said you can drop it into Claude Code to run the next migration the same way.

The most underrated cost in a migration is validation. Writing the code takes a week; proving it isn't broken takes longer. Test pass is not completion; real-traffic coverage is. Use the old system as an oracle, diff fingerprints as clues, and review comments as a source of rules. This method is not only for Python to Rust.

rari also cited his own long article on harnesses, loops, and graphs. The key line: when an agent fails, don't just change the prompt; first look at the space it works in, the retry loop, and how steps are routed. That also holds for this migration. Passing tests does not equal task completion.

Original tweet: https://x.com/0xwhrrari/status/2125646473849131152

发布时间: 2026-11-26 02:28