Description
A dropped connection to the AI Gateway kills the assistant turn instead of being retried, surfacing as:
GatewayResponseError: Invalid error response format: Gateway request failed
(cause: AI_APICallError: Cannot connect to API: The socket connection was closed unexpectedly)
The retry path in session/retry.ts is already set up to handle this. RETRYABLE_MESSAGE_PATTERNS includes socket connection was closed. It never matches, because @ai-sdk/gateway rewrites the message before opencode sees it.
Running the two strings against opencode's own patterns:
"Invalid error response format: Gateway request failed" -> no match, turn dies
"Cannot connect to API: The socket connection was closed unexpectedly" -> matches, would retry
Three checks fail at once:
- The rewritten message matches none of the
RETRYABLE_MESSAGE_PATTERNS entries.
- The Gateway preserves a 200 status on these, so the
status >= 500 check does not catch it either.
error.data.isRetryable is false.
This was fixed upstream in vercel/ai#19890 ("mark response body network errors as retryable"), released in @ai-sdk/gateway 3.0.185. packages/opencode and packages/core both pin 3.0.104, which is 87 patch versions behind, so opencode does not have it.
It affects both failure shapes. In my own logs across 151 occurrences, 60% fail before any response byte and 25% fail more than 60s in, mid-stream. Both are response-body network errors and both are covered by the upstream fix.
Related to #30611, which asks for the same outcome from the opposite direction (widening opencode-side classification). This issue is specifically the stale dependency pin.
Plugins
None relevant
OpenCode version
1.18.30
Steps to reproduce
- Use the
vercel provider against the AI Gateway for an extended session.
- Wait for the edge to retire a pooled keep-alive connection mid-session.
- The turn ends with
Invalid error response format: Gateway request failed instead of retrying.
Frequency here is roughly 0.9% of streams (151 failures across 16,510), and they cluster in bursts, so a long session is the practical way to hit it.
Operating System
macOS 15 (arm64)
Description
A dropped connection to the AI Gateway kills the assistant turn instead of being retried, surfacing as:
The retry path in
session/retry.tsis already set up to handle this.RETRYABLE_MESSAGE_PATTERNSincludessocket connection was closed. It never matches, because@ai-sdk/gatewayrewrites the message before opencode sees it.Running the two strings against opencode's own patterns:
Three checks fail at once:
RETRYABLE_MESSAGE_PATTERNSentries.status >= 500check does not catch it either.error.data.isRetryableis false.This was fixed upstream in vercel/ai#19890 ("mark response body network errors as retryable"), released in
@ai-sdk/gateway3.0.185.packages/opencodeandpackages/coreboth pin 3.0.104, which is 87 patch versions behind, so opencode does not have it.It affects both failure shapes. In my own logs across 151 occurrences, 60% fail before any response byte and 25% fail more than 60s in, mid-stream. Both are response-body network errors and both are covered by the upstream fix.
Related to #30611, which asks for the same outcome from the opposite direction (widening opencode-side classification). This issue is specifically the stale dependency pin.
Plugins
None relevant
OpenCode version
1.18.30
Steps to reproduce
vercelprovider against the AI Gateway for an extended session.Invalid error response format: Gateway request failedinstead of retrying.Frequency here is roughly 0.9% of streams (151 failures across 16,510), and they cluster in bursts, so a long session is the practical way to hit it.
Operating System
macOS 15 (arm64)