Repository navigation
Conversation
3ee4682 to
113eea2
Compare
| if not isinstance(exc, _TIMEOUT_EXCEPTIONS): | ||
| return False |
There was a problem hiding this comment.
this only catches builtin and google.auth timeouts, but a LiteLlm judge times out with litellm.Timeout (an openai.APITimeoutError) and AnthropicLlm with anthropic.APITimeoutError. neither is a TimeoutError, so the non Gemini judges from point 2 in the description still never get retried. checking the SDK classes that are already imported covers them without pulling openai or anthropic in at import time:
+import sys
...
+_SDK_TIMEOUT_EXCEPTIONS = (
+ ("openai", "APITimeoutError"),
+ ("anthropic", "APITimeoutError"),
+)
+
+
+def _is_timeout_error(exc: BaseException) -> bool:
+ if isinstance(exc, _TIMEOUT_EXCEPTIONS):
+ return True
+ for module_name, class_name in _SDK_TIMEOUT_EXCEPTIONS:
+ exc_type = getattr(sys.modules.get(module_name), class_name, None)
+ if exc_type is not None and isinstance(exc, exc_type):
+ return True
+ return False
...
- if not isinstance(exc, _TIMEOUT_EXCEPTIONS):
+ if not _is_timeout_error(exc):
return Falsefixed this plus a test in this commit, you can just cherry pick it instead of redoing it: its-amann@1165522
There was a problem hiding this comment.
Thanks for checking this. You're right: litellm.Timeout subclasses openai.APITimeoutError, not TimeoutError, so this change does not retry it, and point 2 of the description overstated the scope. I've corrected the description.
This PR is scoped to #8075: the builtin and google.auth timeouts that the evaluators' own retry_options were meant to cover but never did. LiteLlm already forwards http_options.retry_options.attempts to LiteLLM as num_retries, so catching SDK timeouts here as well could stack a second retry layer on top of LiteLLM's. If maintainers want SDK-specific timeouts handled at the evaluator level, I'd rather do that in a follow-up that accounts for each SDK's own retries.
Add timeout_retry_kwargs() in _retry_options_utils.py and wrap LLM judge calls in LlmAsJudge, PerTurnUserSimulatorQualityV1, and HallucinationsV1Evaluator with tenacity.AsyncRetrying for client-side TimeoutError and google.auth.exceptions.TimeoutError when not already retried by google-genai's aiohttp transport. Closes google#8075
113eea2 to
f09f9f8
Compare
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
ADK's LLM-backed evaluators (
LlmAsJudge,PerTurnUserSimulatorQualityV1, andHallucinationsV1Evaluator) calladd_default_retry_options_if_not_present(llm_request)to populatellm_request.config.http_options.retry_options(_DEFAULT_HTTP_RETRY_OPTIONS, 7 attempts with exponential backoff).However, when a judge call times out on the client side waiting for TTFB on long multi-turn evaluation prompts:
google-genaiversions (<= 3.0.0) usingaiohttp,_api_client._AIOHTTP_TRANSIENT_EXConly includes(ClientConnectorError, ClientOSError, ServerDisconnectedError)and omitsasyncio.TimeoutErrorandgoogle.auth.exceptions.TimeoutError(raised whenAsyncAuthorizedSessionwrapsaiohttptimeouts).BaseLlmjudges resolved throughLLMRegistrythat do not consumeGenerateContentConfig.http_options.retry_optionsget no retry on a builtin orgoogle.authtimeout. (SDK-specific timeouts such aslitellm.Timeout/openai.APITimeoutErrorandanthropic.APITimeoutErrorare out of scope;LiteLlmalready forwardsretry_options.attemptsasnum_retries.)LlmAsJudge.evaluate_invocations(), a single failed sample discards allnum_samplesfor that invocation and marks itEvalStatus.NOT_EVALUATED.Solution:
timeout_retry_kwargs(llm_request, model)insrc/google/adk/evaluation/_retry_options_utils.pythat buildstenacity.AsyncRetryingarguments fromllm_request.config.http_options.retry_optionsfor(TimeoutError, google.auth.exceptions.TimeoutError).modelis aGeminiinstance and the installedgoogle.genai._api_client._AIOHTTP_TRANSIENT_EXCalready covers the exception (preventing double-retries once fix(retry): retry on aiohttp and google-auth timeout exceptions with HttpRetryOptions googleapis/python-genai#3330 ships).generate_content_asynccalls inLlmAsJudge._evaluate_single_sample,PerTurnUserSimulatorQualityV1._sample_llm, andHallucinationsV1Evaluator._evaluate_nl_responsewithtenacity.AsyncRetrying(**timeout_retry_kwargs(...)).Testing Plan
Unit Tests:
Added unit tests in
tests/unittests/evaluation/test_retry_options_utils.pyandtests/unittests/evaluation/test_llm_as_judge.py.pytestsummary:Pre-commit & lint:
Manual End-to-End (E2E) Tests:
Verified with the reproducer script in #8075 (first sample attempt raises
asyncio.TimeoutError, second attempt yields a valid judge response):calls: 2 status: EvalStatus.NOT_EVALUATEDcalls: 3 status: EvalStatus.PASSEDChecklist
Additional context
Companion upstream fix in
googleapis/python-genai: googleapis/python-genai#3330.