Skip to content

[Bug]: Session corruption: orphaned tool_result after interrupted request + compaction #15691

@TheWayWithin

Description

@TheWayWithin

Summary

Session transcripts become corrupted with orphaned tool_result blocks after a request is interrupted and later compacted. This causes the Anthropic API to reject all subsequent requests with:

messages.X.content.Y: unexpected tool_use_id found in tool_result blocks: toolu_XXXX. Each tool_result block must have a corresponding tool_use block in the previous message.

Environment

  • Clawdbot version: 2026.1.24-3
  • OS: Ubuntu Linux (AWS)
  • Model: claude-opus-4-5
  • Multi-agent setup: 2 agents

Reproduction

  1. Run a long session with many tool calls (600+)
  2. Interrupt a request mid-tool-execution
  3. Clawdbot inserts synthetic tool_result for transcript repair
  4. Continue until context compaction triggers
  5. After compaction, tool_use is removed but synthetic tool_result remains
  6. API rejects all future requests

Frequency

Occurred 2 times in 2 days. 28 deleted session files suggest repeated occurrences.

Workaround

Delete the .jsonl transcript file and restart gateway. Agent loses history but workspace files intact.

Suggested Fix

During compaction, ensure tool_result blocks have matching tool_use preserved, or remove orphaned tool_results.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions