Repository navigation
fix(guardian): retry the gateway's transient inference_failed 400 (#779) - #780
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the base provider's retry mechanism to allow subclasses to define their own transient exceptions, enabling the OpenCode provider to retry on HTTP 400 inference_failed errors. It also improves error handling by preserving the response body in raised exceptions and adds comprehensive unit tests. The review feedback recommends a more robust check for the inference_failed error by parsing the JSON response and verifying the specific error code rather than performing a substring search on the raw response body.
Owner
Author
|
/guardian review |
|
This was referenced Nov 5, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Closes #779.
What changed
BaseProvider._retrynow catchesself._retryable_exceptions(); the default is the existing transport set, so every other provider behaves exactly as before, and a provider whose gateway signals a retryable failure with an HTTP status can widen it without changing the loop.OpenCodeProviderwidens it withOpenCodeTransientError: a400whose body marksinference_failed. That is a transient upstream failure, not a request-validation error — the gateway retries it itself only sometimes (console log:attemptCount1 on the runs that failed, 2 on the one that succeeded). It is now retried throughMAX_ATTEMPTSwith the usual backoff.response.text[:400], instead ofraise_for_status()dropping the body. That is what made guardian(opencode): retry transient inference_failed 400s and carry the gateway's response body #779 read as a bare400 Bad Request.429keepsOpenCodeQuotaError; other 4xx/5xx still fail on the first attempt.Tests
tests/unit/test_guardian_opencode.py: transient 400 retried then succeeds (2 calls, 2 s backoff); exhausted afterMAX_ATTEMPTSwith[2, 4]backoff; non-transient 400 raises on the first attempt with its body; a 502 carries status + body; the existing 429, truncation and reasoning-only cases stay as they were.pytest tests/unit/test_guardian_opencode.py tests/unit/test_guardian_providers.py tests/unit/test_guardian_runner.py— 110 passed.ruff check,ruff format --checkandpyrefly check --baselineare green.Not addressed here (recorded in #779)
The 8000-token completion budget — the successful large call spent all 8000 output tokens on reasoning (
reasoningTokens: 8000), so the answer never started — plus per-chunk prompt size (chunk requests reached 161 KB vs 99 KB single-pass) and the ~60 s upstream window. The retry is the first, independent step; re-running the chunked review of #777 is the live check for it.