Same reply, different turn
“I’ll check the forecast,” said my fake reply. It had a tool call for Montréal, too. I’d picked a small job for a streaming adapter: read the reply, call a function, and carry the result into the next request. I could see the words and the city in the assembled message. I couldn’t tell from that whether the function had run.
I borrowed the replay idea from Anthropic’s account of porting its Messages API to Rust. In April the port passed about 98 percent of its tests, but only about a quarter of the compared inputs matched on production traffic. To compare how the two versions handled replies, Anthropic ran the model once and replayed its output to Rust. That way a different answer from the model wouldn’t look like a bug in the new code. My reply was made up, so I could change it one piece at a time.
My first check watched for the event that closes a tool block. Splitting the city argument across more events did nothing to what the watcher saw. Moving the close ahead of the last piece did: the watcher saw {} even though the assembled reply still had Montréal. With the close missing altogether, the watcher saw nothing to hand off. Then I tried the early and missing closes with the Python SDK’s synchronous beta streaming runner, version 0.125.0. The runner waited for the stream to drain. It called the function with Montréal in both cases and sent the same follow-up body as in the intact run. I’d been watching an event the runner didn’t use as its cue to call the tool.
Then I cut off the final message_stop but left the arguments and the tool_use stop reason. I served that short reply twice from localhost over HTTP/1.1. When the length in the header matched the short body, the function ran and the server got the same follow-up body as with the full stream. When I left the original, longer length in the header, the connection closed at the same byte, but HTTPX was still expecting more. It raised RemoteProtocolError; the function never ran, and the server never received a second POST. A replay that sets the body length to the size of the recording would turn that interrupted response into a complete HTTP body.
Watching the next POST caught a different mistake in my test adapter. I gave it two good calls, for Montréal and Québec, and supplied the made-up forecast for Québec first. The adapter kept both call IDs but gave each city the other city’s forecast because it joined the lists by position. Joining by tool_use_id kept the forecasts with their calls in both orders.
I’d keep the interrupted response in a rewrite test, along with the complete short one that has the same event bytes. I’d check the argument at the function and the value under each call ID in the next request. And I’d leave Québec going first. When I supplied Montréal’s forecast first, even the positional join passed.
The event replay and the loopback replay are both runnable with Python. Save them next to each other without renaming them; the loopback test loads the event fixtures from its sibling. Neither calls a model or a weather service.
python -m pip install anthropic==0.125.0 httpx==0.28.1 httpcore==1.0.9 h11==0.16.0
python -E stream-reply-replay.py.txt
python -E stream-http-framing.py.txt
Comments