Skip to content

fix(llm): finalize pending OpenAI Responses tool calls at completion - #41895

Open
patil2001 wants to merge 1 commit into
anomalyco:devfrom
patil2001:fix/llm-finalize-pending-response-tools
Open

fix(llm): finalize pending OpenAI Responses tool calls at completion#41895
patil2001 wants to merge 1 commit into
anomalyco:devfrom
patil2001:fix/llm-finalize-pending-response-tools

Conversation

@patil2001

@patil2001 patil2001 commented Aug 12, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #37159

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

A V2 session can leave a local tool permanently "pending" when an OpenAI Responses-compatible stream announces a function call with response.output_item.added but reaches response.completed without a matching response.output_item.done. The parser only finalized pending ToolStream entries in onOutputItemDone, so the terminal handler closed the lifecycle without flushing state.tools. The client then has tool-input-start but no call to settle or fail, and the Patch card stays stuck until the session is interrupted.

The fix flushes any remaining pending tool assembly when the response completes or finishes incomplete. response.completed / response.incomplete now finalize pending tool input through ToolStream.finishAll, which emits tool-input-end followed by a parsed tool-call. Empty accumulated arguments parse to {} (via the existing parseToolInput fallback), so an abandoned call fails ordinary schema validation immediately instead of hanging. hasFunctionCall is set so the emitted step-finish uses the tool-calls reason. A regression test reproduces the exact reported sequence and asserts the settled call.

How did you verify your code works?

  • bun test --timeout 30000 in packages/llm passes (299 pass / 0 fail), including the new regression test streaming output_item.added (empty patch arguments) then response.completed.
  • tsgo --noEmit clean in packages/llm.
  • oxlint clean on the changed files.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

A function call announced via response.output_item.added but never
completed by response.output_item.done stayed pending in the parser
state, leaving a client tool permanently pending until the session was
interrupted.

Flush any remaining tool assembly when the response completes or
finishes incomplete, emitting tool-input-end plus a parsed tool-call
(empty accumulated input becomes {} so normal schema validation can
settle the call) and preserving the tool-calls finish reason.
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Aug 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(v2): finalize pending OpenAI Responses tool calls at response completion

1 participant