Skip to content

Treat Anthropic APITimeoutError as retryable in the stream error classifier - #4

Open
shoemoney wants to merge 1 commit into
perplexityai:mainfrom
shoemoney:fix/retry-classifier-timeout
Open

Treat Anthropic APITimeoutError as retryable in the stream error classifier#4
shoemoney wants to merge 1 commit into
perplexityai:mainfrom
shoemoney:fix/retry-classifier-timeout

Conversation

@shoemoney

Copy link
Copy Markdown

is_retryable_anthropic_stream_error (agents/relay/providers/anthropic/events.py:162) decides retry by comparing type(error).__name__ against {"APIConnectionError", "APIStatusError"}. In the pinned anthropic SDK (0.116.0 per uv.lock), APITimeoutError subclasses APIConnectionError, so an isinstance check would already have treated timeouts as retryable, but the __name__ equality check does not see subclasses. A timeout is also not an httpx.TransportError and carries no status_code, so it falls through every branch and the classifier returns False. The result is that a single network timeout on the managed-agent event stream aborts the run (endpoint.py:379/396/560, files.py:123) instead of retrying, which is precisely the transient failure the retry loop exists for.

Fix: add "APITimeoutError" and "TimeoutError" to the name set, matching the set already used by _is_retryable_openai_error in agents/relay/providers/openai/endpoint.py. Kept the name-based comparison style used by both classifiers rather than switching to isinstance.

Test: added agents/relay/providers/anthropic/test_events_retry.py. Constructing anthropic.APITimeoutError(request=...) against the locked SDK, the classifier returned False before this change and True after; non-retryable errors (400) still return False. Verified with uv sync --locked; ruff check per .github/workflows/checks.yml passes.

is_retryable_anthropic_stream_error compares type(error).__name__ against
a fixed name set. anthropic.APITimeoutError subclasses APIConnectionError,
but the name comparison does not see subclasses, so a request timeout on
the managed-agent event stream aborted the run instead of retrying.

Add APITimeoutError and TimeoutError to the set, matching the name set
already used by _is_retryable_openai_error in the OpenAI provider, and
add a regression test.
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.

1 participant