Skip to content

Merge and other PR actions act on the PR URL bb already found - #7070

Merged
ymichael merged 3 commits into
mainfrom
bb/pr-merge-re-discovers-the-pr-thr_2di5n4tdqh
Nov 5, 2026
Merged

ymichael merged 3 commits into
mainfrom
bb/pr-merge-re-discovers-the-pr-thr_2di5n4tdqh

Conversation

@ymichael

@ymichael ymichael commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

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

@ymichael
ymichael force-pushed the bb/pr-merge-re-discovers-the-pr-thr_2di5n4tdqh branch from 6b58336 to 4a188a9 Compare November 5, 2026 06:25
@ymichael
ymichael merged commit 6a666b6 into main Nov 5, 2026
49 checks passed
@ymichael
ymichael deleted the bb/pr-merge-re-discovers-the-pr-thr_2di5n4tdqh branch November 5, 2026 17:42
ymichael added a commit that referenced this pull request Nov 5, 2026
)

## Human comments

## What was wrong

[Windows
CI](https://github.com/get-bb/bb/actions/runs/42103646525/job/127512847896)
timed out after 5,058ms in the host test that runs ready, draft, and
merge. Those are three independent commands, but their sequential
child-process launches shared one five-second test deadline. The test
was added in #7070 after the repository-template improvements in #7049.
It does not test a state transition between actions: the fake GitHub CLI
only records each invocation and returns success.

## What changed

Make the host-boundary check table-driven, with one case for each
action. Every case keeps its own real tracked-fork repository and
fake-gh child process, checks successful completion, and asserts the
exact checked PR URL and command flags. All three actions and all prior
assertions remain covered. Each case uses the existing five-second
deadline.

This is a test-only reliability change. It does not change production
behavior, retries, timeouts, CI shards, or cache handling. The extra
private fixture copies cost about 0.74 seconds in a local alternating
comparison (median combined action-test duration: 0.40s before, 1.14s
after); this is not a CI speedup claim.

## How you verified

- Full package: `pnpm exec turbo run test lint typecheck
--filter=bb-plugin-bb--github-pr-status` — all 180 tests, lint, and
typecheck passed.
- Controlled process-start delay: temporarily added 1.8 seconds to each
fake-gh action child. The original combined test failed at its existing
five-second deadline; all three new host cases passed at the same
deadline. The delay was removed.
- Coverage controls: independently changed the host handler to forward a
wrong URL for ready, draft, then merge. Each mutation failed the
original test and its corresponding new case. Restored the production
file byte-for-byte.
- Fresh CI executions at this head:
[Windows](https://github.com/get-bb/bb/actions/runs/42108415313/job/127529530828)
and
[Linux](https://github.com/get-bb/bb/actions/runs/42108415313/job/127529531423)
each passed all 180 package tests; both were test cache misses. The
local delay experiment is a controlled reproduction, not a claim to
reproduce Windows scheduling.
- Formatter, `git diff --check`, code-review guidance, and test audit
completed; independent root-agent review found no issues.

> AGENT GENERATED
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.

1 participant