Skip to content

guardian(opencode): retry transient inference_failed 400s and carry the gateway's response body #779

Closed

Description

@zaebee

Found while checking big-PR reviews after #775.

Problem

On large diffs the opencode-go gateway returns HTTP 400 with errorCode: inference_failed. The console request log shows this is a transient upstream failure, not a bad request:

  • a request that succeeded had attemptCount: 2: first attempt 400 in 171 ms, second attempt 200 in 55 s;
  • the failing chunked-run requests had attemptCount: 1 — the gateway did not retry them.

Our provider does not retry a 400: BaseProvider._retry only retries httpx.TimeoutException/NetworkError, and _post calls response.raise_for_status(), which also drops the response body. CI therefore shows only Client error '400 Bad Request' with no reason, and a transient gateway failure becomes a failed review (or, under chunking, a review degraded to "⚠ finder call failed").

What to change

  • On any non-429 HTTP error, raise with the status and response.text[:400], so the gateway's reason reaches the job log.
  • Treat a 400 whose body marks inference_failed as transient and retry it through the existing _retry loop (MAX_ATTEMPTS with backoff). Other 4xx must still fail on the first attempt — a validation error must not burn three paid calls.
  • Keep OpenCodeQuotaError for 429 as it is.

Done when

  • a 400 carrying inference_failed is retried and succeeds when the next attempt succeeds;
  • a 400 with any other body raises immediately with the body in the message;
  • exhausted retries raise the transient error (not a silent empty verdict);
  • tests cover retried-then-success, exhausted, and non-transient-4xx; the focused provider/runner tests and the repository gates are green;
  • the chunked review of a large PR (feat(guardian): add opencode-go DeepSeek provider over GitHub OIDC #777) either produces findings or the remaining failure is a different, named cause recorded in this issue.

Not in scope

The 8000-token completion budget (the successful large request spent all 8000 output tokens on reasoning — reasoningTokens: 8000), per-chunk context size (chunk prompts reached 161 KB vs 99 KB single-pass), and the ~60 s upstream window. Those are separate measurements; note them if the retry alone does not make large-PR reviews work.

Refs #775, #778.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions