Skip to content

fix(tanstack-ai): generate unique toolCallIds in the non-streaming fallback path - #647

Open
shoemoney wants to merge 1 commit into
cloudflare:mainfrom
shoemoney:fix/workers-ai-fallback-tool-call-ids
Open

fix(tanstack-ai): generate unique toolCallIds in the non-streaming fallback path#647
shoemoney wants to merge 1 commit into
cloudflare:mainfrom
shoemoney:fix/workers-ai-fallback-tool-call-ids

Conversation

@shoemoney

Copy link
Copy Markdown

The non-streaming fallback in WorkersAiTextAdapter.chatStream (used when a model rejects stream: true, e.g. GPT-OSS) forwards the provider's raw tc.id as toolCallId. Workers AI models can emit the same deterministic tool_call id for every call in a step, as documented in #526 and #527 and already fixed for the streaming path in this adapter and in workers-ai-provider. When the fallback response contains multiple tool calls, the duplicate ids collide downstream.

This mirrors the streaming branch's existing pattern: replace the provider id with generateId("chatcmpl-tool"), using the same id for the paired TOOL_CALL_START/TOOL_CALL_END events, with the same explanatory comment.

Adds a regression test: a fallback response with two tool calls sharing one deterministic id must produce two unique generated toolCallIds, with START/END agreeing per call. Fails on main, passes with this change. Full suite: 309 passed. Changeset included (patch, @cloudflare/tanstack-ai).

Workers AI models can emit the same deterministic tool_call id for every
call in a step (cloudflare#526/cloudflare#527). The streaming path already replaces provider
ids with generated ones; the non-streaming fallback still forwarded tc.id
raw, so multi-tool-call responses collided. Mirror the streaming path's
generateId("chatcmpl-tool") replacement and add a regression test.
@changeset-bot

changeset-bot Bot commented Aug 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 326645e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/tanstack-ai Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.

1 participant