Skip to content

fix(pull-requests): protect provider API budgets - #6466

Merged
juliusmarminge merged 26 commits into
pingdotgg:mainfrom
Bil0000:fix/github-graphql-rate-limit
Aug 16, 2026
Merged

fix(pull-requests): protect provider API budgets#6466
juliusmarminge merged 26 commits into
pingdotgg:mainfrom
Bil0000:fix/github-graphql-rate-limit

Conversation

@Bil0000

@Bil0000 Bil0000 commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Problem

Pull request browsing could drain source-control API quotas. One GitHub detail load spent 104 GraphQL points because T3 Code requested up to 100 replies per review thread, followed every reply cursor, and refreshed activity every minute.

GitLab, Bitbucket, and Azure DevOps used different APIs, but none had a shared host cooldown after a provider returned a rate limit. Concurrent clients could keep sending requests during the same throttle window.

Fix

  • Add one Effect-based cooldown service shared by all pull request providers and keyed by provider plus host.
  • Detect native GitHub, GitLab, Bitbucket, and Azure DevOps rate-limit failures.
  • Honor exact reset times and Retry-After when available. Otherwise, back off from 30 seconds up to 15 minutes.
  • Stop automatic reads during an active cooldown. Keep user actions available while still recording any throttle they receive.
  • Track GitHub GraphQL cost per host, reserve in-flight query cost, and protect the final 10% for interactive action checks.
  • Route every direct GitHub pull request GraphQL read through that budget.
  • Reuse the shared provider cooldown error for GraphQL budget pauses instead of a GitHub-only error path.
  • Request 10 initial replies per review thread. Load older replies only when the user selects Load more comments.
  • Refresh visible, active views every five minutes. Refresh activity only when updatedAt changes.
  • Remove the redundant baseline list refresh.
  • Keep loaded review comments visible after edits and reactions.
  • Verify paged GitHub review threads belong to the requested repository and pull request.

Result

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

When any supported provider throttles T3 Code, automatic reads stop locally instead of causing a retry storm. GitHub also protects quota for user actions before the hard limit is reached.

Verification

  • 321 provider and transport tests pass on the latest cleanup; the broader 410-test PR suite also passed.
  • Contracts, client runtime, server, and web typechecks pass.
  • Targeted lint and format checks pass.
  • Live GitHub measurement confirmed the initial-query reduction from 104 points to 14.

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

Note

Protect provider API budgets with rate-limit gating and paginated review thread comments

  • Introduces SourceControlRateLimit, a process-local coordinator that enforces per-provider/host backoff with exponential fallback; read-like PR operations are blocked when paused, while interactive operations (replies, reactions, reviews) bypass the gate.
  • Adds GitHubGraphQlBudget, a client-side budget tracker that injects rateLimit fields into GitHub GraphQL queries and blocks reads when remaining quota falls below 10%, with per-host isolation and out-of-order response resilience.
  • All four providers (GitHub, GitLab, Azure DevOps, Bitbucket) now classify rate-limit exits/responses as a distinct rate-limited failure reason, propagating retryAt parsed from Retry-After headers where available.
  • Adds explicit pagination for GitHub review thread comments: listReviewThreadComments no longer auto-fetches all pages; clients use a new threadComments RPC (pullRequests.threadComments) and a "Load more comments" button in ReviewThreadCard.
  • Slows live refresh cadence from 1 minute to 5 minutes and raises the idle cutoff from 5 to 6 minutes to reduce background API pressure.
  • Behavioral Change: long review threads previously returned all comments eagerly; they now return a cursor and require explicit client-driven pagination.

Macroscope summarized db693e5.

@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: b2df5b6b-a222-495c-b512-b61ba021a0b8

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 new rate-limiting infrastructure and GraphQL budget tracking that gates API access based on quota state. It also changes polling intervals (1min → 5min) and thread comment loading behavior. These are significant runtime behavioral changes 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.

@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.

One finding in the review-thread card's new paging state. Everything else in the changed web files (the Button size="xs" variant="ghost" load-more control, the merge helper, and the refresh cadence constants) is consistent with the existing patterns in these files.

Posted via Macroscope — UI Consistency

Comment thread apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx Outdated
Comment thread apps/server/src/pullRequest/PullRequestService.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.

One finding on error construction in the new rate-limit wrapper. Everything else in the new SourceControlRateLimit and GitHubGraphQlBudget services follows the service conventions (namespace subpath imports, Context.Service with an inline interface, real make, exported layer, dependencies acquired with yield*, structured Schema.TaggedErrorClass failures with messages derived from attributes).

Posted via Macroscope — Effect Service Conventions

Comment thread apps/server/src/pullRequest/PullRequestService.ts Outdated
Comment thread apps/server/src/sourceControl/SourceControlRateLimit.ts
Comment thread apps/server/src/sourceControl/githubGraphQlBudget.ts Outdated
@github-actions github-actions Bot added size:XXL 1,000+ changed lines (additions + deletions). and removed size:XL 500-999 changed lines (additions + deletions). labels Aug 15, 2026
@Bil0000 Bil0000 changed the title fix(github): protect pull request API budget fix(pull-requests): protect provider API budgets Aug 15, 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.

One layout finding in PullRequestReviewAnnotation.tsx: the new "Load more comments" control and the existing "Reply" trigger are both inline-level siblings of a block card, so they render on the same line with no gap when a thread is unfinished and replying is allowed.

Posted via Macroscope — UI Consistency

Comment thread apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx
@github-actions github-actions Bot added size:XL 500-999 changed lines (additions + deletions). and removed size:XXL 1,000+ changed lines (additions + deletions). labels Aug 16, 2026
@juliusmarminge
juliusmarminge merged commit ba46f92 into pingdotgg:main Aug 16, 2026
18 of 19 checks passed
github-actions Bot added a commit to omarcresp/t3code-flake that referenced this pull request Aug 17, 2026
## What's Changed
* fix(pull-requests): protect provider API budgets by @Bil0000 in pingdotgg/t3code#6466
* feat(web): configurable browser defaults in Settings → Integrations by @juliusmarminge in pingdotgg/t3code#7082


**Full Changelog**: pingdotgg/t3code@v0.0.34-nightly.20260816.1112...v0.0.34-nightly.20260817.1113

Upstream release: https://github.com/pingdotgg/t3code/releases/tag/v0.0.34-nightly.20260817.1113
torturado pushed a commit to torturado/t3code that referenced this pull request Aug 17, 2026
frankdavidcorona pushed a commit to frankdavidcorona/t3code that referenced this pull request Aug 17, 2026
NeilTheFisher pushed a commit to NeilTheFisher/t3code that referenced this pull request Aug 18, 2026
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.

2 participants