Skip to content

Session compaction produces orphaned tool_use blocks in long tool-heavy sessions (400 from Anthropic) #17065

Closed as not planned

Description

@ke7in-zz

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

  1. Start a session with a Claude model that makes many tool calls (e.g. reading multiple files, running multiple shell commands).
  2. Let the session run until it triggers compaction (high message count, e.g. ~300 messages).
  3. Send the next user message after compaction completes.
  4. Observe 400 from Anthropic: tool_use ids were found without tool_result blocks.

Screenshot and/or share link
N/A

Operating System
macOS 26.2

Terminal
macOS Terminal

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 11, 2026
  2. github-actions commented on Mar 11, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  3. ke7in-zz commented on Mar 11, 2026

    @ke7in-zz
    Author

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

coreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions