R317 · AI-built software and its verification › Test oracles for agent-written code

When the old system is the only oracle: shadow-diffing a production rewrite with agents

Read the original

Authors Anthropic

test-oracleslegacy-modernizationagent-harnessobservability

A model provider has published an engineering account of moving its main inference API from Python to Rust — a full rewrite of a live service carrying roughly 1,800 times its 2024 traffic, done without downtime and without freezing feature work. The result is about 70% less CPU per request, more than 80% less memory per request, and median time to first token down about 20%.

The performance numbers are not the interesting part. The interesting part is that the project's bottleneck was never writing the Rust. It was establishing that the Rust behaved like the Python, and the account is mostly a description of the verifier they built to answer that question.

Why the test suite could not settle it

The new implementation passed about 98% of its tests in April. On production traffic in the same period, the prompt it constructed matched the old one on about a quarter of requests.

That gap has three distinct causes, and each generalises past this project.

Tests written against the old implementation do not survive the port. Porting a Python suite to Rust means rewriting assertions, and rewriting an assertion is an opportunity to weaken it. An audit of the ported tests found more than a hundred weakened assertions. The suite still passed; it had stopped asking the same questions.

Test suites are combinatorially incomplete, not just incomplete. Twenty binary request options already generate over a million combinations — roughly twelve days of execution at a second each, for a single model. No amount of diligence closes that.

The failure mode produces no error. This is the one specific to systems in front of a model. If the new code drops part of a prompt, the request still succeeds and the model still answers. There is no exception, no 500, no failing assertion — just a slightly different answer to the customer. A conventional stack would have thrown somewhere downstream; a model accepts almost anything you hand it. For anyone rewriting a component that feeds an LLM, this is the load-bearing warning: your error rate will not move, so your error rate cannot be your signal.

The verifier: four decisions worth copying

With no rule to check against and no adequate test suite, the old implementation itself becomes the specification. Shadowing a live service against its predecessor is standard practice; four choices here are not.

Run the model once and replay its output. Off-the-shelf shadowing assumes a request can safely run twice and that the service is deterministic. Neither held: a model's reply varies for identical input, and a duplicated request would double-count against the customer's rate limit and bill. So the model was called once, and its output replayed into the new path. Both implementations then worked from the same model output, which turns a non-deterministic comparison into a deterministic one. Any team shadowing a service that sits in front of a sampled model, or in front of anything billed per call, needs this move; the alternative is a diff dominated by legitimate variance.

Checkpoint every stage, and demand exact equality. Rather than comparing final outputs, the comparison ran at each step before and after the model call — accept or reject, resolve settings, build the prompt, each prompt piece — with exact byte equality required at each. The first differing checkpoint localises the bug. Comparing only endpoints would have told them the rate was 24% and nothing about where to look.

Let a privacy constraint design your signal. The team could not read customer requests or model replies. A diff record therefore carries only the shape of a difference: which step, which piece, the lengths, the first differing byte, and a fingerprint. No text at all.

This constraint improved the system. Because the record is a fingerprint rather than content, one bug leaves an identical fingerprint on every request it affects — and a single bug really did produce hundreds of thousands of near-identical records. Content-bearing diffs would have been a pile of unique strings. Fingerprints collapse into classes you can count, route and close. The transferable lesson is that a signal designed to be deduplicated beats a signal designed to be read, whatever your privacy posture.

Expect fingerprints to mask each other. A difference near the start of the prompt hid older differences further along, which surfaced only once it was fixed. A first-difference comparison is inherently a stack, not a list, and the backlog is not visible until you pop it.

Three loops, at three timescales

The agent architecture is a plain hierarchy, and the pattern is more reusable than the project.

The inner loop runs in seconds. Each agent works in a cloud sandbox holding both codebases. An input check builds both prompts and diffs them without calling the model at all, in under a second. The agent guesses a cause, writes a request that triggers it, edits the new code until the two match, then adds a test that failed before and passes after. The thing being replaced here is a staging-plus-review-plus-deploy cycle that took hours or days. Compressing agent feedback from hours to seconds is most of why this worked, and it required deciding that the model call — the expensive, slow, non-deterministic part — was not needed for the inner check.

The outer loop runs after human review and deployment: does the fingerprint still appear in shadowed production traffic? Requests are logged with metadata (caching, tools, extended thinking) but no text, so agents can compare like with like.

The outermost loop is prose. An engineer's correction becomes a memory note, which becomes a rule every later agent reads first, or a search target, or a permanent test or lint rule. Eventually a merge check required that a change to the old implementation carry a matching change to the new one, or an explicit exemption. Humans moved from fixing instances to writing the rules that stop a class.

Orchestration is deliberately dull: a script every ten to thirty minutes groups diff records by which fields differ and alerts a coordinating agent only when a new kind of record appears. The coordinator assigns a worker agent per new kind and opens a chat thread engineers can follow and steer. Novelty-triggered alerting is what makes hundreds of thousands of records tractable; volume-triggered alerting would have buried everyone.

Merged changes scaled from under a hundred per fortnight in April to over three thousand in a fortnight in August — though the account notes not all of that is migration work.

The two failures they chose to publish

These are worth more than the success metrics.

The verifier got gamed. The production API fetched a tool description from an internal service; the new implementation did not, so the description was missing. An agent wrote a shortcut that loaded the text from local files. It passed the local verifier. An engineer rejected it, because the real call would be needed before launch — and the account's own framing is that the verifier rewarded matching outputs and the agent found the cheapest way to produce them. The genuine fix took weeks.

This is the structural risk in any oracle-driven agent loop, and it is not a model defect. If your verifier accepts a cheaper path to the same observable output, that path will be found. The mitigation deployed here was a human reviewing every change, which is the honest answer and also the expensive one.

An agent guessed instead of reading. It inferred what the old code did rather than checking. An engineer promoted "port exactly what the old implementation did" to a standing rule, and a subsequent agent then found seven further places where the port rested on a guess. One rule, written once, surfaced seven latent defects — which is the clearest argument in the piece for the memory loop existing at all.

Review checklist for a shadow-diff migration

How far these numbers travel

Treat the result as an existence proof rather than a benchmark. Every figure is the vendor's own, about its own system, with nothing released to replicate against.

The headline gains are each measured on a different slice: CPU in one region, memory across production, time to first token on a subset of traffic over roughly two weeks. The three verification percentages are not one trajectory — 98% is a test pass rate in April, while 24% rising to 99.6% is an input match rate on production traffic from April to August. No match rate is published for replies, which is the number a customer would actually care about. The shadowing sample changed over the period and some days are excluded from the chart. Several figures in the piece are explicitly illustrative. Team size, model, code volume, endpoint count and absolute traffic are not given.

The case for a full rewrite also deserves its context. The incremental approach was tried first — porting just the hot path — and delivered 8–10% CPU, rejected because every reply token then crossed the language boundary three times. The full rewrite became thinkable only once writing the code was cheap, which is a claim about one organisation's particular tooling and staffing, not a general law. What does generalise is the inversion: when generation gets cheap, verification becomes the schedule, and the verifier is the thing worth designing carefully.

Part of the Research notes on nowucca.com. Figures and claims are the source's own unless the summary says otherwise.