Skip to content

fix(opencode): retry network errors wrapped by providers - #53397

Closed
moritzWa wants to merge 2 commits into
anomalyco:devfrom
moritzWa:fix/retry-wrapped-network-errors
Closed

moritzWa wants to merge 2 commits into
anomalyco:devfrom
moritzWa:fix/retry-wrapped-network-errors

Conversation

@moritzWa

@moritzWa moritzWa commented Oct 5, 2026 •

Copy link
Copy Markdown

Issue for this PR

Closes #53396

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Retry only looks at the error message, so a network error wrapped by a provider (e.g. "Cursor HTTP/2 connection failed" with ENOTFOUND on .cause) isn't retried and the session stops.

  • fromError walks the cause chain for a network code (ENOTFOUND, ECONNREFUSED, ETIMEDOUT, ...) and returns a retryable APIError with that code in metadata. It stops at an error marked transient: false / isRetryable: false, so a provider that already gave up isn't retried again.
  • The same code is read from the cause of an AI SDK APICallError. Direct providers (Anthropic, OpenAI) wrap a failed fetch as Cannot connect to API: ... with the socket error on cause; before, those got only the default 5 retries.
  • Bun's fetch uses its own codes (ConnectionRefused, FailedToOpenSocket, ConnectionClosed, ConnectionResetByPeer, ConnectionTimeout) and messages (Unable to connect. Is the computer able to access the url?, Was there a typo in the url or port?). Both are now recognized.
  • Network errors get 720 retries instead of 5. With the existing backoff (capped at 30s) that's about 6 hours, so an outage is waited out instead of failing the turn; the session shows the retry status throughout. Other errors keep 5.
  • The code list lives in retry.ts. I removed its unused MessageV2 import so message-v2.ts can import it without a cycle.

How did you verify your code works?

  • New tests: a wrapped ENOTFOUND is retryable, a wrapped error marked transient: false is not, and the policy allows 24 retries for network errors.
  • bun test test/session/retry.test.ts test/session/message-v2.test.ts and bun run typecheck pass.
  • To reproduce: use cursor-opencode-provider, start a prompt, and turn off Wi-Fi. Before this change the session stops with "Cursor HTTP/2 connection failed". After it, the session shows retry status and continues once you're back online.

Screenshots / recordings

N/A

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Session stops on a dropped connection when the provider wraps the network error

2 participants