Skip to content

fix: skip synthetic tool_result for aborted assistant messages#6831

Closed
zerone0x wants to merge 1 commit intoopenclaw:mainfrom
zerone0x:fix/transcript-repair-aborted-tool-calls
Closed

fix: skip synthetic tool_result for aborted assistant messages#6831
zerone0x wants to merge 1 commit intoopenclaw:mainfrom
zerone0x:fix/transcript-repair-aborted-tool-calls

Conversation

@zerone0x
Copy link
Contributor

@zerone0x zerone0x commented Feb 2, 2026

Summary

Fixes #6788

When a user interrupts an assistant mid-tool-call, the message gets stopReason: "aborted" but the transcript repair logic still extracts tool call IDs from the partial content and creates synthetic tool_result entries. Anthropic's API then rejects the transcript with invalid_request_error: unexpected tool_result block, making the session unusable.

Changes

  • session-transcript-repair.ts: extractToolCallsFromAssistant() now returns [] for messages with stopReason === "aborted", preventing synthetic tool_result generation for incomplete tool calls
  • session-tool-result-guard.ts: Same check in the guard's extractAssistantToolCalls() to prevent queuing pending results for aborted messages
  • session-transcript-repair.test.ts: Added 2 tests verifying the fix

Test Plan

  • New test: aborted assistant with tool calls produces no synthetic tool_result
  • New test: non-aborted assistant with tool calls still produces synthetic tool_result
  • All 4971 existing tests pass

Generated with Claude Code (issue-hunter-pro)

Co-Authored-By: Claude noreply@anthropic.com

Greptile Overview

Greptile Summary

This PR updates transcript repair and tool-result guarding to treat stopReason: "aborted" assistant messages as having no tool calls, preventing generation/queuing of synthetic toolResult blocks from partial tool-call content. It also adds unit tests covering the aborted vs non-aborted transcript-repair behavior to avoid Anthropic API rejections caused by unexpected tool_result blocks in repaired transcripts.

Confidence Score: 5/5

  • This PR appears safe to merge and directly addresses the reported transcript rejection failure mode.
  • Changes are small and targeted (early-return on stopReason === "aborted") in two extraction helpers, and transcript-repair behavior is covered by new tests. No behavioral impact for non-aborted messages, and the new condition is narrowly scoped.
  • No files require special attention

Context used:

  • Context from dashboard - CLAUDE.md (source)
  • Context from dashboard - AGENTS.md (source)

@rodbland2021
Copy link
Contributor

Supporting This PR

I independently implemented the same fix and submitted PR #11729 (now closed as duplicate). After reviewing the 10+ duplicate PRs, this one (#6831) appears to be the best solution.

Why this PR should be merged:

  • Complete fix - addresses both session-transcript-repair.ts AND session-tool-result-guard.ts
  • Well-tested - adds proper regression tests
  • Clean implementation - minimal, focused changes
  • Greptile verified - 5/5 confidence score
  • Properly documented - clear description and test plan

Testing verification:
I ran the same tests locally and can confirm:

  • All existing tests pass with this fix
  • The aborted message tests now pass (were failing before)
  • No regressions introduced

Impact on production:
This bug is actively causing session corruption for many users (including myself). The fix eliminates the #1 source of "unexpected tool_use_id" API errors.

To maintainers: Please prioritize merging this PR. There are 10+ duplicates submitted over the past 11 days, all trying to fix the same issue. This is one of the cleanest implementations.

Tested-by: @rodbland2021

@sebslight
Copy link
Member

Closing as duplicate of #4844. If this is incorrect, comment and we can reopen.

@sebslight sebslight closed this Feb 13, 2026
@zerone0x zerone0x deleted the fix/transcript-repair-aborted-tool-calls branch February 13, 2026 03:50
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.

Transcript repair creates orphaned tool_result for aborted tool calls

3 participants