Skip to content

SSE serialization corruption causes incorrect 429 error classification and unnecessary retry loops #21704

@gsquared94

Description

@gsquared94

When the Gemini CLI receives a 429 QUOTA_EXHAUSTED response over an SSE (alt=sse) connection, the server's SSE serializer can inject a stray comma into the JSON error body at a line boundary:

"domain": "cloudcode-pa.googleapis.com",
 ,       "metadata": {
This corruption has two cascading effects:

JSON parsing fails — JSON.parse() rejects the malformed body, so our error classifier can't extract the structured error details. Without them, the 429 falls through to a generic RetryableQuotaError instead of being correctly identified as a TerminalQuotaError.

Domain validation fails — even when parsing succeeds via an alternate code path, the domain string carries a trailing comma ("cloudcode-pa.googleapis.com,"), which fails the exact-match check against known Cloud Code domains. Same result: misclassified as retryable.

The misclassification sets a retry delay of ~19 hours (the server's quota reset time). That 69 million millisecond value overflows setTimeout's 32-bit signed integer limit, wrapping to ~1ms — causing a rapid-fire retry loop that burns through all retry attempts before finally surfacing the error to the user.

This is an environment-specific issue — it only manifests against certain server endpoints where the SSE serializer produces the stray comma. Same account, same code, different results depending on which backend serves the request, which made it particularly difficult to reproduce and diagnose.

Metadata

Metadata

Assignees

Labels

status/need-triageIssues that need to be triaged by the triage automation.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions