fix(#3996): diagnose Gemini requests and sanitize API failures - #4017
Open
aheritier wants to merge 3 commits into
Open
fix(#3996): diagnose Gemini requests and sanitize API failures#4017aheritier wants to merge 3 commits into
aheritier wants to merge 3 commits into
Conversation
aheritier
force-pushed
the
gemini-request-diagnostics
branch
from
August 24, 2026 15:12
d0e681d to
fe025fe
Compare
aheritier
force-pushed
the
gemini-request-diagnostics
branch
from
August 25, 2026 20:24
fe025fe to
f931b11
Compare
aheritier
force-pushed
the
gemini-request-diagnostics
branch
2 times, most recently
from
September 1, 2026 16:20
54bf686 to
f931b11
Compare
aheritier
force-pushed
the
gemini-request-diagnostics
branch
from
September 1, 2026 16:29
f931b11 to
c17dfaf
Compare
aheritier
force-pushed
the
gemini-request-diagnostics
branch
from
September 6, 2026 16:14
c17dfaf to
f832743
Compare
aheritier
force-pushed
the
gemini-request-diagnostics
branch
from
September 7, 2026 11:34
f832743 to
a6d352d
Compare
aheritier
force-pushed
the
gemini-request-diagnostics
branch
from
September 7, 2026 16:25
a6d352d to
f75783e
Compare
aheritier
force-pushed
the
gemini-request-diagnostics
branch
from
September 7, 2026 16:47
f75783e to
deb255c
Compare
aheritier
force-pushed
the
gemini-request-diagnostics
branch
from
September 8, 2026 06:17
deb255c to
67d780d
Compare
aheritier
force-pushed
the
gemini-request-diagnostics
branch
from
September 8, 2026 07:57
67d780d to
b5dbfaa
Compare
aheritier
force-pushed
the
gemini-request-diagnostics
branch
from
September 8, 2026 17:31
b5dbfaa to
448e41a
Compare
aheritier
force-pushed
the
gemini-request-diagnostics
branch
from
September 8, 2026 20:32
448e41a to
2c5fd91
Compare
aheritier
marked this pull request as ready for review
September 8, 2026 20:38
Record Gemini request modalities, tool/config counts, structured-output presence, thinking options and transport category after building the request. Log NoThinking options to explain utility-call construction. Do not log prompts, tool schemas, media payloads or credentials. The summary omits content fields but does not validate arbitrary strings: modality, function-mode and API-surface values are supplied by the request builder. Tests cover constructed shapes, including empty config fields.
Add chat.SanitizeDisplayName and chat.TruncateUTF8Bytes with a 128-byte sanitized-field bound. Neutralize controls, path separators, traversal-like sequences and angle brackets before names enter display or prompt metadata. Preserve rune boundaries when truncating valid UTF-8 strings. Centralize the helpers so diagnostics and generated-media metadata can use the same boundary rules; test unsafe names and multibyte truncation.
Match genai.APIError by value so status errors reach the existing runtime error seam. Categorize 400s using fixed request-field keywords and general unsupported-feature phrases, with action hints for each category. Retain a bounded SDK Message alongside the hint for overflow, transient retry and authentication context. Redact recognizable credentials, collapse controls, and neutralize JSON-object delimiters before rendering it; never surface Details. Use chat.TruncateUTF8Bytes rather than another truncator. Preserve status-based retry behavior and test classification, redaction, bounding, multibyte text and JSON-envelope neutralization.
dgageot
force-pushed
the
gemini-request-diagnostics
branch
from
September 9, 2026 07:41
2c5fd91 to
8a71d76
Compare
dgageot
approved these changes
Sep 9, 2026
rumpl
approved these changes
Sep 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
Record Gemini request shape without prompt, schema, media-payload, or credential fields, and classify invalid arguments into bounded actionable categories. Keep sanitized SDK context while preserving the original cause for classification. Shared UTF-8 helpers bound display metadata. This PR adds diagnostics, not image-output request policy.
Part of #3996. Review this PR against its immediate parent, #4016, rather than the aggregate stack against
main.Commit inventory
Head:
2c5fd913464ef376471cc098b8e9481367f16b6a; parent SHA:309a95662d205a795722eae67a1b3c9d906f99bc.a8d51970aa6c3737d0573a1c5686d7aa754db34e— feat(Epic: Gemini image output with workspace deliverables and portable session copies #3996): capture request-shape diagnostics for image requests1cc2ffa077f613d2605441a2d010373a85113411— feat(Epic: Gemini image output with workspace deliverables and portable session copies #3996): add shared UTF-8-safe display-name sanitization helpers2c5fd913464ef376471cc098b8e9481367f16b6a— fix(Epic: Gemini image output with workspace deliverables and portable session copies #3996): classify Gemini API 400s into actionable categoriesValidation
Build, test compilation, owning-package tests and the named fixture passed at this PR head.
Exact deterministic fixture command:
Matched top-level tests:
pkg/model/provider/gemini: 14.Deterministic scope: the named local fixture exercises this PR boundary with disposable configuration/stores and fake or loopback providers as applicable. Every listed package ran nonzero matching top-level tests.
Deferred/live scope: Live provider, remote CI, and platform execution are not claimed by this deterministic receipt. The final stack head passed build, lint, full tests, an uncached full suite, focused race tests and documentation checks in disposable environments. Remote CI is tracked by the checks below; no new paid-provider or active-database validation was run.