Skip to content

fix(openai-base): ignore arguments deltas after a tool call ended - #2264

Merged
AlemTuzlak merged 3 commits into
TanStack:mainfrom
canblmz1:fix/openai-responses-late-args-delta
Nov 30, 2026
Merged

AlemTuzlak merged 3 commits into
TanStack:mainfrom
canblmz1:fix/openai-responses-late-args-delta

Conversation

@canblmz1

@canblmz1 canblmz1 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Changes

In the OpenAI Responses adapter (@tanstack/openai-base), a response.function_call_arguments.delta that arrives after the call has already ended, via response.function_call_arguments.done or the response.output_item.done backstop, was still emitted as TOOL_CALL_ARGS after TOOL_CALL_END. Core appends it to the finalized arguments, so {"city":"Paris"} plus a late } fails to parse and the tool never runs (Failed to parse tool arguments as JSON).

The delta handler already guards metadata.started (no ARGS before START). This adds the matching metadata.ended guard (no ARGS after END) and logs the dropped delta through logger.errors, like the existing orphan-delta branch. The .done handler already skips on metadata.ended, so the two now agree.

  • Unit: a parameterized case for both completion events. The pre-completion delta still streams, exactly one END carries the final arguments, no ARGS follows END, and the drop is logged once. It fails on main and passes here.
  • E2E: openai-late-args-delta-wire replays the raw SSE through createOpenaiChat and asserts that the server tool runs once with { city: 'Paris' }. On main, both cases fail with the parse error above.
  • Docs: not updated. No public API or documented behavior changes; this only stops an invalid ARGS-after-END event.

Not in this PR: @tanstack/ai-openrouter's Responses adapter has the same delta handler. I can send the same guard there separately if you'd like.

Verified locally: @tanstack/openai-base test:lib (508 passed), test:types and test:oxlint (no new warnings); @tanstack/ai-e2e test:types; the new Playwright spec (2 passed; both fail without the fix); oxfmt --check. I did not run the full pnpm run test:pr.

The fix and tests were written with AI assistance (Claude, reviewed with Codex and Antigravity); 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
    • Late-arriving tool-call argument updates are now ignored after the call has completed. They no longer change the completed input or generate additional argument updates.
    • Completed tool calls and their results remain consistent when streamed events arrive after completion, whether the call completes through either supported completion event.
    • Late updates are logged for troubleshooting without affecting the completed call or its results.

A response.function_call_arguments.delta that arrived after
function_call_arguments.done or output_item.done was emitted as
TOOL_CALL_ARGS after TOOL_CALL_END, so it was appended to the finalized
arguments and the tool failed to parse them. Drop and log it instead.

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

changeset-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 57589cd

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

This PR includes changesets to release 1 package
Name Type
@tanstack/openai-base 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 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Responses adapter now logs and ignores function-argument deltas that arrive after a tool call ends. Unit and end-to-end tests cover both completion events and verify the tool input and subsequent response.

Changes: Late argument delta handling

Layer / File(s) Summary
Guard ended tool calls
packages/openai-base/src/adapters/responses-text.ts, packages/openai-base/tests/responses-text.test.ts, .changeset/openai-responses-late-args-delta.md
The adapter logs and drops argument deltas when the tracked call has ended. Parameterized tests cover both completion events and check that no argument event follows TOOL_CALL_END. The changeset declares a patch for @tanstack/openai-base.
Exercise the streamed chat flow
testing/e2e/src/routes/api.openai-late-args-delta-wire.ts, testing/e2e/src/routeTree.gen.ts, testing/e2e/tests/openai-late-args-delta-wire.spec.ts
The test route streams a completed tool call followed by a late delta, then returns a mocked text response. Route registration and end-to-end tests cover both completion modes.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Possibly related PRs

  • TanStack/ai#2274: Adds a guard in the core tool-call manager and stream processor for late TOOL_CALL_ARGS, covering adapters and custom streams.

Suggested reviewers: alemtuzlak

Merge Risk: Minimal · up to 57589

The change makes the OpenAI Responses adapter ignore and log function-argument deltas that arrive after a tool call has ended. This should prevent argument-parse failures that kept the tool from running. Unit and end-to-end tests cover both completion orders, and no merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the scope (openai-base) and the main behavior change: arguments deltas that arrive after a tool call ended are now ignored. The changeset, adapter code, and tests all match this change…
Description check Passed The description follows the template sections: Changes, Checklist, and Release Impact. It explains the root cause, the guard added, the logging behavior, and the unit and E2E tests. It also lists the …
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 scope (openai-base) and the main behavior change: arguments deltas that arrive after a tool call ended are now ignored. The changeset, adapter code, and tests all match this change. It is short, specific, and follows the conventional commit style.

