fix(opencode): retry nested OpenAI errors

Merged
MA
3mo ago
+61-5

Issue for this PR

No linked issue.

Type of change

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

What does this PR do?

OpenAI Responses streams can report a transient failure as a nested response.failed event with the error at response.error. The existing parser only recognized top-level error events, so nested server_error and server_is_overloaded events became terminal unknown errors.

This keeps the parser change narrow: those two nested transient codes become retryable APIError values and flow through the existing SessionRetry policy. Other nested response.failed codes retain their current terminal behavior.

Follow-up risk intentionally left out of scope: SessionRetry caps each backoff wait, but generic retryable API errors do not currently have a total-attempt cap.

How did you verify your code works?

  • bun test test/session/retry.test.ts --timeout 30000: 37 passed
  • bun typecheck from packages/opencode: passed
  • pre-push filtered workspace typecheck: 16/16 packages passed

Added regression coverage for both nested transient codes and for a nested non-retryable code remaining terminal.

Screenshots / recordings

Not applicable; no UI change.

Checklist

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

Summary by cubic

Makes nested OpenAI stream server errors retryable so transient failures don’t abort sessions. Detects server_error and server_is_overloaded inside response.failed events and routes them through the existing retry policy.

  • Bug Fixes
    • Updated opencode parser to handle nested response.failed errors: server_error and server_is_overloaded now map to retryable API errors; other nested codes stay terminal.
    • Added regression tests for both retryable and non-retryable nested cases.