Repository navigation
Description
Package
@magpie-community/opencode-antigravity-auth (0.2.3, packages/antigravity/index.mjs)
Problem
In complete() (send() at packages/antigravity/index.mjs line 1595) and webSearch() (line 2212), fetch("${DAILY}/v1internal:streamGenerateContent?alt=sse", ...) is called without timeout: false. Under Magpie's Bun plugin host (Bun 1.4.4), fetch applies Bun's built-in ~300-second socket timeout (TimeoutError, code 23, The operation timed out.).
Relying on Bun's fixed ~300s socket deadline creates two operational issues on Gemini 4 streaming requests.
-
Silent upstream stalls take 5+ minutes per attempt and stack with retries. On
gemini-4-carbon, Google'sv1internal:streamGenerateContentendpoint occasionally accepts the request payload and stalls without emitting response headers or SSE chunks (similar upstream behavior is tracked ingoogle-antigravity/antigravity-cli#1402and#1546). Each stalledfetchblocks for ~300–330 seconds before throwingTimeoutError. Because no SSE event reached the gateway (ttftremains empty), Magpie records502and retries after 1 second, stretching a single upstream stall to 9–10 minutes. Ifcomplete()also performs internalRETRY_BAD_CALLretries (holdThoughts/badCallloop at lines 1639–1661) before a subsequent attempt stalls, the earlier attempts stay hidden from the gateway and extend the wait even further. -
Pre-first-chunk waiting and active SSE streaming share one fixed runtime timer. Without
timeout: falseand explicit stream-stage timers, slow dead connections cannot fail earlier than ~300s while healthy long-running streams lack dedicated per-chunk activity tracking.
Measured Behavior
Across a day of live gemini-4-carbon traffic through Magpie (Bun 1.4.4) up to 292k input tokens, we observed a clear gap between normal single-ask latency and silent stalls.
- 74 of 75 successful
gemini-4-carbonturns delivered their first gateway event within180.4s(most complex turns landed between70sand180s). The single338.8soutlier (80reasoning tokens) came from an internal two-askINVALID_ARGUMENTretry insidecomplete(). - Stalled
gemini-4-carbonattempts consistently hit Bun's default timeout at312.3s,327.0s, and330.0swith zero TTFT (502). - On one stalled turn (
327.0son the first attempt), Magpie's automatic retry succeeded in28.5sonce a fresh upstream request was opened. On another stalled turn (312.3son the first attempt), the second attempt also stalled until the caller cancelled at556.6s(9m17stotal). - Reproducing the silent server locally on Magpie's bundled
Bun 1.4.4confirmed that reading the request body and withholding headers or SSE bytes produces the sameTimeoutError(code: 23) and triggers Magpie's 1-second502retry.
Proposed Improvement
- Pass
timeout: falsein thefetchinit insidesend()(packages/antigravity/index.mjsline 1595) so Bun's fixed ~300s socket timer is disabled in favor of explicit stage deadlines. - Wrap the
v1internal:streamGenerateContentcall and its responseReadableStreamwith two separateAbortControllertimers linked toinit?.signal- First-chunk deadline (for example
210sdefault) armed until the first non-empty SSE chunk arrives from upstream, then cleared. - Stream-idle deadline (for example
180sdefault) reset on eachreader.read()pull after the first chunk arrives so active long streams can run arbitrarily long while mid-stream stalls still abort cleanly.
- First-chunk deadline (for example
- Propagate caller cancellation on
init?.signalimmediately and clear all timers on stream completion, cancellation, or error.
Activity