Skip to content

fix(guardian): retry the gateway's transient inference_failed 400 (#779) - #780

Merged
zaebee merged 3 commits into
mainfrom
fix/779-opencode-transient-400
Nov 5, 2026
Merged

zaebee merged 3 commits into
mainfrom
fix/779-opencode-transient-400

Conversation

@zaebee

@zaebee zaebee commented Nov 5, 2026

Copy link
Copy Markdown
Owner

Closes #779.

What changed

  • BaseProvider._retry now catches self._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.
  • OpenCodeProvider widens it with OpenCodeTransientError: a 400 whose body marks inference_failed. That is a transient upstream failure, not a request-validation error — the gateway retries it itself only sometimes (console log: attemptCount 1 on the runs that failed, 2 on the one that succeeded). It is now retried through MAX_ATTEMPTS with the usual backoff.
  • Any other non-429 HTTP error now raises with the status and response.text[:400], instead of raise_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 bare 400 Bad Request. 429 keeps OpenCodeQuotaError; 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 after MAX_ATTEMPTS with [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.
  • Focused run: 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 --check and pyrefly check --baseline are 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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/cgis/guardian/providers/opencode.py Resolved
@zaebee

zaebee commented Nov 5, 2026

Copy link
Copy Markdown
Owner Author

/guardian review

@sonarqubecloud

sonarqubecloud Bot commented Nov 5, 2026

Copy link
Copy Markdown

@zaebee
zaebee merged commit 5310423 into main Nov 5, 2026
4 checks passed
@zaebee
zaebee deleted the fix/779-opencode-transient-400 branch November 5, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant