Skip to content

stewards: merge a gate-met pull request instead of filing a Merge item (BB-257) - #293

Merged
trotterdylan merged 3 commits into
bb/bb-256-mergebehind-hold-stewards-thr_vaxkrw2h9ufrom
bb/bb-257-plugin-merges-a-gate-met-pr-thr_t4pmjpbx34
Nov 9, 2026
Merged

trotterdylan merged 3 commits into
bb/bb-256-mergebehind-hold-stewards-thr_vaxkrw2h9ufrom
bb/bb-257-plugin-merges-a-gate-met-pr-thr_t4pmjpbx34

Conversation

@trotterdylan

@trotterdylan trotterdylan commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Implements BB-257. The gate-met branch of syncNeeds now takes the merge step instead of filing the plugin's own Merge item: when the binding's playbook permits merge, it calls the shared mergePullRequest path (the one bb stewards merge and the page's Merge button use). A ticket binding always merges; a pr binding only when its may includes merge; a review binding (a teammate's) is unchanged.

Note: a merge to bb-plugins main moves the pin and stages a restart for every developer's server (Restart now, or in the 03:00–05:00 ET quiet window).

Sibling PR: the .bb half on bb-gate (stewards/playbooks/deps-prs.md and AGENTS.md), bitcomplete/bb-gate#102.

Classification

owner-reviewed: "The stewards plugin's roles parsing, ready gate and approval and escalation plumbing outside the hard-coded self-widening list" (user), the decide-list entry the plugin matched. This changes what the plugin does once the gate is met.

What changes

  • plugins/stewards/server.ts — in the gate-met branch of syncNeeds, when bindingMayMerge (new, exported from wake.ts) is true, the plugin calls the shared mergePullRequest path instead of filing a Merge item. On success it notes the merge into this look's changes and schedules a reconcile, so the steward's wake carries the merge note and it proceeds to the deployment watch. A steward-filed Merge item is left alone (the hand-off shape) and no merge happens over it.
  • plugins/stewards/server.ts — the merge is skipped while Pause stewards is on (the item is filed as before), and mergePullRequest passes the head it judged (gate.headSha) as the merge PUT's sha, so a push between the look and the merge makes GitHub refuse with 409 and the plugin waits for the next look instead of merging a head whose checks have not run.
  • plugins/stewards/server.ts — a refused merge (conflict, branch protection) is recorded against the head sha plus the reviewer marker and lane (mergeAttemptKey). One note and one stuck escalation per refusal; the same gate is not retried and not re-raised on later looks. A push or a new review round changes the key and a fresh attempt follows; the escalation names bb stewards merge <key> as the manual retry.
  • plugins/stewards/wake.ts — one exported bindingMayMerge decides it, so the worker skill line and the gate-met branch cannot disagree; a standing rule tells the steward the plugin merges once the gate is met and not to file a Merge item for a pull request its playbook may merge.
  • Tests cover: a ticket binding merging itself (note, comment, no item); a pr binding under github-prs merging; a pr binding under a deps-prs playbook without merge still filing the item; a deps-prs playbook with merge merging; a steward-filed item left alone; the refusal recorded once and not retried until the head moves; the head moving between the look and the merge; Pause stewards suppressing the merge; the merge hold still suppressing both.

