-
-
Notifications
You must be signed in to change notification settings - Fork 40.3k
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Bug Description
When an assistant message with a tool_use block is terminated/aborted mid-execution (stopReason: "error", errorMessage: "terminated"), the transcript repair logic inserts a synthetic tool_result for the orphaned tool call. However, when building the API payload, the terminated assistant message appears to be excluded while the synthetic tool_result is still included, causing an API rejection:
400 {"type":"error","error":{"type":"invalid_request_error","message":"messages.108.content.1: unexpected `tool_use_id` found in `tool_result` blocks: toolu_014PfKm8xZYg6Q6ZnotRoM54. Each `tool_result` block must have a corresponding `tool_use` block in the previous message."}}
Steps to Reproduce
- Start a conversation that uses tools
- Terminate/abort a request mid-tool-call (e.g., kill the process, network interruption)
- The session file now has an assistant message with
stopReason: "error"containing atool_useblock - The repair logic in
session-transcript-repair.jsinserts a synthetictool_result - On next request, the API rejects due to orphan
tool_result
Expected Behavior
The repair logic should either:
- Not insert synthetic
tool_resultsfor assistant messages that will be excluded from the API payload (those withstopReason: "error") - OR ensure the terminated assistant message (with its
tool_use) is included when its synthetictool_resultis included
Workaround
Clear the session file:
rm ~/.clawdbot/agents/main/sessions/*.jsonlEnvironment
- clawdbot version: (latest as of 2026-01-31)
- Provider: Anthropic
- Model: claude-opus-4-5
Relevant Code
The repair logic is in dist/agents/session-transcript-repair.js - the repairToolUseResultPairing function correctly handles orphan tool_results but doesn't account for the case where the parent assistant message is excluded due to error status.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working