Repository navigation
Return branch and upstream from github-pr-status views instead of a separate upstream call - #7071
Merged
ymichael merged 1 commit intoNov 5, 2026
Conversation
…eparate upstream call
Every PR load first made an `upstream` host call per environment (detect,
symbolic-ref, rev-parse @{u}) and then the batched `views` call, which for a
branch discovery read the branch again and ran `git config --get-regexp`
twice. Each read in `views` now returns the workspace's branch and upstream
OID, the server passes the known PR URL with the branch it was found on, and
the host rediscovers when the branch moved. A discovery reads branch config
once.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
ymichael
deleted the
bb/pr-discovery-per-environment-git-fan-out-thr_xxncinuj9y
branch
November 5, 2026 00:56
ymichael
added a commit
that referenced
this pull request
Nov 5, 2026
## Human comments
## What was wrong
Merge, Mark ready and Convert to draft did two lookups to find a pull
request bb already had. First, `requireActionTarget` always ran an
uncached branch discovery (`loadPullRequest(env, null, true)`: git
config reads, then a GraphQL search by head branch). Then `act` ran `gh
pr merge` with no selector, after reading the branch config again. With
no selector, gh resolves the PR from the branch itself: five more git
processes (`remote -v`, two `config --get-regexp`, `symbolic-ref`,
`rev-parse @{push}`) and its own GraphQL search by branch. Each git
process is slow in `~/Projects/bb` (about 4.5k branches, a 10k-line
`.git/config`). This is finding #13 in the Nov 4 hot-path audit ("Merge:
precheck by URL and pass it to gh").
## What changed
Only `plugins/github-pr-status`. This is rebased on #7071, which made
`views` take `known: { url, branchName }` and return the workspace's
`refs`.
- `server.ts`: the action precheck passes the PR URL the store already
holds as `known`. It still bypasses caches, so state and mergeability
are checked fresh. The precheck now gets `refs` back from its own
`views` result. It then rediscovers by branch when the PR has merged or
closed, or when its `headRefName` isn't `refs.branchName` from that same
read. A stale stored URL is therefore never acted on. For example, after
a branch switch, a refused Mark ready updates the plugin's branch map
without touching the stored URL, and the next Merge would otherwise act
on the old branch's PR. A fork PR whose upstream branch has a different
name never matches the local branch, so it always rediscovers. That
costs main's lookup plus one URL read, and still acts on the right PR.
With no stored URL, the precheck discovers by branch, as before. `act`
receives the URL of the PR that passed the precheck.
- `contract.ts` / `host.ts` / `host/git-host.ts`: `act` takes a required
`url` and runs `gh pr merge|ready <url> …`. The host no longer reads the
current branch or the upstream config for actions.
`runPullRequestActionForCurrentBranch` becomes `runPullRequestAction`.
- One visible change: an action from a detached workspace now fails in
the precheck with "No pull request found" instead of the host's "Cannot
update pull request from a detached workspace".
- No `HOST_DAEMON_PROTOCOL_VERSION` bump and no plugin SDK change. `act`
is this plugin's own host contract, and the server ships the host
artifact for each plugin generation.
- README sentence on actions updated.
## How you verified
**Real data**: the `~/Projects/bb` worktree for this PR's own branch
(open PR #7070), measured on origin/main after #7071 against this
branch. The plugin's real host entry ran under
`experimental_createHostEntryHarness`, making the same `views` → `act`
calls the server makes for a merge. A `gh` shim on `PATH` rewrote `gh pr
merge|ready <args>` into `gh pr view <same selector> --json <the fields
gh pr merge fetches>`. That exercises gh's PR finder without merging.
The merge mutation itself is the same on both sides and is not in these
numbers. Three interleaved rounds of 15 per side ran at load average
8–11.
| per merge | main (after #7071) | branch |
|---|---|---|
| git processes | 12 | 3 |
| gh processes (GraphQL round trips) | 2 | 2 |
| precheck p50 (n=45) | 853 ms | 767 ms |
| act, excluding the mutation, p50 (n=45) | 614 ms | 433 ms |
| total p50 / mean (n=45) | 1494 / 1510 ms | 1188 / 1252 ms |
Per-round total p50, main → branch: 1552 → 1242, 1466 → 1170, 1424 →
1188 ms.
What remains is GitHub latency: one GraphQL read for the precheck plus
gh's own read before the mutation.
**Tests**: `pnpm exec turbo run test typecheck lint
--filter=bb-plugin-bb--github-pr-status` passes (179 tests). New server
tests use a fake host that applies the real `views` rule: URL read only
when `known.branchName` matches the workspace branch.
- A merge after a load prechecks with `known` set to the stored URL and
branch, and passes that URL to `act`.
- When the stored PR has closed and the branch has a newer PR, the newer
PR's URL is used.
- Branch switch, then a refused Mark ready, then Merge: the stored URL
points at an open PR for another branch, so the action must go to the
current branch's PR. Without the head-branch check this test fails,
because it acts on pull/6 instead of pull/7.
- Host tests assert `gh pr ready|merge <url>` args, including from a
fork-tracking workspace.
> AGENT GENERATED
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human comments
What was wrong
Finding #11 of the Nov 4 hot-path overreach audit, still present on
origin/main(7775a0f). Every github-pr-status load ranprepareLoad, which made a separateupstreamhost call per environment:rev-parse --is-inside-work-tree,symbolic-ref,rev-parse --verify @{u}. Only after that came the batchedviewscall. The server used the result just to decide "read the known PR URL, or rediscover because the branch moved?" and to record the upstream OID that later ref events compare against. On a branch discovery,viewsthen read the branch again and rangit config --get-regexptwice:getPullRequestTarget, thenresolveBranchReadTarget, with overlapping patterns. That is 7 git processes and N + 1 host calls for N environments. It runs on every load: sidebar row watches, polls,refresh, and turn ends.What changed
All changes are in
plugins/github-pr-status.viewsread takesknown: { url, branchName } | nullinstead ofurl. Each result is{ lookup, refs: { oid, branchName } | null }.viewsreads the branch and upstream OID once per read. It reads the known URL only while the workspace is still onknown.branchName, and otherwise rediscovers from the current branch. A failed ref read now fails only that read, as the separateupstreamcall used to.prepareLoadno longer calls the host. It records the branch and OID from eachviewsresult. Settled PRs still rediscover.upstreamis still used for ref events (inspectRefs), unchanged.git config --get-regexpcovering both pattern sets.actuses the same read.viewsresult.There is no user-visible behaviour change. No HOST_DAEMON_PROTOCOL_VERSION bump: the daemon fetches the plugin's host bundle by digest from the server, so the plugin's server and host halves always ship together. No plugin SDK change.
Left out on purpose: the audit's "skip turn-end discovery when the upstream OID is unchanged". bb worktrees are created
--no-track, so agit pushwithout-uleaves@{u}unset, and PRs created through MCP tools or on github.com don't move it either. For an environment without a PR, turn end is the main point where such a PR gets discovered, so skipping it would make PRs show up late. That would be a visible change, so it is not in this PR.How you verified
Benchmark. Real
~/Projects/bbcheckout (4,482 branches; 117 worktrees on a branch), main vs this branch, alternating runs. The server plugin runs in the SDK'screateFakePluginHost, and host calls go to the real host entry throughexperimental_createHostEntryHarnessagainst real worktrees. A localghstub answers GraphQL so the network doesn't hide the local cost. Git processes were counted with a PATH shim in a separate run. The harness calls host methods in process, so it leaves out the per-call server→daemon→worker round trip, which this change also removes. Load average was 33–55 throughout.pullRequests/refreshper envupstream+ 1viewsviewsupstream+ 1viewsviewsThe known-PR re-read does the same git work in one host call instead of 118. Its in-process wall time is within noise.
Tests and checks.
vitest runinplugins/github-pr-status, 176 passed.pnpm exec turbo run lint typecheck --filter=bb-plugin-bb--github-pr-status: clean.viewscall carryingknown, and a ref event reloads only when the upstream OID moved. It fails if the OID fromviewsisn't recorded.🤖 Generated with Claude Code