fix: add 429 rate limit retry with exponential backoff#832
Open
xodn348 wants to merge 1 commit intoanthropics:mainfrom
Open
fix: add 429 rate limit retry with exponential backoff#832xodn348 wants to merge 1 commit intoanthropics:mainfrom
xodn348 wants to merge 1 commit intoanthropics:mainfrom
Conversation
Agent sessions can fail after a recoverable 429 from the Claude Code subprocess. This adds bounded retry with exponential backoff, preserves the original ProcessError when retries are exhausted, and captures stderr so retry detection can see the API error payload. Constraint: Keep retry disabled by setting rate_limit_max_retries=0 and avoid changing caller git config.\nRejected: Treat every subprocess failure as retryable | would mask non-rate-limit process errors.\nConfidence: medium\nScope-risk: moderate\nTested: uv run --extra dev pytest -q tests/test_rate_limit_retry.py; uv run --extra dev ruff check src/claude_agent_sdk tests/test_rate_limit_retry.py; uv run --extra dev mypy src/claude_agent_sdk tests/test_rate_limit_retry.py; python3 -m compileall -q src/claude_agent_sdk tests/test_rate_limit_retry.py\nNot-tested: Live Claude Code 429 from the API.
2bee4ae to
07aa047
Compare
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.
Fixes #812.
This makes transient 429 rate limit failures recoverable for agent sessions:
rate_limit_max_retriestoClaudeAgentOptionswith a default of 3 and0as an opt-out429/rate_limit_errorProcessErrorcarries the API error payload needed for retry detectionRateLimitErrorafter retry exhaustion with the originalProcessErrorattachedI rebased this on current
upstream/mainand kept the retry path scoped to rate-limit process errors.Testing:
Results: 14 targeted tests passed; ruff passed; mypy passed; compileall passed.