You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Session compaction produces orphaned tool_use blocks in long tool-heavy sessions (400 from Anthropic) #17065
Description
After a compaction event in a long tool-heavy session, OpenCode constructs a message history where a tool_use block exists without a corresponding tool_result block. Anthropic's API then rejects every subsequent message with a 400:
tool_use ids were found without tool_result blocks
The session becomes unrecoverable — all further messages fail until the session is abandoned.
Root cause (investigated): compaction drops tool_result blocks while retaining their paired tool_use blocks. Confirmed by isolating variables — hai-proxy (used as a local proxy) is a transparent passthrough that forwards Anthropic's 400 verbatim. The stage-aware-compaction plugin only calls output.context.push(string) and never touches message history.
Plugins stage-aware-compaction (inject-only experimental.session.compacting hook — does not modify message history)
OpenCode version
1.2.22
Steps to reproduce
Start a session with a Claude model that makes many tool calls (e.g. reading multiple files, running multiple shell commands).
Let the session run until it triggers compaction (high message count, e.g. ~300 messages).
Send the next user message after compaction completes.
Observe 400 from Anthropic: tool_use ids were found without tool_result blocks.
Closing as duplicate of #14367 — same root cause (filterCompacted leaving orphaned tool_use blocks). Investigation findings (proxy confirmed as transparent passthrough) added as a comment on #14367.
Activity
github-actions commentedon Mar 11, 2026
This issue might be a duplicate of existing issues. Please check:
tool_useblocks without matchingtool_resultblocks, causing 400 errors (reported against Kiro API but same underlying logic infilterCompacted)tool_use ids were found without tool_result blocks) occurring in long sessions after compactionke7in-zz commentedon Mar 11, 2026
Closing as duplicate of #14367 — same root cause (filterCompacted leaving orphaned tool_use blocks). Investigation findings (proxy confirmed as transparent passthrough) added as a comment on #14367.