Skip to content

Sessions die on transient socket closes because @ai-sdk/gateway is pinned 87 versions behind the retryability fix #48761

Description

@R-Taneja

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:

  1. The rewritten message matches none of the RETRYABLE_MESSAGE_PATTERNS entries.
  2. The Gateway preserves a 200 status on these, so the status >= 500 check does not catch it either.
  3. 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

  1. Use the vercel provider against the AI Gateway for an extended session.
  2. Wait for the edge to retire a pooled keep-alive connection mid-session.
  3. 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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions