-
-
Notifications
You must be signed in to change notification settings - Fork 39.9k
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Summary
When a request is aborted mid-tool-call, OpenClaw's session repair mechanism creates a synthetic tool result, but the API subsequently rejects the session 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.
Steps to Reproduce
- Start a conversation that involves tool calls
- Interrupt/abort a request while a tool call is in progress (network hiccup, timeout, or user interruption)
- The assistant message gets
stopReason: "aborted"with a partial/incomplete tool call (haspartialJson) - OpenClaw detects the orphan and inserts a synthetic error result:
{"role":"toolResult","toolCallId":"toolu_XXXX","content":[{"type":"text","text":"[openclaw] missing tool result in session history; inserted synthetic error result for transcript repair."}],"isError":true} - On next user message, the API rejects with tool_use_id mismatch
Root Cause
When reconstructing messages to send to the API, the aborted assistant message's tool_use block is either:
- Not included (because it's incomplete/partial), OR
- Malformed in a way the API doesn't recognize
But the synthetic tool_result IS included, creating a mismatch.
Session Log Evidence
Line N: assistant → stopReason: "aborted", toolCall id: toolu_01Hoo9VQsRSw7Nafu2QFt8KK (partialJson present)
Line N+1: toolResult → toolCallId: toolu_01Hoo9VQsRSw7Nafu2QFt8KK (synthetic repair)
Line N+2: user message
Line N+3: assistant → stopReason: "error", API rejects with tool_use_id mismatch
Suggested Fix
When an aborted message contains a partial/incomplete tool call:
- Option A: Strip BOTH the aborted tool_use AND its synthetic result before sending to API
- Option B: Complete/normalize the tool_use structure so it's valid before adding a result
- Option C: Don't insert synthetic results for aborted tool calls at all
Workaround
Manually delete/reset the corrupted session file:
rm ~/.openclaw/agents/main/sessions/<session-id>.jsonlEnvironment
- OpenClaw: 2026.2.2-3
- Model: claude-opus-4-5 (Anthropic)
- OS: Ubuntu (WSL2)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working