Skip to content

fix(ai): ignore TOOL_CALL_ARGS after a tool call ended - #2274

Merged
AlemTuzlak merged 2 commits into
TanStack:mainfrom
canblmz1:fix/core-ignore-args-after-end
Nov 30, 2026
Merged

AlemTuzlak merged 2 commits into
TanStack:mainfrom
canblmz1:fix/core-ignore-args-after-end

Conversation

@canblmz1

@canblmz1 canblmz1 commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Changes

After a tool call's TOOL_CALL_END, core still accepted TOOL_CALL_ARGS for the same call:

  • ToolCallManager.addToolCallArgsEvent appended the late delta (or replaced the arguments with args), so the server tool ran with different arguments or failed JSON.parse and never ran.
  • StreamProcessor.handleToolCallArgsEvent appended it to the UI part's finalized arguments, and could move a part that had already reached complete / error back to input-complete / input-streaming.

Both now ignore TOOL_CALL_ARGS for a call that has ended (manager: after TOOL_CALL_END; processor: when the call is input-complete or its part is terminal). Arguments before END are handled as before. This protects every adapter and custom stream; #2264 and #2273 fix two adapters that emitted such events.

  • Unit: new cases in tool-call-manager.test.ts (late delta, late full args) and stream-processor.test.ts (input-complete, complete, error). All 5 fail on main; tool-call-manager + stream-processor: 320 passed.
  • E2E: late-tool-args-wire streams a getWeather call, then a late } delta after TOOL_CALL_END, from a server route through ChatClient over HTTP. On main the part ends with arguments: {"city":"Paris"}} and Failed to parse tool arguments as JSON; with this change it's complete with Sunny in Paris.
  • Docs: one sentence in docs/chat/stream-events.md: TOOL_CALL_END finalizes the arguments, and later TOOL_CALL_ARGS for the same call are ignored.

Verified locally: @tanstack/ai test:lib and test:types, oxlint, oxfmt --check, and the new Playwright spec against the dev server. I did not run the full pnpm run test:pr.

The fix and tests were written with AI assistance (Codex, Claude); I reviewed and verified them as above.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request. (Ran the affected package and E2E checks listed above, not the full test:pr.)
  • I fully understand the code in this pull request, including any code generated with AI assistance.
  • Docs: I updated docs/ for this change, or this change is not user-facing.
  • Changeset: I added a changeset (pnpm changeset), or this PR does not change a published package.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Tool calls now retain the arguments finalized when the call ends. Late argument updates no longer change completed or failed calls, helping ensure tools execute once with the intended input and chat clients preserve the finished call.
  • Documentation
    • Clarified that argument updates received after a tool call ends are ignored.

ToolCallManager appended a late TOOL_CALL_ARGS delta (or replaced the
arguments) after TOOL_CALL_END, so the server tool failed to parse its
finalized arguments or ran with different ones; StreamProcessor corrupted
the UI arguments and could move a finished part back to input-complete.
Ignore ARGS for a call that has ended in both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0027e8d

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

This PR includes changesets to release 2 packages
Name Type
@tanstack/ai Patch
@tanstack/ai-optimize-evals 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

@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The chat stream processor and tool-call manager now ignore argument events received after a tool call ends. Unit and end-to-end tests cover late events, and the stream-events documentation describes this behavior.

Changes: Late tool-call argument handling

Layer / File(s) Summary
Ignore arguments after completion
packages/ai/src/activities/chat/stream/processor.ts, packages/ai/src/activities/chat/tools/tool-calls.ts, packages/ai/tests/stream-processor.test.ts, packages/ai/tests/tool-call-manager.test.ts, docs/chat/stream-events.md, .changeset/ignore-late-tool-call-args.md
The stream processor ignores argument chunks for completed or terminal tool calls. The tool-call manager tracks ended IDs and ignores later argument events. Unit tests cover late deltas and full arguments; the docs describe the behavior.
Exercise late arguments in an SSE stream
testing/e2e/src/routes/api.late-tool-args-wire.ts, testing/e2e/src/routeTree.gen.ts, testing/e2e/tests/late-tool-args-wire.spec.ts
A test route emits a TOOL_CALL_ARGS chunk after TOOL_CALL_END. The end-to-end test checks the completed tool call, its arguments and input, and the forecast output.

