GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Session compaction produces orphaned tool_use blocks in long tool-heavy sessions (400 from Anthropic) · Issue #17065 · anomalyco/opencode

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

New issue
Copy link
New issue
Copy link
Closed as not planned
Closed as not planned
Session compaction produces orphaned tool_use blocks in long tool-heavy sessions (400 from Anthropic)#17065
Copy link
Assignees
rekram1-node
Labels
coreAnything pertaining to core functionality of the application (opencode server stuff)

Description

@ke7in-zz
ke7in-zz
opened on Mar 11, 2026
Issue body actions

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. github-actions
    assigned
    rekram1-node
    on Mar 11, 2026
  2. github-actions
    added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 11, 2026
  3. github-actions commented on Mar 11, 2026

    @github-actions
    github-actionsBot
    on Mar 11, 2026 – with GitHub Actions
    Contributor
    More actions

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

    • Kiro API 400 error after compaction due to mismatched toolUses/toolResults #14367: Same root cause — compaction trims history leaving orphaned tool_use blocks without matching tool_result blocks, causing 400 errors (reported against Kiro API but same underlying logic in filterCompacted)
    • AI_APICallError: tool_use blocks found without corresponding tool_result blocks #2720: Same error message (tool_use ids were found without tool_result blocks) occurring in long sessions after compaction
  4. ke7in-zz commented on Mar 11, 2026

    @ke7in-zz
    ke7in-zz
    on Mar 11, 2026
    Author
    More actions

    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.

  5. ke7in-zz
    closed this as not plannedon Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @rekram1-node
    rekram1-node

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

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.