fix(tanstack-ai): generate unique toolCallIds in the non-streaming fallback path - #647
Open
shoemoney wants to merge 1 commit into
Open
fix(tanstack-ai): generate unique toolCallIds in the non-streaming fallback path#647shoemoney wants to merge 1 commit into
shoemoney wants to merge 1 commit into
Conversation
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 detectedLatest commit: 326645e The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
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.
The non-streaming fallback in
WorkersAiTextAdapter.chatStream(used when a model rejectsstream: true, e.g. GPT-OSS) forwards the provider's rawtc.idastoolCallId. 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).