Skip to content

[Bug]: [compaction] safeguard mode creates orphan tool_result blocks causing API rejection at ~78% context #3462

@bottodavide

Description

@bottodavide

Compaction mode safeguard corrupts conversation history when context reaches ~78%. Removes tool_use blocks but leaves orphan tool_result blocks, causing API error: unexpected tool_use_id found in tool_result blocks

Bug Report: Compaction breaks tool_use/tool_result pairing
Version: 2026.1.24-3 (885167d)
Environment:

OS: Ubuntu 24 (linux 6.8.0-90-generic x64)
Node: 22.22.0
Model: claude-opus-4-5 (200k context)
Install: pnpm
Channel: stable

Configuration:
json"compaction": {
"mode": "safeguard"
}


**Symptoms:**
- Session reaches ~78% context (157k/200k tokens)
- Subsequent messages fail with API error
- Error returned to user via channel

**Error message:**

LLM request rejected: messages.406.content.1: unexpected tool_use_id found in tool_result blocks: toolu_XXXXX. Each tool_result block must have a corresponding tool_use block in the previous message.


**Log evidence:**

warn agent/embedded Profile anthropic:default hit Cloud Code Assist format error. Tool calls will be sanitized on retry.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions