fix(llm): finalize pending OpenAI Responses tool calls at completion - #41895
Open
patil2001 wants to merge 1 commit into
Open
fix(llm): finalize pending OpenAI Responses tool calls at completion#41895patil2001 wants to merge 1 commit into
patil2001 wants to merge 1 commit into
Conversation
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.
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
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.
Issue for this PR
Closes #37159
Type of change
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.addedbut reachesresponse.completedwithout a matchingresponse.output_item.done. The parser only finalized pendingToolStreamentries inonOutputItemDone, so the terminal handler closed the lifecycle without flushingstate.tools. The client then hastool-input-startbut 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.incompletenow finalize pending tool input throughToolStream.finishAll, which emitstool-input-endfollowed by a parsedtool-call. Empty accumulated arguments parse to{}(via the existingparseToolInputfallback), so an abandoned call fails ordinary schema validation immediately instead of hanging.hasFunctionCallis set so the emittedstep-finishuses thetool-callsreason. A regression test reproduces the exact reported sequence and asserts the settled call.How did you verify your code works?
bun test --timeout 30000inpackages/llmpasses (299 pass / 0 fail), including the new regression test streamingoutput_item.added(emptypatcharguments) thenresponse.completed.tsgo --noEmitclean inpackages/llm.oxlintclean on the changed files.Screenshots / recordings
Not a UI change.
Checklist