Skip to content

fix(session): classify transport and timeout errors as retryable#30638

Closed
literally-dan wants to merge 1 commit into
anomalyco:devfrom
literally-dan:pr/fix-session-retryable-errors
Closed

fix(session): classify transport and timeout errors as retryable#30638
literally-dan wants to merge 1 commit into
anomalyco:devfrom
literally-dan:pr/fix-session-retryable-errors

Conversation

@literally-dan

Copy link
Copy Markdown

Issue for this PR

Closes #30611

Type of change

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

What does this PR do?

MessageV2.fromError only marked ECONNRESET as retryable and treated every other transport failure as a hard error. This widens it to cover the common transient cases:

  • transient system error codes (ECONNRESET, ETIMEDOUT, ENOTFOUND, EAI_AGAIN, ECONNREFUSED, EHOSTUNREACH, ENETUNREACH, EPIPE)
  • TimeoutError from AbortSignal.timeout
  • bare network error messages (fetch failed, socket hang up, terminated, other side closed, and similar)

A bare AbortError stays a cancel, classified by the error itself rather than an external flag, so a user cancelling a turn is never retried.

How did you verify your code works?

Unit tests in message-v2.test.ts cover each system code, each message pattern, the TimeoutError case, and the cancel-vs-timeout distinction. bun typecheck passes.

Screenshots / recordings

Not applicable.

Checklist

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

MessageV2.fromError previously only treated ECONNRESET as retryable and
classified everything else (including transient transport failures) as a
hard error. Broaden it so a network blip recovers instead of failing the
session:

- transient SystemError codes (ECONNRESET, ETIMEDOUT, ENOTFOUND,
  EAI_AGAIN, ECONNREFUSED, EHOSTUNREACH, ENETUNREACH, EPIPE)
- DOMException TimeoutError (AbortSignal.timeout)
- bare network-error Error messages (fetch failed, socket hang up, SSE
  read timed out, terminated, other side closed, ...)

A bare AbortError stays a cancel (classified by error identity, not an
external flag), so user cancellation is never retried.

Verified with unit tests in message-v2.test.ts covering each code,
message pattern, and the abort/timeout distinction.
@literally-dan
literally-dan force-pushed the pr/fix-session-retryable-errors branch from fbeac4e to c315f71 Compare June 19, 2026 10:49
@huzpsb

huzpsb commented Jun 20, 2026

Copy link
Copy Markdown

+1, really need this

@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

@IraLivor

Copy link
Copy Markdown

I am not the PR's creator, but I request this PR be reopened. This PR is still an absolutely necessary resolution to a bug in OpenCode that causes tool calls to trigger an error and terminate agents. This PR is related to an open issue 30221 which still requires its resolution to be delivered.

OpenCode, as it is now, is completely unreliable to use because once this bug occurs, the running session is unrecoverable. Any further tool calls, in the same session, will trigger the same error and termination 100% of the time.

Automating the closing of such a valuable PR is completely unwise. You should not close PRs simply because the OpenCode team has yet to have time to review and approved/reject them, for existing an open bug.

@literally-dan

Copy link
Copy Markdown
Author

I've rebased this PR and think it should be reopened. It solves an existing bug that's really annoying when dealing with subagents.

@literally-dan

Copy link
Copy Markdown
Author

Rebased and refreshed the source branch against current dev at literally-dan/opencode@c38f0f45. The isolated patch passes bun typecheck plus 131 focused tests covering retry classification, message projection, and stream transport. This PR now has two positive reactions, and the linked bug remains active. Because the cleanup bot closed the PR, GitHub will not allow me to reopen it directly; could a maintainer please review and reopen it?

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Sessions fail on transient network errors instead of retrying

3 participants