Open binding the BB-256 hold should cover

  • BB-254 (bitcomplete/bb-plugins#292): gate met (reviewer approved 81a5fec, checks green, owner approved), no merge hold, waiting on the 0.49 restart after the 2026-11-10 03:00–05:00 ET window. If BB-257 lands while it is still waiting, the plugin would merge stewards: raise the per-turn brief cap to bb 0.49's 32768 limit (BB-254) #292 early. Please set a BB-256 merge hold on it before this lands.

Base-branch state

The PR is based on bb/bb-256-mergebehind-hold-stewards-thr_vaxkrw2h9u (BB-256 / #291). #291 and #290 merged into their parent branches rather than main; main has BB-253/BB-255 only, and #292 re-lands BB-254 on main without BB-256. BB-257 needs BB-256's mergeBehind, so it stays stacked until BB-256 re-lands; the project steward has asked that it be retargeted onto BB-256's re-land branch once that opens, then onto main. It must not merge before #292 (BB-254) has merged.

Testing

  • cd bb-plugins/plugins/stewards && npm run typecheck: pass.
  • npx vitest run: pass (1435 tests). CI's quality_checks (stewards) runs the same suite and is green on this head.

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Independent review running in bb thread @thread:thr_6eb5ci4c5k.

— from bb thread thr_t4pmjpbx34

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 1 (Claude Opus 5.5, at 168d0f4)

Owner review required: yes — this changes what the gate code does once the gate is met: the plugin now merges by itself instead of filing a Merge item. The decide-list entry is "The stewards plugin's roles parsing, ready gate and approval and escalation plumbing outside the hard-coded self-widening list" (decide: user). @trotterdylan, this one needs your approval. The escalation is binding: a project-steward bb-approval will not meet the gate; your unsigned approval will. BB-257's spec approval of 2026-11-09 covers the product question.

Blockers

  1. plugins/stewards/server.ts:6800 — the plugin still merges while Pause stewards is on. reconcile and syncNeedsFresh run syncNeeds whatever the setting is; only the wake is deferred (deferred = (await settings.get()).paused … at :4016). Before this PR, a paused server only filed an item. Now it squash-merges, posts "Merged:", runs mergeDispatch and stages a bb-server build for every developer, all while the user has switched stewards off. Pause is the kill switch, so a doorbell during an incident should not be able to ship a merge. Fix: when paused is set, skip the merge. Either file the plugin's Merge item as today or file nothing, and add a test that a paused server records no githubMerges.
  2. plugins/stewards/server.ts:6807 → github.ts:159 — the plugin can merge a head it never judged. The gate is evaluated on observed, which is read at the start of the look, several awaits earlier (loadConfig, ownPullKeys, syncPullApproval, pullDetails). On the syncNeedsFresh path it can even be b.lastSnapshot when the fresh read fails. squashMerge sends no sha, so GitHub merges whatever the head is when the PUT lands. A push in that window is merged before its checks have run, and the gate does not compare the marker sha with the head, so nothing else catches it. When a person pressed Merge, this was a person's race. Now it is unattended. Fix: pass the evaluated head (g.headSha) as sha on the merge PUT (GitHub then refuses with 409 "Head branch was modified"). Treat that 409 like the "gate or worker changed" branch (log it and let the next look decide), not as a stuck refusal. Add a test where the head moves between the look and the merge.

Suggestions

  • plugins/stewards/server.ts:7745 — the refusal escalation says "Resolve the conflict or the branch protection and push; the plugin retries when the head sha … changes". Fixing branch protection (one of the ticket's two named refusals) needs no push. A transient refusal also needs none: 405 "Base branch was modified" is common on a stacked base, and so is a 5xx. mergeRefusalFor also matches resolved escalations, so resolving this one does not re-arm the merge. As written, the PR sits until someone happens to push. Name bb stewards merge <key> in context as the way to retry once the cause is fixed.

Tested

  • Ran: npm run typecheck (pass), npx vitest run in plugins/stewards (31 files, 1432 tests, pass). The PR body says the plugins CI matrix leaves stewards out, but quality_checks (stewards) runs and is green on this head.
  • Off-diff: read sibling bitcomplete/bb-gate#102. The deps-prs may gains merge, and a major bump or an owner-reviewed path still escalates before any reviewer runs, so the Dependabot criterion depends on linear: set and read issue relations (BB-73) #102 landing too. The shipped DEPS_PRS template keeps may without merge, so it still files the item, as tested.

— from bb thread thr_x2iybbcq9u

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 2 (Claude Opus 5.5, at 6c444fd)

Owner review required: yes — unchanged from round 1 (decide: user, approver=owner).

Blockers

  1. plugins/stewards/server.ts:7723 — isHeadMovedRefusal matches \b409\b anywhere in the message, and that message contains the request path: GitHub refused the merge: PUT /repos/<repo>/pulls/<n>/merge failed: <status> … (github.ts:150). On pull request stewards: close the remaining Linear-only gaps (BB-362) #409, or a repo whose name has 409 as its own token, every refusal reads as "head moved". A conflict (405) or branch protection is then logged and retried on every look, with no note and no stuck escalation. That is the silent loop the ticket's last criterion rules out, and bb-plugins is already at stewards: merge a gate-met pull request instead of filing a Merge item (BB-257) #293. Fix: match the status itself (/failed: 409\b/u) or GitHub's text alone. Add a test with a pull request numbered 409 that gets a 405 refusal.

Resolved since round 1

  • Blocker 1 (pause): resolved in 6c444fd. While paused, the plugin files its Merge item and does not merge. After unpausing, the next look merges and closes that item through mergePullRequest. Tested.
  • Blocker 2 (unjudged head): resolved in 6c444fd. squashMerge now sends gate.headSha, which github-watcher fills from headRefOid, the full sha. The 409 waits for the next look. Tested.
  • Suggestion (retry advice): taken. The refusal context now names bb stewards merge <key>.

Tested

  • Ran: npm run typecheck (pass), npx vitest run in plugins/stewards (31 files, 1434 tests, pass).

— from bb thread thr_x2iybbcq9u

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Review round 3 (Claude Opus 5.5, at 5674d2d)

Owner review required: yes — this changes what the gate code does once the gate is met: the plugin now merges by itself instead of filing a Merge item. The decide-list entry is "The stewards plugin's roles parsing, ready gate and approval and escalation plumbing outside the hard-coded self-widening list" (decide: user). @trotterdylan, this one needs your approval. The escalation is binding: a project-steward bb-approval will not meet the gate; your unsigned approval will. Before merging, set the BB-256 hold on BB-254 / #292 that the PR body asks for, or the plugin will merge #292 on its first look.

Resolved since round 2

Tested

  • Ran: npm run typecheck (pass), npx vitest run in plugins/stewards (31 files, 1435 tests, pass).

Looks good.

— from bb thread thr_x2iybbcq9u

@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Approved 5674d2d from the Stewards page

@trotterdylan
trotterdylan merged commit 4290315 into bb/bb-256-mergebehind-hold-stewards-thr_vaxkrw2h9u Nov 9, 2026
22 checks passed
@trotterdylan

Copy link
Copy Markdown
Collaborator Author

Merged: owner-reviewed lane, reviewer approved 5674d2d, checks green, approved by the owner, escalated by the reviewer to the owner.
merge commit 4290315
Note: merging this moves the pin and stages a restart for every developer's server (Restart now, or in the 03:00–05:00 ET quiet window).
dispatched bb-server.yaml on bitcomplete/bb-gate@main

trotterdylan added a commit that referenced this pull request Nov 9, 2026
…m (BB-257) (#293)

Implements [BB-257](https://linear.app/bit-complete/issue/BB-257/stewards-merge-a-gate-met-pull-request-instead-of-filing-a-merge-item). The gate-met branch of `syncNeeds` now takes the merge step instead of filing the plugin's own Merge item: when the binding's playbook permits `merge`, it calls the shared `mergePullRequest` path (the one `bb stewards merge` and the page's Merge button use). A ticket binding always merges; a `pr` binding only when its `may` includes `merge`; a `review` binding (a teammate's) is unchanged.

> Note: a merge to `bb-plugins` `main` moves the pin and stages a restart for every developer's server (Restart now, or in the 03:00–05:00 ET quiet window).

Sibling PR: the `.bb` half on `bb-gate` (`stewards/playbooks/deps-prs.md` and `AGENTS.md`), bitcomplete/bb-gate#102.

owner-reviewed: "The stewards plugin's roles parsing, ready gate and approval and escalation plumbing outside the hard-coded self-widening list" (user), the decide-list entry the plugin matched. This changes what the plugin does once the gate is met.

- `plugins/stewards/server.ts` — in the gate-met branch of `syncNeeds`, when `bindingMayMerge` (new, exported from `wake.ts`) is true, the plugin calls the shared `mergePullRequest` path instead of filing a Merge item. On success it notes the merge into this look's changes and schedules a reconcile, so the steward's wake carries the merge note and it proceeds to the deployment watch. A steward-filed Merge item is left alone (the hand-off shape) and no merge happens over it.
- `plugins/stewards/server.ts` — the merge is skipped while **Pause stewards** is on (the item is filed as before), and `mergePullRequest` passes the head it judged (`gate.headSha`) as the merge `PUT`'s `sha`, so a push between the look and the merge makes GitHub refuse with 409 and the plugin waits for the next look instead of merging a head whose checks have not run.
- `plugins/stewards/server.ts` — a refused merge (conflict, branch protection) is recorded against the head sha plus the reviewer marker and lane (`mergeAttemptKey`). One note and one `stuck` escalation per refusal; the same gate is not retried and not re-raised on later looks. A push or a new review round changes the key and a fresh attempt follows; the escalation names `bb stewards merge <key>` as the manual retry.
- `plugins/stewards/wake.ts` — one exported `bindingMayMerge` decides it, so the worker skill line and the gate-met branch cannot disagree; a standing rule tells the steward the plugin merges once the gate is met and not to file a Merge item for a pull request its playbook may merge.
- Tests cover: a ticket binding merging itself (note, comment, no item); a `pr` binding under `github-prs` merging; a `pr` binding under a deps-prs playbook without `merge` still filing the item; a deps-prs playbook with `merge` merging; a steward-filed item left alone; the refusal recorded once and not retried until the head moves; the head moving between the look and the merge; Pause stewards suppressing the merge; the merge hold still suppressing both.

- **BB-254** (`#292`): gate met (reviewer approved `81a5fec`, checks green, owner approved), no merge hold, waiting on the 0.49 restart after the 2026-11-10 03:00–05:00 ET window. If BB-257 lands while it is still waiting, the plugin would merge #292 early. Please set a BB-256 merge hold on it before this lands.

The PR is based on `bb/bb-256-mergebehind-hold-stewards-thr_vaxkrw2h9u` (BB-256 / #291). #291 and #290 merged into their parent branches rather than `main`; `main` has BB-253/BB-255 only, and #292 re-lands BB-254 on `main` without BB-256. BB-257 needs BB-256's `mergeBehind`, so it stays stacked until BB-256 re-lands; the project steward has asked that it be retargeted onto BB-256's re-land branch once that opens, then onto `main`. It must not merge before #292 (BB-254) has merged.

- `cd bb-plugins/plugins/stewards && npm run typecheck`: pass.
- `npx vitest run`: pass (1435 tests). CI's `quality_checks (stewards)` runs the same suite and is green on this head.
trotterdylan added a commit that referenced this pull request Nov 9, 2026
A gate-met stacked pull request keeps the plugin-filed Merge item: its base
is another pull request's branch, which may already be merged and dead, so
auto-merging it there strands the change off the default branch (the
#290/#291/#293 failure). A person or worker merges a stacked pull request
into its parent. A default-branch read that fails is treated as not the
default, so the item is filed.
trotterdylan added a commit that referenced this pull request Nov 9, 2026
…m (BB-257) (#296)

Implements [BB-257](https://linear.app/bit-complete/issue/BB-257/stewards-merge-a-gate-met-pull-request-instead-of-filing-a-merge-item). The gate-met branch of `syncNeeds` now takes the merge step instead of filing the plugin's own Merge item: when the binding's playbook permits `merge`, it calls the shared `mergePullRequest` path (the one `bb stewards merge` and the page's Merge button use). A ticket binding always merges; a `pr` binding only when its `may` includes `merge`; a `review` binding (a teammate's) is unchanged.

This is a re-land of the reviewed [#293](#293). That PR was approved and merged into BB-256's stacked branch (`bb/bb-256-mergebehind-hold-stewards-thr_vaxkrw2h9u`), which was never re-landed on `main`, so the diff is not on `main`. It is stacked here on BB-256's re-land [#295](#295) (`bb/bb-256-mergebehind-reland-thr_k2uwubpyfp`), which has now squash-merged to `main` as `80a4d2e`; this PR is rebased onto `main` and retargeted to `main`, so the diff is only the BB-257 change. #293's review and approval cover this diff; the only conflict against the re-landed code was the test fake's return object, resolved by keeping BB-256's extra fields and adding #293's `setMoveHeadOnMerge` — no behaviour changed.



[#297](#297) (BB-258, rename goal stewards to initiative stewards) was stacked on this PR and has merged into this branch, so this landing carries it to `main` too; #297's own review and owner approval cover its diff.

> Note: a merge to `bb-plugins` `main` moves the pin and stages a restart for every developer's server (Restart now, or in the 03:00–05:00 ET quiet window).

Sibling PR: the `.bb` half on `bb-gate` (`stewards/playbooks/deps-prs.md` and `AGENTS.md`), [bitcomplete/bb-gate#102](bitcomplete/bb-gate#102) — already merged.

## Classification
owner-reviewed: "The stewards plugin's roles parsing, ready gate and approval and escalation plumbing outside the hard-coded self-widening list" (user), the decide-list entry the plugin matched. This changes what the plugin does once the gate is met.

## What changes
- `plugins/stewards/server.ts` — in the gate-met branch of `syncNeeds`, when `bindingMayMerge` (new, exported from `wake.ts`) is true, the plugin calls the shared `mergePullRequest` path instead of filing a Merge item. On success it notes the merge into this look's changes and schedules a reconcile, so the steward's wake carries the merge note and it proceeds to the deployment watch. A steward-filed Merge item is left alone (the hand-off shape) and no merge happens over it.
- `plugins/stewards/server.ts` — **the plugin merges only into the repository's default branch.** A stacked pull request's base is another pull request's branch, which may already be merged and left dead, so auto-merging it there would strand the change off the default branch (how #290/#291/#293 were stranded). A stacked pull request keeps the plugin-filed Merge item and a person or worker merges it into its parent; a default-branch read that fails is treated as not the default, so the item is filed. This guard was added after review round 1 on this PR.
- `plugins/stewards/server.ts` — the merge is skipped while **Pause stewards** is on (the item is filed as before), and `mergePullRequest` passes the head it judged (`gate.headSha`) as the merge `PUT`'s `sha`, so a push between the look and the merge makes GitHub refuse with 409 and the plugin waits for the next look instead of merging a head whose checks have not run.
- `plugins/stewards/server.ts` — a refused merge (conflict, branch protection) is recorded against the head sha plus the reviewer marker and lane (`mergeAttemptKey`). One note and one `stuck` escalation per refusal; the same gate is not retried and not re-raised on later looks. A push or a new review round changes the key and a fresh attempt follows; the escalation names `bb stewards merge <key>` as the manual retry. The head-moved refusal is matched by status (`failed: 409`), never a bare `409` in a URL path.
- `plugins/stewards/wake.ts` — one exported `bindingMayMerge` decides it, so the worker skill line and the gate-met branch cannot disagree; a standing rule tells the steward the plugin merges once the gate is met and not to file a Merge item for a pull request its playbook may merge.
- `plugins/stewards/github.ts` — `squashMerge` takes the judged head sha and sends it as the merge `PUT`'s `sha`.
- Tests cover: a ticket binding merging itself (note, comment, no item); a `pr` binding under `github-prs` merging; a `pr` binding under a deps-prs playbook without `merge` still filing the item; a deps-prs playbook with `merge` merging; a steward-filed item left alone; the refusal recorded once and not retried until the head moves; the head moving between the look and the merge; Pause stewards suppressing the merge; the merge hold still suppressing both; a `409` in the URL path not read as a head-moved refusal.

## Testing
- `cd bb-plugins/plugins/stewards && npm run typecheck`: pass.
- `npx vitest run`: pass (1441 tests; the two new ones cover the stacked-base guard). CI's `quality_checks (stewards)` runs the same suite.
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