Skip to content

fix(#3996): diagnose Gemini requests and sanitize API failures - #4017

Open
aheritier wants to merge 3 commits into
mainfrom
gemini-request-diagnostics
Open

fix(#3996): diagnose Gemini requests and sanitize API failures#4017
aheritier wants to merge 3 commits into
mainfrom
gemini-request-diagnostics

Conversation

@aheritier

@aheritier aheritier commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

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.

Validation

Build, test compilation, owning-package tests and the named fixture passed at this PR head.

Exact deterministic fixture command:

go test -v -count=1 ./pkg/model/provider/gemini -run 'TestNewRequestShape|TestRequestShape_LogAttrsNeverLeaksToolSchemas|TestWrapGeminiError'

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.

@aheritier aheritier added area/providers/gemini Google Gemini provider support area/testing Test infrastructure, CI/CD, test runners, evaluation kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Aug 22, 2026
@aheritier
aheritier force-pushed the gemini-request-diagnostics branch from d0e681d to fe025fe Compare August 24, 2026 15:12
@aheritier
aheritier force-pushed the gemini-request-diagnostics branch from fe025fe to f931b11 Compare August 25, 2026 20:24
@aheritier
aheritier force-pushed the gemini-request-diagnostics branch 2 times, most recently from 54bf686 to f931b11 Compare September 1, 2026 16:20
@aheritier
aheritier force-pushed the gemini-request-diagnostics branch from f931b11 to c17dfaf Compare September 1, 2026 16:29
aheritier

This comment was marked as resolved.

@aheritier
aheritier force-pushed the gemini-request-diagnostics branch from c17dfaf to f832743 Compare September 6, 2026 16:14
@aheritier
aheritier force-pushed the gemini-request-diagnostics branch from f832743 to a6d352d Compare September 7, 2026 11:34
@aheritier
aheritier force-pushed the gemini-request-diagnostics branch from a6d352d to f75783e Compare September 7, 2026 16:25
@aheritier
aheritier force-pushed the gemini-request-diagnostics branch from f75783e to deb255c Compare September 7, 2026 16:47
@aheritier
aheritier force-pushed the gemini-request-diagnostics branch from deb255c to 67d780d Compare September 8, 2026 06:17
@aheritier
aheritier force-pushed the gemini-request-diagnostics branch from 67d780d to b5dbfaa Compare September 8, 2026 07:57
@aheritier
aheritier force-pushed the gemini-request-diagnostics branch from b5dbfaa to 448e41a Compare September 8, 2026 17:31
@aheritier
aheritier force-pushed the gemini-request-diagnostics branch from 448e41a to 2c5fd91 Compare September 8, 2026 20:32
@aheritier aheritier changed the title fix(#3996): classify Gemini API 400s into safe, actionable categories fix(#3996): diagnose Gemini requests and sanitize API failures Sep 8, 2026
@aheritier
aheritier marked this pull request as ready for review September 8, 2026 20:38
@aheritier
aheritier requested a review from a team as a code owner September 8, 2026 20:38
Base automatically changed from media-input-modalities to main September 9, 2026 07:41
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
dgageot force-pushed the gemini-request-diagnostics branch from 2c5fd91 to 8a71d76 Compare September 9, 2026 07:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/providers/gemini Google Gemini provider support area/testing Test infrastructure, CI/CD, test runners, evaluation kind/fix PR fixes a bug (maps to fix:). Use on PRs only.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants