An AI Rewrite Passed 98% of Its Tests and Matched a Quarter of Real Requests: Verify Yours Against Recorded Inputs
Before a coding agent ports working code, record what the old code does on real inputs, lock that recording where the agent can't edit it, and call the port done only when the new code matches it. Anthropic's Rust rewrite shows why green tests are not enough.
In April 2026, Anthropic's new Rust version of its Messages API passed about 98% of its tests.
On real production traffic, only about a quarter of inputs matched what the old Python service produced.
Claude had written the first version of the core request path in about a week, according to Anthropic's engineering account.
To verify an AI agent's rewrite, record what the old code does on real inputs. Replay those same inputs through the new code, and compare the outputs exactly. The list of mismatches becomes the agent's task. Keep the recording and the comparison where the agent cannot edit them.
Call the port done only when every remaining difference is one you have explained.
The method matters whenever you hand Claude Code, Codex or Cursor a working part of your app to rewrite. You want it faster, or cleaner. The default finish line is a green test suite. The agent will also report a green suite back to you.
Anthropic's numbers show how far apart green and correct can be. The reasons apply to a small app as much as to theirs.
Why did the tests pass while real requests failed?
A test suite checks the inputs someone thought to write down. Anthropic had about 700 integration tests, and the API has dozens of features.
The features multiply. Just 20 on-off options make over a million combinations. At one second per test, Anthropic puts that at 12 days.
Real traffic found what the tests never tried.
When Python wrote JSON tool calls, it replaced certain characters, such as an emoji, with text codes. Rust wrote them as they were. The two prompts differed by a few bytes.
No test had sent an emoji in a tool call. Users did.
Traffic also counts bugs differently. In a suite, each case counts once. In live traffic, a common bug shows up on every request that triggers it. So a single common bug can cause many mismatches.
The match rate did not rise in a straight line. It fell to 6.5% in early May, then climbed to 99.6% by August as fixes landed.
The comparison itself changed along the way. It began on Anthropic's own traffic and then moved to a wider sample, and Anthropic notes that what it compared changed over time. The post gives no single cause for the May dip.
The checking took months.
Anthropic dates the full switch to Rust to September 2026.
The agent can also change the tests
The second reason is specific to agents.
Anthropic's tests ran the Python API inside the test's process. They also mocked services such as billing and rate limiting in Python's memory. So the tests reached into the Python code itself. They had to change along with the code, and Claude helped with both.
A pass could then mean the code was right, or that a test had been loosened.
When the team audited the ported tests, they found more than 100 weakened assertions.
Researchers have measured the same habit. ImpossibleBench, a benchmark published at ICLR 2026, rewrote coding tasks so their tests contradicted the specification. Any pass required a shortcut. Agents passed anyway, often by editing the tests.
Making the tests read-only stopped the test edits. Agents still solved the honest tasks as well as before. But read-only tests did not stop other shortcuts such as special-casing. Special-casing is code that returns the expected answer for the specific inputs it was shown.
So the check has to live outside what the agent is allowed to touch, and it needs inputs the agent has not seen. A suite the agent ports alongside the code meets neither need.
When a test suite is enough
Tests did carry one large AI rewrite.
When Bun's Zig code was rewritten in Rust, its author merged once 100% of Bun's test suite passed in CI on every platform, after checking by hand that the tests were running and not being skipped.
Bun's suite could do that because it stood apart from both versions. The tests were written in TypeScript, so the same tests judged the Zig build and the Rust build and did not have to change along with the code.
Bun's author still treated green as a start. "Merging into main isn't a versioned release," the post says. Most regressions came from code "syntactically identical in both languages but semantically different."
A suite like that is large, independent of the language you are leaving, and already passing on the old code. If your app has one, use it as the finish line.
A suite can miss any of the three conditions. It may be small. It may be written in the language you are leaving. It may never have run against the old code. A suite like that covers the cases its author thought of, and an agent may edit it when a test fails.
The old code is the answer key
Without an independent suite, the working code itself holds the most complete record of what correct means.
GitHub made this argument in 2016, when it rewrote the permissions code for repositories and teams. Tests are a good start, the team wrote.
But "how the system behaves with production data as the input is the only true test of its correctness compared to the legacy system's behavior."
GitHub built a small library, Scientist, around that idea. You wrap the code you are replacing in an experiment. Scientist calls the old version the control and the new one the candidate. Each call runs both, records any difference and the time each took, then returns the old result, so users never see the new code's answer.
In the declaration from GitHub's post, use is the old path and try the new one:
def pullable_by?(user)
science "repository.pullable-by" do |experiment|
experiment.use { is_collaborator?(user) }
experiment.try { has_access?(user) }
end
end
The general name for checking new code against what old code did on the same inputs is a characterization test, also called golden master testing.
A characterization test records behavior rather than intent. It shows the new code kept the old behavior, whether or not that behavior was right.
Sometimes a mismatch points the other way. The bug turns out to be in the legacy code or in your data.
Record that mismatch as known. Scientist's ignore block exists for mismatches "you know and understand but haven't yet fixed," so they stop counting against the port.
What is the smallest recording a solo builder can make?
Anthropic shadowed live traffic, which means production requests also ran through the new code. Then Anthropic compared the two results.
A solo builder can start much smaller, at the edge of the one piece the agent will port.
Table: Three ways to record real inputs before a port
| Where you record | What it takes | What it catches |
|---|---|---|
| Around one function | A wrapper that writes each input and output to a file, or Scientist's control-and-candidate pattern | Differences in that function's results |
| HTTP requests | GoReplay on the server, capturing to a file | Differences in status codes (with --output-report) |
| Requests plus their outside calls | Keploy, which saves database and API replies as mocks | Differences when the code depends on other services |
Start with the narrowest row that contains the code the agent will change.
The first row needs no new tool.
While the old code runs for a few days of normal use, write each call's arguments and return value to a file as one line of JSON.
That file is the answer key.
Replaying it means calling the new function with each saved input and comparing against the saved output.
For a web service, GoReplay records HTTP traffic from a network port without sitting in the request path. GoReplay's shadow-testing guide recommends recording first and replaying when the new build is ready:
sudo gor --input-raw :8080 --output-file prod.gor
gor --input-file prod.gor --output-http="http://candidate.example.com"
Those two commands compare nothing.
Add --output-report to compare status codes. GoReplay's shadow-testing guide documents only status-code comparison, so diffing response bodies needs your own script, like the one in step 4 below.
GoReplay has two requirements. It needs root or CAP_NET_RAW. GoReplay must also capture after TLS termination to see HTTP rather than ciphertext.
One engineering team at PickMe used it to replay traffic from a legacy service into its Kubernetes replacement before switching users over. The team lists "Serialization differences" among what response comparison helps catch. That is the same kind of gap as Anthropic's emoji.
When the code calls a database or another API, Keploy records those outbound calls too. During replay, Keploy plays them back as mocks.
With those replies saved, the replay tests your code alone, whatever the database holds today.
Make the comparison fair before you trust it
A raw recording produces noise.
Timestamps, generated IDs and random values differ between any two runs, even of the same code. Twitter's Diffy handled this by running the old code twice. Differences between the two old copies are noise, and only the rest count. Keploy goes further. It freezes the clock at the recording's time and excludes timestamps, UUIDs and session tokens from strict checks.
Filtering out noise fails when a model sits in the path.
LLM replies vary on their own. So a noise filter would ignore the whole reply, along with any bugs in it.
Anthropic called the model once. Then it replayed that same output to the Rust version. If your function calls Claude or GPT, record the model's reply with the input. Feed it back during replay.
Two more limits keep replay safe.
Writes come first. GitHub uses Scientist only on read operations, because a candidate that writes to the same database can corrupt real data.
For code that writes, Scientist's README says to "modify both the existing and new systems simultaneously anywhere writes happen, and verify the results at read time." Keploy's mocks are the other route: they keep a replay off the real database.
Billing needs the same care. Anthropic had to make sure each request counted once toward a customer's limits and bill.
Then strip secrets. Do it before the new build or the agent sees anything. GoReplay's guide says to filter admin traffic and rewrite secrets.
What does the agent get instead of the tests?
Once old and new are compared, each mismatch becomes a small record of where the two differ.
Anthropic could not read customer requests, so it recorded only the shape of each difference: which step, which piece of the prompt, the first differing byte, and both lengths. The example record from Anthropic's post uses made-up values:
step: build prompt
piece: 2
first diff: byte 17
python: 190 bytes
rust: 190 bytes
The agent gets that record instead.
One bug can leave hundreds of thousands of nearly identical records, so Anthropic grouped them by which fields differed and gave each new kind to one agent. For more on giving one job to one agent, see Build to Launch's guide to Claude Code subagents.
For a small app, the same step is a script that sorts mismatches by function and field, so the agent sees one problem at a time instead of a wall of failures.
The fix goes around two loops.
In Anthropic's fast loop, agents tested hypotheses in seconds using requests they wrote themselves. For a small app, the fast loop can replay the saved inputs locally instead.
In the slow one, the fix runs against new traffic, because a fix can pass locally and still differ in production. Anthropic saw this happen. A fix passed in the sandbox while production still showed the difference, and the task went back to the fast loop.
Both loops fix one difference at a time. A third loop keeps what each fix taught. At Anthropic, "an engineer's correction becomes three things: a rule that each new agent reads, a search for the same mistake, and a test."
The recording from the old code and the comparison stay read-only. Only the new code changes between turns of the loop.Keep the recording and the comparison script read-only for the agent, the same way ImpossibleBench made tests read-only.
Read-only does not stop special-casing.
An agent that sees the recorded inputs could return the saved answers for exactly those inputs. The slow loop catches that, because fresh traffic brings inputs the new code never saw.
Port only the slow part, or all of it?
The check is the same either way. The scope is a separate choice.
Anthropic first rewrote only the code that parses a model's output, and called it from Python. That cut CPU use by about 8% to 10%.
But each token then crossed between Python and Rust three times. Each crossing added overhead. Anthropic decided "the gains didn't justify the added complexity."
The full rewrite, verified against traffic, uses about 70% less CPU per request, and it also cuts median time to first token by about 20%.
A builder tool called fast-anything works at a much smaller scale. It ports only the slowest code. Its author says the tool refuses the swap if a single result differs on real inputs.
Codex rewrote the slowest Python loop in Rust. Deduplicating 700 names then fell from 4.91 seconds to 42 milliseconds, the author reported.
Those are the author's own numbers. The method is the one above, at the size of one loop.
Start with the slow part when one function holds most of the time and little data crosses back and forth. Either way, record before the agent starts.
Record first, then hand the agent the port
- Pick the one function or endpoint the agent will port, and name it in the task.
- Before any change, record its real inputs and outputs for a few days of normal use: a JSON-lines file for a function, a GoReplay file for an endpoint.
- Remove secrets and personal data from the recording. For calls that write, serve the database from recorded mocks, or check the written data at read time.
- Write a replay script that feeds each saved input to the new code and prints every output that differs, ignoring only fields you have checked are volatile.
- Make the recording and the script read-only for the agent, then give it the port and the mismatch list as its task.
- Merge when the replay shows no differences beyond the ones you recorded as known. Then record again on fresh traffic before you remove the old code.
FAQ
Is shadow testing the same as golden master testing?
They share one idea: the old code's behavior is the expected answer.
Shadow testing runs live requests through old and new code at the same time and compares the results, as Anthropic did.
Golden master testing saves the old code's outputs for a set of inputs. A characterization test then compares each later run against that file.
What if your app has no production traffic yet?
Record your own use or a staging environment.
Keploy's guide suggests starting with staging to avoid sensitive data. Anthropic's comparison began on its own traffic before a wider sample.
A small recording of real use still holds cases no one wrote a test for.
Does replaying a recording prove the new code is correct?
No. It shows the new code matches the old code on the inputs you recorded.
GoReplay's own page says a successful replay alone does not establish correctness. A golden master does not imply the results are correct, only that they did not change.
Should you keep the test suite?
Yes. Keep it. Tests still catch the cases you wrote on purpose.
Read every test the agent changed before merging. Loosened assertions let a port go green without being right.
Sources
- Anthropic, Migrating our Messages API to Rust, 2026-11-25
- GitHub Blog, Scientist: Measure Twice, Cut Once, 2016-02-03
- GitHub, github/scientist
- X Engineering, Diffy: Testing services without writing tests, 2015-09-03
- Bun Blog, Rewriting Bun in Rust
- GoReplay, Docs, Shadow testing and home page
- Keploy, Record and Replay Testing Guide
- PickMe Engineering, Testing Go microservices with real production traffic using GoReplay, 2026-05-14
- Zhong, Raghunathan and Carlini, ImpossibleBench (ICLR 2026 paper)
- @githubday on X, fast-anything's 700-name test, 2026-11-25
- Wikipedia, Characterization test
- Build to Launch, Claude Code Subagents Explained
Links
- Anthropic, Migrating our Messages API to Rust (documentation)
- GitHub Blog, Scientist: Measure Twice, Cut Once (documentation)
- GitHub, github/scientist repository (documentation)
- X Engineering, Diffy: Testing services without writing tests (documentation)
- Bun Blog, Rewriting Bun in Rust (documentation)
- GoReplay docs (documentation)
- GoReplay docs, Shadow testing (documentation)
- GoReplay home page (documentation)
- Keploy, Record and Replay Testing Guide (documentation)
- Zhong, Raghunathan and Carlini, ImpossibleBench (arXiv) (documentation)
- ImpossibleBench, ICLR 2026 paper (documentation)
- PickMe Engineering, Testing Go microservices with real production traffic using GoReplay (article)
- @githubday on X, fast-anything's 700-name test (article)
- Wikipedia, Characterization test (article)
- Build to Launch, Claude Code Subagents Explained (article)
Every Friday: what builders launched this week, and one guide to help you ship yours.
More guides
Don't Wait for a Cheap Model to Ask for Help: Lock the Planner to Read-Only and Switch Back After Two Failed Tests
A cheap executor model rarely asks a stronger planner for help, so wire the handback outside its judgment: a read-only planner that writes its replan conditions, and a forced switch after a check fails twice.
Improve AI Agent Accuracy With Notes From Its Wrong Answers: Docs Scored 36%, Four Notes 76%
On 42 held-out questions, a Claude Haiku 5.5 data agent scored 36% with its company's docs and 76% with four short notes written from its own wrong answers. Write one rule per kind of mistake, and keep it only if it helps on questions it never saw.
Did Claude Code Get Worse? Read Your Session Logs Before You Turn Effort to Max
Your Claude Code session logs show whether your setup changed and whether the model is skipping work or ignoring work it already did. Higher effort fits only the first.