Orphaned web_search server_tool_use in history causes permanent 400 (session unrecoverable)
Summary
A session's history ends up with a server-side web_search tool use that has no matching web_search_tool_result. From then on, every request to Anthropic fails with 400, and the session cannot continue. It happened early in the session (messages.5), so there was nothing to compact, and clearing the session was the only way out.
Error
Anthropic API error (400 Bad Request): {"type":"error","error":{"type":"invalid_request_error","message":"messages.5: `web_search` tool use with id `srvtoolu_017Bq7tKmKKZJbMjWQucjurZ` was found without a corresponding `web_search_tool_result` block"}}
Context
- Long-running swarm session on the Anthropic provider, with provider-native web search (likely related to #1620).
- Probably caused by an interrupted turn, or one cut mid-stream, that contained a
server_tool_use.
Expected
When history is saved, loaded or compacted, an orphaned server_tool_use is either dropped or paired with an error result, so the session recovers on its own.
Environment
- jcode v0.90.0 (a7f005e8c), installed from the stable channel (
~/.jcode/builds/versions/0.90.0) - macOS 26.6.2, arm64
- Provider: Anthropic, with provider-native
web_searchenabled - Session: a swarm lane in a multi-session swarm (several sessions on one shared jcode server);
agents.swarm_model = "claude-sonnet-5"
I’ve started tracing this against current master. The reported failure lines up with the new provider-native web search path: normal ContentBlock::ToolUse entries go through the existing dangling-tool repair, but Anthropic server_tool_use / web_search_tool_result blocks are stored as ProviderNative and replayed separately. A replay containing the server tool block without its matching result can therefore reach Anthropic unchanged and trigger the 400 in #1638.
I’m narrowing this to a focused regression at the Anthropic message-formatting boundary so interrupted native-search history can recover without breaking valid pause_turn resume behavior.