Repository navigation
fix(responses): stream readiness for tool-call-only chunks (#3612) #3661
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
diegosouzapw
merged 1 commit into
release/v3.8.22
from
fix/3612-stream-readiness-toolcall
Jun 11, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,19 +104,29 @@ function hasOpenAIResponseLifecyclePayload( | |
| } | ||
|
|
||
| function hasChatCompletionToolCallStart(value: unknown): boolean { | ||
| const hasToolCallId = (item: unknown) => isRecord(item) && hasNonEmptyString(item.id); | ||
| if (Array.isArray(value)) return value.some(hasToolCallId); | ||
| return hasToolCallId(value); | ||
| // Accept a tool_call item if it has a non-empty id (fully-formed chunk) OR if it | ||
| // carries a numeric index (first OpenAI streaming chunk — id/name arrive in later | ||
| // chunks). Either form signals that a tool call has started. (#3612) | ||
| const hasToolCallStart = (item: unknown) => | ||
| isRecord(item) && (hasNonEmptyString(item.id) || typeof item.index === "number"); | ||
| if (Array.isArray(value)) return value.some(hasToolCallStart); | ||
| return hasToolCallStart(value); | ||
| } | ||
|
|
||
| function hasChatCompletionFunctionCallStart(value: unknown): boolean { | ||
| return isRecord(value) && hasNonEmptyString(value.name); | ||
| } | ||
|
|
||
| function hasChatCompletionChunkStartPayload(payload: Record<string, unknown>): boolean { | ||
| if (payload.object !== "chat.completion.chunk" && payload.type !== "chat.completion.chunk") { | ||
| return false; | ||
| } | ||
| // If object or type is PRESENT and is clearly a non-chat-chunk type, reject early. | ||
| // If both are absent (many OA-compatible backends omit object), we fall through and | ||
| // let the choices structure decide. (#3612) | ||
| const obj = payload.object; | ||
| const typ = payload.type; | ||
| const hasForeignObject = | ||
| (typeof obj === "string" && obj !== "chat.completion.chunk") || | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WARNING: Non-string This guard only rejects string mismatches, so |
||
| (typeof typ === "string" && typ !== "chat.completion.chunk"); | ||
| if (hasForeignObject) return false; | ||
|
|
||
| const choices = payload.choices; | ||
| if (!Array.isArray(choices) || choices.length === 0) return false; | ||
|
|
||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WARNING:
indexshould be validated as a non-negative integerA numeric
indexis enough to mark a tool-call start, but malformed values like-1or0.5would also pass. UseNumber.isInteger(item.index) && item.index >= 0so only valid OpenAI chunk indices are accepted.