fix(models): retry 200 responses that carry a gateway error payload - #1673
Merged
Yunnglin merged 2 commits intoAug 31, 2026
Merged
Conversation
Some gateways commit `200 OK` headers before the upstream has produced
anything, holding the connection open with whitespace padding so the request
does not time out. When the request then fails, the status line is already on
the wire and cannot be retracted, so the error is appended to the body of an
otherwise successful response:
HTTP/1.1 200 OK
content-type: application/json
\n \n ... (whitespace keepalive) ...
{"error":{"message":"Insufficient balance","code":402}}
The OpenAI SDK deserializes that into a `ChatCompletion` whose `choices` is
None, keeping the real error in `model_extra`. Nothing raises, so `retry_call`
sees a successful call and returns. `chat_choices_from_openai` then raises
ValueError — outside the retry boundary — which propagates through
`_predict_sample` and, with the default `ignore_errors=False`, discards the
entire run. Observed on OpenRouter, where a single transient upstream blip
ended a 1319-sample GSM8K run at sample 44; the same failure recurred three
times in a later 200-sample run.
Check for a choiceless completion inside `_create_and_collect`, so the failure
is raised where `retry_call` can act on it, and surface the gateway's own error
message instead of the current `id=None, model=None` report.
Responses that fail fast still return honest status codes and are unaffected:
they continue to be handled by the SDK's own retry and by
NON_RETRYABLE_OPENAI_ERRORS. Only the choices=None shape changes behaviour.
Claude-Session: https://claude.ai/code/session_0195nPGwxPjJGtQukF28BJfS
4 tasks
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 #1674
Summary
Some OpenAI-compatible gateways return an error payload with
200 OK. The OpenAI SDK deserializes it as aChatCompletionwithchoices=None, so the error previously surfaced outside EvalScope's retry boundary with limited diagnostics.This PR:
model_extra;400,401,402,403,404, and422errors;ValueErrorcompatibility and streaming behavior.Tests
Added deterministic, network-free coverage for: