Repository navigation
fix(guardian): fall back to prompt-only JSON when response_format is unavailable (#781) - #782
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a fallback mechanism in the OpenCode provider to handle cases where the gateway rejects structured output (response_format) as unavailable. When this occurs, the provider retries the request using a prompt-only payload and remembers the refusal for subsequent calls in the same run. Additionally, unit tests were added to verify this fallback behavior. Feedback on the changes suggests optimizing the payload modification by using payload.pop() instead of a dictionary comprehension to remove the response_format key.
|
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 #781.
What changed
OpenAICompatibleProviderbuilds theresponse_formatpayload in one helper (_response_format), so the base pass and the new fallback describe the same schema.OpenCodeProvider.generate_structurednow handles the gateway's400 invalid_request_errorwhose message says "This response_format type is unavailable now": it re-sends the same prompt withoutresponse_formatand returns the answer. The prompt already asks for the same JSON and the caller parses defensively, so this is the prompt-only mode OpenRouter already relies on when a model ignores the parameter — a real answer instead of a failed review._raise_for_http_errorraises the newOpenCodeStructuredOutputUnavailableErrorfor that body only;inference_failedkeeps its retry (fix(guardian): retry the gateway's transient inference_failed 400 (#779) #780), 429 keepsOpenCodeQuotaError, every other 4xx/5xx still fails on the first attempt with its body.Tests
tests/unit/test_guardian_opencode.py: fallback success (second body has noresponse_format); the refusal is remembered (three POSTs for two calls, the third body prompt-only); a failed fallback raises with its body; plus the existing transient/429/truncation/reasoning cases.pytest tests/unit/test_guardian_opencode.py tests/unit/test_guardian_openrouter.py tests/unit/test_guardian_providers.py tests/unit/test_guardian_runner.py— 130 passed;ruff check,ruff format --check,pyrefly check --baselinegreen.Why it matters
This is the failure that made the chunked review of #777 degrade to "⚠ finder call failed" after #780: every chunk asked for structured output and the upstream refused it as unavailable. With the fallback, the request is answerable; whether a chunk still fails on the 8000-token reasoning budget is a separate, measurable question (#779).