Skip to content

guardian(opencode): fall back to prompt-only JSON when the gateway rejects response_format #781

Closed

Description

@zaebee

Found while re-running the chunked review of #777 after #780 landed.

Problem

All chunk finder calls returned HTTP 400 with this body (now visible thanks to #780):

{"error":{"param":null,"type":"invalid_request_error","code":"invalid_request_error",
"message":"Upstream request failed: [invalid_request_error] This response_format type is unavailable now (request_id: ...)"}}

The gateway does not accept response_format (the json_schema structured-output request) on the upstream route it picked at that moment. It is not the transient inference_failed handled in #780 — retrying invalid_request_error unchanged is not the answer, and the provider correctly does not retry it. A single-pass request minutes earlier got a 200, so structured output is available only sometimes.

The finder relies on generate_structured, so every call fails and the chunked review degrades to "⚠ finder call failed".

Fix

  • Add OpenCodeStructuredOutputUnavailable, raised when a 400 body marks response_format as unavailable.
  • In generate_structured: when that error is raised, drop response_format from the payload and send the request again. The prompt already asks for the same JSON, and the caller parses defensively — this is the prompt-only mode OpenRouter already relies on when a model ignores the parameter, so it is a real answer rather than a failed review.
  • Keep the inference_failed retry and the first-attempt failure for every other 4xx unchanged.
  • Move the response_format payload construction to one helper on OpenAICompatibleProvider, so the base and the fallback build it identically.

Done when

  • a response_format-unavailable 400 causes exactly one retry without response_format, and a successful reply is returned;
  • if the fallback also fails, the error surfaces with its body (never an empty verdict);
  • tests cover fallback success (second body has no response_format), fallback failure, and that other 400s are still not retried;
  • gates green; the chunked review of feat(guardian): add opencode-go DeepSeek provider over GitHub OIDC #777 produces findings instead of "⚠ finder call failed" (or the remaining failure is a different, named cause).

Refs #775, #779, #780.

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