Skip to content

feat: add Octokit retry and throttling plugins for resilient API calls#11

Merged
Leundai merged 4 commits intomainfrom
feat/octokit-retry-throttling-plugins
Jan 9, 2026
Merged

feat: add Octokit retry and throttling plugins for resilient API calls#11
Leundai merged 4 commits intomainfrom
feat/octokit-retry-throttling-plugins

Conversation

@Leundai
Copy link

@Leundai Leundai commented Jan 9, 2026

Summary

This PR adds official Octokit plugins for automatic retry and rate limit handling, making our GitHub API interactions more resilient to transient failures.

Changes

Dependencies

  • Added @octokit/plugin-retry (^6.0.0) - Automatic retries for 5xx errors and network failures
  • Added @octokit/plugin-throttling (^8.0.0) - Graceful rate limit handling

Configuration

Retry Plugin:

  • Automatically retries on 5xx server errors
  • Automatically retries on network failures (ECONNRESET, ETIMEDOUT, etc.)
  • Configured to NOT retry: 400, 401, 403, 404, 422 (these are not transient)
  • Uses exponential backoff by default

Throttling Plugin:

  • Handles GitHub rate limits (HTTP 429) gracefully
  • Respects Retry-After header from GitHub
  • Retries up to 3 times on primary rate limits
  • Retries once on secondary rate limits (abuse detection)
  • Logs rate limit events for visibility

Why Official Plugins?

Instead of implementing custom retry logic, we chose to use Octokit's official plugins because:

  1. Battle-tested: Used by thousands of projects in production
  2. Well-maintained: Actively maintained by the Octokit team
  3. Handles edge cases: Proper handling of rate limit headers, secondary limits, etc.
  4. Less code: Minimal changes to our codebase
  5. Future-proof: Will receive updates as GitHub API evolves

Testing

  • Lint passes
  • Manual testing with rate limit scenarios (optional)

Potential Future Improvements

  1. Make retry count configurable: Allow users to configure max retries via manifest config
  2. Add GraphQL throttling: Currently only REST API calls go through Octokit; GraphQL has its own retry logic
  3. Metrics/observability: Add structured logging or metrics for retry/throttle events
  4. Circuit breaker pattern: For extended outages, fail fast instead of retrying repeatedly

- Add @octokit/plugin-retry for automatic retries on 5xx errors and network failures
- Add @octokit/plugin-throttling for graceful rate limit handling
- Configure retry to skip 400, 401, 403, 404, 422 errors (non-retryable)
- Configure throttling to retry up to 3 times on rate limits
- Configure throttling to retry once on secondary rate limits
- Log rate limit events for visibility

This uses battle-tested official Octokit plugins instead of custom retry logic,
providing better compatibility and maintenance.
- Use integers instead of strings for doNotRetry status codes
- Add 409 (Conflict) and 410 (Gone) to doNotRetry list
- Preserve calling context in error stack traces through plugin layers
- Remove explicit type annotations from throttle handlers (let TS infer)

All 1063 tests now pass.
- Node 18 reached EOL in April 2025
- Update CI matrix to test Node 20 and 22
- Fix deprecated npm flag (--production → --omit=dev)
- Update actions/setup-node to v4
@Leundai Leundai merged commit 017f56f into main Jan 9, 2026
6 checks passed
@Leundai Leundai deleted the feat/octokit-retry-throttling-plugins branch January 9, 2026 19:35
@nombotv2 nombotv2 bot mentioned this pull request Jan 9, 2026
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