Skip to content
Source
Sign inSign up
TanStack/ai

fix(ai-gemini): end MALFORMED_FUNCTION_CALL and LANGUAGE finishes with RUN_ERROR #2234

Mergedpcbeingused33(GitHub profile, opens in a new tab)merged 3 commits intomain fromrefs/pull/2234/headmerged by AlemTuzlak View on GitHub

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

🎯 Changes

Follows #2183, which did the same for Mistral.

The Gemini text adapter ended every finish reason other than MAX_TOKENS and the content-filter set as RUN_FINISHED with stop. When Gemini finishes a turn with MALFORMED_FUNCTION_CALL (it could not form the function call) or LANGUAGE (unsupported language), the chunk has no text and no tool call. The run then looks like a normal stop, and an agent loop ends with no output and no error.

These two finish reasons now end the run with a RUN_ERROR (codes malformed_function_call and language). The error carries usage and no RUN_FINISHED follows, the same way MAX_TOKENS already works and like the Mistral adapter handles its error finish reason. OTHER stays a normal stop, as the existing test requires. docs/adapters/gemini.md lists the two new codes next to max_tokens.

Test plan

The @tanstack/ai-gemini vitest suite (68 tests) passes with the change; the full pnpm run test:pr was not run. It includes the new parameterized test in tests/gemini-adapter.test.ts. It streams a chunk with each finish reason and checks for a RUN_ERROR with the right code and usage, and no RUN_FINISHED. Both cases fail without the change in src/adapters/text.ts.

✅ 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.
  • 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).

This pull request was prepared with the assistance of an AI agent (Claude).

Summary by CodeRabbit

  • Bug Fixes
    • Gemini responses ending with MALFORMED_FUNCTION_CALL or LANGUAGE now report an error instead of indicating successful completion. The error includes usage information and a reason-specific code.
    1. Pushed2c7c051

    2. Pushed4e5da6e

    3. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit 4e5da6ecd816d82c85a653490378d071a3ba0b9d

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded3m 8sView ↗
      nx run-many --targets=build --exclude=examples/...✅ Succeeded15sView ↗
      nx run-many --targets=test:coverage --projects=...✅ Succeeded3sView ↗

      💡 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 09:19:40 UTC

    4. AlemTuzlak approved these changes

    5. AlemTuzlak merged thisc374f07

    6. AlemTuzlak closed this

Sign in to join this conversation.