Add retry and rate-limit handling to GitHubClient#15
Merged
Conversation
Contributor
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
|
User devin-ai-integration[bot] does not have write permissions |
Keramikus-97
approved these changes
Jun 9, 2026
Keramikus-97
approved these changes
Jun 9, 2026
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
GitHubClientnow transparently retries transient failures and honors GitHub's rate-limit signals, instead of raising on the first non-2xx/transport error. This makes the client resilient to the429/403rate limits and5xx/network blips that are common against the GitHub API._requestgained a retry loop:Idempotency: transient errors (
5xx/transport) are retried only for idempotent methods so a non-idempotentPOST(e.g.create_issue_comment) is never duplicated. Rate-limit responses are retried for all methods, since a rate-limited request was rejected before taking effect.Retry delay precedence:
Retry-Afterheader →X-RateLimit-Reset(whenX-RateLimit-Remaining == 0) → exponential backoff with full jitter, all capped atmax_backoff.New/changed interfaces:
RateLimitError(GitHubAPIError)carrying parsedretry_after/reset_at(orNonewhen headers are absent/unparseable). Exported from the package.GitHubClient(..., max_retries=3, backoff_factor=0.5, max_backoff=60.0, sleep=None).sleepis injectable so tests run instantly and deterministically (defaults toasyncio.sleep).GitHubClient.from_config(config, sleep=None)builds a client fromConfig.Configgainsmax_retries/backoff_factor, read fromOPENCODE_MAX_RETRIES/OPENCODE_BACKOFF_FACTORwith safe fallbacks/clamping.Behavior note: a
403without a rate-limit signal is treated as a normal error (raised immediately, not retried), so permission errors are not masked.Testing
ruff check .clean,pyright srcclean.pytest— 143 passed; total coverage 98.8% (github_client.py99%).RateLimitErroron exhaustion,Retry-Afterhonored,X-RateLimit-Reset-driven delay, 403-rate-limit vs non-rate-limit 403, backoff cap,max_retries=0, invalid-header fallbacks,204 → None, and idempotency (POST not retried on 5xx/transport, POST retried on 429).github_clienttests updated only to inject the no-opsleepvia theclientfixture (assertions unchanged).Link to Devin session: https://app.devin.ai/sessions/bee4c1ccb6884995a794d0e8e454ed27
Requested by: @Keramikus-97