Orphaned advisor_tool_result after auto-compaction breaks session with API 400 (still on v2.1.207)
Version: 2.1.207 | Platform: macOS (Darwin 25.5.0) | Model: claude-fable-5
Error:
API Error: 400 messages.7.content.0: unexpected `tool_use_id` found in
`advisor_tool_result` blocks: srvtoolu_018awTYbWiUkYfU33GaHebqQ. Each
`advisor_tool_result` block must have a corresponding `server_tool_use`
block before it.
Repro pattern: Long session with advisor tool enabled. Advisor is called at some point, session continues until auto-compaction fires. After compaction, every subsequent request fails with the 400 above. The compactor drops the server_tool_use block for a prior advisor call but retains its advisor_tool_result, leaving an orphan that violates the API pairing contract.
Frequency: Recurring across multiple sessions, reliably correlated with auto-compaction after advisor use. Not a one-off.
Impact: Session is unrecoverable in place; requires /rewind to a pre-corruption checkpoint or /clear, losing working context mid-task.
Related: #56515 (closed as duplicate with no linked fix), #62885, #53594. Filing because this still reproduces on 2.1.207, well past the v2.1.156 threshold mentioned in the error reference docs.
Expected: Compaction should either preserve server_tool_use/advisor_tool_result pairs atomically or drop both.