bug: guard against empty choices in Fireworks AI stream chunks#1638
Open
Jwrede wants to merge 1 commit into
Open
bug: guard against empty choices in Fireworks AI stream chunks#1638Jwrede wants to merge 1 commit into
Jwrede wants to merge 1 commit into
Conversation
narengogi
approved these changes
May 11, 2026
Member
|
@Jwrede please sign your commits |
696217a to
5468210
Compare
Author
|
@narengogi Done -- commit is now signed (5468210). |
Fireworks AI may send stream chunks with an empty choices array (e.g. usage-only chunks). Accessing choices[0] on these chunks caused a runtime crash. Extract choice via optional chaining and emit an empty choices array when no choice is present. Fixes Portkey-AI#1627 Signed-off-by: Jonathan Wrede <wrede.jonathan00@gmail.com>
5468210 to
5912651
Compare
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.
Summary
parsedChunk.choices?.[0]inFireworksAIChatCompleteStreamChunkTransformso usage-only chunks with an emptychoicesarray no longer crash withTypeError: Cannot read properties of undefined (reading 'index')choices: []when no choice is present, matching the pattern used in Fix/unhandled exception in groq streaming requests #1073 (Groq) and fix: handle undefined choice in together ai finish reason transform #1321 (Together AI)[DONE], and usage passthroughTest plan
npx jest src/providers/fireworks-ai/chatComplete.test.ts-- all 5 tests passnpm run format:check)npm run buildvia pre-push hook)Fixes #1627