Skip to content

fix(eval): retry client-side timeouts in LLM judge evaluators - #8076

Open
rladeira wants to merge 1 commit into
google:mainfrom
rladeira:fix/eval-timeout-retry
Open

rladeira wants to merge 1 commit into
google:mainfrom
rladeira:fix/eval-timeout-retry

Conversation

@rladeira

@rladeira rladeira commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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, and HallucinationsV1Evaluator) call add_default_retry_options_if_not_present(llm_request) to populate llm_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:

  1. In released google-genai versions (<= 3.0.0) using aiohttp, _api_client._AIOHTTP_TRANSIENT_EXC only includes (ClientConnectorError, ClientOSError, ServerDisconnectedError) and omits asyncio.TimeoutError and google.auth.exceptions.TimeoutError (raised when AsyncAuthorizedSession wraps aiohttp timeouts).
  2. Custom BaseLlm judges resolved through LLMRegistry that do not consume GenerateContentConfig.http_options.retry_options get no retry on a builtin or google.auth timeout. (SDK-specific timeouts such as litellm.Timeout / openai.APITimeoutError and anthropic.APITimeoutError are out of scope; LiteLlm already forwards retry_options.attempts as num_retries.)
  3. In LlmAsJudge.evaluate_invocations(), a single failed sample discards all num_samples for that invocation and marks it EvalStatus.NOT_EVALUATED.

Solution:

  • Add timeout_retry_kwargs(llm_request, model) in src/google/adk/evaluation/_retry_options_utils.py that builds tenacity.AsyncRetrying arguments from llm_request.config.http_options.retry_options for (TimeoutError, google.auth.exceptions.TimeoutError).
  • Skip retrying at the evaluator layer when model is a Gemini instance and the installed google.genai._api_client._AIOHTTP_TRANSIENT_EXC already covers the exception (preventing double-retries once fix(retry): retry on aiohttp and google-auth timeout exceptions with HttpRetryOptions googleapis/python-genai#3330 ships).
  • Wrap judge generate_content_async calls in LlmAsJudge._evaluate_single_sample, PerTurnUserSimulatorQualityV1._sample_llm, and HallucinationsV1Evaluator._evaluate_nl_response with tenacity.AsyncRetrying(**timeout_retry_kwargs(...)).

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Added unit tests in tests/unittests/evaluation/test_retry_options_utils.py and tests/unittests/evaluation/test_llm_as_judge.py.

pytest summary:

$ uv run pytest tests/unittests/evaluation/test_retry_options_utils.py tests/unittests/evaluation/test_llm_as_judge.py tests/unittests/evaluation/test_hallucinations_v1.py tests/unittests/evaluation/simulation/test_per_turn_user_simulation_quality_v1.py -q
94 passed in 6.12s

Pre-commit & lint:

$ uv run pre-commit run --files src/google/adk/evaluation/_retry_options_utils.py src/google/adk/evaluation/llm_as_judge.py src/google/adk/evaluation/hallucinations_v1.py src/google/adk/evaluation/simulation/per_turn_user_simulator_quality_v1.py tests/unittests/evaluation/test_retry_options_utils.py tests/unittests/evaluation/test_llm_as_judge.py
All checks passed (ruff, isort, pyink, addlicense, compliance-checks, codespell).

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):

  • Before (main): calls: 2 status: EvalStatus.NOT_EVALUATED
  • After (this PR): calls: 3 status: EvalStatus.PASSED

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

Companion upstream fix in googleapis/python-genai: googleapis/python-genai#3330.

Comment on lines +66 to +67
if not isinstance(exc, _TIMEOUT_EXCEPTIONS):
return False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 False

fixed this plus a test in this commit, you can just cherry pick it instead of redoing it: its-amann@1165522

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@rladeira
rladeira force-pushed the fix/eval-timeout-retry branch from 113eea2 to f09f9f8 Compare November 26, 2026 06:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Eval LLM judges do not retry client-side TimeoutError / google.auth.exceptions.TimeoutError despite HttpRetryOptions

3 participants