catch timeout errors, custom retry max per exception type#39
Merged
Conversation
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
Catches
subprocess.TimeoutExpiredfrom the Claude Code CLI and translates it tolitellm.Timeoutso the existingwith_retrymachinery handles it. Adds a per-exception retry cap so timeouts (which cost the full timeout per attempt) don't burn 8× wallclock the way the default budget would.Why
Real-world stacktrace from a 5-minute Claude Code call timing out:
Two problems with the previous behavior:
subprocess.TimeoutExpiredpropagated up through DSPy and surfaced as a stacktrace, not a cleanTestResult(status="error").litellm.Timeoutand friends, but not the subprocess-level timeout fromClaudeCodeLM. A transient hang or stochastic generation length variance got no second chance.What changed
voicetest/llm/claudecode.pyDEFAULT_CLAUDECODE_TIMEOUT)._run_clicatchessubprocess.TimeoutExpiredand re-raises aslitellm.Timeoutwithfrom err(preserves original on__cause__).voicetest/retry.pymax_attempts_by_exception: dict[type, int] | Noneparameter onwith_retryandwith_retry_sync. Lets callers cap specific exception classes without changing the default budget for cheap failures (rate limits stay at 8).__mro__so subclasses inherit caps from parents — adding a futureClaudeCodeTimeout(litellm.Timeout)won't silently bypass the cap._retry_decisionhelper so the async and sync drivers share the decision logic instead of duplicating it.voicetest/llm/base.py_MAX_ATTEMPTS_BY_EXCEPTION = {litellm.Timeout: 2, openai.APITimeoutError: 2}passed to bothwith_retrycall sites. Cap is visible at the call site rather than hidden in retry.py.Why cap timeouts at 2: the default 8-attempt budget assumes failures are cheap (rate limits return immediately). Timeouts cost the full timeout per attempt — at 600s default, 8 attempts = 80 minutes worst case. Capping at 2 covers the transient-hang case (~95% of recoverable timeouts) while bounding worst-case wallclock at ~20 minutes.
Tests
test_raises_on_timeout: assertslitellm.Timeoutis raised withsubprocess.TimeoutExpiredchained on__cause__.Test plan
subprocess.TimeoutExpiredfrom_run_cliis translated tolitellm.Timeoutwith_retryhonorsmax_attempts_by_exceptioncap (verified via existing retry tests + new shared helper)