Skip to content

fix(core): keep parallel streamed tool calls apart in Azure and Copilot adapters - #652

Merged
JackChen-me merged 2 commits into
open-multi-agent:mainfrom
OsamaAnsar:fix/azure-copilot-unindexed-tool-calls
Nov 4, 2026
Merged

JackChen-me merged 2 commits into
open-multi-agent:mainfrom
OsamaAnsar:fix/azure-copilot-unindexed-tool-calls

Conversation

@OsamaAnsar

@OsamaAnsar OsamaAnsar commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

AzureOpenAIAdapter.stream() and CopilotAdapter.stream() now keep parallel streamed tool calls apart when the server omits index. The slot selection that #642 added to OpenAIAdapter moves into a shared helper, createToolCallSlotResolver in openai-common.ts, and all three adapters use it. When the server sends index, behavior is unchanged.

Motivation

Both handlers did const idx = toolCallDelta.index and used it as the key of toolCallBuffers. A server that omits index (Gemini's OpenAI-compatible endpoint, the case in #642) makes every call share the undefined key, so parallel calls collapse into one buffer. #642 fixed only openai.ts.

Repro through each adapter's stream() with a mocked client: two whole tool calls in separate chunks, ids call_1 / call_2, arguments {"city":"Paris"} / {"city":"Tokyo"}, no index.

before after
Azure one tool_use, id call_2, input: {} two tool_use blocks with their own ids and inputs
Copilot one tool_use, id call_2, input: {} two tool_use blocks with their own ids and inputs

The input is {} before because the two argument strings are concatenated into invalid JSON, which these handlers surface as an empty object.

Scope and impact

  • Core only: llm/azure-openai.ts, llm/copilot.ts, llm/openai-common.ts, llm/openai.ts, plus tests.
  • openai.ts changes only to call the shared helper in place of its inline copy of the same logic; the existing OpenAI tests, including the ones from fix(openai): keep parallel streamed tool calls apart when the server omits index #642, still pass.
  • I checked the other adapters. deepseek.ts extends OpenAIAdapter and inherits its stream handler, and ai-sdk.ts delegates to the SDK bridge instead of reading raw deltas. Azure, Copilot and OpenAI are the only places that read toolCallDelta.index.
  • No public API, dependency or docs change. The helper is exported from openai-common.ts like the other shared helpers there; it is not part of the package entry point.

Validation

Node 24, from packages/core on Windows:

  • npx vitest run azure-openai-adapter copilot-adapter openai-adapter openai-fallback openai-common openai-sdk-boundary --maxWorkers=2 --minWorkers=1: 122 passed.
  • With only the azure-openai.ts and copilot.ts changes reverted (helper and openai.ts kept): the two new "keeps parallel tool calls apart when the server omits index" tests fail (received one tool_use with input: {}, expected two), 63 other tests in those two files pass. The "fragments that have neither index nor id" tests pass with and without the change; they pin the continuation behavior.
  • npm run lint (tsc --noEmit -p tsconfig.lint.json): clean.
  • git diff --check: clean.
  • npx vitest run --maxWorkers=2 --minWorkers=1 (all of core): 2329 passed, 27 skipped, 31 failed. All 31 failures are in cli.test.ts (dashboard file export), eval-file-store.test.ts and file-trace-store.test.ts, and the ones I inspected report SYNC_FAILED ... causeCode: 'EPERM' from the Windows filesystem. None touch the LLM adapters; I did not investigate them further.

Not run: npm run build, npm run test:zod3, npm run test:scaffold, other workspaces, or any request to a live Azure or Copilot endpoint.

Checklist

  • Tests were added or updated for changed behavior, or a rationale is provided
  • User-facing documentation and examples were updated, or this is not applicable (no docs describe tool-call buffering)
  • Compatibility, breaking changes, and migration requirements are documented, or this is not applicable
  • Dependency changes are justified and preserve the package ownership boundaries (no dependency changes)
  • A relevant issue is linked when one exists (none found; follow-up to fix(openai): keep parallel streamed tool calls apart when the server omits index #642)

…ot adapters

Both stream handlers keyed their tool-call buffers by `toolCallDelta.index`.
Servers that omit `index` (Gemini-style OpenAI endpoints) made every call share
one `undefined` buffer, so parallel calls collapsed into one with merged,
invalid arguments. Move the slot selection added to the OpenAI adapter in open-multi-agent#642
into a shared helper in openai-common.ts and use it in the OpenAI, Azure and
Copilot adapters. Behavior is unchanged when `index` is present.

@JackChen-me JackChen-me left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — the shared slot resolver is a line-for-line extraction of the #642 OpenAI logic, Azure and Copilot now handle unindexed parallel tool calls, and existing OpenAI tests still cover the refactor. CI is green. Thanks!

@JackChen-me
JackChen-me merged commit c753516 into open-multi-agent:main Nov 4, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants