Skip to content

feat: support native Gemini GenerateContent - #3

Merged
etwk merged 2 commits into
mainfrom
feat/gemini-protocol
Oct 18, 2026
Merged

etwk merged 2 commits into
mainfrom
feat/gemini-protocol

Conversation

@etwk

@etwk etwk commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add native Gemini generateContent, countTokens, and transactional SSE streamGenerateContent?alt=sse, including standard Vertex AI project/location paths.
  • Preserve native payloads, tool calls, thought signatures, authentication, and trailing usage. Buffer through clean EOF and candidate completion; abort failed committed transports without replay.
  • Add independent PROXY_GEMINI_BUFFER_MS configuration (default 600000 ms), Google-shaped errors, API-key archive redaction, regression coverage, and setup/operations documentation.
  • Report explicit Gemini thinkingLevel values in access and retry logs, accepting camelCase and snake_case fields. Do not infer levels from token budgets or model defaults.

Reliability fixes

  • Decode array-wrapped non-SSE HTTP errors without losing authentication retry classification or error context.
  • Accept ProtoJSON candidate-count spellings and numeric representations.
  • Make gateway-forbidden Gemini 408/429/5xx failures terminal to SDKs that ignore X-Should-Retry.
  • Accept SSE control frames and empty data messages without mistaking them for model output or completion.
  • Reject contradictory prompt blocks accompanied by candidates instead of hiding incomplete generation.
  • Preserve URL-derived model names in archived attempts, including local retries.
  • Preserve HTTP error-body read failures before validation heuristics; incomplete or malformed Gemini error JSON cannot establish a permanent validation error. Retain authoritative retry hints and HTTP cooldowns.
  • Preserve attempt deadline causes during HTTP/2 response-body reads, preventing proxy timeouts from becoming terminal client_gone failures across Gemini, Responses, and Messages.
  • Honor native google.rpc.RetryInfo.retryDelay for HTTP and in-band SSE errors when no valid positive HTTP Retry-After exists. Round fractional seconds up and prevent long delays from overflowing local retry/deadline arithmetic.

Codex CLI review

  • Initial feature: codex review --uncommitted twice; three initial P2 findings fixed before the original PR was published.
  • Full-PR follow-up: codex review --base origin/main; both reproduced P2 findings fixed (error-body read failures and native RetryInfo cooldowns).
  • The next codex review --uncommitted reproduced an HTTP/2 cancellation-cause regression; fixed at the transport-body boundary with a cross-protocol regression and 3 compiled-proxy HTTP/2 checks.
  • Final codex review --uncommitted: no actionable regressions. The reviewer also passed full tests, race tests, 32-bit tests, vet, and diff checks.

Verification

  • go test -race -p 1 ./... -count=1
  • GOARCH=386 go test ./... (final Codex review)
  • go vet ./...
  • make release-test (9 tests)
  • Compiled-proxy follow-up HTTP checks: 31 passed (16 thinking/stream/archive checks, 11 error/cooldown checks, 1 long-cooldown check with the timed live switch disabled, and 3 HTTP/2 deadline checks).
  • Go sources formatted with gofmt.

@etwk
etwk merged commit 5a47529 into main Oct 18, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant