Skip to content

fix(ai-mistral): ignore argument deltas after TOOL_CALL_END - #2303

Open
canblmz1 wants to merge 1 commit into
TanStack:mainfrom
canblmz1:fix/mistral-args-after-end
Open

canblmz1 wants to merge 1 commit into
TanStack:mainfrom
canblmz1:fix/mistral-args-after-end

Conversation

@canblmz1

@canblmz1 canblmz1 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Changes

The Mistral adapter emitted TOOL_CALL_ARGS for a tool call it had already closed. When a chunk with finish_reason: "tool_calls" ends a call (TOOL_CALL_END, ended = true) and a later chunk carries an arguments delta for the same index, the argsDelta !== undefined && toolCall.started branch never checked ended. Core ignores such events since #2274, but they still reach clients as TOOL_CALL_ARGS after TOOL_CALL_END.

The adapter now drops an arguments delta for a call that has ended and logs it through logger.errors, the same as the openai-base Responses adapter since #2264.

  • Unit: a new case in mistral-adapter.test.ts closes a call with finish_reason: "tool_calls", then sends a late } delta, and checks the call's events are exactly START, ARGS, END, that END keeps {"city":"Paris"}, and that the error is logged. It fails on main (an extra TOOL_CALL_ARGS); @tanstack/ai-mistral: 146 passed.
  • E2E: late-tool-args-wire gets a mistral case that drives createMistralText through wrapFetch with the same stream, next to the existing fake case. The fake case still sees the late delta on the client; the mistral case must not, and the tool part ends complete with the original input.
  • Docs: one sentence in docs/adapters/mistral.md.

Verified locally: the package's vitest run and typecheck, oxfmt --check, oxlint, and both Playwright cases of the spec. 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
    • Mistral now ignores and logs tool-call argument updates that arrive after a tool call has ended, preventing late data from changing or re-emitting the completed call.
  • Tests
    • Added coverage confirming completed tool calls retain their arguments and results when late updates arrive.

A Mistral stream that sent an arguments delta for a tool call after its
finish_reason had closed it reached consumers as TOOL_CALL_ARGS after
TOOL_CALL_END. Drop such deltas and log them, as openai-base's Responses
adapter does since TanStack#2264.

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

changeset-bot Bot commented Dec 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 97dd734

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

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

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Mistral adapter now logs and ignores tool argument deltas received after TOOL_CALL_END. Unit and end-to-end tests cover the behavior, and the adapter documentation and changeset describe it.

Changes: Mistral late tool argument handling

Layer / File(s) Summary
Ignore late argument deltas
packages/ai-mistral/src/adapters/text.ts, packages/ai-mistral/tests/mistral-adapter.test.ts, docs/adapters/mistral.md, .changeset/mistral-late-tool-arguments.md
The adapter logs and skips argument deltas for ended tool calls. The unit test checks emitted events, raw arguments, and the warning. The documentation and changeset describe the behavior.
End-to-end provider coverage
testing/e2e/src/routes/api.late-tool-args-wire.ts, testing/e2e/tests/late-tool-args-wire.spec.ts
The route supplies a late argument fragment for Mistral. The test checks the completed tool call for both Mistral and the fake provider.

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

Change: Bug fix

Possibly related PRs

  • TanStack/ai#2274: The core stream layer already ignores tool argument events after TOOL_CALL_END, and this change applies corresponding handling in the Mistral adapter.

Suggested reviewers: alemtuzlak, tombeckenham, cstrnt

Merge Risk: Minimal · up to 97dd7

The Mistral adapter now ignores late tool-argument fragments after a tool call ends, so clients no longer see arguments after the end event. The change is small and has unit and end-to-end tests, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the package (ai-mistral) and the specific fix: the adapter now ignores argument deltas that arrive after TOOL_CALL_END. The raw summary confirms the text.ts change, the test, and the c…
Description check Passed The description follows the template sections: Changes, Checklist, and Release Impact. It explains the root cause (the args branch never checked ended), the fix (drop and log late deltas via logger.er…
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 package (ai-mistral) and the specific fix: the adapter now ignores argument deltas that arrive after TOOL_CALL_END. The raw summary confirms the text.ts change, the test, and the changeset all match this main change. It uses the conventional fix(scope) form and is 59 characters.

Full details: Description check

Explanation

The description follows the template sections: Changes, Checklist, and Release Impact. It explains the root cause (the args branch never checked ended), the fix (drop and log late deltas via logger.errors), the unit test, the E2E mistral case, and the docs sentence. Verification steps are listed. The checklist marks the full test:pr run as unchecked and explains why. Changeset and docs boxes are checked, and the raw summary confirms both files exist.

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: d3b4245a-df5c-40dc-b00b-69bb0edf0c48
Commits

Reviewing files that changed from the base of the PR and between 840ea56 and 97dd734.

Files selected for processing: 6

  • .changeset/mistral-late-tool-arguments.md
  • docs/adapters/mistral.md
  • packages/ai-mistral/src/adapters/text.ts
  • packages/ai-mistral/tests/mistral-adapter.test.ts
  • testing/e2e/src/routes/api.late-tool-args-wire.ts
  • testing/e2e/tests/late-tool-args-wire.spec.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
github-actions Bot requested a review from jherr December 2, 2026 02:35
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR, @canblmz1! 🙌 @jherr 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 Dec 2, 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.

2 participants