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

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).

@changeset-bot

changeset-bot Bot commented Aug 23, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 86283e6

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

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.
@shoemoney
shoemoney force-pushed the fix/workers-ai-fallback-tool-call-ids branch from 326645e to 86283e6 Compare November 25, 2026 04:30
@shoemoney

shoemoney commented Nov 25, 2026 •

Copy link
Copy Markdown
Author

Rebased onto current main (it was 18 commits behind). Locally, with the repo's own pinned pnpm and the same targets CI runs for this package: test:ci, type-check and build pass for @cloudflare/tanstack-ai (309 tests), and oxlint and oxfmt are clean on the changed files. The workflows here are waiting on approval to run for a fork PR, so they have not run against the new head yet.

@mattzcarey, I saw your structural truncation fix in cloudflare/agents#2224. Since you work on this corner of the tool-output handling, would you be up for a look at this one?

Also, a side question if you don't mind: I'm talking with the Developer Tooling team soon. If you're close to that group, what are they spending most of their time on right now?

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