Full details: Description check

Explanation

The description follows the template sections: Changes, Checklist, and Release Impact. It explains the root cause, the guard added, the logging behavior, and the unit and E2E tests. It also lists the verification commands that ran and the one that did not. The one unchecked item (full test:pr) is explicitly explained. The Docs checkbox is marked as not user-facing, with a reason given. The description is complete enough for review.

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: 53cbb4c
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 81aefa74-8550-4f1c-9627-72338a5317d2
Commits

Reviewing files that changed from the base of the PR and between ea64829 and 57589cd.

Files selected for processing: 2

  • packages/openai-base/src/adapters/responses-text.ts
  • 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! 🙌 @tombeckenham 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 26, 2026
@nx-cloud

nx-cloud Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 57589cd

Command Status Duration Result
nx run-many --targets=build --exclude=examples/... ✅ Succeeded 3m 4s 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 10:58:41 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@2264

@tanstack/ai-acp

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

@tanstack/ai-angular

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

@tanstack/ai-anthropic

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

@tanstack/ai-bedrock

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

@tanstack/ai-byteplus

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

@tanstack/ai-cartesia

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

@tanstack/ai-claude-code

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

@tanstack/ai-client

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

@tanstack/ai-cloudflare

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

@tanstack/ai-code-mode

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

@tanstack/ai-code-mode-snippets

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

@tanstack/ai-codex

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

@tanstack/ai-cohere

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

@tanstack/ai-compaction

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

@tanstack/ai-computer-local

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

@tanstack/ai-computer-playwright

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

@tanstack/ai-computer-sandbox

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

@tanstack/ai-computer-use

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

@tanstack/ai-devtools-core

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

@tanstack/ai-durable-stream

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

@tanstack/ai-effect

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

@tanstack/ai-elevenlabs

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

@tanstack/ai-event-client

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

@tanstack/ai-fal

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

@tanstack/ai-gemini

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

@tanstack/ai-grok

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

@tanstack/ai-grok-build

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

@tanstack/ai-groq

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

@tanstack/ai-harness

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

@tanstack/ai-harness-cli

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

@tanstack/ai-isolate-cloudflare

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

@tanstack/ai-isolate-daytona

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

@tanstack/ai-isolate-e2b

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

@tanstack/ai-isolate-node

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

@tanstack/ai-isolate-quickjs

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

@tanstack/ai-isolate-quickjs-bun

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

@tanstack/ai-llmgateway

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

@tanstack/ai-lovable

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

@tanstack/ai-mcp

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

@tanstack/ai-mcp-sandbox

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

@tanstack/ai-memory

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

@tanstack/ai-meshy

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

@tanstack/ai-mistral

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

@tanstack/ai-muse

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

@tanstack/ai-neon

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

@tanstack/ai-octane

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

@tanstack/ai-ollama

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

@tanstack/ai-ollaya

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

@tanstack/ai-openai

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

@tanstack/ai-opencode

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

@tanstack/ai-openrouter

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

@tanstack/ai-optimize

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

@tanstack/ai-perplexity

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

@tanstack/ai-persistence

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

@tanstack/ai-preact

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

@tanstack/ai-react

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

@tanstack/ai-reactor

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

@tanstack/ai-remix

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

@tanstack/ai-sandbox

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

@tanstack/ai-sandbox-blaxel

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

@tanstack/ai-sandbox-boxd

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

@tanstack/ai-sandbox-cloudflare

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

@tanstack/ai-sandbox-daytona

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

@tanstack/ai-sandbox-docker

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

@tanstack/ai-sandbox-e2b

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

@tanstack/ai-sandbox-local-process

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

@tanstack/ai-sandbox-railway

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

@tanstack/ai-sandbox-sprites

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

@tanstack/ai-sandbox-upstash-box

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

@tanstack/ai-sandbox-vercel

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

@tanstack/ai-skills

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

@tanstack/ai-solid

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

@tanstack/ai-svelte

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

@tanstack/ai-tripo

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

@tanstack/ai-typesafe

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

@tanstack/ai-uthana

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

@tanstack/ai-utils

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

@tanstack/ai-vercel-compat

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

@tanstack/ai-vercel-gateway

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

@tanstack/ai-vertex

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

@tanstack/ai-vue

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

@tanstack/ai-worldlabs

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

@tanstack/openai-base

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

@tanstack/preact-ai-devtools

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

@tanstack/react-ai-devtools

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

@tanstack/solid-ai-devtools

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

@tanstack/svelte-ai-devtools

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

commit: 57589cd

@AlemTuzlak
AlemTuzlak merged commit ba37c63 into TanStack:main Nov 30, 2026
15 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 30, 2026
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.

3 participants