Skip to content

Retry primary rate limit errors in GitHub API client - #188

Closed
bfs2021 wants to merge 1 commit into
devarshishimpi:mainfrom
bfs2021:fix/primary-rate-limit-retry
Closed

bfs2021 wants to merge 1 commit into
devarshishimpi:mainfrom
bfs2021:fix/primary-rate-limit-retry

Conversation

@bfs2021

@bfs2021 bfs2021 commented Nov 18, 2026

Copy link
Copy Markdown

Problem

The GitHub API client retries secondary rate limits (403 + "secondary rate limit"), HTTP 429, and 5xx errors, but not primary rate limits. GitHub returns HTTP 403 with body "API rate limit exceeded for installation ID ..." for primary limits, so those requests fail immediately and abort in-progress reviews. Fixes #175.

Root cause

withRetry only classified a 403 as retryable when the body contained "secondary rate limit". Primary rate-limit 403s fell through to the non-retryable path. Separately, GitHubError did not carry response headers, so the x-ratelimit-reset value needed to compute an exact wait was discarded by assertResponseOk.

Fix

  • Detect primary rate-limit 403s ("rate limit exceeded" / "api rate limit" in the body) alongside secondary ones.
  • Carry response headers on GitHubError; assertResponseOk now passes response.headers.
  • When x-ratelimit-reset is present, wait Math.max(0, reset*1000 - now) + 1000; otherwise use the existing exponential backoff (2^attempt * 30s for rate limits).

Testing

  • Added packages/provider-github/test/http-rate-limit.spec.ts: 4 tests covering primary 403 retry-and-succeed, exact x-ratelimit-reset wait, backoff fallback, and header propagation through assertResponseOk. Written red first (4 failures), green after the fix.
  • npm test -w @codraoss/provider-github — 4/4 pass.
  • npm run typecheck -w @codraoss/provider-github — pass.
  • npx eslint on all changed files — pass.

Detect HTTP 403 primary rate limits alongside secondary ones, carry response headers on GitHubError, and honor x-ratelimit-reset for exact retry waits. Fixes devarshishimpi#175.

Signed-off-by: bfs2021 <[email protected]>

@codra-app-personal codra-app-personal Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codra Review

✅ Nothing to flag. Reviewed 3 files (158 changed lines) and found no issues worth raising.

Reviewed commit: 7f5c7c8fb9

ℹ️ About Codra in GitHub

Your team has set up Codra to review pull requests in this repo. Reviews are triggered when you:

  • Open a pull request for review
  • Mark a draft as ready

Every review posts a summary here. A clean pass also gets a 👍 on the pull request itself.

@devarshishimpi

Copy link
Copy Markdown
Owner

Hey! @bfs2021 I'll require you to sign the CLA and complete the PR format first in order to review the PR.

@devarshishimpi

Copy link
Copy Markdown
Owner

Seems like mass creation of PRs with AI. Closing this.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix GitHub Primary Rate Limit Errors Not Retried

2 participants