-
-
Notifications
You must be signed in to change notification settings - Fork 40.3k
Closed
Description
Description
When a tool call is interrupted/terminated mid-execution, clawdbot inserts a "synthetic error result" to repair the transcript. However, when the session is later replayed for API calls, the tool_use/tool_result pairing becomes misaligned, causing Anthropic API to reject the request.
Error Message
LLM request rejected: messages.228.content.1: unexpected tool_use_id found in tool_result blocks: toolu_01TKLcHJJkbDgtJEvitNxEFg. Each tool_result block must have a corresponding tool_use block in the previous message.
Steps to Reproduce
- Start a conversation with an agent via Telegram
- Trigger a long-running tool call (e.g.,
execcommand) - Interrupt/terminate the agent mid-tool-call (send "stop" or similar)
- Continue the conversation
- Eventually the session becomes corrupted and all requests fail
Session Analysis
Looking at the corrupted session JSONL:
Line 255: assistant message with toolCall id="toolu_01TKLcHJJkbDgtJEvitNxEFg", stopReason="error", errorMessage="terminated"
Line 256: synthetic toolResult with matching toolCallId, content="[clawdbot] missing tool result..."
Line 259+: API errors referencing the same tool_use_id
The synthetic result IS in the session file directly after the assistant message, but when repairToolUseResultPairing() runs in-memory before API calls, the pairing is not correctly reconstructed.
Root Cause Hypothesis
The issue is in src/agents/session-transcript-repair.js:
- The synthetic result is inserted into JSONL at the correct position
- But when building API messages from session entries, the message indexing differs
- The repair logic may be dropping the synthetic result as an "orphan" in edge cases
Environment
- Clawdbot version: 2026.1.24-3
- Provider: Anthropic (Claude Opus 4.5)
- Channel: Telegram
- Compaction mode: safeguard
Workaround
Delete the corrupted session file and restart:
rm ~/.clawdbot/agents/main/sessions/<session-id>.jsonl
systemctl --user restart clawdbot-gatewayReported by: Nicolas Delrieu
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels