fix(opencode): retry transient network errors instead of surfacing as terminal with raw content#31440
Open
Sylchi wants to merge 1 commit into
Open
fix(opencode): retry transient network errors instead of surfacing as terminal with raw content#31440Sylchi wants to merge 1 commit into
Sylchi wants to merge 1 commit into
Conversation
… terminal with raw content When a network request drops mid-flight (ECONNRESET, ECONNREFUSED, fetch failure, premature close, etc.), the error was classified as NamedError.Unknown and never retried, leaving a large raw error body on screen. Two changes: 1. Add isTransientNetworkError() detection in MessageV2.fromError() that catches SystemError codes (ECONNRESET, ECONNREFUSED, ETIMEDOUT, ...), TypeError from fetch, and common transient message patterns. These now produce an APIError with isRetryable: true so SessionRetry retries. 2. Truncate e.responseBody in ProviderError.message() at 200 chars to prevent dumping long HTML error pages or raw content into the visible error message. Closes anomalyco#31133, anomalyco#20822, anomalyco#15350, anomalyco#21893
Contributor
|
The following comment was made by an LLM, it may be inaccurate: Based on the search results, I found one potentially related PR: PR #30638 -
The other results (PR #29627 and #19204) are related to error handling and retries but address different specific scenarios (undici TypeError, 5xx status codes) and appear to be distinct from this PR's focus. |
Contributor
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
Closes #31133, closes #20822, closes #15350, closes #21893
Type of change
What does this PR do?
When a network request drops mid-flight (ECONNRESET, ECONNREFUSED, fetch failure, premature close, etc.), the error was classified as
NamedError.Unknownand never retried — leaving the raw error body (potentially an HTML error page or thousands of characters) dumped on screen.Two changes:
Transport error detection in
MessageV2.fromError()— AddedisTransientNetworkError()helper that catches SystemError codes (ECONNRESET, ECONNREFUSED, ETIMEDOUT, ENOTFOUND, EAI_AGAIN, ENETUNREACH, EPIPE), TypeError from fetch, and common transient message patterns. These now produce anAPIErrorwithisRetryable: truesoSessionRetryretries instead of surfacing a terminal error.Truncate long error response bodies in
ProviderError.message()— When a proxy/gateway returns an HTML error page or any long non-JSON body,e.responseBodywas embedded verbatim. Now truncated at 200 chars with"..."suffix.How did you verify your code works?
bun typecheckin packages/opencode)Screenshots / recordings
N/A
Checklist