Skip to content

Conversation

@ghinks
Copy link
Owner

@ghinks ghinks commented Aug 22, 2025

Summary

Implements intelligent GitHub API rate limiting to prevent hitting API limits while maintaining optimal performance.

Key Features

  • Smart backoff logic - Monitors X-RateLimit-Remaining and X-RateLimit-Reset headers
  • Configurable thresholds - 10 request buffer with minimum 60-second sleep
  • Dual implementation - Async for get_reviewers_rest.py and sync for get_prs.py
  • Robust error handling - Gracefully handles missing or invalid headers
  • Informative logging - Shows remaining requests and sleep duration
  • Header compatibility - Supports both hyphenated and underscore variations

Implementation Details

Async Rate Limiting (get_reviewers_rest.py)

  • check_rate_limit_and_sleep() function integrated into fetch operations
  • Sleeps until rate limit reset when remaining requests ≤ 10
  • Uses asyncio.sleep() for non-blocking operation

Sync Rate Limiting (get_prs.py)

  • backoff_if_ratelimited() function called after each API response
  • Calculates sleep time based on reset timestamp with 5-second buffer
  • Uses time.sleep() for synchronous operation

Testing

  • ✅ All 60 tests pass
  • ✅ MyPy type checking passes
  • ✅ Ruff linting clean
  • ✅ No functionality broken

Example Behavior

GitHub API rate limit approaching. Remaining: 8, sleeping for 245 seconds.

🤖 Generated with Claude Code

- Added async rate limiting function in get_reviewers_rest.py
- Checks X-RateLimit-Remaining and X-RateLimit-Reset headers
- Sleeps until rate limit reset when approaching threshold (10 requests buffer)
- Added synchronous rate limiting function in get_prs.py
- Handles both hyphenated and underscore header variations
- Robust error handling for missing or invalid headers
- Informative logging when rate limits are approached
- Fixed mypy type error with float conversion
- All 60 tests pass and code style is clean

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@ghinks ghinks merged commit b1537fc into main Aug 22, 2025
9 checks passed
@ghinks ghinks deleted the feat/github-ratelimit-backoff branch August 22, 2025 18:25
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.

2 participants