Skip to content

fix: skip synthetic toolResult for aborted/errored assistant messages#3054

Closed
dominicnunez wants to merge 1 commit intoopenclaw:mainfrom
dominicnunez:fix/skip-synthetic-toolresult-for-aborted-messages
Closed

fix: skip synthetic toolResult for aborted/errored assistant messages#3054
dominicnunez wants to merge 1 commit intoopenclaw:mainfrom
dominicnunez:fix/skip-synthetic-toolresult-for-aborted-messages

Conversation

@dominicnunez
Copy link
Contributor

@dominicnunez dominicnunez commented Jan 28, 2026

Summary

Skip inserting synthetic toolResult entries for assistant messages with stopReason: "error" or "aborted"

Problem

When an assistant message is aborted mid-tool-call (e.g., due to timeout, reboot, or interrupt), the transcript repair mechanism inserts a synthetic toolResult. On subsequent API calls, the aborted toolCall may be filtered out while the synthetic toolResult remains, causing Anthropic's API to reject the request with:

unexpected tool_use_id found in tool_result blocks: toolu_XXX

This makes the session permanently broken until manual intervention.

Solution

Modified extractToolCallsFromAssistant() to return [] when the assistant message has stopReason: "error" or "aborted". This prevents synthetic toolResult entries from being created for incomplete tool calls that won't be included in API requests anyway.

Testing

  • Added test: "does not insert synthetic toolResult for aborted assistant message"
  • Added test: "does not insert synthetic toolResult for errored assistant message"
  • Added test: "still inserts synthetic toolResult for normal assistant message with missing result"

Fixes #1826


AI-Assisted PR

  • Mark as AI-assisted in the PR title or description
  • Note the degree of testing: lightly tested (unit tests added, not run locally due to dependency install timeout)
  • Confirm you understand what the code does

This PR was AI-assisted using Claude. The fix checks stopReason at the start of extractToolCallsFromAssistant() and returns early for incomplete turns, preventing synthetic toolResults from being created for tool calls that never executed.

@dominicnunez dominicnunez force-pushed the fix/skip-synthetic-toolresult-for-aborted-messages branch from b69c267 to 747b849 Compare January 28, 2026 01:44
@openclaw-barnacle openclaw-barnacle bot removed the gateway Gateway runtime label Jan 28, 2026
@dominicnunez dominicnunez deleted the fix/skip-synthetic-toolresult-for-aborted-messages branch January 28, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Synthetic tool_result for terminated tool_use causes all subsequent requests to fail

1 participant