fix(stream): handle audio completion markers#1991
Merged
HAYDEN-OAI merged 2 commits intoJul 22, 2026
Merged
Conversation
jbeckwith-oai
approved these changes
Jul 22, 2026
jbeckwith-oai
left a comment
Contributor
There was a problem hiding this comment.
Reviewed head 5ee5d86. The audio fields are accumulated correctly, inferred completion is narrowly gated on a complete audio payload plus a terminal expires_at-only delta, and later deltas invalidate that marker. I also checked multi-choice behavior, explicit finish reasons, and incomplete audio. Local targeted tests, four additional boundary probes, the full test suite (1,198 passed), pnpm lint, and pnpm build all passed; GitHub CI is green.
Merged
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.
Changes being requested
id,data, andtranscriptfragments with each later deltafinalChatCompletion()to finalize audio streams that end with a terminalexpires_at-only chunk and no separatefinish_reasonfinish_reasonerror for non-audio, incomplete, malformed, or continued-after-expiry streamsAdditional context & links
Fixes #1206.
gpt-4o-audio-previewcan finish streaming with an audio delta containing onlyexpires_at. The stream helper currently requires an explicitfinish_reason, sofinalChatCompletion()throws even though the audio response is complete. The existing generic delta merge also overwrites earlier audio fragments, leaving only the final audio object.This change tracks whether the last meaningful choice delta is an
expires_at-only audio completion marker and only infersfinish_reason: stopwhen the accumulated audio has all required fields. It does not add a general missing-finish fallback.Verification:
pnpm test --runInBand tests/lib/ChatCompletionStream.test.tspnpm lintpnpm test --runInBand