Repository navigation
Conversation
…l name
`pi --model agentgateway/gemini/gemini-4-neon` failed with an empty 404 while
the unlayered `agentgateway/gemini-4-neon` worked.
Resolve strips only the outer agentgateway/ wrapper, so a layered route reaches
the native Gemini client as `gemini/<id>`. The genai SDK pastes the model into
the URL path and escapes nothing (createAPIURL -> url.JoinPath), so the slash
split the request into an extra segment:
/v1beta/models/gemini/gemini-4-neon:generateContent -> 404, empty body
The gateway resolves a layered name on its OpenAI-compatible endpoint, where
the model is a JSON field, but not on the native one. Escaping the slash keeps
it one path segment and the gateway routes and strips it correctly:
/v1beta/models/gemini%2Fgemini-4-neon:... -> 200
Nothing in the 404 named the model or the slash, which is what makes this worth
fixing rather than documenting. Verified against the local gateway: the fixed
binary answers, the installed one still 404s.
The escape is applied per request on the wire, not to Name(). That string is
user-facing and reaches session metadata and the TUI label, so a %2F there
would be a second bug; ADK also rebuilds every request as
LLMRequest{Model: f.Model.Name()}, so escaping inside NewGemini alone would be
overwritten on the next turn. An unlayered id has no slash and is unchanged.
url.PathEscape rather than a slash replacement: it escapes exactly the
characters that would change the URL's structure and leaves colons, dashes and
dots in an id alone.
Signed-off-by: pi <dimetron@me.com>
dimetron
left a comment
There was a problem hiding this comment.
Reviewed git diff main...HEAD at ac85e83. One actionable P2 finding is attached inline.
Standards
The wrapper breaks ADK Gemini's supported request-model precedence, exposed through before-model callbacks. No additional actionable standards findings.
Spec
The same finding affects the promised per-request escaping: the constructor name is escaped instead of the effective request name. No additional spec findings.
Validation: go test ./internal/provider/ ./internal/agent/ -timeout 180s passed (1,785 tests). A temporary Go test overlay reproduced both override failures against an HTTP test server; the native Gemini control passed. Tracked files remain unchanged.
— Codex review
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #491 +/- ##
==========================================
- Coverage 92.21% 92.21% -0.01%
==========================================
Files 426 426
Lines 57744 57757 +13
==========================================
+ Hits 53251 53261 +10
- Misses 4487 4490 +3
Partials 6 6 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…onfigured name The wire-name wrapper wrote its configured model name into every request, which discarded a req.Model set by a BeforeModelCallback. The genai SDK honors that override, so an overridden call silently went to a different model than the caller asked for — a worse failure than the 404 this wrapper fixes, since the answer comes back from a model nobody requested. Escape the requested name instead, falling back to the configured one only when the request names none, which is the case the SDK itself falls back on. A layered request retargeted to a bare id now drops the escape, and a bare route retargeted to a layered id gains one. Found by Codex review on PR #491; reproduced against the pre-fix wrapper before fixing. Signed-off-by: pi <dimetron@me.com>
dimetron
left a comment
There was a problem hiding this comment.
Found one issue, and it is already fixed on the branch (416532b). Recording it here with the inline anchor so the finding and its resolution stay in one place.
req.Model override is discarded. gatewayGeminiWireName.GenerateContent wrote the configured model name into every request, ignoring a req.Model set by a BeforeModelCallback. The genai SDK honors that override (geminiModel.modelName prefers req.Model), so an overridden call would silently go to a different model than the caller asked for — worse than the 404 this wrapper fixes, because the answer comes back from a model nobody requested.
Reproduced against the pre-fix wrapper:
gateway=gemini/gemini-4-neon req.Model=gemini-3.8-flash -> /v1beta/models/gemini%2Fgemini-4-neon:generateContent
gateway=gemini-4-neon req.Model=gemini/gemini-3.8-flash -> /v1beta/models/gemini/gemini-3.8-flash:generateContent
Both paths are wrong: the first sends the original model despite the override, the second drops the escape the override needs.
Fixed by escaping the requested name, falling back to the configured one only when the request names none — the same fallback the SDK makes. TestAgentGatewayGeminiWireNameHonorsRequestOverride covers all three cases and fails on the pre-fix wrapper.
The rest of the change verified clean: the escaping itself is correct and confirmed against the live gateway (/v1beta/models/gemini%2Fgemini-4-neon:streamGenerateContent → 200), the guard asserts on r.URL.EscapedPath() for the right reason, and Name() is correctly left unescaped so the TUI and session metadata keep the name the user typed.
— Codex review
govulncheckScanner: No findings with an available fix. The gate passes. 9 findings are reported but do not fail, because no fixed version exists to upgrade to — all of them in The answer is only true for this database snapshot; the set will move as upstream cuts releases. |
The bug
pi --model agentgateway/gemini/gemini-4-neon "hi"failed with an empty 404, while the unlayeredagentgateway/gemini-4-neonworked:This also affects the shape the gateway's own
pi-fastfailover uses (gemini/gemini-3.8-flash).Root cause
Resolvestrips only the outeragentgateway/wrapper, so a layered route reaches the native Gemini client asgemini/<id>. The genai SDK pastes the model into the URL path and escapes nothing (createAPIURL→url.JoinPath), so the slash splits the request into an extra segment:The gateway resolves a layered name on its OpenAI-compatible endpoint, where the model is a JSON field, but not on the native one. The native path is required — it exists so Gemini's server-side
google_searchtool is not silently dropped — so switching endpoints is not a fix.A genuine unknown model returns a JSON
NOT_FOUNDnaming the model; this 404 hadcontent-length: 0. Nothing in it named the model or the slash, which is what makes it worth fixing rather than documenting.The fix
url.PathEscapethe model name per request, on the wire only. Two deliberate choices:Name(). That string is user-facing and reaches session metadata (SetSessionModel) and the TUI model label; a%2Fthere would be a second, cosmetic bug.NewGemini. ADK rebuilds every request asLLMRequest{Model: f.Model.Name()}(base_flow.go:430,793), so escaping at construction would be overwritten on the next turn. The request value is copied, not mutated, because the same pointer feeds tracing hooks.url.PathEscaperather than a slash replacement: it escapes exactly the characters that would change the URL's structure (/ ? #) and leaves colons, dashes and dots in an id alone. An unlayered id has no slash and is byte-for-byte unchanged, so this is a no-op for the common case.Verification
The regression test asserts on
r.URL.EscapedPath(), notr.URL.Path— the distinction is the bug, since Go's URL decodes%2Fback to/inPath, so a test readingPathcannot tell the two requests apart. It fails on the unfixed code with the exact bad path, and passes with the fix.End to end against the local gateway, the gateway's own log:
go build ./...— cleango test ./internal/provider/ ./internal/agent/— passgo testover all 69 remaining packages — pass, 0 failuresmake vet— cleanmake lint— 0 issuesinternal/clihangs in this environment, on unmodifiedmainas well (300s timeout, blocked reading/dev/tty); it is excluded from the run above and is unrelated to this change.Note on the gateway
This fixes the pi-go side. The gateway still does not strip a provider prefix on the native
generateContentpath the way it does for/v1/chat/completions, so any other client sending a layered name unescaped will hit the same empty 404.