Skip to content

fix(github): protect pull request API budget - #6466

Open
Bil0000 wants to merge 13 commits into
pingdotgg:mainfrom
Bil0000:fix/github-graphql-rate-limit
Open

fix(github): protect pull request API budget#6466
Bil0000 wants to merge 13 commits into
pingdotgg:mainfrom
Bil0000:fix/github-graphql-rate-limit

Conversation

@Bil0000

@Bil0000 Bil0000 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Problem

Opening a pull request could spend 104 GitHub GraphQL points in one read. T3 Code requested up to 100 replies for each review thread, followed every reply cursor, and refreshed activity every minute.

That can drain GitHub's shared 5,000-point hourly budget while one detail panel stays open.

Fix

  • Add rate-limit data to GitHub GraphQL reads.
  • Track the budget per GitHub host.
  • Pause automatic reads at the final 10% until GitHub resets the limit.
  • Keep mutations available while reads are paused.
  • Request 10 initial replies per review thread.
  • Load older replies only when the user selects Load more comments.
  • Change live refresh from one minute to five minutes.
  • Stop polling in hidden or idle clients.
  • Poll cheap core detail first. Refresh activity only when updatedAt changes.
  • Remove the redundant baseline list refresh.

Result

A measured 44-thread pull request now costs 14 GraphQL points on its initial read instead of 104. That is an 86.5% reduction. Extra reply pages cost points only when requested.

The reserve guard also prevents T3 Code background reads from consuming the final quota needed by other GitHub clients.

Verification

  • 228 focused tests pass.
  • Contracts, client runtime, server, and web typechecks pass.
  • Targeted lint and format checks pass.
  • Live GitHub query measured 104 points before and 14 after.

Built with Codex (GPT-5.6-sol) in T3 Code.

Note

Protect GitHub GraphQL API budget and add paginated review thread comment loading

  • Introduces GitHubGraphQlBudget service that tracks GitHub GraphQL rate limit usage per host, injects rateLimit fields into read queries, and blocks reads with GitHubGraphQlBudgetPausedError when remaining quota is at or below 10% of the limit until the reset window expires.
  • Adds a new getReviewThreadComments RPC (pullRequests.threadComments) for explicit cursor-based pagination of review thread comments; listReviewThreadComments no longer auto-fetches additional comment pages per thread.
  • ReviewThreadCard gains a 'Load more comments' button that lazy-loads additional pages, de-duplicates comments, and resets paginated state after edits, replies, or reactions.
  • Reduces comments fetched per review thread page from GRAPHQL_PAGE_SIZE to 10, and validates that a requested thread belongs to the target pull request before returning results.
  • Slows live refresh polling from 1 minute to 5 minutes and refreshes pull request activity only when updatedAt changes for the same PR.
  • Behavioral Change: callers of listReviewThreadComments now receive truncated threads with a nextCommentsCursor rather than fully expanded comment lists; reads will fail with a typed error when GitHub quota is nearly exhausted.

Macroscope summarized 8815403.

@coderabbitai

coderabbitai Bot commented Aug 13, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7c773545-f5ed-46c6-a99f-c0ae816ad499

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Aug 13, 2026
@macroscopeapp

macroscopeapp Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Needs human review

This PR introduces a new rate limiting service that can pause GitHub API calls, changes the review thread loading strategy from eager to lazy pagination, increases the refresh interval from 1 to 5 minutes, and adds a new RPC endpoint. These are significant runtime behavior changes affecting core functionality that warrant human review.

You can customize Macroscope's approvability policy. Learn more.

macroscopeapp[bot]
macroscopeapp Bot previously approved these changes Aug 13, 2026
@macroscopeapp
macroscopeapp Bot dismissed their stale review August 13, 2026 14:53

Dismissing prior approval to re-evaluate d0bec12

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). and removed vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:XS 0-9 changed lines (additions + deletions). labels Aug 13, 2026
Comment thread apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx
Comment thread apps/server/src/pullRequest/PullRequestService.ts
Comment thread apps/web/src/hooks/useLiveRefresh.ts
@Bil0000 Bil0000 changed the title fix(server): cut pull request GraphQL cost fix(github): protect pull request API budget Aug 13, 2026

@macroscopeapp macroscopeapp Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two Effect service convention issues in the new GraphQL budget path. Details inline.

Posted via Macroscope — Effect Service Conventions

Comment thread apps/server/src/sourceControl/githubGraphQlBudget.ts Outdated
Comment thread apps/server/src/pullRequest/GitHubPullRequestCli.ts Outdated

@macroscopeapp macroscopeapp Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two Effect service convention issues in the new GraphQL budget path. Details inline.

Posted via Macroscope — Effect Service Conventions

Comment thread apps/server/src/pullRequest/GitHubPullRequestCli.ts Outdated
Comment thread apps/server/src/sourceControl/githubGraphQlBudget.ts Outdated
Reject thread IDs from another pull request without adding a second GraphQL request.
Track quota inside the injected Effect layer and report local pauses as structured errors instead of synthetic CLI failures.
@github-actions github-actions Bot added size:XL 500-999 changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). labels Aug 13, 2026
Comment thread apps/server/src/sourceControl/githubGraphQlBudget.ts Outdated
Concurrent reads can finish out of order. Keep the lower remaining quota within one reset window and ignore responses from older windows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL 500-999 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant