Skip to content

fix(#3996): drop gateway SSE keepalive frames before the genai parser - #4022

Draft
aheritier wants to merge 2 commits into
title-generation-model-filterfrom
gemini-gateway-transport
Draft

fix(#3996): drop gateway SSE keepalive frames before the genai parser#4022
aheritier wants to merge 2 commits into
title-generation-model-filterfrom
gemini-gateway-transport

Conversation

@aheritier

@aheritier aheritier commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

What

Filters gateway SSE keepalive frames before they reach the Gemini genai parser, while retaining normal response events.

Why

Gateway transport heartbeats are not model events and can otherwise cause parser failures or corrupt streaming behavior.

Validation

task test; HTTP SSE filter and Gemini transport tests.

Test instructions

Run:

task test

Stream a Gemini response containing gateway SSE keepalive frames followed by content and a terminal event. Expected: keepalive frames are discarded before parsing, content remains intact, and the stream terminates normally.

Exhaustively cover wantsImageResponseModalities (added by the preceding
compatibility-guard commit): true only on supported Gemini surfaces, only
when output_capabilities.image resolves true (explicit override taking
precedence over models.dev output modalities), and only outside
title-generation/compaction utility calls. Also pin catalogue resolution,
override precedence, request construction, and the existing request-shape
diagnostics.
During long generations (e.g. Gemini image output) the Docker AI Gateway
emits `event: keepalive` + `data: {}` frames. google.golang.org/genai
treats any `event:` line as a fatal invalid stream chunk, so a single
keepalive killed the whole stream.

Add an opt-in httpclient.WithSSEKeepaliveFilter that makes the shared SSE
filter transport also drop payload-free keepalive frames, and enable it
only on the Gemini gateway HTTP client. The shared default path is
unchanged: Anthropic-style named events with meaningful data still pass
through verbatim, and only the gateway surface — never direct
Gemini/Vertex — gets the new behavior.
@aheritier aheritier added area/providers/gemini Google Gemini provider support kind/fix PR fixes a bug (maps to fix:). Use on PRs only. labels Aug 22, 2026
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 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.

1 participant