fix(llm): raise on API failure instead of silent empty fallback#326
Open
ZwwWayne wants to merge 1 commit into
Open
fix(llm): raise on API failure instead of silent empty fallback#326ZwwWayne wants to merge 1 commit into
ZwwWayne wants to merge 1 commit into
Conversation
AsyncOpenAIWrapper.chat() previously returned a fabricated ChatCompletion with empty content when all retries were exhausted. Callers had no way to distinguish a real empty response from a total API outage, which silently corrupted downstream results. - Remove the fallback_response pattern; raise RuntimeError after retries are exhausted so callers can handle the failure explicitly. - Non-retryable exceptions are re-raised immediately instead of being swallowed. - Replace print() with logger.warning() for retry diagnostics. - Clean up unused imports (uuid, Choice, ChatCompletionMessage).
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.
Summary
AsyncOpenAIWrapper.chat()previously returned a fabricatedChatCompletionwith empty content when all retries were exhausted. Callers could not distinguish a real empty response from a total API outage, which silently corrupted downstream results (e.g. evaluation pipelines saw 0-score rounds with no indication of the actual failure).RuntimeErrorafter retries are exhausted so callers can handle failures explicitly.print()withlogger.warning()for retry diagnostics.uuid,Choice,ChatCompletionMessage).Motivation
When using
AsyncOpenAIWrapperin a benchmark evaluation harness, intermittent 502/timeout errors from the API resulted in 15 out of 27 tasks silently producing zero-score results — the fallbackChatCompletion(content='')was indistinguishable from a valid but empty model response. The caller had no opportunity to retry at a higher level or log the actual failure.Test plan
from lagent.llms.openai import AsyncOpenAIWrapperimports cleanlytry/except RuntimeErrorto handle persistent failures gracefully🤖 Generated with Claude Code