fix(ai): apply max_tokens to Gemini requests #3567
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
pcbeingused333
what
gemini.Clientnow sendsai.providers.gemini.max_tokensasgenerationConfig.maxOutputTokenson every request.SendMessageandSendMessageWithHistorypassed anilconfig, and the two tool-calling methods only setTools, so the limit was read intoConfig.MaxTokensandGetMaxTokens()but never used.generateContentConfig, used by all four send methods. Amax_tokensof zero leaves the model default.TestClient_SendsConfiguredMaxTokensruns each send method against anhttptestserver and checks the request body.why
max_tokensfor the Gemini provider had no effect, unlike the Anthropic and OpenAI clients, which passMaxTokenson each request. A smaller limit could not be used to cap output, and a larger one did not raise it.8192(DefaultMaxTokens, also shown in the docs' Gemini example) now applies whenmax_tokensis not set. Before, requests ran with the model's own output limit, so a deployment that relied on answers longer than 8192 tokens without configuringmax_tokensshould set it explicitly.references
mainfor all four send methods (maxOutputTokensmissing from the request) and passes with the change.go test ./pkg/ai/agent/gemini/passes (golang:1.27.3);gofmt -lis clean.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 -->