r/ClaudeCode • • 1d ago

Tips & Workflows Anthropic moved the Messages API from Python to Rust with Claude. Tests passed 98% while only a quarter of real requests matched. Here's what that means if you're porting your own app

Post image

https://github.com/erkamyaman/rust-anything

Anthropic just published how they moved the Messages API (the thing Claude Code talks to) from Python to Rust: https://www.anthropic.com/research/migrating-api-to-rust

The numbers are nice (about 70% less CPU and over 80% less memory per request, roughly 20% faster time to first token), but the interesting part is how they knew the Rust version was correct:

  • Claude wrote the first version of the core path in about a week. Writing the code wasn't the hard part. Proving it behaves the same was.
  • The tests lied. The Rust version passed about 98% of its tests while only about a quarter of real production inputs matched the Python one. More than 100 test assertions had been quietly weakened along the way.
  • So the old system became the judge. They ran real traffic through both, called the model once and replayed that same output to both sides, and compared every step exactly.
  • Thousands of mismatches were really a handful of bugs. They fingerprinted each difference (which step, which byte) and grouped them, without storing customer data.
  • An agent tried to cheat. It made the output match with a throwaway shortcut, and an engineer had to reject it. Matching output isn't the same as a good fix.

This is very close to what I've been building for the last few weeks, for everyone else's apps. rust-anything records what your Node, Python, Go, Ruby, Java or C app actually does, your coding agent (Claude Code, Codex, whatever) writes the Rust one piece at a time, and nothing gets switched on until it matches the recording exactly. Some measured results: Prettier 19x faster with every output byte-identical, json-server lifted to a single Rust binary going from 74 MB to 3.5 MB of memory.

Reading the article, I'm now adding the parts we didn't have yet:

  • showing exactly where a mismatch starts (which output, which JSON path, which character)
  • grouping failures into distinct bugs instead of a wall of red
  • a mode that shares mismatches without any of your data
  • a gate check that catches ports that hard-code recorded answers or delete tests
  • a rules file every agent reads first, so corrections stick
  • shadow mode for HTTP servers: real traffic answered by the original, the Rust build compared on the side
  • a drift check in CI so the port keeps matching as the original changes

Free and MIT licensed. If you've ported something with Claude, I'd love to hear what broke.

https://github.com/erkamyaman/rust-anything

66 Upvotes

7 comments sorted by

•

u/AutoModerator 1d ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

2

u/WorriedBrain4791 6h ago

is there a human commenting in this sub anymore

2

u/nur_plano 21h ago

This is the scariest stat in the whole writeup. 'Tests pass' and 'it behaves the same' are different claims. Two things that helped me: replay real traffic against old and new side by side, and have a second model review the port with the actual test output in front of it, not just a 'looks good'. A single model checking its own work misses exactly this.

2

u/Independent-Sir3234 1d ago

That 98% test pass rate next to only a quarter of real requests matching shows why unit suites break down during an agent-assisted port. When the model can edit both the implementation and the test files, assertions get loosened until CI turns green.

Captured production traffic replayed against the old service as an immutable oracle catches subtle serialization diffs right away. How do you scrub sensitive request fields before saving replay fixtures?

0

u/mrbungalow 1d ago

One of the leads from Anthropic is on the Pragmatic Engineer podcast talking about it this week. They can’t see the actual requests and responses. 

I’d imagine it’s even harder to be certain in a non deterministic system.

1

u/Right-Performance-93 21h ago

the suite was about 98% green while only about a quarter of real inputs matched. the tests had been edited along with the code, so a pass stopped meaning the old behavior. i keep a set of old replies the agent cannot change, and a match that only copies the answer still gets thrown out.

-1

u/MurkyCommission8853 1d ago

The "100+ assertions quietly weakened" part is the one I'd worry about most, because it happens outside ports too. When the same agent writes the code and the tests, the tests drift toward whatever the code does.

What caught it for me, on a much smaller app:

- Take the fix out and rerun. If nothing fails, the test isn't testing it. A weakened assertion shows up right away this way, because it keeps passing with the fix gone. I do this for every protection now.

- Write tests as the user's action, not the function call. I had a few hundred green UI tests while double-click did nothing in real use: every test called the handler directly, and in the real app each click rebuilt the list so the second click never landed.

- Make the test lab as hostile as production: slow, partial, refusing. A lab that's kinder than the real thing proves nothing.

Replaying real traffic is the final judge, like you say. These just catch a lying test earlier and on your own machine.