Skip to content
Source
Sign inSign up
TanStack/ai

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

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

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

🎯 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.
    1. 🦋 Changeset detected

      Latest commit: 97dd734d2aa73d4ffe72bddd89fec094ef9fd0ff

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

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

      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 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 nameStatusExplanation
      Title checkPassedThe 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 checkPassedThe 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 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 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 840ea56621f4c32de4359849a0beaa343db60fe3 and 97dd734d2aa73d4ffe72bddd89fec094ef9fd0ff.

      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.

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

Sign in to join this conversation.