[Bug] Antigravity /v1beta: final SSE chunk has empty-text thoughtSignature-only part, breaking strict Gemini clients (Antigravity CLI)
Summary
The Antigravity-compatible Gemini endpoint (/antigravity/v1beta/models/{model}:streamGenerateContent?alt=sse) forwards a final SSE chunk from the upstream that contains a part with empty text and only thoughtSignature:
{"thoughtSignature": "EuQCCuEC…", "text": ""}
sub2api passes this chunk through verbatim, but Google's official Gemini v1beta API never emits this shape (there, thoughtSignature is attached to non-empty text parts). Strict clients that validate stream chunks — including Google's own Antigravity CLI (agy) — reject it and abort the stream with:
agent executor error: generating and executing: iterateResponseStream: invalid stream chunk:
data: {"candidates": [{"content": {"role": "model","parts": [{"thoughtSignature": "…", "text": ""}]},"finishReason": "STOP"}],"usageMetadata": {...},"modelVersion": "gemini-3.8-flash","responseId": "…"}
The answer text is actually delivered before the error, but every streamed response ends with this error, which makes the CLI unusable in practice. Non-streaming requests (generateContent) and sub2api's own account test work fine — the issue is specific to the SSE stream shape.
Environment
- sub2api: v0.2.4 (Docker,
weishaw/sub2api:latest, imageccf47a1c62e3) - Platform/account:
antigravityOAuth accounts (Pro plan), group with Gemini models via/antigravity/v1beta - Client: Google Antigravity CLI 1.2.2 (
agy) withGOOGLE_GEMINI_BASE_URL=https://<sub2api>/antigravity/v1betaandGEMINI_API_KEYauth - Model:
gemini-3.8-flash-*(happens on every thinking-enabled model I tried, with any reasoning effort)
Steps to reproduce
- Point agy at sub2api (
GOOGLE_GEMINI_BASE_URL=…/antigravity/v1beta,GEMINI_API_KEY=sk-…). - Run any prompt:
agy -p "Say hi". - The response arrives, then agy prints
invalid stream chunkwith the final chunk shown above (withfinishReason: "STOP", emptytext,thoughtSignatureonly). Reproduced 3/3 runs.
Captured raw SSE from sub2api (last two chunks):
data: {"candidates": [{"content": {"role": "model","parts": [{"text": "привет"}]}}],"usageMetadata": {...}}⏎⏎⏎
data: {"candidates": [{"content": {"role": "model","parts": [{"thoughtSignature": "EuwCCukCARFNMg+R…", "text": ""}]},"finishReason": "STOP"}],"usageMetadata": {...,"thoughtsTokenCount": 52},"modelVersion": "gemini-3.8-flash","responseId": "mHuoapanOdSu28oP7dDxyQI"}⏎⏎⏎
(The signature value is intentionally truncated.)
Root cause
AntigravityGatewayService.unwrapV1InternalResponse (backend/internal/service/antigravity_gateway_service.go) extracts response with gjson and forwards it verbatim, so the upstream's signature-only part reaches the client unchanged. Tolerant clients (e.g. Vercel AI SDK @ai-sdk/google) ignore the empty part and work fine; strict parsers reject it. Against the real Google endpoint the same agy build works without errors, which confirms the shape difference comes from the antigravity upstream and survives sub2api's passthrough.
Suggested fix
In the antigravity → v1beta conversion, sanitize the final part:
- if a part has
text == ""and containsthoughtSignatureand no other content fields:- merge
thoughtSignatureinto the previous non-empty text part of the same candidate, or - drop the part if there is no previous text part;
- merge
- keep everything else as is.
This keeps signature state for follow-up turns while restoring compatibility with strict Gemini clients, including the Antigravity CLI itself.
Happy to test a build/patch against our setup (2 OAuth accounts, gemini-3.8-flash-* models) if useful.
Same symptom here (v0.2.4, Antigravity CLI), but I believe the attribution is off — the thoughtSignature-only part is not what agy rejects. The culprit is the extra blank line between SSE events, which is visible in your own capture as ⏎⏎⏎. Details and raw bytes in #7161; the short version:
- go-genai's
iterateResponseStreamsplits the stream on\n\n, then doesbytes.Cut(line, ":")and switches on the prefix.invalid stream chunkis only produced in thedefaultbranch, i.e. when the prefix is notdata. A line that starts withdata:never reaches that error, whatever JSON it carries — an empty-text part would go throughjson.Unmarshal+ the response converter, which accept it. - sub2api writes each upstream
data:line asdata: …\n\nand then also forwards the upstream blank separator line as another\n(antigravity_gateway_streaming.go,handleGeminiStreamingResponse). With\n\n\nbetween events, the second\n\n-delimited token is\ndata: {…}, its prefix is\ndata, and the SDK aborts. - That is why the error text has a line break right after
chunk:— the message is formatted as%s:%swith prefix\ndata. The newline in the error is the extra separator. - It always looks like "the final chunk is bad" because the final chunk is simply the second event; the first one is always parsed fine. Non-streaming and sub2api's account test are unaffected because there is no separator to double.
The fix is one line — skip the empty line in the passthrough loop, since the data: branch already emitted \n\n (sangkaka/sub2api#5 has the patch with a regression test). Sanitizing the signature-only part would not make agy work on its own.
One more thing that bites go-genai clients even after that: sub2api's stream keepalive (gateway.stream_keepalive_interval, default 10s) emits an SSE comment :\n\n when the upstream is quiet, and go-genai currently rejects :-prefixed lines too (googleapis/go-genai#898). Long-thinking requests will hit that.