claude-code - 💡(How to fix) Fix Context compression orphans advisor_tool_result blocks, causing unrecoverable 400 errors [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
anthropics/claude-code#55535Fetched 2026-05-03 04:50:54
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Author
Timeline (top)
labeled ×2commented ×1

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."}}

Error Message

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."}}

Root Cause

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."}}

Fix Action

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.

Code Example

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."}}
RAW_BUFFERClick to expand / collapse

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.

extent analysis

TL;DR

Modify the context compression logic to treat server_tool_use and advisor_tool_result blocks as an atomic pair, ensuring both are kept or dropped together.

Guidance

  • Review the context compression algorithm to identify why server_tool_use blocks are being removed while corresponding advisor_tool_result blocks are retained.
  • Verify that the compression logic correctly handles the atomic pair requirement for these blocks.
  • Consider implementing a check to ensure that every advisor_tool_result block has a preceding server_tool_use block before allowing the session to proceed.
  • Investigate the session data for 0165UkzS53TbA6tF7nsyqu2h to understand the specific circumstances leading to this issue.

Example

No code snippet can be provided without more information on the implementation details of the context compression logic.

Notes

The provided information suggests that the issue is related to the context compression algorithm, but the exact implementation details are not available. Therefore, the suggested fix is high-level and may require further investigation to implement correctly.

Recommendation

Apply a workaround by modifying the context compression logic to treat server_tool_use and advisor_tool_result blocks as an atomic pair, as this is the most direct way to address the issue and prevent session failures.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

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.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

claude-code - 💡(How to fix) Fix Context compression orphans advisor_tool_result blocks, causing unrecoverable 400 errors [1 comments, 2 participants]