fix(ai-openrouter): ignore Responses argument deltas after TOOL_CALL_END #2304
main fromrefs/pull/2304/head·opened View on GitHub🎯 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 endedinopenrouter-responses-adapter.test.tschecks the call's events are exactlySTART,ARGS,ENDand thatENDkeeps{ location: 'Berlin' }. It fails onmain;@tanstack/ai-openrouter: 425 passed. - E2E:
openrouter-responses-late-args-delta-wirestreams aget_weathercall throughcreateOpenRouterResponsesText(anHTTPClientfetcher), then one more}delta afterfunction_call_arguments.doneor afteroutput_item.done. It records the call's events fromchat(). Onmainboth cases endSTART, ARGS, END, ARGS; with this changeSTART, 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 fulltest: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
tanstack-source added labelsbug
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.mdThe 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.tsThe 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 toa109a-
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:
4-
Check name Status Explanation Title check 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, … Description check 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 befo…Linked Issues check Check skipped because no linked issues were found for this pull request. Out of Scope Changes check Check 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.
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.mdpackages/ai-openrouter/src/adapters/responses-text.tspackages/ai-openrouter/tests/openrouter-responses-adapter.test.tstesting/e2e/src/routeTree.gen.tstesting/e2e/src/routes/api.openrouter-responses-late-args-delta-wire.tstesting/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.
-
-
github-actions[bot](GitHub profile, opens in a new tab) assignedtombeckenham
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
github-actions[bot](GitHub profile, opens in a new tab) added labelswaiting-on: maintainer
Sign in to join this conversation.
🦋 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
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