Skip to content

fix: retry streamed provider error envelopes#23841

Closed
Disaster-Terminator wants to merge 1 commit into
anomalyco:devfrom
Disaster-Terminator:fix/retry-stream-error-envelopes
Closed

fix: retry streamed provider error envelopes#23841
Disaster-Terminator wants to merge 1 commit into
anomalyco:devfrom
Disaster-Terminator:fix/retry-stream-error-envelopes

Conversation

@Disaster-Terminator
Copy link
Copy Markdown

Issue for this PR

Closes #16214

Type of change

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

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 reaches SessionRetry.retryable() as a JSON UnknownError message, it has no HTTP status, so the existing 5xx retry fallback cannot classify it.

This change teaches SessionRetry.retryable() to inspect nested error.type, error.code, and error.message for those envelopes. It preserves the existing too_many_requests and rate_limit handling, and treats server_error, upstream_error, and stream_read_error envelopes as retryable. If the provider supplied an error message, that message is used as the retry reason; otherwise it falls back to Provider is overloaded so an empty streamed error message still retries.

I added regression tests for the OpenAI server_error shape from #16214, an empty-message server_error, upstream stream_read_error, and an upstream error with a non-stream_read_error code.

How did you verify your code works?

  • bun test test/session/retry.test.ts -> 31 pass, 0 fail
  • bun run typecheck
  • git diff --check

Screenshots / recordings

N/A. This is not a UI change.

Checklist

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

@Disaster-Terminator Disaster-Terminator marked this pull request as ready for review April 22, 2026 10:51
@Disaster-Terminator Disaster-Terminator force-pushed the fix/retry-stream-error-envelopes branch from ea32fb8 to 348c51e Compare April 26, 2026 09:04
@github-actions
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.

@spark4862
Copy link
Copy Markdown
Contributor

Opened #30323 rebased on current dev with broader OpenAI/Codex stream error coverage (stream_read_error, overload, rate limit), including parseStreamError, retryable(), and fromError(Error.message) paths plus regression tests. Would appreciate a 👍/review if this matches what you are seeing — especially for Codex gpt-5.x unattended runs. This supersedes the closed automated-cleanup PR with a wider OpenAI/Codex-specific fix.

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.

Intermittent OpenAI streamed server_error (sequence_number:2) with gpt-5.3-codex; retries degrade session

2 participants