-
-
Notifications
You must be signed in to change notification settings - Fork 559
Description
Summary
transformAntigravityResponse() in request.js consumes the response body via response.text() at the top of a try block. If anything throws later (e.g. detectErrorType, rewriteAntigravityPreviewAccessError, etc.), the catch block returns the consumed original response. When OpenCode's AI SDK (@ai-sdk/provider-utils@3.0.20) then calls response.text() in its failedResponseHandler, it gets TypeError: Body already used, which is wrapped as:
AI_APICallError: Failed to process error response
Caused by: Body already used
Root Cause
In plugin/request.js, the transformAntigravityResponse function:
// line ~1207
try {
const text = await response.text(); // ← BODY CONSUMED
// ... 110 lines of processing ...
}
catch (error) {
return response; // ← BUG: returns consumed body
}Secondary Bug: THINKING_RECOVERY_NEEDED silently swallowed
detectErrorType() at line ~1224 can trigger throw new Error("THINKING_RECOVERY_NEEDED") at line ~1230. This throw is caught by the same catch block at the bottom of the function, so it never reaches the outer catch in plugin.js:1940 where the retry logic lives. Thinking recovery is effectively broken.
Fix
Two-line change:
// Clone BEFORE consuming
const responseFallback = response.clone();
try {
const text = await response.text();
// ... unchanged ...
}
catch (error) {
// Re-throw recovery errors for outer handler
if (error instanceof Error && error.message === "THINKING_RECOVERY_NEEDED") {
throw error;
}
logAntigravityDebugResponse(debugContext, response, {
error,
note: "Failed to transform Antigravity response",
});
return responseFallback; // ← Return unconsumed clone
}Environment
- OpenCode v1.1.65
- opencode-antigravity-auth v1.5.1
@ai-sdk/provider-utils@3.0.20(bundled in OpenCode binary)- Model:
antigravity-claude-opus-4-6-thinking - Error confirmed in logs from new session (PID started fresh)
Reproduction
Intermittent — triggers when the Google API returns an error response (403/429/500) AND something throws during error body processing in transformAntigravityResponse. The Body already used error is deterministic once this code path is reached.
Stack Trace from Logs
AI_APICallError: Failed to process error response
at <anonymous> (../../node_modules/.bun/@ai-sdk+provider-utils@3.0.20+d6123d32214422cb/node_modules/@ai-sdk/provider-utils/dist/index.mjs:790:19)
at processTicksAndRejections (native:7:39)
Notes
- This is distinct from issue [BUG] Failed to process error response #200 (thinking block signatures, fixed in v1.3.1)
- This is distinct from [Bug] Plugin doesn't strip x-goog-api-key header, causing 400 when user has apiKey in provider config #410 (x-goog-user-project header, fixed in v1.5.0)
- The fix is also applicable on the AI SDK side (v4.0.x adds
response.clone()before reading), but since OpenCode v1.1.65 bundles v3.0.20, the Antigravity Auth plugin should protect against it