fix(opencode): retry transient network errors instead of surfacing as terminal with raw content - #31440
fix(opencode): retry transient network errors instead of surfacing as terminal with raw content#31440Sylchi 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
|
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. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
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:
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. |
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