feat(github): honor rate limit reset headers on API retries#1532
Open
cleanjunc wants to merge 2 commits into
Open
feat(github): honor rate limit reset headers on API retries#1532cleanjunc wants to merge 2 commits into
cleanjunc wants to merge 2 commits into
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
GitHub returns the exact wait time on a rate limited response through the
Retry-Afterheader (seconds) or thex-ratelimit-resetheader (epoch seconds). The retry paths ingittensor/utils/github_api_tools.pyignored these hints and waited a short flat or generic interval, so a rate limit window that lasts minutes drained the retry budget and surfaced as a transient failure.A new reusable helper,
github_retry_delay, reads the advertised reset window and decides how long to wait:MAX_RATE_LIMIT_WAIT_SECONDS, 300s): wait the advertised window so a single sleep clears the limit.Both retry sites (
get_github_identityandexecute_graphql_query) route through the helper, so rate limit timing lives in one place and stays consistent. Header lookups rely on the case insensitive headers thatrequestsexposes, matching the lowercase names GitHub sends.Related Issues
Closes #1531
Type of Change
Enhancement to the existing GitHub rate limit retry handling.
Testing
Added unit tests in
tests/utils/test_github_api_tools.pycovering header priority, thex-ratelimit-resetepoch path, the case where the window exceeds the cap, fallback when no header is present, and both retry sites honoring the headers. The fulltests/utilsandtests/validatorsuites pass (712 passed). The helper was also exercised against realrequestsCaseInsensitiveDictheaders to confirm GitHub's lowercase casing resolves correctly.Checklist