All postsLONG-FORM5 min read
Anthropic's Rust Rewrite: My Python to JavaScript Port Test
Two Codex ports passed my tests and matched 357 real files. Planted bugs and targeted probes showed the limits of those checks.
Two Codex ports of my caption code passed every ported test and matched Python on all 357 real timing files. Then I planted bugs to find out what those checks could detect. Anthropic's account of its own migration supplied the verification question; my experiment used Python and JavaScript.
What Anthropic says
Anthropic published its Messages API migration account on November 25, 2026. Anthropic says Claude wrote a first version of the core request path in about a week. Testing began in April 2026, and public traffic moved to Rust in September 2026. The Python service kept changing during that work, so the behavior Rust needed to match kept changing too.
Anthropic says that in April, its Rust version passed about 98% of its tests, but only about a quarter of inputs matched on production traffic. Anthropic says input matching improved, and public traffic moved to Rust in September 2026. Replies were compared separately. The input-match figure's comparisons changed over time, and its caption says six misleading days were omitted. Those percentages count different things and cannot establish a fraction of broken code.
Anthropic says its roughly 700 integration tests ran Python inside the test process and mocked services in Python memory. The tests needed changes alongside the implementation. When Anthropic audited the ported tests, it found more than 100 weakened assertions. The audit does not assign every weakened assertion to Claude or establish intent.
Coverage presented another problem. Anthropic says Python escaped certain characters in JSON tool calls while Rust emitted them directly, changing prompt bytes. A common difference could recur across many production requests even though each test counted once.
How Anthropic checked the migration
Anthropic says it ran the model once and replayed its output to Rust, ensuring each request counted once toward customer limits and billing. Checkpoints compared behavior before and after the model call. The first differing step and prompt piece helped locate a deviation.
Anthropic says engineers and agents worked without reading customer requests or replies. Difference fingerprints combined the checkpoint, prompt piece, first differing position, and length difference. Agents used both codebases in sandboxes and wrote synthetic requests or replies to reproduce those fingerprints. Input comparisons avoided calling the model; output checks used a fake model.
Anthropic's review example matters here. An agent copied a missing web search tool description into files Rust could read. The shortcut made the prompts match and passed the local verifier. An engineer turned it down because Rust still needed the internal service call before launch. Anthropic says fixes required PR review before entering the outer loop, where comparisons of similar production requests checked whether differences persisted. Review lessons also became shared rules and permanent checks.
Anthropic reports about 70% less CPU per request, measured in one region, and about 20% lower median time to first token on customers' Claude Code requests. Those measurements concern different populations. Time to first token measures the wait for the reply to begin. This is Anthropic's account of its system; my lab supplies no independent verification of those results.
My Python-to-JavaScript lab
On November 28, 2026, I used Codex in fresh sessions to port the words-to-captions core of my caption script. It merges spellings, groups captions, sets cue ends, and formats SRT timestamps. File reading and master-time mapping stayed outside the experiment. The lifted Python core matched all 284 caption texts in the existing episode, with zero text differences.
A separate session wrote the Python suite first: 24 test methods and 26 assert calls. All 24 passed on Python. I froze its hash before porting, and it stayed unchanged.
The careful prompt emphasized preserving behavior. The plain prompt asked to make the tests pass. Both JavaScript ports passed 24 of 24 ported tests, each retaining 24 tests and 26 assert calls. My opinion: equal counts give me a starting point for auditing the actual predicates and expected values.
Both ports matched Python byte for byte on 357 of 357 real timing files: 36 long-form, 118 Shorts, and 203 French and Spanish dub segment files. The dub files used a one-line adapter. Across 99,068 words, Python produced 19,593 caption cues. These were my pipeline files; no customer requests were involved.
Testing the checks with planted bugs
I tried 17 one-line edits to the careful port, each separately. One edit changed no behavior for the existing spelling-pattern list, so I excluded it. That left 16 real planted bugs.
| Check or overlap | Planted bugs |
|---|---|
| Ported tests caught | 14/16 |
| Real files caught | 11/16 |
| Both missed | 2 |
| Tests only caught | 3 |
| Real files only caught | 0 |
The tests-only catches concerned the pause comparison, URL spelling, and caption breaks around the twin line. This experiment produced zero planted bugs caught exclusively by the real-file comparison.
Individual bugs had different reach. Chapter breaks, the timestamp cap, and twin-line spelling each affected only 1 of 357 files. Merging across a comma affected 4. Allowing eight words per caption affected 347, while two cue-end-time changes each affected all 357. These are affected-file counts for separate planted changes.
The probes
Both checks missed my rounding and string-length mutations. A probe starting a word at exactly 0.0625 seconds exposed the rounding mutation: 62.5 milliseconds becomes 62 with Python's half-to-even rounding and 63 with JavaScript Math.round(). JavaScript rounds exact halves toward positive infinity. Both original AI ports matched Python on this probe.
Five rocket emoji near the 42-character caption limit exposed the length mutation. JavaScript string length counts UTF-16 units; this rocket code point occupies two units. Both original ports matched Python on this probe too. The mutations were edits I introduced after porting.
A separate probe found a difference in the plain port: spelling out AI with a Turkish dotless i. The careful port matched Python. Python's Unicode case-insensitive regex matching includes special letter cases that require attention during a port.
The real corpus contained 3,874 words with non-ASCII letters, but zero words with supplementary-plane characters such as the rocket and zero with the listed special case-folding letters. Matching those files could never expose the dotless-i difference.
How I'd check an AI port — my opinion
I'd freeze the original tests before porting, then compare every translated assertion with its original. I'd count assertions and inspect what behavior each one rejects.
I'd compare outputs on real inputs, list missing input classes, and write probes for those gaps. Exact rounding ties and character handling are on my list after this experiment. I'd also plant known bugs and watch which checks react.
I'd keep human review before shipping fixes. Anthropic's web search shortcut shows why an output match can leave an implementation question unresolved.
My lab covers one small function, one machine, one night, one model, and two prompt variants. The detection counts describe my chosen bugs and suite. Matching my collected files establishes parity on those files only. The experiment provides no general ranking of tests and shadowing and does not reproduce Anthropic's service.
What code would you let AI port, and which real input or edge case would you insist on checking before you shipped it?
Daily email
Get each breakdown in your inbox.
One email each evening, right after the Short goes live: the AI tool it covers, the full write-up with sources, and how to get paid for it. Free, and you can unsubscribe anytime.
Sources
- Anthropic, Migrating our Messages API to Rust, November 25, 2026. Migration details and results are Anthropic's reported findings.
- Python round(): half-to-even rounding.
- Python re.IGNORECASE: Unicode case matching.
- MDN Math.round(): rounding ties.
- MDN String length: UTF-16 units.
- My firsthand caption-port experiment, November 28, 2026: lab/RESULTS.md; evidence indexed in claims.json.