Estimated code review effort: 2 (Simple) | ~15 minutes

Change: Bug fix

Possibly related PRs

  • TanStack/ai#2264: The OpenAI Responses adapter drops argument deltas received after a tool call ends; this PR adds a corresponding guard in core stream handling.

Suggested reviewers: tombeckenham

Merge Risk: Minimal · up to 0027e

Late tool-argument events after a tool call ends are now ignored, which protects completed tool calls from corrupted arguments. Tests cover the behavior and no actionable merge risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the primary change: late TOOL_CALL_ARGS events are ignored after a tool call ends. The changeset, manager and processor edits, tests, and docs all support this. The title follows the c…
Description check Passed The description follows the repository template. It covers the change and its reasoning, and it lists unit, E2E, and docs verification. It has all template sections, including the checklist and releas…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the primary change: late TOOL_CALL_ARGS events are ignored after a tool call ends. The changeset, manager and processor edits, tests, and docs all support this. The title follows the conventional fix(ai) form and is specific to the change.

Full details: Description check

Explanation

The description follows the repository template. It covers the change and its reasoning, and it lists unit, E2E, and docs verification. It has all template sections, including the checklist and release impact. The checklist item for test:pr is left unchecked, and the author explains why in the text. The author also marks the changeset and docs items as done, which matches the changeset and docs edits in the summary.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: TanStack/ai
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 7fbfa5d
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9a5d2717-6f5b-48c7-967d-df6daf542f9d
Commits

Reviewing files that changed from the base of the PR and between c28f580 and 0027e8d.

Files selected for processing: 1

  • testing/e2e/src/routeTree.gen.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for the PR, @canblmz1! 🙌 @AlemTuzlak will take a look.

Automated pre-review checks

  • ✅ CI passing
  • ✅ No merge conflicts
  • ✅ Changeset present
  • ✅ E2E test changes included

Automated triage — a human review follows.

@github-actions github-actions Bot added the waiting-on: maintainer The ball is in the maintainers’ court label Nov 27, 2026
@nx-cloud

nx-cloud Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 0027e8d

Command Status Duration Result
nx run-many --targets=test:coverage --projects=... ✅ Succeeded 4s View ↗
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 12m 15s View ↗
nx run-many --targets=build --exclude=examples/... ✅ Succeeded 2m 42s View ↗

💡 With Ultracache enabled, Nx Cloud learns each task's file inputs in CI and uses them on later runs. Turn on Ultracache in workspace settings ↗ · Read docs ↗


☁️ Nx Cloud last updated this comment at 2026-11-30 09:49:31 UTC

@pkg-pr-new

pkg-pr-new Bot commented Nov 30, 2026

Copy link
Copy Markdown

Open in StackBlitz

@tanstack/ai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@2274

@tanstack/ai-acp

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-acp@2274

@tanstack/ai-angular

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-angular@2274

@tanstack/ai-anthropic

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@2274

@tanstack/ai-bedrock

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-bedrock@2274

@tanstack/ai-byteplus

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-byteplus@2274

@tanstack/ai-cartesia

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cartesia@2274

@tanstack/ai-claude-code

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-claude-code@2274

@tanstack/ai-client

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@2274

@tanstack/ai-cloudflare

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cloudflare@2274

@tanstack/ai-code-mode

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode@2274

@tanstack/ai-code-mode-snippets

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode-snippets@2274

@tanstack/ai-codex

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-codex@2274

@tanstack/ai-cohere

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-cohere@2274

@tanstack/ai-compaction

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-compaction@2274

@tanstack/ai-computer-local

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-computer-local@2274

@tanstack/ai-computer-playwright

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-computer-playwright@2274

@tanstack/ai-computer-sandbox

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-computer-sandbox@2274

@tanstack/ai-computer-use

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-computer-use@2274

@tanstack/ai-devtools-core

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@2274

@tanstack/ai-durable-stream

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-durable-stream@2274

@tanstack/ai-effect

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-effect@2274

