fix(server): stop PR status lookups amplifying GitHub rate limits #5673
main fromrefs/pull/5673/head·merged by t3dotgg(GitHub profile, opens in a new tab) View on GitHubProblem#
I keep getting throttled on the GitHub API. Digging through logs, most of it is
my own agents running gh in bursts, but T3 Code makes it worse in two ways.
The PR status badge caches a successful lookup for 2 minutes and a failed
one for 20 seconds. GitHub rejects a throttled request instantly, so once you're
rate limited the poller starts asking six times faster than it does when
everything is healthy. On top of that, lookupStatusPr catches the failure and
returns the last known PR, so the poll reports success and
VcsStatusBroadcaster's exponential backoff never engages. Nothing ever slows
down, and a transient 429 turns into a sustained one.
Separately, the badge asks the provider about every branch, including branches that were never pushed anywhere. Those queries cannot match a PR. On this machine 66% of sampled t3code worktrees are in that state, so two thirds of the baseline API spend was guaranteed-empty.
Solution#
Failed lookups now back off per branch (20s, 40s, 80s, ... capped at 15 min) instead of retrying on a flat 20s timer, so a failing branch drops below the healthy refresh rate after a couple of attempts rather than above it.
Branches git has no record of on any remote skip the provider call entirely. The
check looks for a remote-tracking ref rather than upstream config, because
git push writes that ref even without -u, which is how most terminal and
agent pushes land. Repositories that track no remotes at all can't answer the
question, so they keep the old behaviour, as does any failed probe: hiding a PR
badge is worse than spending the lookup.
Tests cover the backoff curve, the skip, and the case that makes the naive
version wrong (a branch pushed without --set-upstream still gets looked up).
Not in this PR#
Two bigger wins from the same investigation, kept separate because they change lookup semantics and deserve their own review:
- Batch the sidebar into one
gh pr listper repo matched locally by branch, instead of one call per branch. Caps the worst case (expanded thread list, 262 distinct cwds here) at a few calls instead of thousands. - Stop worktree dev servers from polling GitHub at all. Four servers were live during the investigation, each with independent pollers and caches against the same token.
Made by Claude Opus 5 (1M context) in Claude Code, on T3 Code.
Note
Medium Risk Changes PR badge lookup timing and when GitHub is contacted; incorrect unpublished detection could hide a PR badge, though failures fall back to the old lookup path.
Overview Reduces GitHub API load from VCS PR status polling by changing how failed lookups are cached and when provider calls run.
Failed PR lookups no longer use a flat 20s cache TTL. They use per-branch exponential backoff (20s → 40s → … capped at 15 minutes), with streak tracking cleared on success, so rate-limited branches retry less often than the healthy 2-minute refresh instead of more often.
For branches without upstream config, status can skip gh pr list when git shows remotes exist but no refs/remotes/*/<branch> for the current head—treating never-pushed local branches as having no PR. Branches that were pushed without -u still get looked up because remote-tracking refs exist. Ambiguous cases (no remotes, or probe failure) still call the provider.
Tests cover the backoff curve, the never-pushed skip, and push-without-upstream still querying GitHub.
Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a76cbc6376373f3a17458b31105988a6161edb89. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).Note
Fix PR status lookups amplifying GitHub rate limits via exponential backoff and branch skip logic#
- Repeated PR lookup failures now back off exponentially per branch (base 20s, max 15min) using a new
prLookupFailureTtl(consecutiveFailures)function, resetting on success. - Branches that have never been pushed to any remote skip the provider PR lookup entirely, using a new
isUnpublishedBranchcheck viagit for-each-ref. - Branches pushed without
--set-upstreamstill perform the provider lookup as before. - Behavioral Change: branches with no remote-tracking ref and no push history return no PR without making any GitHub API calls.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Provider Metric Main baseline This PR Impact PR ceiling Codex Total thread wire 11.3 KiB 11.3 KiB +23 B (+0.2%) 15.1 KiB ✅ Codex Thread snapshot wire 5.5 KiB 5.5 KiB +3 B (+0.1%) 7.3 KiB ✅ Codex Live turn WebSocket wire 5.9 KiB 5.9 KiB +20 B (+0.3%) 7.8 KiB ✅ Codex Live turn WebSocket decoded 49.7 KiB 49.7 KiB 0 B (0.0%) 66.4 KiB ✅ Codex Live turn messages 16 16 0 (0.0%) 21 ✅ Claude Total thread wire 11.3 KiB 11.3 KiB −19 B (−0.2%) 15.1 KiB ✅ Claude Thread snapshot wire 5.5 KiB 5.5 KiB 0 B (0.0%) 7.3 KiB ✅ Claude Live turn WebSocket wire 5.9 KiB 5.8 KiB −19 B (−0.3%) 7.8 KiB ✅ Claude Live turn WebSocket decoded 50.6 KiB 50.6 KiB 0 B (0.0%) 66.4 KiB ✅ Claude Live turn messages 16 16 0 (0.0%) 21 ✅ Baseline:
31891a1· PR result:a76cbc6· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
- Codex decoded thread snapshot: 94.6 KiB
- Claude decoded thread snapshot: 95.4 KiB
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Approvability#
Verdict: Approved a76cbc6
Self-contained performance optimization that adds exponential backoff for failed PR lookups and skips unnecessary API calls for branches never pushed to a remote. Well-tested with clear, conservative logic.
You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).t3dotgg(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
74956aaf-5cb4-41d9-8824-56b90fc108fcYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
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