[AI-Assisted] fix: skip tool_use blocks with stopReason error in transcript repair#3060
Closed
sid1943 wants to merge 1 commit intoopenclaw:mainfrom
Closed
[AI-Assisted] fix: skip tool_use blocks with stopReason error in transcript repair#3060sid1943 wants to merge 1 commit intoopenclaw:mainfrom
sid1943 wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Fixes openclaw#1826 When an assistant message has stopReason: error, the tool_use blocks within it are incomplete/terminated and were never actually executed. The transcript repair mechanism was incorrectly creating synthetic tool_results for these errored tool calls, causing all subsequent API requests to fail with: invalid_request_error: unexpected tool_use_id found in tool_result blocks Changes: - Check stopReason before extracting tool calls in repairToolUseResultPairing() - Skip tool call extraction when stopReason is error - Prevents synthetic tool_results for incomplete/terminated tool calls This ensures sessions remain usable after tool execution errors or interruptions, without requiring manual JSONL editing. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This was referenced Jan 28, 2026
Author
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1826
When an assistant message has
stopReason: "error", the tool_use blocks within it are incomplete/terminated and were never actually executed. The transcript repair mechanism was incorrectly creating synthetic tool_results for these errored tool calls, causing all subsequent API requests to fail with:This breaks the session permanently until the synthetic tool_result is manually removed from the JSONL file.
Changes
stopReasonbefore extracting tool calls inrepairToolUseResultPairing()stopReasonis"error"Root Cause
The issue occurred in
src/agents/session-transcript-repair.tsat line 119:Before:
After:
Impact
Before this fix:
After this fix:
Testing Status
Files Changed
src/agents/session-transcript-repair.ts- Added stopReason check (10 lines added)AI-Assisted Development
🤖 This PR was created with assistance from Claude Sonnet 4.5
Checklist
Generated with Claude Code