Fix GitHub Primary Rate Limit Errors Not Retried

Offen
#175 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
72/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
github, typescript

Rechercherichtung

Start in packages/provider-github/src/http.ts, especially withRetry and assertResponseOk, then read the GitHubError definition and nearby tests. Add coverage for primary rate limit 403 responses, reset-header backoff, and Retry-After handling. Done means these errors retry using the provided timing headers where present, and the issue’s listed typecheck, test, and lint commands pass.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

bug good first issue

Summary

Codra's GitHub API client retries secondary rate limit errors (HTTP 403 with body "secondary rate limit") and HTTP 429/5xx errors, but does not retry primary rate limit errors. GitHub returns HTTP 403 (not 429) for primary rate limits, so these requests fail immediately and permanently, aborting in-progress reviews.

Affected File

packages/provider-github/src/http.ts - withRetry (lines 45-85):

const isSecondaryRateLimit =
  error instanceof GitHubError &&
  error.status === 403 &&
  error.body?.toLowerCase().includes("secondary rate limit");

const isRetryable =
  isSecondaryRateLimit ||
  (error instanceof GitHubError && (error.status === 429 || error.status >= 500)) ||
  error.name === "TimeoutError" ||
  error.message.includes("timeout");

Why GitHub Uses 403 for Primary Rate Limits

GitHub's REST API returns HTTP 403 Forbidden with the error body "API rate limit exceeded for installation ID ..." and includes these response headers:

  • x-ratelimit-remaining: 0 - confirms the quota is exhausted
  • x-ratelimit-reset: <epoch> - UTC epoch second when the quota resets

Since the check only recognizes "secondary rate limit" text, primary rate limit 403s fall through to the non-retryable path and immediately throw, causing the review to fail.

Proposed Fix

  1. Detect primary rate limit 403s:
const isPrimaryRateLimit =
  error instanceof GitHubError &&
  error.status === 403 &&
  (error.body?.toLowerCase().includes("rate limit exceeded") ||
   error.body?.toLowerCase().includes("api rate limit"));
  1. Capture x-ratelimit-reset from response headers and use it to calculate precise sleep duration:
// In assertResponseOk - capture headers
throw new GitHubError(response.status, errText, path, `...`, response.headers);
// In withRetry - respect x-ratelimit-reset
const rateLimitReset = error.headers?.get("x-ratelimit-reset");
const delay = rateLimitReset
  ? Math.max(0, parseInt(rateLimitReset, 10) * 1000 - Date.now()) + 1000
  : Math.pow(2, attempt) * 30000;

Done When

  • HTTP 403 responses with primary rate limit body text are retried with appropriate backoff
  • x-ratelimit-reset header is used to calculate wait time where present
  • Retry-After header on 429 responses is also respected
  • GitHubError carries response headers for use in retry logic
  • Tests cover primary rate limit 403 retry and x-ratelimit-reset backoff calculation
  • npm run typecheck, npm test, and npm run lint all pass
Vorherrschende Sprache
TypeScript
Sterne
125
Forks
23
Ø Merge
2 T. 13 Std.
Gemergte PRs (30 T.)
12

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus devarshishimpi/codra

Alle Issues in devarshishimpi/codra

Ähnliche Issues

Weitere Issues zu TypeScript

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.