Skip to content

Gemini CLI: NumericalClassifierStrategy routing errors flood agent logs #2403

@lpcox

Description

@lpcox

Problem

The Gemini CLI produces hundreds of NumericalClassifierStrategy failed errors during smoke test runs. In run #25258365325 (PR #2401), there were 252 occurrences of this error — over 60% of all errors in the agent step.

Error

Error generating content via API.
_ApiError: {"error":{"code":400,"message":"Please ensure that function response turn comes immediately after a function call turn.","status":"INVALID_ARGUMENT"}}
    at throwErrorIfNotOK (file:///opt/hostedtoolcache/node/24.14.1/x64/lib/node_modules/@google/gemini-cli/bundle/chunk-JS5WSGB2.js:35831:24)
[Routing] NumericalClassifierStrategy failed: Error: Failed to generate content: ...

Root Cause

The Gemini CLI uses a NumericalClassifierStrategy internally to route/classify responses. This classifier makes a separate API call to Gemini, but the conversation history at that point has a tool response (function response) that is not immediately preceded by the corresponding function call turn — violating the Gemini API's strict turn-ordering requirement.

This happens repeatedly (every ~5-10 seconds) throughout the agent session, generating hundreds of error log lines.

Impact

  • Log noise: 252 errors in a single run makes it hard to find real issues
  • Latency: Each failed API call adds ~3-5 seconds of wasted time
  • Run duration: The cumulative effect likely adds minutes to each Gemini smoke test run
  • The agent still completes — these errors are caught and retried internally, so the workflow succeeds despite the noise

Observed In

Possible Mitigations

  1. Upstream fix: Report to the Gemini CLI team — the NumericalClassifierStrategy should handle function response turns gracefully or skip classification when the conversation state would violate turn ordering
  2. Log filtering: Add a post-step that filters known Gemini routing errors from logs to reduce noise
  3. Retry budget: If the Gemini CLI supports configuration, limit the number of routing retries

Related

This is separate from the safe-output tool discovery issue where Gemini cannot find MCP tools like noop, add_comment, etc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions