Repository navigation
fix(openai): keep parallel streamed tool calls apart when the server omits index - #642
Merged
JackChen-me merged 3 commits intoOct 29, 2026
Conversation
…omits index Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
5 tasks done
5 tasks done
JackChen-me
pushed a commit
that referenced
this pull request
Nov 4, 2026
…ot adapters (#652) `AzureOpenAIAdapter.stream()` and `CopilotAdapter.stream()` keyed every streamed tool-call delta by `toolCallDelta.index`; when a server omits `index`, all calls collapsed into one buffer and surfaced as a single `tool_use` with the last id and empty input. Move the slot-selection logic added to the OpenAI adapter in #642 into a shared `createToolCallSlotResolver()` in `openai-common.ts` and use it from all three adapters. Indexed streams are unchanged; tests cover Azure and Copilot alongside the existing OpenAI cases.
5 tasks done
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.
Problem
OpenAIAdapter.stream()keys its tool-call buffers bytoolCallDelta.index. OpenAI-compatible servers that do not sendindexmake every streamed call share one buffer (undefined), so parallel calls collapse into one: the last id and name win and the arguments are concatenated. Gemini's OpenAI-compatible endpoint (https://generativelanguage.googleapis.com/v1beta/openai) streams parallel calls like this: in a capturedgemini-3.5-flashstream, twoget_weathercalls arrive as two chunks, each a whole call with its ownid, name and arguments, and noindex. The agent then runs one tool call with merged, invalid arguments instead of two.Fix
The slot is chosen like this: an
indexis used when the server sent one (unchanged for OpenAI and any indexed stream); otherwise a delta with a newidopens a new slot, a delta with a knownidcontinues that slot, and a fragment with neither continues the latest one.Tests
In
tests/openai-adapter.test.ts: two whole, unindexed calls in separate chunks yield twotool_useblocks (fails without the change, one merged call before), and an id-then-fragment pair without index still yields one call. The existing OpenAI, Azure and fallback-repair adapter tests pass (60 tests) andnpm run lintfor core is clean. No request was made to a live API for this change.This change was prepared with an AI coding assistant (Claude).