Skip to content

fix(server-utils): Keep Workers AI streamed tool calls that have no index - #25835

Open
pcbeingused333 wants to merge 1 commit into
getsentry:developfrom
pcbeingused333:fix/workers-ai-stream-tool-calls-without-index
Open

pcbeingused333 wants to merge 1 commit into
getsentry:developfrom
pcbeingused333:fix/workers-ai-stream-tool-calls-without-index

Conversation

@pcbeingused333

Copy link
Copy Markdown
Contributor

Why: The Workers AI streaming instrumentation (accumulateStreamingToolCalls) keyed every tool-call delta by toolCall.index ?? 0. OpenAI-compatible endpoints that omit index and send each parallel call whole in its own chunk therefore ended up as a single call: the first call's id and name, with the arguments of every call concatenated, and the other calls missing from gen_ai.response.tool_calls and gen_ai.output.messages. Same situation #25622 fixed for the OpenAI instrumentation.

Tool calls with a numeric index are grouped by it exactly as before. A delta without a usable index (missing or null) is kept in a separate list, in arrival order, so it can never collide with a real index: a delta whose id is already known continues that call, a new id (or a function name without an id) starts a new call, and anything else, such as an arguments fragment with neither, continues the latest one. Native and indexed streams (including the top-level name/arguments shape) behave as before.

How to review: getUnindexedToolCall and the ToolCallAccumulator split in packages/server-utils/src/ai/workers-ai/streaming.ts; the three new cases in workers-ai-streaming.test.ts (two parallel calls without an index stay separate, argument fragments of one unindexed call are merged, an unindexed call does not merge into an indexed call at index: 0). The first and third fail without the change; the whole test/ai/lib/tracing folder passes.

Unsure about: whether an unindexed delta with neither id nor name should continue the latest call (chosen here, mirrors #25622) or be dropped.

Closes: no linked issue; same class of bug as #25622.

This change was prepared with the assistance of an AI coding agent (Claude).

…ndex

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pcbeingused333
pcbeingused333 requested a review from a team as a code owner October 28, 2026 15:41
@pcbeingused333
pcbeingused333 requested review from isaacs and mydea and removed request for a team October 28, 2026 15:41
@github-actions github-actions Bot added the external PR from an external contributor label Oct 28, 2026
@RulaKhaled
RulaKhaled self-requested a review October 29, 2026 13:33

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external PR from an external contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant