Skip to content

Comments

fix: skip incomplete tool calls with partialJson in session repair#5822

Closed
ghost wants to merge 1 commit intomainfrom
unknown repository
Closed

fix: skip incomplete tool calls with partialJson in session repair#5822
ghost wants to merge 1 commit intomainfrom
unknown repository

Conversation

@ghost
Copy link

@ghost ghost commented Feb 1, 2026

Summary

When streaming is aborted mid-tool-call, the assistant message contains a toolCall with partialJson (incomplete arguments) instead of complete arguments. The repair logic was creating synthetic tool_results for these incomplete calls, but since the incomplete tool_use blocks are skipped during API conversion, this caused "unexpected tool_use_id" errors from the Anthropic API.

Changes

  • Updated extractToolCallsFromAssistant() to skip tool calls that have partialJson but no arguments field
  • Added 2 test cases to verify the fix

Test plan

  • All existing tests pass
  • New tests verify incomplete tool calls are skipped
  • Verified gateway starts without crash after clearing corrupted session

Greptile Overview

Greptile Summary

This PR updates the session transcript repair logic to ignore incomplete streamed tool calls that contain partialJson but no arguments. This prevents the repair step from inserting synthetic toolResult messages for tool calls that will later be omitted during Anthropic API conversion, avoiding "unexpected tool_use_id" validation errors. Two Vitest cases were added to cover skipping incomplete tool calls and ensuring synthetic results are still generated for complete calls.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk.
  • Change is narrowly scoped to filtering incomplete streamed tool calls and is covered by new focused tests; it does not alter tool result pairing logic for valid calls.
  • No files require special attention

(2/5) Greptile learns from your feedback when you react with thumbs up/down!

Context used:

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

When streaming is aborted mid-tool-call, the assistant message contains
a toolCall with partialJson (incomplete arguments) instead of complete
arguments. The repair logic was creating synthetic tool_results for
these incomplete calls, but since the incomplete tool_use blocks are
skipped during API conversion, this caused "unexpected tool_use_id"
errors from the Anthropic API.

This fix updates extractToolCallsFromAssistant() to skip tool calls
that have partialJson but no arguments field, preventing synthetic
results from being created for tool calls that won't be sent to the API.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Feb 1, 2026
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No files reviewed, no comments

Edit Code Review Agent Settings | Greptile

This pull request was closed.
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.

0 participants