Skip to content

Preserve HTTP status on UnknownError so plugins can fallback #47039

Closed

Description

@RaviTharuma

Summary

Provider HTTP failures (401, 429, 5xx, auth-expired) are often collapsed to UnknownError with Unexpected server error and no status on the session error. Plugins that implement model/provider fallback cannot classify the failure.

Related: #39340 (overloaded_error becomes UnknownError and is not retried).

Repro

  1. Point a provider baseURL at https://gateway.example/v1.
  2. Have the gateway return 401 or 429 on chat completions.
  3. opencode run -m provider/model-id ping

Actual

CLI prints UnknownError / unexpected server error. Session error object has no HTTP status.

Expected

Session error includes status (or original provider error name) so plugins can hop. User-visible message should include the status when known.

Suggested fix

Propagate status / error.name from the AI SDK / fetch layer onto session.error instead of wrapping everything as UnknownError.

Activity

  1. github-actions commented on Sep 3, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. RaviTharuma commented on Sep 3, 2026

    @RaviTharuma
    Author

    Both cited issues are still open, and neither covers this one.

    This issue is narrower and is a prerequisite for both: the session error object loses the HTTP status when a provider failure is wrapped as UnknownError. Whatever retries — OpenCode's own logic in #30611, the failover in #42513, or an external plugin — cannot classify 401 vs 429 vs 503 if the status was already discarded at the wrap site. Fixing the wrap does not implement either of those features, and implementing either of them without the status still leaves the classifier blind.

    PR #47092 preserves the status on the Error wrap and does not change retry policy, which keeps it independent of the decisions still open on #30611 and #42513.

  3. neriousy commented on Oct 19, 2026

    @neriousy
    Member

    This is fixed in v2: session errors preserve the provider’s HTTP status when available and expose typed classifications such as provider.auth, provider.rate-limit, and provider.internal, along with the response body. Plugins can classify these failures without relying on a generic UnknownError message; this does not add automatic failover.

    To get v2, run npm i -g @opencode/cli@latest. If you still see this on v2, please open a new issue with the details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions