Skip to content

feat: add GitHub API rate-limit budget manager#695

Open
pavsoss wants to merge 1 commit into
Coder-s-OG-s:mainfrom
pavsoss:rate-limit
Open

feat: add GitHub API rate-limit budget manager#695
pavsoss wants to merge 1 commit into
Coder-s-OG-s:mainfrom
pavsoss:rate-limit

Conversation

@pavsoss

@pavsoss pavsoss commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Introduces a shared GitHub API rate-limit budget manager to coordinate primary REST API usage across heavy background jobs.

Multiple Inngest jobs can run concurrently and independently consume the same GitHub App installation quota. This change tracks the known per-installation API budget and pauses heavy background work when the remaining quota falls below a safe threshold.

Changes Made

Rate-Limit Budget Manager

  • Added src/lib/github/rate-budget.ts.
  • Tracks the latest known x-ratelimit-remaining and x-ratelimit-reset values.
  • Scopes cached budget state per GitHub App installation.
  • Supports a configurable GITHUB_API_BUDGET_THRESHOLD with a default of 500.
  • Explicitly handles unknown budget state by allowing requests until the real budget is learned.
  • Validates rate-limit values before updating the cache.
  • Fails open if the cache backend is unavailable so budget tracking cannot break GitHub API requests.

Octokit Integration

  • Added an Octokit request wrapper through hook.wrap('request').
  • Captures rate-limit headers from both successful and failed GitHub API responses.
  • Preserves successful responses and rethrows original request errors unchanged.
  • Automatically updates the installation budget for requests made through getInstallOctokit.

Background Job Coordination

Added budget checks to heavy GitHub API background jobs:

  • issues-sweep
  • pr-backfill
  • maintainer-discover

When the known remaining quota falls below the configured threshold, jobs use step.sleepUntil to pause until the GitHub reset window plus a small safety buffer.

Sleep steps use deterministic scoped IDs to remain compatible with Inngest's durable execution model.

User-visible GitHub writes remain ungated so the reserved quota can continue serving interactive workflows.

Tests

  • Added budget manager tests covering:
    • unknown budget state
    • available budget
    • depleted budget
    • invalid threshold configuration
    • malformed rate-limit values
  • Updated Octokit tests to verify rate-limit header capture for successful and failed responses.
  • Updated Inngest test mocks for budget checks and durable sleep behavior.

Closes #667

@vercel

vercel Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

@pavsoss is attempting to deploy a commit to the codersogs-3057's projects Team on Vercel.

A member of the Team first needs to authorize it.

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.

[FEATURE] GitHub API Rate-Limit Budget Manager

1 participant