Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai-openrouter): ignore Responses argument deltas after TOOL_CALL_END #2304

Opencanblmz1(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/2304/headopened View on GitHub

canblmz1(GitHub profile, opens in a new tab)commented

🎯 Changes

The follow-up I mentioned in #2264: the OpenRouter Responses adapter has the same gap. Its response.function_call_arguments.delta handler only checked metadata.started, so a delta for a call already closed by function_call_arguments.done or the output_item.done backstop was emitted as TOOL_CALL_ARGS after TOOL_CALL_END. Core ignores such events since #2274, but clients still receive them.

The handler now drops a delta for an ended call and logs it through logger.errors, with the same wording as openai-base's Responses adapter.

  • Unit: drops an arguments delta that arrives after the call ended in openrouter-responses-adapter.test.ts checks the call's events are exactly START, ARGS, END and that END keeps { location: 'Berlin' }. It fails on main; @tanstack/ai-openrouter: 425 passed.
  • E2E: openrouter-responses-late-args-delta-wire streams a get_weather call through createOpenRouterResponsesText (an HTTPClient fetcher), then one more } delta after function_call_arguments.done or after output_item.done. It records the call's events from chat(). On main both cases end START, ARGS, END, ARGS; with this change START, ARGS, END, and the tool runs once with { city: 'Paris' }.

Verified locally: the package's vitest run, oxfmt --check, oxlint (no new findings), and the new route against the e2e dev server with and without the change. I did not run the full pnpm run test:pr.

The fix and tests were written with AI assistance (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
    • Fixed an issue where late function-argument updates could be emitted after a tool call had completed. These updates are now ignored, preventing duplicate tool-call events and changes to finalized inputs.
  • Tests
    • Added coverage for late argument updates following either supported tool-call completion event.
    1. 🦋 Changeset detected

      Latest commit: a109a7643c08133e7dfdd47312d2fe444fddeac8

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

      This PR includes changesets to release 1 package
      NameType
      @tanstack/ai-openrouterPatch

      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

    2. tanstack-source added labelsbug

    3. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Explain Change →

      No actionable comments were generated in the recent review.

      Walkthrough

      The OpenRouter Responses adapter now ignores and logs function-argument deltas received after a tool call ends. Unit and end-to-end tests cover late deltas after two types of completion event.

      Changes: Late argument delta handling

      Layer / File(s)Summary
      Guard late deltas and verify adapter events
      packages/ai-openrouter/src/adapters/responses-text.ts, packages/ai-openrouter/tests/openrouter-responses-adapter.test.ts, .changeset/openrouter-responses-late-args-delta.md
      The adapter logs and skips argument deltas after a tool call ends. A regression test checks the event sequence and completed input. The changeset records the patch.
      Exercise late deltas through the end-to-end route
      testing/e2e/src/routes/api.openrouter-responses-late-args-delta-wire.ts, testing/e2e/src/routeTree.gen.ts, testing/e2e/tests/openrouter-responses-late-args-delta-wire.spec.ts
      The test route simulates late deltas after either completion event. The generated route tree registers the route, and the end-to-end test checks tool events, executed input, request count, and text.

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

      Change: Bug fix

      Suggested reviewers: alemtuzlak, tombeckenham, pcbeingused33

      Merge Risk: Minimal · up to a109a

      This change stops late function-argument deltas from reaching consumers after a tool call ends. It is narrowly scoped and covered by unit and end-to-end tests, so merge risk is minimal.

      Pre-merge checks: Passed 4

      Check nameStatusExplanation
      Title checkPassedThe title names the actual change: the OpenRouter Responses adapter now ignores argument deltas that arrive after TOOL_CALL_END. The changeset, the adapter change in responses-text.ts, the unit test, …
      Description checkPassedThe description follows the template. It explains the change and its reason, and it links the follow-up to #2264. It gives concrete test evidence, including the unit test name, the e2e route, the befo…
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Title check

      Explanation

      The title names the actual change: the OpenRouter Responses adapter now ignores argument deltas that arrive after TOOL_CALL_END. The changeset, the adapter change in responses-text.ts, the unit test, and the e2e route all match this scope. The title follows the conventional commit form and is specific enough for a teammate scanning history.

      Full details: Description check

      Explanation

      The description follows the template. It explains the change and its reason, and it links the follow-up to #2264. It gives concrete test evidence, including the unit test name, the e2e route, the before and after results on main, and the commands run. The checklist is filled in. The author states that the full pnpm run test:pr was not run, and the checklist marks that item as unchecked with a reason. The changeset is present per the raw summary. The description is complete enough to pass.

      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: 840ea56
      • Layers: Repository YAML
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 718da6d0-bca1-4e43-bee8-a75f6411f0b1
      Commits

      Reviewing files that changed from the base of the PR and between 840ea56621f4c32de4359849a0beaa343db60fe3 and a109a7643c08133e7dfdd47312d2fe444fddeac8.

      Files selected for processing: 6

      • .changeset/openrouter-responses-late-args-delta.md
      • packages/ai-openrouter/src/adapters/responses-text.ts
      • packages/ai-openrouter/tests/openrouter-responses-adapter.test.ts
      • testing/e2e/src/routeTree.gen.ts
      • testing/e2e/src/routes/api.openrouter-responses-late-args-delta-wire.ts
      • testing/e2e/tests/openrouter-responses-late-args-delta-wire.spec.ts

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

    4. 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.
    5. github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer

Sign in to join this conversation.