← Back to Pull requests

fix(ai): apply max_tokens to Gemini requests #3567

Closed
unknown closed this pull request without merging on Nov 05, 2026 01:13 UTC
View on GitHub
unknown unknown commented on Oct 29, 2026 01:58 UTC
Author

what

  • gemini.Client now sends ai.providers.gemini.max_tokens as generationConfig.maxOutputTokens on every request. SendMessage and SendMessageWithHistory passed a nil config, and the two tool-calling methods only set Tools, so the limit was read into Config.MaxTokens and GetMaxTokens() but never used.

  • The request config is built in one helper, generateContentConfig, used by all four send methods. A max_tokens of zero leaves the model default.

  • New test TestClient_SendsConfiguredMaxTokens runs each send method against an httptest server and checks the request body.
  • why

  • Setting max_tokens for the Gemini provider had no effect, unlike the Anthropic and OpenAI clients, which pass MaxTokens on each request. A smaller limit could not be used to cap output, and a larger one did not raise it.

  • Note on behavior: the provider's documented default of 8192 (DefaultMaxTokens, also shown in the docs' Gemini example) now applies when max_tokens is not set. Before, requests ran with the model's own output limit, so a deployment that relied on answers longer than 8192 tokens without configuring max_tokens should set it explicitly.
  • references

  • The new test fails on main for all four send methods (maxOutputTokens missing from the request) and passes with the change. go test ./pkg/ai/agent/gemini/ passes (golang:1.27.3); gofmt -l is clean.

  • Not run against the live Gemini API.
  • This change was made with Claude Code; the tests above were run before opening the PR.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    Improvements
    Configured output token limits now apply consistently to messages sent with or without tools, including conversation history.
    When no positive limit is configured, the model’s default output limit is used.
    Limits above the supported maximum are capped, preventing an excessively high configured value from being sent.
    * Tool-enabled requests continue to include tool information, while requests without tools remain tool-free.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 276 lines (+207 / -69) across 3 files Reviewer: pcbeingused333 Review duration: 10034m
    All Vouch review confidence checks passed
    Residual risk 0.29 = Change Risk (0.68) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.68 · 276 lines diff across 3 files
    0.68
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.336
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.068
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #3567"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 67.8% (HIGH) · Higher = larger blast radius
    67.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.3% · Safe to merge
    29.3%