fix: retry streamed provider error envelopes#23841
Conversation
ea32fb8 to
348c51e
Compare
|
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. |
|
Opened #30323 rebased on current |
Issue for this PR
Closes #16214
Type of change
What does this PR do?
OpenAI can surface a streamed JSON error envelope like
{ type: "error", sequence_number: 2, error: { type: "server_error" } }. When that envelope reachesSessionRetry.retryable()as a JSONUnknownErrormessage, it has no HTTP status, so the existing 5xx retry fallback cannot classify it.This change teaches
SessionRetry.retryable()to inspect nestederror.type,error.code, anderror.messagefor those envelopes. It preserves the existingtoo_many_requestsandrate_limithandling, and treatsserver_error,upstream_error, andstream_read_errorenvelopes as retryable. If the provider supplied an error message, that message is used as the retry reason; otherwise it falls back toProvider is overloadedso an empty streamed error message still retries.I added regression tests for the OpenAI
server_errorshape from #16214, an empty-messageserver_error, upstreamstream_read_error, and an upstream error with a non-stream_read_errorcode.How did you verify your code works?
bun test test/session/retry.test.ts-> 31 pass, 0 failbun run typecheckgit diff --checkScreenshots / recordings
N/A. This is not a UI change.
Checklist