fix: remove fallbacks key from gemini requests - #3464
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughNormalize raw Gemini generate-content requests for compatibility and remove the JSON "fallbacks" field in the core normalizer, and apply that normalization in VideoGeneration and BatchCreate; includes a utils update, types additions, and a regression test. ChangesGemini request body normalization and fallback field removal
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.12.2)level=error msg="[linters_context] typechecking error: pattern ./...: directory prefix . does not contain main module or its selected dependencies" Comment |
|
tejas ghatte seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
🧪 Test Suite AvailableThis PR can be tested by a repository admin. |
Confidence Score: 5/5The change is a targeted, low-risk fix with good test coverage; the core normalization logic is correct and the safety-net deletions are harmless no-ops when the field is already absent. All three changed code paths behave correctly. The two observations about Embedding() and GeminiEmbeddingRequest.Fallbacks are improvements outside the PR's stated scope and do not affect the correctness of the changes made here. The Embedding() function in gemini.go and the Fallbacks field tag on GeminiEmbeddingRequest in types.go are worth revisiting in a follow-up. Important Files Changed
Reviews (3): Last reviewed commit: "fix: remove fallbacks key from gemini re..." | Re-trigger Greptile |
c7a3125 to
e93bf8a
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
core/providers/gemini/gemini_test.go (1)
3163-3218: ⚡ Quick winAdd regression coverage for nested
generationConfig.fallbacks.Current cases verify top-level
fallbacksstripping, but notgenerationConfig.fallbacks. Adding this case prevents path-specific regressions.♻️ Proposed test case
@@ { + name: "StripsGenerationConfigFallbacksField", + input: `{"contents":[{"parts":[{"text":"Hi"}]}],"generationConfig":{"temperature":0.7,"fallbacks":["openai/gpt-4o"]}}`, + validate: func(t *testing.T, m map[string]interface{}) { + gc := genConfig(m) + require.NotNil(t, gc) + assert.NotContains(t, gc, "fallbacks") + assert.Contains(t, gc, "temperature") + }, + }, + { name: "StripsFallbacksAlongsideCompatFields", input: `{"contents":[{"parts":[{"text":"Hi"}]}],"fallbacks":["openai/gpt-4o"],"generationConfig":{"temperature":0.5,"presencePenalty":0.2}}`, validate: func(t *testing.T, m map[string]interface{}) { assert.NotContains(t, m, "fallbacks")🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@core/providers/gemini/gemini_test.go` around lines 3163 - 3218, Add a new table-driven test case in the tests slice that covers nested generationConfig.fallbacks: construct input JSON where "generationConfig" contains a "fallbacks" array (e.g. `{"generationConfig":{"temperature":0.6,"fallbacks":["openai/gpt-4o"]},"contents":[{"parts":[{"text":"Hi"}]}]}`), then in the validate func use genConfig(m) to get the nested map and assert that the nested "fallbacks" key is not present while other valid fields like "temperature" and top-level "contents" are preserved; place this alongside the other cases (e.g. near "StripsFallbacksAlongsideCompatFields") so it runs with the existing test harness.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@core/providers/gemini/gemini_test.go`:
- Around line 3163-3218: Add a new table-driven test case in the tests slice
that covers nested generationConfig.fallbacks: construct input JSON where
"generationConfig" contains a "fallbacks" array (e.g.
`{"generationConfig":{"temperature":0.6,"fallbacks":["openai/gpt-4o"]},"contents":[{"parts":[{"text":"Hi"}]}]}`),
then in the validate func use genConfig(m) to get the nested map and assert that
the nested "fallbacks" key is not present while other valid fields like
"temperature" and top-level "contents" are preserved; place this alongside the
other cases (e.g. near "StripsFallbacksAlongsideCompatFields") so it runs with
the existing test harness.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 85e1916c-2b9e-4ac4-9da3-2a9b6f0f0556
📒 Files selected for processing (3)
core/providers/gemini/gemini.gocore/providers/gemini/gemini_test.gocore/providers/gemini/utils.go
✅ Files skipped from review due to trivial changes (1)
- core/providers/gemini/utils.go
🚧 Files skipped from review as they are similar to previous changes (1)
- core/providers/gemini/gemini.go
e93bf8a to
81b1f91
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@core/providers/gemini/types.go`:
- Line 1169: The Fallbacks field is being serialized to outbound Gemini DTOs;
make it non-serializable by removing it from outbound structs or changing its
struct tag to prevent JSON marshaling (e.g., update the Fallbacks field
declaration in core/providers/gemini/types.go to use json:"-" so it is omitted
from JSON output). Locate the Fallbacks field in the relevant DTO definition and
either delete the field from the outbound DTO or replace its tag with json:"-"
(and any other relevant tags like yaml:"-"/protobuf omission if used) so it
cannot be forwarded accidentally.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5c8992dc-95c1-4cb2-a0f5-6dee409a621d
📒 Files selected for processing (4)
core/providers/gemini/gemini.gocore/providers/gemini/gemini_test.gocore/providers/gemini/types.gocore/providers/gemini/utils.go
🚧 Files skipped from review as they are similar to previous changes (3)
- core/providers/gemini/utils.go
- core/providers/gemini/gemini.go
- core/providers/gemini/gemini_test.go

Summary
Ensures the
fallbacksfield is stripped from request bodies sent to the Gemini provider, preventing unrecognized fields from being forwarded to the Gemini API. Also applies raw body normalization to theVideoGenerationendpoint and normalizes raw bodies inBatchCreatebefore further processing.Changes
normalizeRawGenerateContentBodynow unconditionally removes thefallbacksfield from the JSON body, regardless of whether raw body mode is active.VideoGenerationnow callsnormalizeRawGenerateContentBodybefore constructing the HTTP request, bringing it in line with other endpoints.BatchCreateappliesNormalizeRawGenerateContentRequestForCompatibilityto raw request bodies immediately upon extraction, and explicitly deletes thefallbacksfield from the finaljsonDatabefore sending.Type of change
Affected areas
How to test
Send a request to the Gemini
VideoGenerationorBatchCreateendpoints with afallbacksfield included in the request body and verify it is not forwarded to the Gemini API.go test ./...Breaking changes
Related issues
Security considerations
None.
Checklist
docs/contributing/README.mdand followed the guidelines