Overview
The GitHub Achievement CLI implements sophisticated rate limiting to stay within GitHub’s API limits and prevent errors. The tool uses a sliding window algorithm to track requests and automatically manages concurrency.GitHub API Rate Limits
GitHub enforces two main types of rate limits:- Primary rate limit: 5,000 requests per hour for authenticated requests
- Secondary rate limit: 80 content-creating requests per minute (for PRs, commits, issues, etc.)
CLI Rate Limiting Implementation
The tool implements a multi-layered rate limiting system to prevent hitting GitHub’s limits:Operation-Level Limits
Why 15 operations per minute? Each operation makes approximately 5 API calls (create branch, commit, PR, merge, delete branch). This gives us
15 × 5 = 75 API calls per minute, safely under GitHub’s 80 request/minute limit.How It Works
The rate limiter uses a sliding window approach:- Tracks timestamps of all operations in the last 60 seconds
- Cleans up old entries outside the window automatically
- Waits when limits are reached until slots become available
- Enforces concurrency to prevent overwhelming the API
src/utils/rateLimiter.ts:93-107:
Automatic Retry with Backoff
When the CLI encounters a rate limit error (HTTP 429), it automatically retries using exponential backoff:Retry Parameters
- Maximum retries: 5 attempts (from
src/utils/timing.ts:15) - Base delay: 1000ms
- Backoff multiplier: 2x per attempt
- Maximum delay: 60 seconds
- Jitter: Random 0-1000ms added to prevent synchronized retries
The jitter ensures that if multiple operations hit rate limits simultaneously, they don’t all retry at exactly the same time.
Configuring Delays
You can adjust rate limiting behavior through environment variables:DELAY_MS
Adds additional delay between individual operations:src/achievements/base.ts:162-165:
Increase
DELAY_MS if you’re still encountering rate limit errors. Try values like 2000 (2 seconds) or 3000 (3 seconds).Safe Delay Bounds
The CLI enforces minimum and maximum delays for safety:Understanding Rate Limit Errors
Common Error Messages
“Rate limiter: waiting Xms”- Normal operation - the CLI is pacing requests
- No action needed
- GitHub’s 80 requests/minute limit was hit
- The CLI will automatically retry with exponential backoff
- Consider increasing
DELAY_MSor reducingBATCH_SIZE
- Primary rate limit (5000/hour) was reached
- Wait for rate limit to reset (shown in error message)
- Very rare with default settings
Checking Rate Limit Status
The rate limiter provides real-time statistics:Best Practices
Recommended Settings
For most users (default settings work well):Rate Limit Buffer
The CLI adds a 5-second buffer when waiting for rate limits to reset:Advanced: Custom Rate Limiter
You can programmatically configure the rate limiter if using the CLI as a library:See Also
- Concurrency Control - Managing parallel operations
- Configuration - All environment variables
- GitHub Rate Limit Documentation