Context compression orphans advisor_tool_result blocks, causing unrecoverable 400 errors

Resolved 💬 3 comments Opened May 2, 2026 by herrhaase Closed May 5, 2026

Description

After extended sessions with multiple advisor() calls, context compression removes the server_tool_use block while keeping the corresponding advisor_tool_result block. This violates the API's requirement that every tool result has a preceding tool use block, and every subsequent API call fails with:

API Error: 400 {"type":"error","error":{"type":"invalid_request_error",
"message":"messages.7.content.0: unexpected `tool_use_id` found in 
`advisor_tool_result` blocks: srvtoolu_011cbRG78Yy2sdVA3xAWNF4u. 
Each `advisor_tool_result` block must have a corresponding 
`server_tool_use` block before it."}}

Impact

The session becomes completely unrecoverable — no further messages can be sent. Any conversation-only state (plans, decisions, reasoning) is lost. Work written to disk survives but the session itself is dead.

Expected behavior

Context compression should treat server_tool_use and advisor_tool_result blocks as an atomic pair — either both are kept or both are dropped.

Reproduction

Difficult to trigger deterministically. Occurs in long sessions with multiple advisor() calls when the conversation approaches context limits and compression activates. Model: claude-opus-4-6[1m].

Session: 0165UkzS53TbA6tF7nsyqu2h

Workaround

None within the session. Starting a new session is the only option. Users can mitigate data loss by writing plans/decisions to files early rather than keeping them only in conversation context.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