feat(fetch): add retry/backoff for transient 429/5xx and network errors#4456
Open
chakshu-dhannawat wants to merge 1 commit into
Open
feat(fetch): add retry/backoff for transient 429/5xx and network errors#4456chakshu-dhannawat wants to merge 1 commit into
chakshu-dhannawat wants to merge 1 commit into
Conversation
- Retry on HTTP 429, 500, 502, 503, 504 and httpx.TransportError - Respect Retry-After header on 429; fall back to full-jitter exponential backoff capped at 30 s - Default 3 retries; configurable via max_retries param and --max-retries CLI flag - Add 12 new tests covering retry path, exhaustion, 404 non-retry, and Retry-After parsing
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
Resolves #4449.
The Python fetch server currently raises
McpErrorimmediately on any HTTP error or non-2xx status. This means a single transient 429 (rate-limit), 503 (overloaded server), or momentary network timeout causes the fetch to fail completely, forcing the LLM to retry the whole tool call.Changes:
max_retries(default 3)httpx.TransportError(coversTimeoutException,ConnectError, etc.)Retry-Afterheader on 429; fall back to full-jitter exponential backoff capped at 30 s--max-retriesCLI flag so operators can tune or disable retries (--max-retries 0)_retry_waitunit testsNon-retryable errors (400, 401, 403, 404, etc.) still raise immediately — unchanged behavior.
Test plan
uv run pytest -vuv run ruff check .uv run pyright--max-retries 0to verify backwards-compatible opt-out🤖 Generated with Claude Code