Repository navigation
fix(models): count non-200 responses against OpenAI retry limit - #2752
Open
pcbeingused333 wants to merge 1 commit into
Open
pcbeingused333 wants to merge 1 commit into
pcbeingused333 wants to merge 1 commit into
Conversation
OpenAI._generate hit 'continue' on any non-200 response before reaching max_num_retries += 1, so a persistent 401/400/500 looped forever instead of raising after self.retry attempts. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Symptom. An evaluation using
OpenAIwith an invalid key (HTTP 401) hangs forever instead of failing, since the non-200 branch never consumes a retry.Root cause. In
OpenAI._generate(opencompass/models/openai_api.py), a non-200 HTTP response logs the error and doescontinue. That skipsmax_num_retries += 1(which sits after thefinally), so a persistent 401/400/500 never reaches theRuntimeErrorafterself.retryattempts and the evaluation loops forever.Fix. Increment
max_num_retriesbefore thecontinueon the non-200 branch, so it consumes one retry like the connection-error path does. HTTP 429 is the exception: it is transient, so it sleeps 10 s and retries without consuming one (same as the existingrate_limit_exceededhandling), so rate limiting does not turn into a failure.Behaviour change. A persistent non-429 error (401/400/5xx) now raises
RuntimeErrorafterretryattempts instead of retrying forever, the same as the connection-error path; raiseretryfor flaky backends.Test.
test_generate_non_200_respects_retry_limitmocks a permanent 401 withretry=2and assertsRuntimeErrorafter exactly 2 requests (before the fix the loop never terminates; the mock aborts after 10 calls).test_generate_429_then_successcovers 429, 429, 200 withretry=2succeeding.Disclosure: this change was prepared with the assistance of an AI coding tool (Claude Code) and submitted for review by the contributor.