@tanstack/ai-elevenlabs

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-elevenlabs@2274

@tanstack/ai-event-client

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-event-client@2274

@tanstack/ai-fal

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-fal@2274

@tanstack/ai-gemini

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@2274

@tanstack/ai-grok

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@2274

@tanstack/ai-grok-build

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok-build@2274

@tanstack/ai-groq

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-groq@2274

@tanstack/ai-harness

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-harness@2274

@tanstack/ai-harness-cli

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-harness-cli@2274

@tanstack/ai-isolate-cloudflare

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-cloudflare@2274

@tanstack/ai-isolate-daytona

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-daytona@2274

@tanstack/ai-isolate-e2b

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-e2b@2274

@tanstack/ai-isolate-node

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-node@2274

@tanstack/ai-isolate-quickjs

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs@2274

@tanstack/ai-isolate-quickjs-bun

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs-bun@2274

@tanstack/ai-llmgateway

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-llmgateway@2274

@tanstack/ai-lovable

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-lovable@2274

@tanstack/ai-mcp

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mcp@2274

@tanstack/ai-mcp-sandbox

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mcp-sandbox@2274

@tanstack/ai-memory

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-memory@2274

@tanstack/ai-meshy

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-meshy@2274

@tanstack/ai-mistral

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mistral@2274

@tanstack/ai-muse

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-muse@2274

@tanstack/ai-neon

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-neon@2274

@tanstack/ai-octane

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-octane@2274

@tanstack/ai-ollama

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@2274

@tanstack/ai-ollaya

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollaya@2274

@tanstack/ai-openai

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@2274

@tanstack/ai-opencode

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-opencode@2274

@tanstack/ai-openrouter

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@2274

@tanstack/ai-optimize

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-optimize@2274

@tanstack/ai-perplexity

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-perplexity@2274

@tanstack/ai-persistence

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-persistence@2274

@tanstack/ai-preact

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@2274

@tanstack/ai-react

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@2274

@tanstack/ai-reactor

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-reactor@2274

@tanstack/ai-remix

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-remix@2274

@tanstack/ai-sandbox

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox@2274

@tanstack/ai-sandbox-blaxel

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-blaxel@2274

@tanstack/ai-sandbox-boxd

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-boxd@2274

@tanstack/ai-sandbox-cloudflare

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-cloudflare@2274

@tanstack/ai-sandbox-daytona

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-daytona@2274

@tanstack/ai-sandbox-docker

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-docker@2274

@tanstack/ai-sandbox-e2b

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-e2b@2274

@tanstack/ai-sandbox-local-process

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-local-process@2274

@tanstack/ai-sandbox-railway

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-railway@2274

@tanstack/ai-sandbox-sprites

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-sprites@2274

@tanstack/ai-sandbox-upstash-box

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-upstash-box@2274

@tanstack/ai-sandbox-vercel

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-vercel@2274

@tanstack/ai-skills

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-skills@2274

@tanstack/ai-solid

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@2274

@tanstack/ai-svelte

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@2274

@tanstack/ai-tripo

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-tripo@2274

@tanstack/ai-typesafe

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-typesafe@2274

@tanstack/ai-uthana

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-uthana@2274

@tanstack/ai-utils

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-utils@2274

@tanstack/ai-vercel-compat

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vercel-compat@2274

@tanstack/ai-vercel-gateway

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vercel-gateway@2274

@tanstack/ai-vertex

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vertex@2274

@tanstack/ai-vue

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@2274

@tanstack/ai-worldlabs

npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-worldlabs@2274

@tanstack/openai-base

npm i https://pkg.pr.new/TanStack/ai/@tanstack/openai-base@2274

@tanstack/preact-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@2274

@tanstack/react-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@2274

@tanstack/solid-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@2274

@tanstack/svelte-ai-devtools

npm i https://pkg.pr.new/TanStack/ai/@tanstack/svelte-ai-devtools@2274

commit: 0027e8d

@AlemTuzlak
AlemTuzlak merged commit 53cbb4c into TanStack:main Nov 30, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-on: maintainer The ball is in the maintainers’ court

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants