Skip to content

Read GitHub PR branch lookups with a light scan plus the newest PR's details - #8150

Merged
ymichael merged 1 commit into
mainfrom
bb/5704-host-daemon-pr-status-reads-exhaust-the-git-thr_zectst65km
Nov 25, 2026
Merged

ymichael merged 1 commit into
mainfrom
bb/5704-host-daemon-pr-status-reads-exhaust-the-git-thr_zectst65km

Conversation

@ymichael

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The GitHub PR Status plugin's branch lookup (plugins/github-pr-status/host/git-host.ts) asked GitHub for up to 100 PRs on the branch, each with every detail field: reviewRequests(first: 100), commits(last: 1) and statusCheckRollup.contexts(first: 100). GitHub prices a query by the most it could return, so every lookup cost 3 points even on a branch with no PR, and 25 environments in one document cost 75 points. Repeated across many environments, that used up the 5,000-point hourly GraphQL allowance shared with every gh call on the machine (#5704; measured by cameronm123 on 0.50.1). The same query also timed out after 10 s on head names shared by many fork PRs (for example main in microsoft/vscode), so in those cases it never covered 100 PRs.

What changed

  • The branch scan still lists the branch's 100 newest PRs, but only with the fields matchesBranchTarget needs (url state isCrossRepository headRepositoryOwner). The same repository selection adds newest: pullRequests(..., first: 1) with full details.
  • If the matched PR is the newest one, its details are used directly. Otherwise the match is read again by URL, the same path used for PRs bb already knows.
  • reviewRequests(first: 0) { totalCount }: only the count is used.
  • The 500,000-node document splitting is removed because it can no longer trigger (a 25-branch document is about 5,000 nodes). Documents are still capped at 25 reads.
  • README batching paragraph updated.

This differs from the issue comment's proposal (first: 5/10/50). A 5-PR page misses the right PR when newer fork PRs share its head name (on microsoft/vscode main the matches were at positions 9, 12 and 22). Smaller reviewRequests or contexts pages save no points, because cost depends only on the number of connection requests.

No wire, CLI or protocol changes.

How you verified

  • Cost, priced with rateLimit(dryRun: true) on the exact query the plugin sends (captured through a gh shim):

    Branch lookups in one document Before After
    1 3 pts (20,200 nodes) 1 pt (203 nodes)
    10 30 pts 1 pt
    25 75 pts 1 pt (5,075 nodes)
  • Latency on real GitHub, median of 5 runs: a branch with a PR takes 847 ms before and 780 ms after. A branch with no PR takes 432 ms before and 516 ms after; I read that as noise and didn't investigate further.

  • Old vs new code against real GitHub for 9 branch targets (same-repo open, same-repo none, default branch, and 6 fork-owner targets on microsoft/vscode main) plus 3 URL reads. Where the old code returned a result, the new code returned the same PR, state, check count and review-request count. The 5 fork-heavy targets the old code timed out on now resolve. Two of them reported a different merge state (BLOCKED, then UNKNOWN) on a later run; GitHub computes merge state lazily.

  • End to end on pnpm start:worktree: bb pull-request show on a project-checkout environment for Sign other devices in to bb, enforced by a Require sign-in switch #8146's branch found the PR through branch discovery.

  • New tests:

    • host.test.ts, "finds the branch's PR behind many newer PRs from other forks with the same head name": fails when the scan page is cut to 5.
    • host/batch.test.ts, "reads 25 branch lookups in one document with details for only each branch's newest PR": fails if the detail fields go back into the 100-PR scan.
  • pnpm exec turbo run test typecheck lint --filter=bb-plugin-bb--github-pr-status: 183 passed.

Fixes #5704

AGENT GENERATED

🤖 Generated with Claude Code

…details

A branch lookup listed up to 100 PRs with every detail field, including
reviewRequests(first: 100) and statusCheckRollup contexts(first: 100).
GitHub prices that at 3 points per environment even when the branch has
no PR, so 25 environments cost 75 points per document. On head names
shared by many fork PRs (for example `main`), it also timed out after 10 s.

The branch scan now asks only for the fields that pick the PR (url,
state, head owner) across the same 100 newest PRs, plus full details for
the newest PR. When the match is that newest PR, its details are used
directly; otherwise the match is read again by URL, as known PRs already
are. reviewRequests is read with first: 0 because only totalCount is
used. Measured with rateLimit(dryRun: true): a 25-branch document costs
1 point (was 75). Check contexts still page 100 at a time and the review
request count still comes from totalCount, so nothing shown in the UI or
CLI changes.

Fixes #5704

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ymichael
ymichael merged commit 562cbc3 into main Nov 25, 2026
49 checks passed
@ymichael
ymichael deleted the bb/5704-host-daemon-pr-status-reads-exhaust-the-git-thr_zectst65km branch November 25, 2026 01:04
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.

Host daemon PR status reads exhaust the GitHub GraphQL hourly limit

1 participant