-
-
Notifications
You must be signed in to change notification settings - Fork 40.3k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Description
We hit the tool_use/tool_result mismatch bug (#1685) through a compaction-specific path that isn't fully covered by the existing reports.
Our Reproduction
- Agent (Elliot/forge) ran a heavy session: 855 messages, 218K tokens — lots of image analysis, screenshots, file writes
- Safeguard compaction fired at the token limit (218,109 tokens)
- Compaction pruned older messages including some
tool_useblocks - Agent continued working after compaction — more tool calls from 15:20-15:26
- At 15:26:30, agent called
writetool → result was a synthetic error:[clawdbot] missing tool result in session history; inserted synthetic error result for transcript repair. - The synthetic result's
tool_use_id(toolu_01ApYXdC1pESwmh5Tek2bMTq) referenced atool_useblock that had been pruned during compaction - Every subsequent API call failed permanently
Key Difference from #1826/#2087
Those issues focus on interrupted/terminated tool calls (stopReason: "error"). Our case is different:
- The tool call was not interrupted — the agent was actively working
- The corruption came from compaction separating paired messages — the
tool_usewas in older history that got summarized away, but thetool_resultsurvived in recent messages - The compaction summary itself already noted a prior repair:
"Tool Failures: image: [clawdbot] missing tool result in session history"
Suggested Fix (extends #1826's proposal)
In addition to skipping errored assistant messages, repairToolUseResultPairing() should also:
- Validate that referenced tool_use blocks exist in the active context before inserting synthetic results
- Drop orphaned tool_results whose tool_use was compacted away (rather than keeping them)
- Post-compaction: re-validate tool_use/tool_result pairing integrity
Environment
- Clawdbot version: 2026.1.24-3
- Provider: Anthropic (Claude Opus 4.5)
- Channel: Discord (multi-agent setup, forge agent)
- Compaction mode: safeguard
- Context pruning: cache-ttl, 1h TTL
Workaround
Deleted the corrupted session JSONL + cleared sessions.json, restarted gateway.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working