Skip to content

feat(bin): add in-house merge queue with landing-crew briefs - #38

Merged
twilwa merged 12 commits into
mainfrom
fm/fm-merge-queue-policy
Oct 20, 2026
Merged

twilwa merged 12 commits into
mainfrom
fm/fm-merge-queue-policy

Conversation

@twilwa

@twilwa twilwa commented Oct 20, 2026 •

Copy link
Copy Markdown
Owner

Intent

Ask: if we can do a merge queue in house and effectively add that as a firstmate policy, that's good enough. Context: on 2026-10-19 the bbchat queue of 39 open PRs landed at two to three merges per hour on six self-hosted runners because each landing cost about 4.5 full CI runs (54 runner-minutes each): a run per fix round, a fresh run every time main was merged into the branch, and reruns for flakes. A GitHub merge queue is unavailable (private repo without Pro) and a hosted queue would have to take over merging from firstmate's review ledger and merge guards, so the decision is an in-house queue. The captain also decided: stop merging main into branches that do not conflict, batch the lineup ("batch it"), one scoped Feedback run for intermediate fixes with the full four-job run only as the final merge proof, and CI admission with a cap on concurrent full runs (two including main tonight) enforced by a pre-push lease hook that firstmate grants. Tonight's manual version: a landing crew builds a candidate branch fm/batch- from current main plus the next review-complete PRs in landing order, firstmate leases one push, one CI run proves the candidate, then every member PR merges on its own already-green head through bin/fm-pr-merge.sh without being refreshed; a member that conflicts with the batch is dropped from it and refreshed alone; the candidate branch is deleted after the batch lands.

What Changed

  • bin/fm-brief.sh has a new --landing-crew scaffold, with tests in tests/fm-brief.test.sh. The brief tells the crew to build fm/batch-<n> candidate branches from a fresh fetch of origin's default branch plus the member PRs at the heads firstmate names, in the order it names them. A member that conflicts, or whose head has moved, is dropped. The crew pushes only under a firstmate lease, never with --no-verify. It never opens or merges a PR, never rewrites history and never deletes a local branch. The next batch number is one more than the highest fm/batch-* number among remote and local refs, and the crew detaches before teardown so local batch refs are kept. The scaffold refuses --mode, --forge, --shape and --base-branch, and its test scope defaults to none. bin/fm-dod-lib.sh renders that scope as "the candidate's CI run is the only proof."

  • New docs/merge-queue.md, registered in docs/documentation-audiences.json, covers the queue's mechanics and why it exists:

    • when a project qualifies
    • how a candidate is built
    • lease admission against a per-project cap on concurrent full CI runs, which counts the default branch's own runs
    • how a candidate run counts as proof
    • landing as one batch PR, or member by member on unchanged green heads as the fallback
    • member close-out and cleanup
    • no refreshing a branch that does not conflict
  • AGENTS.md and the ship-landing skill set the policy:

    • Never merge the default branch into a PR branch that does not conflict with it, unless the forge requires an up-to-date branch.
    • Batch-land when more than two review-complete PRs wait on one project.
    • A green candidate run never replaces a member's own required checks, review ledger or merge authority.

    The skill adds the batch procedure: choosing members, how to handle a red candidate (bisect by halving, one rerun for a flaky job), and the backlog record to keep. docs/configuration.md and docs/scripts.md now list the landing-crew brief.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change is mostly policy documentation plus a self-contained --landing-crew brief scaffold with strict flag refusals, and the latest fix round only narrows one sentence of brief wording to match docs/merge-queue.md; earlier recorded human decisions already settled the batch-PR-primary shape and the batch numbering.

Testing

I ran the targeted brief test file, then drove the landing-crew surface live in throwaway lab homes. I scaffolded the brief, tested refusals, and diffed ship, scout, and secondmate briefs against the base commit (all identical). I then ran a real end-to-end landing crew: a real Claude crewmate spawned through bin/fm-spawn.sh --scout against a local bare origin with PR refs. It built fm/batch-4 on the advanced main, merged PRs 1, 2, and 5 at their named heads, and dropped PR3 for a conflict and PR4 because its head moved. It asked for a lease without pushing and pushed exactly once after bin/fm-send.sh granted it. On steer it deleted the remote candidate and detached before its done line. bin/fm-teardown.sh then kept the local batch refs, so the next number is 5. Every driven scenario passed. The forge-side firstmate steps (opening the batch PR, counting GitHub CI runs under the cap, the guarded merge of the batch PR, member close-out, the pre-push lease hook) could not be driven, because no disposable GitHub repository with Actions is available. They are reported untested. Everything this change adds is brief text plus documented procedure; the scripts it names were not changed. The only change outside the labs is Claude's own workspace-trust and session entries for the lab path, written under the normal Claude config dir, which the runbook treats as expected. All labs were removed.

  • Live validation: ✅ go - 8 of 9 scenarios driven live against the product
Scenario Result Live Evidence
Firstmate scaffolds a landing crew with bin/fm-brief.sh &lt;id&gt; &lt;repo&gt; --landing-crew and gets a brief that declares the landing kind, carries no delivery contract, defaults to test scope none with the… ✅ pass live s1-landing-crew-scaffold.txt; fm-brief-test.log
Adversarial: --landing-crew combined with --mode, --scout, --secondmate, --base-branch, --forge/--shape, or --branch-prefix is refused with a reason and writes no brief ✅ pass live s2-landing-crew-refusals.txt
Regression: ship, scout, and secondmate briefs from the changed fm-brief.sh are byte-identical to the base commit's output ✅ pass live s3-ship-scout-secondmate-unchanged.txt
Firstmate spawns the filled landing-crew brief with bin/fm-spawn.sh &lt;id&gt; &lt;project&gt; --scout and a real Claude crewmate launches as kind=scout ✅ pass live s4-landing-crew-brief-as-spawned.md; s4a-before-lease.txt (spawn output: spawned lq1 harness=claude kind=scout)
Crew builds the candidate from freshly fetched origin main, merges each member at its named head in landing order, drops a conflicting member (PR3) via merge --abort and a moved-head member (PR4), and… ✅ pass live s4a-before-lease.txt; s4c-done-before-teardown.txt (crew report)
Adversarial numbering: with remote fm/batch-2 and only-local fm/batch-3 already present, the crew names its candidate fm/batch-4 ✅ pass live s4a-before-lease.txt; s4c-done-before-teardown.txt
Lease guard: the crew pushes nothing before the lease, pushes exactly the leased head once after bin/fm-send.sh --resolve-key batch-4-lease, parks paused, and never touches main or any member ref ✅ pass live s4a-before-lease.txt; s4b-after-lease.txt
On firstmate's 'landed, delete remote, queue finished' steer the crew deletes remote fm/batch-4, detaches, and writes done; bin/fm-teardown.sh then keeps local fm/batch-4, so the next batch number i… ✅ pass live s4c-done-before-teardown.txt; s4d-teardown-keeps-batch-refs.txt; s5-next-batch-number-after-teardown.txt
Firstmate-side forge steps: open the batch PR, count queued and in-progress GitHub full runs under the cap, run the guarded merge of the batch PR (fm-pr-merge.sh / fm-pr-review.sh merge) with per-memb… ⏸️ untested no These steps need a GitHub repository with pull requests and Actions runners. The lab used a local bare origin, which has no forge, PRs, or CI. Creating a GitHub repo or PR is outward-facing and not au…
Evidence: Targeted brief suite log (landing-crew tests included)

Source: Targeted brief suite log (landing-crew tests included)

ok - fm-brief: scaffolds leave the worker role scope to the launch boundary and keep the secondmate contract
ok - fm-brief.sh: bash -n succeeds
/tmp/fm-brief.0k2dTt/heredoc-in-substitution.sh:2
ok - fm-brief.sh: no heredoc is nested inside a command substitution (Bash 3.2 parse-safe)
ok - fm-brief.sh: --help renders the complete header
ok - fm-brief.sh: no-mistakes/direct-PR/local-only briefs generate cleanly
ok - fm-brief.sh: ship and scout carry host safety without a home include
ok - fm-brief.sh: ship --mode is required and closed-set validated
ok - fm-brief.sh: the explicit ship mode wins over the registered posture
ok - fm-brief.sh: --yolo and scout/secondmate --mode are refused, never silently dropped
ok - fm-brief.sh: faster paths use configured authority without stacked review
ok - fm-brief.sh: no-mistakes DOD keeps its apostrophe prose and bans --yes outright
ok - fm-brief.sh: no-mistakes DOD detects a green PR from the drive call, not a status poll
ok - fm-brief.sh: PR-based done requires a non-draft PR; a deliberate draft declares a wait
ok - fm-brief.sh: no-mistakes ask-user findings use one event plus a verbatim snapshot
ok - fm-brief.sh: ship project-memory wording bounds edits to corrections of wrong information
ok - fm-brief.sh: --herdr-lab emits the complete hard safety contract
ok - fm-brief.sh: --herdr-lab uses its quoted Firstmate-owned helper path
ok - fm-brief.sh: ship and scout scaffolds make omitted Herdr intent fail-visible
ok - fm-brief.sh: the documented {TASK} and {FIRSTMATE_SPEC} fills cannot corrupt the Herdr safety gate
ok - fm-brief.sh: Herdr lab contract covers scouts and rejects secondmate misuse
ok - fm-brief.sh: --no-projects scaffolds a project-less charter and guards misuse
ok - fm-brief.sh: marked requests avoid generic acknowledgements and preserve material reporting
ok - fm-brief.sh: relative directory inputs ignore CDPATH, render stable absolute charter paths, or fail loudly
ok - fm-brief.sh: custom pause verb renders in every scaffold
ok - fm-brief.sh: ship and scout scaffolds declare a validation-round pause once, then hold it
ok - fm-brief.sh: investigation and visual-review completions load the shared decision policy
ok - fm-brief: scout and secondmate code paths still scaffold well-formed briefs
ok - fm-brief.sh: --landing-crew scaffolds the merge-queue landing contract
ok - fm-brief.sh: --landing-crew refuses ship-only and conflicting kind flags
ok - fm-brief.sh: scout Lavish hosting follows the bootstrap lavish-axi floor
ok - fm-brief: workers end the turn on a decision, wait in one bounded shell command, and never poll
ok - fm-brief: without config/wait-no-turns the brief and drive text stay as they were
ok - fm-brief.sh: the home brief include lands last on ship and scout, verbatim, and fails closed
ok - fm-brief.sh: --base-branch records the base, targets the PR at it, and is refused where no PR carries it
ok - fm-brief.sh: --branch-prefix omitted defaults every ship mode to fm/<task-id>
ok - fm-brief.sh: a --branch-prefix override renders identically across every generated section
ok - fm-brief.sh: an empty --branch-prefix override resolves to a bare <task-id> branch
ok - fm-brief.sh: --branch-prefix is refused on scout and secondmate scaffolds
ok - fm-brief.sh: --branch-prefix value is validated against embedded spaces and a leading dash
Switched to a new branch '$(touch${IFS}/tmp/fm-brief.0k2dTt/branch-prefix-shell-safe-marker)brief-branch-safe-g3'
ok - fm-brief.sh: ref-format-valid shell metacharacters stay literal in generated branch commands
ok - fm-brief.sh: every crewmate scaffold forbids administering the shared worktree pool
Evidence: S1: generated landing-crew brief from bin/fm-brief.sh --landing-crew

Source: S1: generated landing-crew brief from bin/fm-brief.sh --landing-crew

$ bin/fm-brief.sh landing-q1 alpha --landing-crew
scaffolded: /tmp/fm-lab.mq0Jxp/data/landing-q1/brief.md (landing crew; replace {TASK} and {FIRSTMATE_SPEC}; spawn with --scout)
exit=0

----- generated /tmp/fm-lab.mq0Jxp/data/landing-q1/brief.md -----
You are a crewmate: an autonomous worker agent managed by firstmate. Work on your own; do not wait for a human.

# Task
## Captain's intent
{TASK}

## Firstmate spec
{FIRSTMATE_SPEC}

## Test scope
Scope: none.
Permits: no local test runs; the candidate's CI run is the only proof.
Expected duration: 0 minutes.

Task budget: wall_secs=21600 output_tokens=1000000

# Herdr lifecycle declaration - NOT ENABLED
**HARD SAFETY GATE:** this scaffold cannot inspect the task text filled in above.
If the task will start, stop, delete, restart, profile, or otherwise drive Herdr lifecycle behavior, stop and regenerate the brief with `--herdr-lab` before dispatch.
Do not add Herdr lifecycle commands to this unguarded brief by hand.

# Setup
You are in a disposable git worktree of alpha, at a detached HEAD on a clean default branch.
This is a LANDING CREW task: you build merge-queue candidate branches that one CI run proves; firstmate opens and merges every pull request itself - the batch pull request by default, member pull requests only in the fallback - and you never open or merge one.
`~/.no-mistakes/worktrees/8be14fbb8fb5/01M5C49NTYG8BH66TND8NV2K5D/docs/merge-queue.md` owns the candidate mechanics; read it before the first build.

# Rules
1. Never open, close, edit, approve, or merge a pull request, and never push to the default branch or to any member pull request's branch.
   Push only a candidate branch, only after a firstmate steering message grants a lease naming that branch and head, and only once per lease; never pass `--no-verify`.
   Delete a remote candidate branch only when a firstmate steering message says its batch landed or was abandoned.
2. Never rebase, reset, amend, or force-push, and never delete a local branch; a rebuilt candidate is a new branch with the next batch number.
   The next batch number is 1 + the highest `<n>` of any `fm/batch-<n>` seen across `git ls-remote --heads origin` and the local refs of the shared repository (`git for-each-ref refs/heads/fm/batch-*`), so no batch number is reused while those refs remain.
   Stay inside this worktree; the only files you may write outside it are the report, the status file, and the steering-inbox acknowledgements below.
3. Use gh-axi for GitHub operations and chrome-devtools-axi for browser operations.
4. Report status by appending one line:
   `echo "{state} [at=<epoch>]: {one short line}" >> '/tmp/fm-lab.mq0Jxp/state/landing-q1.status' && { [ ! -e '/tmp/fm-lab.mq0Jxp/config/fleet-ledger' ] || '~/.no-mistakes/worktrees/8be14fbb8fb5/01M5C49NTYG8BH66TND8NV2K5D/bin/fm-fleet-ledger.sh' appended '/tmp/fm-lab.mq0Jxp/config' '/tmp/fm-lab.mq0Jxp/state/landing-q1.status' >/dev/null 2>&1 || true; }`
   States: working, needs-decision, blocked, paused, done, failed.
   Substitute `<epoch>` with the current Unix time in seconds - run `date +%s` and write the number it printed; a stamp that is not plain digits records no time at all.
   Each append wakes firstmate, so report sparingly: a built candidate, a pushed candidate, and the needs-decision/blocked/paused/done/failed states.
   Whenever you mention a PR anywhere - a status line, your terminal, the report - write its full
   https:// URL exactly as the forge printed it, never a bare number such as "PR 108"; firstmate
   copies that URL from your line rather than assembling one.
   When a candidate is built, ask for its lease with `needs-decision [at=<epoch>] [key=batch-<n>-lease]: candidate fm/batch-<n> head=<sha> base=<sha> members=<PR url>,... dropped=<PR url> (<reason>),...; push lease?` and end your turn.
   After the leased push, append `paused [at=<epoch>] [key=batch-<n>]: candidate fm/batch-<n> head=<sha> pushed; waiting for firstmate to report its CI result` and wait for the next steering message.
   Use `paused: {why}` - distinct from `blocked:` - when deliberately waiting for work or an external condition expected to clear on its own, including your own validation round.
   Before ending your turn with your own background shell or monitor still running, or before waiting on your own pipeline run or a long foreground command, append `paused [at=<epoch>]: {job and completion condition}` to the status file.
   Name what you are waiting for and what will let you resume; do not repeat the declaration on every poll.
   Do not declare active implementation or reasoning as a wait.
   Firstmate may still raise one first-sight alert; the declared wait then uses the existing long recheck cadence instead of repeated possible-wedge alarms.
   When you know when the wait clears, include `until <YYYY-MM-DDTHH:MMZ>` (UTC) for a recheck at that time.
   Follow the resolution rule below when the wait clears, then resume the task.
   Use `blocked:` when you are stuck and need help.

5. If you hit the same obstacle twice, append `blocked [at=<epoch>]: {why}` and stop; firstmate will help.
   If you see the current task budget crossed (age = now - start_epoch >= wall_secs), take budget period n = (age - wall_secs) / 14400 rounded down; once per period, append `needs-decision [at=<epoch>] [key=task-budget-<n>]: budget period <n> crossed; continue or stop?` and stop; firstmate decides.
6. If a decision belongs above you (which member to drop, how to resolve a conflict, anything destructive),
   append `needs-decision [at=<epoch>]: {summary of options}` and stop. Firstmate will reply with the decision.
   A decision or blocker you opened stays open until a `resolved` line carrying its exact key lands; a later `done:` or `working:` line never closes it, even when the answer is what started that work.
   Firstmate's reply normally writes that closing line at answer time; when a blocker or wait clears WITHOUT a firstmate reply, append `resolved [at=<epoch>]: {how it cleared}` yourself (same `[key=<slug>]` if you opened it with one) as you resume.
7. Never administer infrastructure that every lane shares. Two things are shared:
   - The `no-mistakes` daemon - one instance serving every lane/home, so stopping, restarting, or
     updating it kills other lanes' in-flight pipeline runs; only firstmate manages the daemon.
     Before you append `blocked:` about the pipeline, run `no-mistakes daemon status` and
     `no-mistakes axi status`. If the daemon socket refuses connections or is missing, append
     `blocked [at=<epoch>]: {the daemon error}` and stop even when the local run record still says running or
     fixing, because that record can be stale after the daemon exits. A run record failed with a
     daemon error is also a real block.
     Only after ruling out socket refusal, if the run is still running or fixing, reattach and keep
     going. A drive-call error, timeout, slow read, or generic unreachability is NOT a daemon error:
     the daemon accepts `respond` immediately and runs the round in the background, so a killed or
     timed-out call was only waiting for a read while the run kept working.
   - The worktree pool your own worktree came from, and the repository every lane's worktree
     shares. Never create, remove, return, prune, move, or reassign a worktree or pool slot, and
     never write into a sibling slot's directory. Rule 2 does not cover this: removing a worktree
     is administration rather than an edit outside your directory, and it lands on lanes that are
     running right now. The act is the rule and commands are only examples of it - `treehouse`
     get/return/remove/prune, the equivalent operations on any other worktree provider or runtime
     backend, and `git worktree add|remove|move|prune`. A slot that looks unused is not evidence
     that it is free, and returning your own worktree is firstmate's job at cleanup, not yours.
   If you genuinely need a second checkout, another slot, or the daemon touched, append
   `blocked [at=<epoch>]: {what you need}` and stop; firstmate arranges it.

# Shared-host safety
Use rg for literal or regex text search across files; use ast-grep (never sg) for code structure such as calls, definitions, imports, metavariable patterns and structural rewrites. Use GNU grep/find only inside portable scripts or to filter small piped output; do not add fd. When a script needs a binary's real path, use `type -P <name>`, never `command -v`.

Before changing PATH or shadowing binaries with shims, wrappers, aliases or functions (including LD_PRELOAD, LD_LIBRARY_PATH, profiling or tracing wrappers); before fork- or process-heavy work (load, stress or benchmark runs, recursive scripts or wide parallel fan-out); before system or user-level config changes (systemd units and timers, cron, sysctl, limits, /etc, shell rc files, global git/npm/mise/claude config); or before killing processes outside your own tree or touching the herdr server, tailscale or ssh config: run a Jev risk check with jev-cli or jevhelper on the exact command or diff. Ask whether it could affect processes, services or state outside your own worktree and process tree or destabilise the shared host. If Jev rates it risky or uncertain, stop and ask your supervisor for approval. Jev is advisory; containment applies regardless.

Run anything approved from this gate inside a systemd-run user scope, sized to the job; see `~/.no-mistakes/worktrees/8be14fbb8fb5/01M5C49NTYG8BH66TND8NV2K5D/docs/configuration.md` for the scope recipe. For any shim or wrapper, resolve its target to an absolute path with `type -P` before prepending the shim directory to PATH, drop its own directory from PATH or carry a recursion-guard environment variable, and check it with `head -n2` before use. A self-referencing shim can trigger uncontrolled process recursion.

# Firstmate instruction inbox
Firstmate steers you through durable message files in '/tmp/fm-lab.mq0Jxp/state/landing-q1.inbox'.
When a terminal message says an instruction is waiting there - and at any natural checkpoint when you are unsure - list '/tmp/fm-lab.mq0Jxp/state/landing-q1.inbox'/*.msg, read and act on each message in numeric order, then acknowledge each handled message by moving it: `mv '/tmp/fm-lab.mq0Jxp/state/landing-q1.inbox'/NNN.msg '/tmp/fm-lab.mq0Jxp/state/landing-q1.inbox'/handled/`.
The move IS the acknowledgement: without it firstmate rings again and eventually treats you as stuck. An empty or absent inbox needs no action.

# Building a candidate
Fetch origin immediately before every build and start the candidate from origin's default branch at that fetch; never reuse an older base.
Merge each member at exactly the head commit firstmate named, in the order firstmate named them.
A member whose forge head no longer matches that commit, or whose merge conflicts with the candidate so far, is dropped: abort that merge, continue with the next member, and report the drop with its reason.
Never resolve a conflict or change a member's code yourself.

# Definition of done
Keep a running record in `/tmp/fm-lab.mq0Jxp/data/landing-q1/report.md`: for every candidate, its branch, base and head commits, each member's PR URL and head commit, every dropped member and why, the CI result firstmate reports, any batch PR URL firstmate reports, and whether its remote branch was deleted.
When a firstmate steering message says the queue is finished, complete the report, leave the worktree clean, append `done [at=<epoch>]: {batches built and members they carried}` to the status file, and stop.
Before every `done`, `failed`, or stopping `blocked` line, run `git switch --detach` so teardown finds no checked-out `fm/batch-*` branch to delete and every local batch ref survives.
Evidence: S2: --landing-crew refusals for ship-only and conflicting flags

Source: S2: --landing-crew refusals for ship-only and conflicting flags

$ bin/fm-brief.sh r1 alpha --landing-crew --mode no-mistakes
error: --mode applies only to ship briefs; a scout delivers a report and a secondmate charter is not a delivery contract
exit=1 brief_written=no

$ bin/fm-brief.sh r2 alpha --landing-crew --scout
error: --landing-crew cannot be combined with --scout or --secondmate
exit=1 brief_written=no

$ bin/fm-brief.sh r3 alpha --secondmate --landing-crew alpha
error: --landing-crew cannot be combined with --scout or --secondmate
exit=1 brief_written=no

$ bin/fm-brief.sh r4 alpha --landing-crew --base-branch release
error: --base-branch takes a branch name and applies only to ship and scout briefs
exit=1 brief_written=no

$ bin/fm-brief.sh r5 alpha --landing-crew --forge gerrit --shape squash
error: --forge and --shape apply only to ship briefs; a scout delivers a report and a secondmate charter is not a delivery contract
exit=1 brief_written=no

$ bin/fm-brief.sh r6 alpha --landing-crew --branch-prefix fix/
error: --branch-prefix applies only to ship briefs; a scout makes no branch and a secondmate charter is not a delivery contract
exit=1 brief_written=no

$ bin/fm-brief.sh r7 alpha --landing-crew --tests full
scaffolded: /tmp/fm-lab.mq0Jxp/data/r7/brief.md (landing crew; replace {TASK} and {FIRSTMATE_SPEC}; spawn with --scout)
exit=0 brief_written=yes

--- r7 (--tests full accepted) test-scope section:
Scope: full.
Permits: the full local suite, including tests that drive live Herdr, Codex, or Lavish.
Evidence: S3: ship/scout/secondmate briefs identical to base commit

Source: S3: ship/scout/secondmate briefs identical to base commit

Compare briefs generated by base d447e08 vs head c7f3850 (FM_ROOT paths normalised)
s1/brief.md: identical
s2/brief.md: identical
p1/brief.md: identical
p2/brief.md: identical
p3/brief.md: identical
sm1/brief.md: identical
Evidence: S4: filled landing-crew brief as spawned

Source: S4: filled landing-crew brief as spawned

You are a crewmate: an autonomous worker agent managed by firstmate. Work on your own; do not wait for a human.

# Task
## Captain's intent
Land the five review-complete alpha pull requests through the in-house merge queue as one batch.

## Firstmate spec
This is a disposable lab: origin is the local bare repository /tmp/fm-lab.64djP7/origin.git with no forge, so do not use gh-axi or any GitHub command; the pull request URLs below are the forge's labels and member N's forge head is the ref refs/pull/N/head on origin (fetch it with `git fetch origin pull/N/head`).
Build the next candidate from origin's default branch (main) with these members, in this landing order, each at exactly the named head:
1. https://github.com/fm-lab/alpha/pull/1 head=6f05c7175d0553b1efc4e134722452edd6755e8f
2. https://github.com/fm-lab/alpha/pull/2 head=08e297597773090c86359f384171723a8c1fadd4
3. https://github.com/fm-lab/alpha/pull/3 head=779b792347349e0fc4603f92a963b4455f583911
4. https://github.com/fm-lab/alpha/pull/4 head=4c71b5a4f964704cef1f29bff5a65b6b2a99f251
5. https://github.com/fm-lab/alpha/pull/5 head=27b7a92b585c06c89de3243e2d094f752988505f
Then ask for the push lease as your brief says and wait for firstmate's steering.

## Test scope
Scope: none.
Permits: no local test runs; the candidate's CI run is the only proof.
Expected duration: 0 minutes.

Task budget: wall_secs=21600 output_tokens=1000000

# Herdr lifecycle declaration - NOT ENABLED
**HARD SAFETY GATE:** this scaffold cannot inspect the task text filled in above.
If the task will start, stop, delete, restart, profile, or otherwise drive Herdr lifecycle behavior, stop and regenerate the brief with `--herdr-lab` before dispatch.
Do not add Herdr lifecycle commands to this unguarded brief by hand.

# Setup
You are in a disposable git worktree of alpha, at a detached HEAD on a clean default branch.
This is a LANDING CREW task: you build merge-queue candidate branches that one CI run proves; firstmate opens and merges every pull request itself - the batch pull request by default, member pull requests only in the fallback - and you never open or merge one.
`~/.no-mistakes/worktrees/8be14fbb8fb5/01M5C49NTYG8BH66TND8NV2K5D/docs/merge-queue.md` owns the candidate mechanics; read it before the first build.

# Rules
1. Never open, close, edit, approve, or merge a pull request, and never push to the default branch or to any member pull request's branch.
   Push only a candidate branch, only after a firstmate steering message grants a lease naming that branch and head, and only once per lease; never pass `--no-verify`.
   Delete a remote candidate branch only when a firstmate steering message says its batch landed or was abandoned.
2. Never rebase, reset, amend, or force-push, and never delete a local branch; a rebuilt candidate is a new branch with the next batch number.
   The next batch number is 1 + the highest `<n>` of any `fm/batch-<n>` seen across `git ls-remote --heads origin` and the local refs of the shared repository (`git for-each-ref refs/heads/fm/batch-*`), so no batch number is reused while those refs remain.
   Stay inside this worktree; the only files you may write outside it are the report, the status file, and the steering-inbox acknowledgements below.
3. Use gh-axi for GitHub operations and chrome-devtools-axi for browser operations.
4. Report status by appending one line:
   `echo "{state} [at=<epoch>]: {one short line}" >> '/tmp/fm-lab.64djP7/state/lq1.status' && { [ ! -e '/tmp/fm-lab.64djP7/config/fleet-ledger' ] || '~/.no-mistakes/worktrees/8be14fbb8fb5/01M5C49NTYG8BH66TND8NV2K5D/bin/fm-fleet-ledger.sh' appended '/tmp/fm-lab.64djP7/config' '/tmp/fm-lab.64djP7/state/lq1.status' >/dev/null 2>&1 || true; }`
   States: working, needs-decision, blocked, paused, done, failed.
   Substitute `<epoch>` with the current Unix time in seconds - run `date +%s` and write the number it printed; a stamp that is not plain digits records no time at all.
   Each append wakes firstmate, so report sparingly: a built candidate, a pushed candidate, and the needs-decision/blocked/paused/done/failed states.
   Whenever you mention a PR anywhere - a status line, your terminal, the report - write its full
   https:// URL exactly as the forge printed it, never a bare number such as "PR 108"; firstmate
   copies that URL from your line rather than assembling one.
   When a candidate is built, ask for its lease with `needs-decision [at=<epoch>] [key=batch-<n>-lease]: candidate fm/batch-<n> head=<sha> base=<sha> members=<PR url>,... dropped=<PR url> (<reason>),...; push lease?` and end your turn.
   After the leased push, append `paused [at=<epoch>] [key=batch-<n>]: candidate fm/batch-<n> head=<sha> pushed; waiting for firstmate to report its CI result` and wait for the next steering message.
   Use `paused: {why}` - distinct from `blocked:` - when deliberately waiting for work or an external condition expected to clear on its own, including your own validation round.
   Before ending your turn with your own background shell or monitor still running, or before waiting on your own pipeline run or a long foreground command, append `paused [at=<epoch>]: {job and completion condition}` to the status file.
   Name what you are waiting for and what will let you resume; do not repeat the declaration on every poll.
   Do not declare active implementation or reasoning as a wait.
   Firstmate may still raise one first-sight alert; the declared wait then uses the existing long recheck cadence instead of repeated possible-wedge alarms.
   When you know when the wait clears, include `until <YYYY-MM-DDTHH:MMZ>` (UTC) for a recheck at that time.
   Follow the resolution rule below when the wait clears, then resume the task.
   Use `blocked:` when you are stuck and need help.

5. If you hit the same obstacle twice, append `blocked [at=<epoch>]: {why}` and stop; firstmate will help.
   If you see the current task budget crossed (age = now - start_epoch >= wall_secs), take budget period n = (age - wall_secs) / 14400 rounded down; once per period, append `needs-decision [at=<epoch>] [key=task-budget-<n>]: budget period <n> crossed; continue or stop?` and stop; firstmate decides.
6. If a decision belongs above you (which member to drop, how to resolve a conflict, anything destructive),
   append `needs-decision [at=<epoch>]: {summary of options}` and stop. Firstmate will reply with the decision.
   A decision or blocker you opened stays open until a `resolved` line carrying its exact key lands; a later `done:` or `working:` line never closes it, even when the answer is what started that work.
   Firstmate's reply normally writes that closing line at answer time; when a blocker or wait clears WITHOUT a firstmate reply, append `resolved [at=<epoch>]: {how it cleared}` yourself (same `[key=<slug>]` if you opened it with one) as you resume.
7. Never administer infrastructure that every lane shares. Two things are shared:
   - The `no-mistakes` daemon - one instance serving every lane/home, so stopping, restarting, or
     updating it kills other lanes' in-flight pipeline runs; only firstmate manages the daemon.
     Before you append `blocked:` about the pipeline, run `no-mistakes daemon status` and
     `no-mistakes axi status`. If the daemon socket refuses connections or is missing, append
     `blocked [at=<epoch>]: {the daemon error}` and stop even when the local run record still says running or
     fixing, because that record can be stale after the daemon exits. A run record failed with a
     daemon error is also a real block.
     Only after ruling out socket refusal, if the run is still running or fixing, reattach and keep
     going. A drive-call error, timeout, slow read, or generic unreachability is NOT a daemon error:
     the daemon accepts `respond` immediately and runs the round in the background, so a killed or
     timed-out call was only waiting for a read while the run kept working.
   - The worktree pool your own worktree came from, and the repository every lane's worktree
     shares. Never create, remove, return, prune, move, or reassign a worktree or pool slot, and
     never write into a sibling slot's directory. Rule 2 does not cover this: removing a worktree
     is administration rather than an edit outside your directory, and it lands on lanes that are
     running right now. The act is the rule and commands are only examples of it - `treehouse`
     get/return/remove/prune, the equivalent operations on any other worktree provider or runtime
     backend, and `git worktree add|remove|move|prune`. A slot that looks unused is not evidence
     that it is free, and returning your own worktree is firstmate's job at cleanup, not yours.
   If you genuinely need a second checkout, another slot, or the daemon touched, append
   `blocked [at=<epoch>]: {what you need}` and stop; firstmate arranges it.

# Shared-host safety
Use rg for literal or regex text search across files; use ast-grep (never sg) for code structure such as calls, definitions, imports, metavariable patterns and structural rewrites. Use GNU grep/find only inside portable scripts or to filter small piped output; do not add fd. When a script needs a binary's real path, use `type -P <name>`, never `command -v`.

Before changing PATH or shadowing binaries with shims, wrappers, aliases or functions (including LD_PRELOAD, LD_LIBRARY_PATH, profiling or tracing wrappers); before fork- or process-heavy work (load, stress or benchmark runs, recursive scripts or wide parallel fan-out); before system or user-level config changes (systemd units and timers, cron, sysctl, limits, /etc, shell rc files, global git/npm/mise/claude config); or before killing processes outside your own tree or touching the herdr server, tailscale or ssh config: run a Jev risk check with jev-cli or jevhelper on the exact command or diff. Ask whether it could affect processes, services or state outside your own worktree and process tree or destabilise the shared host. If Jev rates it risky or uncertain, stop and ask your supervisor for approval. Jev is advisory; containment applies regardless.

Run anything approved from this gate inside a systemd-run user scope, sized to the job; see `~/.no-mistakes/worktrees/8be14fbb8fb5/01M5C49NTYG8BH66TND8NV2K5D/docs/configuration.md` for the scope recipe. For any shim or wrapper, resolve its target to an absolute path with `type -P` before prepending the shim directory to PATH, drop its own directory from PATH or carry a recursion-guard environment variable, and check it with `head -n2` before use. A self-referencing shim can trigger uncontrolled process recursion.

# Firstmate instruction inbox
Firstmate steers you through durable message files in '/tmp/fm-lab.64djP7/state/lq1.inbox'.
When a terminal message says an instruction is waiting there - and at any natural checkpoint when you are unsure - list '/tmp/fm-lab.64djP7/state/lq1.inbox'/*.msg, read and act on each message in numeric order, then acknowledge each handled message by moving it: `mv '/tmp/fm-lab.64djP7/state/lq1.inbox'/NNN.msg '/tmp/fm-lab.64djP7/state/lq1.inbox'/handled/`.
The move IS the acknowledgement: without it firstmate rings again and eventually treats you as stuck. An empty or absent inbox needs no action.

# Building a candidate
Fetch origin immediately before every build and start the candidate from origin's default branch at that fetch; never reuse an older base.
Merge each member at exactly the head commit firstmate named, in the order firstmate named them.
A member whose forge head no longer matches that commit, or whose merge conflicts with the candidate so far, is dropped: abort that merge, continue with the next member, and report the drop with its reason.
Never resolve a conflict or change a member's code yourself.

# Definition of done
Keep a running record in `/tmp/fm-lab.64djP7/data/lq1/report.md`: for every candidate, its branch, base and head commits, each member's PR URL and head commit, every dropped member and why, the CI result firstmate reports, any batch PR URL firstmate reports, and whether its remote branch was deleted.
When a firstmate steering message says the queue is finished, complete the report, leave the worktree clean, append `done [at=<epoch>]: {batches built and members they carried}` to the status file, and stop.
Before every `done`, `failed`, or stopping `blocked` line, run `git switch --detach` so teardown finds no checked-out `fm/batch-*` branch to delete and every local batch ref survives.
Evidence: S4a: lease request status, untouched origin refs, candidate graph before lease

Source: S4a: lease request status, untouched origin refs, candidate graph before lease

=== BEFORE LEASE: status file
needs-decision [at=1792483522] [key=batch-4-lease]: candidate fm/batch-4 head=c28c7e68a84ea5568807304a1bc9f1a67ba9d188 base=aca6f508eee21d5b015b64c9b81d7984923caeb3 members=https://github.com/fm-lab/alpha/pull/1,https://github.com/fm-lab/alpha/pull/2,https://github.com/fm-lab/alpha/pull/5 dropped=https://github.com/fm-lab/alpha/pull/3 (merge conflict in README.md),https://github.com/fm-lab/alpha/pull/4 (head moved to 703f6bed9c652c6f7b4472e6c1805a9f4738e444); push lease?
=== origin refs (no fm/batch-4 pushed before lease)
refs/heads/fm/batch-2 a322a5387f924152006472f3500cc5bdc636d600
refs/heads/main aca6f508eee21d5b015b64c9b81d7984923caeb3
refs/heads/pr-1 6f05c7175d0553b1efc4e134722452edd6755e8f
refs/heads/pr-2 08e297597773090c86359f384171723a8c1fadd4
refs/heads/pr-3 779b792347349e0fc4603f92a963b4455f583911
refs/heads/pr-4 703f6bed9c652c6f7b4472e6c1805a9f4738e444
refs/heads/pr-5 27b7a92b585c06c89de3243e2d094f752988505f
=== crew candidate graph
*   c28c7e6 Merge commit 'refs/pull/5/head' of file:///tmp/fm-lab.64djP7/origin into fm/batch-4
|\  
| * 27b7a92 PR 5
* |   4ee3717 Merge commit 'refs/pull/2/head' of file:///tmp/fm-lab.64djP7/origin into fm/batch-4
|\ \  
| * | 08e2975 PR 2
| |/  
* |   7fa4f0c Merge commit 'refs/pull/1/head' of file:///tmp/fm-lab.64djP7/origin into fm/batch-4
|\ \  
| * | 6f05c71 PR 1
| |/  
* / aca6f50 main advance
|/  
* a322a53 initial
=== project local refs
refs/heads/fm/batch-3
refs/heads/fm/batch-4
Evidence: S5: next batch number after teardown is 5

Source: S5: next batch number after teardown is 5

Next batch number per the brief rule, computed in the shared repository after crew lq1 was torn down:
$ git ls-remote --heads origin
a322a5387f924152006472f3500cc5bdc636d600	refs/heads/fm/batch-2
c28c7e68a84ea5568807304a1bc9f1a67ba9d188	refs/heads/main
6f05c7175d0553b1efc4e134722452edd6755e8f	refs/heads/pr-1
08e297597773090c86359f384171723a8c1fadd4	refs/heads/pr-2
779b792347349e0fc4603f92a963b4455f583911	refs/heads/pr-3
703f6bed9c652c6f7b4472e6c1805a9f4738e444	refs/heads/pr-4
27b7a92b585c06c89de3243e2d094f752988505f	refs/heads/pr-5
$ git for-each-ref refs/heads/fm/batch-*
refs/heads/fm/batch-3
refs/heads/fm/batch-4
highest=4 next=5  (remote fm/batch-4 was deleted; local ref kept by the detach step keeps 4 from being reused)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

⏭️ **Rebase** - skipped

Step was skipped.

🔧 **Review** - 1 issue found → auto-fixed (3) ✅
  • ⚠️ bin/fm-brief.sh:763 - The landing-crew contract leaves fm/batch-&lt;n&gt; branches behind in the repository that every pool slot shares, and no one numbers batches across crews. Rule 2 says the crew must "never delete a local branch", and docs/merge-queue.md:107 says the crew "keeps its local branch" after deleting the remote one. Each candidate is created with git switch --no-track -c fm/batch-&lt;n&gt; (docs/merge-queue.md:46). Scout teardown deletes only the branch that is checked out at teardown (bin/fm-teardown.sh:3709-3715). So one crew that builds batch-1 through batch-k leaves k-1 refs in the shared repository. A later landing crew for the same project gets its batch number only by convention: docs/merge-queue.md:53 says 'Batch numbers only increase' but names no counter, and the brief says only 'the next batch number'. If that crew reuses a number, git switch -c fails with 'a branch named fm/batch-<n> already exists' and the crew goes blocked. It fails safe, but leaked refs pile up across every queue run. Possible remedies: let the crew delete its own local fm/batch-* branch once the remote one is deleted, or name a durable source for n, for example the highest fm/batch-* seen with git ls-remote plus the local refs. Either one changes a rule the author wrote on purpose (no local branch deletion), so this needs the author's decision. Other sites: docs/merge-queue.md:53 and docs/merge-queue.md:107.

🔧 Fix applied.
2 warnings still open:

  • ⚠️ bin/fm-brief.sh:763 - The landing-crew contract leaves fm/batch-&lt;n&gt; branches behind in the repository that every pool slot shares, and no one numbers batches across crews. Rule 2 says the crew must "never delete a local branch", and docs/merge-queue.md:107 says the crew "keeps its local branch" after deleting the remote one. Each candidate is created with git switch --no-track -c fm/batch-&lt;n&gt; (docs/merge-queue.md:46). Scout teardown deletes only the branch that is checked out at teardown (bin/fm-teardown.sh:3709-3715). So one crew that builds batch-1 through batch-k leaves k-1 refs in the shared repository. A later landing crew for the same project gets its batch number only by convention: docs/merge-queue.md:53 says 'Batch numbers only increase' but names no counter, and the brief says only 'the next batch number'. If that crew reuses a number, git switch -c fails with 'a branch named fm/batch-<n> already exists' and the crew goes blocked. It fails safe, but leaked refs pile up across every queue run. Possible remedies: let the crew delete its own local fm/batch-* branch once the remote one is deleted, or name a durable source for n, for example the highest fm/batch-* seen with git ls-remote plus the local refs. Either one changes a rule the author wrote on purpose (no local branch deletion), so this needs the author's decision. Other sites: docs/merge-queue.md:53 and docs/merge-queue.md:107.
  • ⚠️ bin/fm-brief.sh:764 - The numbering source added in review fix round 1 does not stop reuse, although the brief and docs say "no batch number is ever reused, even by a later landing crew". This defect comes from that fix round. The rule computes n = 1 + the highest fm/batch-<n> across git ls-remote --heads origin and the local refs. Teardown removes the one ref that matters. Nothing in the crew contract switches away from the last candidate, so the crew's worktree is still on fm/batch-k when bin/fm-teardown.sh runs, and both teardown paths delete the checked-out branch (bin/fm-teardown.sh:3693-3696 and 3711-3714 run checkout --detach then branch -D). The remote fm/batch-k is already gone: step 7 deletes it on steer, or the forge deletes it after the merge. Concrete sequence: crew A builds only fm/batch-1, which is the common case. The batch lands, the remote is deleted, and teardown deletes local fm/batch-1. Crew B then sees no fm/batch-* refs and computes n = 1 again. With several batches, A leaves batch-1..k-1 locally, and B reuses k. Running git switch -c succeeds, so nothing fails. But fm/batch-k now names two candidates. A merged or closed batch PR from the same head name already exists, gh-axi run list --branch fm/batch-k returns the old runs as well (the leased-head check still guards the proof), and the backlog and report records become ambiguous. Sibling sites with the same claim: docs/merge-queue.md:54 ("even by a later landing crew") and docs/merge-queue.md:109 ("until then they still count toward the next batch number", which teardown's own deletion of the last ref also makes false). tests/fm-brief.test.sh:1066 asserts only the brief wording, so it passes regardless. The human prescribed this exact source and kept the no-delete rule, so the remedy needs their approval. Two options: (a) have the crew run git switch --detach before its done: line, which keeps every local fm/batch-* ref so teardown deletes none, or (b) add the forge's batch pull-request head names (for example gh-axi pr list --state all --search head:fm/batch-) to the numbering source.

🔧 Fix applied.
3 issues (2 warnings, 1 info) still open:

  • ⚠️ bin/fm-brief.sh:763 - The landing-crew contract leaves fm/batch-&lt;n&gt; branches behind in the repository that every pool slot shares, and no one numbers batches across crews. Rule 2 says the crew must "never delete a local branch", and docs/merge-queue.md:107 says the crew "keeps its local branch" after deleting the remote one. Each candidate is created with git switch --no-track -c fm/batch-&lt;n&gt; (docs/merge-queue.md:46). Scout teardown deletes only the branch that is checked out at teardown (bin/fm-teardown.sh:3709-3715). So one crew that builds batch-1 through batch-k leaves k-1 refs in the shared repository. A later landing crew for the same project gets its batch number only by convention: docs/merge-queue.md:53 says 'Batch numbers only increase' but names no counter, and the brief says only 'the next batch number'. If that crew reuses a number, git switch -c fails with 'a branch named fm/batch-<n> already exists' and the crew goes blocked. It fails safe, but leaked refs pile up across every queue run. Possible remedies: let the crew delete its own local fm/batch-* branch once the remote one is deleted, or name a durable source for n, for example the highest fm/batch-* seen with git ls-remote plus the local refs. Either one changes a rule the author wrote on purpose (no local branch deletion), so this needs the author's decision. Other sites: docs/merge-queue.md:53 and docs/merge-queue.md:107.
  • ⚠️ bin/fm-brief.sh:764 - The numbering source added in review fix round 1 does not stop reuse, although the brief and docs say "no batch number is ever reused, even by a later landing crew". This defect comes from that fix round. The rule computes n = 1 + the highest fm/batch-<n> across git ls-remote --heads origin and the local refs. Teardown removes the one ref that matters. Nothing in the crew contract switches away from the last candidate, so the crew's worktree is still on fm/batch-k when bin/fm-teardown.sh runs, and both teardown paths delete the checked-out branch (bin/fm-teardown.sh:3693-3696 and 3711-3714 run checkout --detach then branch -D). The remote fm/batch-k is already gone: step 7 deletes it on steer, or the forge deletes it after the merge. Concrete sequence: crew A builds only fm/batch-1, which is the common case. The batch lands, the remote is deleted, and teardown deletes local fm/batch-1. Crew B then sees no fm/batch-* refs and computes n = 1 again. With several batches, A leaves batch-1..k-1 locally, and B reuses k. Running git switch -c succeeds, so nothing fails. But fm/batch-k now names two candidates. A merged or closed batch PR from the same head name already exists, gh-axi run list --branch fm/batch-k returns the old runs as well (the leased-head check still guards the proof), and the backlog and report records become ambiguous. Sibling sites with the same claim: docs/merge-queue.md:54 ("even by a later landing crew") and docs/merge-queue.md:109 ("until then they still count toward the next batch number", which teardown's own deletion of the last ref also makes false). tests/fm-brief.test.sh:1066 asserts only the brief wording, so it passes regardless. The human prescribed this exact source and kept the no-delete rule, so the remedy needs their approval. Two options: (a) have the crew run git switch --detach before its done: line, which keeps every local fm/batch-* ref so teardown deletes none, or (b) add the forge's batch pull-request head names (for example gh-axi pr list --state all --search head:fm/batch-) to the numbering source.
  • ℹ️ bin/fm-brief.sh:764 - Fix round 2 left one sibling behind. In docs/merge-queue.md:56 it correctly narrowed the numbering claim to "never reuses a batch number while those refs remain", because docs/merge-queue.md:111 lets Firstmate or the captain prune leftover local fm/batch-* refs. Rule 2 of the generated landing-crew brief still says "so no batch number is ever reused". How it goes wrong: Firstmate prunes every local fm/batch-* ref as the docs allow, and the forge has already deleted the remote candidates. A later crew then sees no refs and computes n = 1 again, which contradicts what its brief promises. Teardown also still deletes a checked-out fm/batch-k when a crew is torn down without writing a done, failed, or stopping blocked line. Example: Firstmate answers a needs-decision task-budget line with stop and then tears the crew down. Smallest fix: end the brief sentence the way the docs do ("...so no batch number is reused while those refs remain"), or drop the clause. tests/fm-brief.test.sh:1066 matches only the sentence prefix, so it keeps passing.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 8 of 9 scenarios driven live against the product
Scenario Result Live Evidence
Firstmate scaffolds a landing crew with bin/fm-brief.sh &lt;id&gt; &lt;repo&gt; --landing-crew and gets a brief that declares the landing kind, carries no delivery contract, defaults to test scope none with the… ✅ pass live s1-landing-crew-scaffold.txt; fm-brief-test.log
Adversarial: --landing-crew combined with --mode, --scout, --secondmate, --base-branch, --forge/--shape, or --branch-prefix is refused with a reason and writes no brief ✅ pass live s2-landing-crew-refusals.txt
Regression: ship, scout, and secondmate briefs from the changed fm-brief.sh are byte-identical to the base commit's output ✅ pass live s3-ship-scout-secondmate-unchanged.txt
Firstmate spawns the filled landing-crew brief with bin/fm-spawn.sh &lt;id&gt; &lt;project&gt; --scout and a real Claude crewmate launches as kind=scout ✅ pass live s4-landing-crew-brief-as-spawned.md; s4a-before-lease.txt (spawn output: spawned lq1 harness=claude kind=scout)
Crew builds the candidate from freshly fetched origin main, merges each member at its named head in landing order, drops a conflicting member (PR3) via merge --abort and a moved-head member (PR4), and… ✅ pass live s4a-before-lease.txt; s4c-done-before-teardown.txt (crew report)
Adversarial numbering: with remote fm/batch-2 and only-local fm/batch-3 already present, the crew names its candidate fm/batch-4 ✅ pass live s4a-before-lease.txt; s4c-done-before-teardown.txt
Lease guard: the crew pushes nothing before the lease, pushes exactly the leased head once after bin/fm-send.sh --resolve-key batch-4-lease, parks paused, and never touches main or any member ref ✅ pass live s4a-before-lease.txt; s4b-after-lease.txt
On firstmate's 'landed, delete remote, queue finished' steer the crew deletes remote fm/batch-4, detaches, and writes done; bin/fm-teardown.sh then keeps local fm/batch-4, so the next batch number i… ✅ pass live s4c-done-before-teardown.txt; s4d-teardown-keeps-batch-refs.txt; s5-next-batch-number-after-teardown.txt
Firstmate-side forge steps: open the batch PR, count queued and in-progress GitHub full runs under the cap, run the guarded merge of the batch PR (fm-pr-merge.sh / fm-pr-review.sh merge) with per-memb… ⏸️ untested no These steps need a GitHub repository with pull requests and Actions runners. The lab used a local bare origin, which has no forge, PRs, or CI. Creating a GitHub repo or PR is outward-facing and not au…
  • bash tests/fm-brief.test.sh (targeted brief suite, including test_landing_crew_scaffold and test_landing_crew_refuses_delivery_flags), exit 0
  • FM_HOME=&lt;lab&gt; bin/fm-brief.sh landing-q1 alpha --landing-crew in a disposable lab home, with the generated brief inspected
  • bin/fm-brief.sh with --landing-crew combined with --mode, --scout, --secondmate, --base-branch, --forge/--shape, --branch-prefix (refused, no brief written) and --tests full (accepted)
  • Ship (no-mistakes, local-only, direct-PR), scout (default and --tests none), and secondmate briefs generated by base d447e08 (git archive) and head c7f3850 in disposable homes, then diffed
  • Disposable lab: fm-lab-home.sh home, local bare origin with refs/pull/1..5/head (PR3 conflicts with PR2, PR4 head moved after naming), remote fm/batch-2 plus local fm/batch-3 leftovers, origin main advanced, treehouse pool under the lab HOME, private tmux socket fm-lab
  • bin/fm-spawn.sh lq1 &lt;lab&gt;/projects/alpha --scout launching a real claude crewmate on the filled landing-crew brief
  • Watched the crew's status file and origin refs until the needs-decision [key=batch-4-lease] line, confirming nothing was pushed before the lease
  • bin/fm-send.sh lq1 --resolve-key batch-4-lease &#39;Lease granted ...&#39;, then verified exactly one push of the leased head and that main and member refs were untouched
  • Simulated the batch landing on origin main, sent the 'CI green, batch landed, delete remote, queue finished' steer with bin/fm-send.sh lq1 ..., and verified the remote deletion, the detached HEAD, and the done line
  • bin/fm-captain-hold.sh complete lq1 --none then bin/fm-teardown.sh lq1, verifying local fm/batch-3 and fm/batch-4 survive teardown
  • Recomputed the brief's next-batch-number rule (git ls-remote --heads origin plus git for-each-ref refs/heads/fm/batch-*) after teardown: next=5
  • Killed the lab tmux server and rm -rf'd every lab, base-archive, and comparison directory; the worktree is clean
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Summary by Sourcery

Introduce an in-house merge queue that batches compatible pull requests behind a leased candidate branch and a shared CI proof while retaining existing review and merge safeguards.

New Features:

  • Add an in-house merge-queue landing-crew workflow for building leased candidate branches and sharing one CI proof across review-complete pull requests.

Bug Fixes:

  • Prevent unnecessary default-branch refreshes from invalidating green checks and review-ledger state for non-conflicting pull requests.
  • Make landing-crew batch numbering and teardown preserve local batch references while they remain available for future numbering.

Enhancements:

  • Document merge-queue eligibility, candidate proof, admission caps, batch and fallback landing, cleanup, and red-candidate handling.
  • Establish policy and skill guidance for batch landing while preserving member-level checks, review authority, and guarded merges.
  • Extend brief generation and test-scope rendering with a dedicated landing-crew contract, safety rules, lease reporting, and strict flag validation.
  • Register the merge-queue documentation and landing-crew brief across project documentation and configuration references.

Documentation:

  • Add user-facing documentation for the in-house merge queue and its operating policy.

Tests:

  • Add targeted coverage for landing-crew scaffolding, conflicting-option refusals, batch numbering, lease behavior, and related live workflow scenarios.
  • Harden startup-network timing validation to wait for the capped timeout record before asserting it.

State the batch-landing policy in AGENTS.md section 7, add the batch
procedure to the ship-landing skill, scaffold the landing crew contract
with fm-brief.sh --landing-crew, and make docs/merge-queue.md the owner of
the queue mechanics and rationale.
A batch can land as one pull request; after a squash or rebase merge each
member pull request is closed with a comment naming the batch PR and the
default-branch commit. Members must be mergeable at lease time, and every
candidate is built on the default branch after the latest merge.
@sourcery-ai

sourcery-ai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

This PR adds an in-house merge queue centered on a lease-gated landing crew: it builds immutable candidate branches from freshly fetched default-branch state, uses one admitted CI run as shared candidate proof, and lands members through guarded batch-PR or unchanged-head merges. The implementation is primarily procedural documentation plus a new fm-brief.sh --landing-crew scaffold with validation, landing-specific test semantics, lifecycle/reporting rules, and focused tests; reviewers should pay particular attention to the untested GitHub batch-PR path and whether its documented ledger ownership, admission, member-guard checks, and rebinding behavior match the existing merge tooling.

Sequence diagram for lease-gated merge queue landing

sequenceDiagram
    participant Firstmate
    participant Crew as LandingCrew
    participant Forge
    participant CI
    participant Merge as GuardedMerge

    Firstmate->>Crew: Name member PR heads in landing order
    Crew->>Forge: git fetch origin and build fm/batch-n
    Crew->>Crew: Drop moved or conflicting members
    Crew-->>Firstmate: needs-decision batch-n-lease
    Firstmate->>CI: Check concurrent full-run cap
    Firstmate-->>Crew: Grant one push lease for exact head
    Crew->>Forge: git push origin fm/batch-n
    Forge->>CI: Run full CI for candidate
    CI-->>Firstmate: Candidate result
    Firstmate->>Merge: Guarded merge of batch PR or unchanged member heads
    Merge->>Forge: Land approved changes
Loading

Flow diagram for merge queue candidate construction

flowchart TD
    A[Freshly fetch origin default branch] --> B[Create fm/batch-n]
    B --> C[Merge named member heads in landing order]
    C --> D{Member head unchanged?}
    D -- No --> E[Drop member and report head moved]
    D -- Yes --> F{Merge conflicts?}
    F -- Yes --> G[git merge --abort and drop member]
    F -- No --> H[Keep member in candidate]
    E --> I[Request firstmate lease]
    G --> I
    H --> I
    I --> J{Lease granted under CI cap?}
    J -- No --> I
    J -- Yes --> K[Push candidate once]
    K --> L[Candidate CI run proves combination]
Loading

File-Level Changes

Change Details Files
Introduces a landing-crew brief type that delegates candidate construction and merge-queue safety to a scout-like worker contract.
  • Adds --landing-crew parsing, validation, default no-local-test scope, and generated instructions.
  • Requires fresh candidate bases, exact named member heads, conflict/head-movement drops, lease-gated single pushes, status reporting, and durable reports.
  • Adds landing-specific test-scope rendering and scaffold/refusal coverage.
bin/fm-brief.sh
bin/fm-dod-lib.sh
tests/fm-brief.test.sh
Defines the in-house merge queue’s operational policy, CI-cost rationale, admission model, proof requirements, and cleanup lifecycle.
  • Documents candidate creation from the fetched default branch and ordered member merges.
  • Documents concurrent full-run caps, lease grants, candidate CI proof, red-candidate bisection, and no-refresh behavior for non-conflicting branches.
  • Defines both batch-PR and member-by-member landing paths, including ledger/merge guards, rebinding after failed batch PRs, member closure, and candidate cleanup.
docs/merge-queue.md
Makes merge-queue landing the default policy for sufficiently large review-complete backlogs while preserving existing merge authority and member safeguards.
  • Adds the no-refresh-unless-conflicting rule and queue threshold to the landing policy.
  • Requires candidate proof to remain distinct from member checks, review ledgers, and merge authority.
  • Adds the batch-landing workflow for selection, leasing, merge-path routing, red-candidate handling, and teardown.
AGENTS.md
.agents/skills/ship-landing/SKILL.md
Aligns documentation indexes and configuration guidance with the new landing-crew brief and merge-queue workflow.
  • Includes landing-crew briefs in brief-include and shared-host safety documentation.
  • Lists the new brief mode and merge-queue mechanics in script and audience documentation.
docs/configuration.md
docs/scripts.md
docs/documentation-audiences.json

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T07:03:42.770974Z 6543414 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 65434142e7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .agents/skills/ship-landing/SKILL.md Outdated
Comment on lines +47 to +48
6. Close out: after a batch pull request squash-merges, close each member pull request with `Landed on main in batch PR #<n> (<sha>)`, because the forge still shows every member open; skip this when the project merges with merge commits, since the forge then marks the members merged.
Tear down each member's task once its pull request is merged or closed as landed, and never the crew on a batch pull request's merged notification, which is informational; only the crew's own `done:` line and report end it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Recheck member heads before closing their pull requests

If a contributor pushes to a member branch after the pre-merge check but before this close-out step, the batch contains only the previously named head, yet this procedure closes the updated pull request with a false “Landed” comment and tears down its task. Re-read each member's head after the batch merge and only close it when it still equals the head included in the batch; moved members must remain open and return to the queue.

AGENTS.md reference: AGENTS.md:L238-L239

Useful? React with 👍 / 👎.

Comment thread .agents/skills/ship-landing/SKILL.md Outdated
Comment on lines +41 to +42
Immediately before merging it, confirm for every member that its head still equals its named head, no captain hold is open on its task, its review-ledger generation passes with no unreleased hold, and its own required checks are green or a current explicit captain waiver names the check; drop a member that fails and have the crew rebuild without it.
Then merge the batch pull request once under the crew's task id with `bin/fm-pr-review.sh merge <crew-task> <batch-url>` when the reviewed-head handoff is required or the away-posture record exists, and otherwise `bin/fm-pr-merge.sh <crew-task> <batch-url>`; that records the batch pull request on the crew's task and arms its merge poll.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Revalidate the candidate base immediately before merging

When an unrelated change lands on the default branch after the candidate's green run, this checklist verifies member heads and ledgers but never verifies that the candidate's recorded base is still the current default head. Because the new preconditions explicitly allow projects without an up-to-date-branch requirement, the guarded merge can then land the candidate against a combination CI never tested; compare the current default SHA with the candidate base immediately before merging and rebuild on any mismatch.

AGENTS.md reference: AGENTS.md:L255-L256

Useful? React with 👍 / 👎.

Comment thread docs/merge-queue.md
Comment on lines +69 to +72
The crew pushes with a plain `git push origin fm/batch-<n>`.
Unless the project lands through member merges, Firstmate then opens the batch pull request from `fm/batch-<n>`, and the landing crew never opens, edits, or merges any pull request.
The batch pull request's `pull_request` CI run is the one the push lease admitted, so there is no separate unadmitted run and the lease covers the run that proves the batch.
Firstmate finds the candidate's run with `gh-axi run list --branch fm/batch-<n>` and accepts it as proof only when the run's head commit equals the leased head and every full-run job passed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Admit the action that actually starts candidate CI

For the documented batch-PR path, the full run starts only when Firstmate opens the pull request, but capacity is checked earlier when the crew requests permission to push. A default-branch run can occupy the last slot between those actions, and opening the PR then exceeds the configured cap; moreover, a push-triggered full workflow would create an additional unadmitted run. Recheck capacity immediately before the PR-opening action and require queue preconditions to exclude an independent full push workflow.

AGENTS.md reference: AGENTS.md:L255-L255

Useful? React with 👍 / 👎.

Comment thread docs/merge-queue.md Outdated
`bin/fm-pr-merge.sh` accepts the crew's next batch URL by itself only once the previous batch pull request's merge has been notified, so after a batch pull request that was refused or abandoned without merging, Firstmate first rebinds the crew with `bin/fm-pr-check.sh <crew-task> <next-batch-url>`, otherwise the merge refuses with `bound to <old>, not <new>`.
On 2026-10-20 bbchat's batch pull request https://github.com/twilwa/bbchat/pull/404 carried three members and merged green on its first run.
A squash merge leaves the member heads unreachable from the default branch, so the forge keeps every member pull request open.
After it, Firstmate closes each member with `gh-axi pr close <number> --comment "Landed on main in batch PR #<n> (<sha>)"` and tears down the member tasks.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Close each member by URL or explicit repository

When Firstmate runs this command from its own repository rather than the member project's clone, the bare pull-request number is resolved against the current repository, so the command can fail or close an unrelated pull request with the same number. The checked gh pr close --help confirms that -R/--repo selects another repository and that a full URL is accepted; use the already-recorded member URL or pass the owning repository explicitly.

Useful? React with 👍 / 👎.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 10 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path=".agents/skills/ship-landing/SKILL.md" line_range="41-42" />
<code_context>
+   Immediately before merging it, confirm for every member that its head still equals its named head, no captain hold is open on its task, its review-ledger generation passes with no unreleased hold, and its own required checks are green or a current explicit captain waiver names the check; drop a member that fails and have the crew rebuild without it.
</code_context>
<issue_to_address>
**Changed members still land**

When a member's head or guard state changes after the preflight but before the batch PR merges, the batch merge checks the crew and batch PR, not each member's current state, so it still lands a member that is now held or red. If the head moves, the batch can merge the older snapshot and close the newer member PR, leaving its current changes unlanded.

Make member-head and guard validation atomic with the batch merge, and refuse the merge so the candidate can be rebuilt whenever a member changes.

Also at `docs/merge-queue.md:86-88`.
</issue_to_address>

### Comment 2
<location path=".agents/skills/ship-landing/SKILL.md" line_range="46" />
<code_context>
+   If anything outside the batch lands on the default branch mid-batch, stop and put the unmerged members into a new candidate.
</code_context>
<issue_to_address>
**Stale-base proof can land**

When the default branch advances after candidate CI passes but before the batch PR merges, the batch PR need not be up to date, and the instruction to stop when an outside landing is noticed does not serialize that check with merging. The merge can therefore land a combination that the candidate run did not prove.

Prevent the merge when the default branch has advanced since the candidate was tested, and rebuild and rerun proof against the new base.

Also at `docs/merge-queue.md:33`, `docs/merge-queue.md:100`, `.agents/skills/ship-landing/SKILL.md:47`.
</issue_to_address>

### Comment 3
<location path=".agents/skills/ship-landing/SKILL.md" line_range="40-42" />
<code_context>
+   Primarily, initialize the batch pull request's review ledger under the landing crew's task id with `bin/fm-pr-review.sh init <crew-task> <batch-url>`.
</code_context>
<issue_to_address>
**Review gate blocks landing**

When the batch uses reviewed-head handoff or away posture and its new review generation has pending gates, `init` creates a generation without checkpoints or final disposition, while `fm-pr-review.sh merge` runs the readiness gate and refuses when required reviews, dispositions, or attestations are missing. The batch does not land.

Document and complete the required review checkpoints, dispositions, and attestations after initialization and before invoking the guarded merge.

Also at `docs/merge-queue.md:85-88`.
</issue_to_address>

### Comment 4
<location path=".agents/skills/ship-landing/SKILL.md" line_range="47" />
<code_context>
+6. Close out: after a batch pull request squash-merges, close each member pull request with `Landed on main in batch PR #<n> (<sha>)`, because the forge still shows every member open; skip this when the project merges with merge commits, since the forge then marks the members merged.
</code_context>
<issue_to_address>
**Rebase leaves member PRs open**

When a batch PR is merged with GitHub rebase-and-merge, rebase rewrites the commits, so the original member heads are not marked merged. The close-out instructions only close member PRs after squash merges, leaving them open and eligible for another batch.

Close each member PR as landed after a rebase merge as well as after a squash merge, then tear down its task.

Also at `docs/merge-queue.md:93-95`, `.agents/skills/ship-landing/SKILL.md:48`.
</issue_to_address>

### Comment 5
<location path=".agents/skills/ship-landing/SKILL.md" line_range="47-48" />
<code_context>
+6. Close out: after a batch pull request squash-merges, close each member pull request with `Landed on main in batch PR #<n> (<sha>)`, because the forge still shows every member open; skip this when the project merges with merge commits, since the forge then marks the members merged.
</code_context>
<issue_to_address>
**Interrupted closeout leaves work open**

When firstmate stops after the batch PR merges but before all member PRs are closed, the remaining member PRs stay open and their tasks are not torn down; an open PR can also be selected in a later batch and land the same changes again.

Make member closeout resumable and idempotent, recording and completing each PR's closure and task teardown.

Also at `docs/merge-queue.md:94`.
</issue_to_address>

### Comment 6
<location path=".agents/skills/ship-landing/SKILL.md" line_range="48" />
<code_context>
+   Tear down each member's task once its pull request is merged or closed as landed, and never the crew on a batch pull request's merged notification, which is informational; only the crew's own `done:` line and report end it.
</code_context>
<issue_to_address>
**Updated member work gets closed**

When a member PR receives a new commit after the pre-merge head check but before Firstmate closes it as landed, the batch contains the named head, not a later push. Firstmate closes the member PR after merging without rechecking its head, so a push between the pre-merge check and close leaves those newer commits unlanded on a closed PR.

Prevent member updates until batch closeout is complete, or leave/reopen any PR whose head changed and keep its task active for the unlanded work.

Also at `docs/merge-queue.md:94`.
</issue_to_address>

### Comment 7
<location path="docs/merge-queue.md" line_range="101" />
<code_context>
+  After the last member lands, `git diff --quiet origin/<default-branch> fm/batch-<n>` should report no tree difference after a fresh fetch, and a difference means something outside the batch landed and the proof no longer covers what follows.
+
+Every merge moves the default branch, so the next candidate is always built on the default branch as it stands after the latest merge, and a pushed candidate whose base is no longer that head, other than through its own members landing, is rebuilt before it can prove anything.
+The crew deletes the remote candidate with `git push origin --delete fm/batch-<n>` on Firstmate's steer and keeps its local branch.
+Cleanup of each member's task follows once its pull request is merged or closed as landed, and cleanup of the crew's copy follows its report.
+
</code_context>
<issue_to_address>
**Already-deleted branch blocks cleanup**

When the repository has automatic deletion of merged pull-request head branches enabled, gitHub deletes the merged batch head branch automatically, so the crew's later `git push origin --delete` fails because the remote ref is absent. The instructions provide no absent-branch success path, leaving cleanup liable to stop despite the branch already being deleted.

Check whether the remote candidate ref still exists and treat its absence as successful cleanup.

Also at `.agents/skills/ship-landing/SKILL.md:49`.
</issue_to_address>

### Comment 8
<location path="bin/fm-brief.sh" line_range="745" />
<code_context>
+# Landing crew: the merge-queue contract. docs/merge-queue.md owns the build,
+# lease, and cleanup mechanics; this text owns only what the crew may do.
+if [ "$KIND" = landing ]; then
+cat > "$BRIEF" <<EOF
+You are a crewmate: an autonomous worker agent managed by firstmate. Work on your own; do not wait for a human.
+
</code_context>
<issue_to_address>
**Interrupted scaffold blocks retry**

When the scaffold process is interrupted while writing the landing-crew brief, the landing brief is written directly to its final path. If the process stops during the heredoc, the partial file remains, and a retry refuses because the brief already exists, leaving the task with no usable scaffold until someone repairs or removes the file.

Write the complete brief to a temporary file in the task directory and atomically publish it only after generation succeeds.
</issue_to_address>

### Comment 9
<location path=".agents/skills/ship-landing/SKILL.md" line_range="48" />
<code_context>
+   Tear down each member's task once its pull request is merged or closed as landed, and never the crew on a batch pull request's merged notification, which is informational; only the crew's own `done:` line and report end it.
</code_context>
<issue_to_address>
**Landed members cannot be torn down**

When a batch PR squash-merges and its member PRs are closed as landed, `fm-teardown.sh` treats a closed-but-unmerged member PR as not merged, so the member task’s normal cleanup refuses even though the batch PR landed its changes. The member task remains active after the procedure says it can be torn down.

Teach teardown to accept an explicit, validated batch-landing record for a closed member PR, or keep member tasks until teardown can prove their work landed another way.

Also at `docs/merge-queue.md:94`.
</issue_to_address>

### Comment 10
<location path="AGENTS.md" line_range="254" />
<code_context>
+Never merge or rebase the default branch into a PR branch that does not conflict with it, because a refresh discards that head's green checks and review-ledger generation and costs a full CI run.
</code_context>
<issue_to_address>
**Some PRs cannot land**

When a project requires PR branches to be up to date before merging and the PR branch does not conflict with the default branch, the ordinary landing fallback cannot satisfy the forge's required up-to-date protection: the forge refuses to merge an unchanged PR branch until the default branch is merged or rebased into it, while `AGENTS.md` forbids that refresh when the branch does not conflict. The PR remains unlandable.

Allow the guarded refresh required by the forge in this case, or provide another explicit path for resolving the up-to-date requirement.

Also at `docs/merge-queue.md:33-36`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread .agents/skills/ship-landing/SKILL.md Outdated
Comment on lines +41 to +42
Immediately before merging it, confirm for every member that its head still equals its named head, no captain hold is open on its task, its review-ledger generation passes with no unreleased hold, and its own required checks are green or a current explicit captain waiver names the check; drop a member that fails and have the crew rebuild without it.
Then merge the batch pull request once under the crew's task id with `bin/fm-pr-review.sh merge <crew-task> <batch-url>` when the reviewed-head handoff is required or the away-posture record exists, and otherwise `bin/fm-pr-merge.sh <crew-task> <batch-url>`; that records the batch pull request on the crew's task and arms its merge poll.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Changed members still land

When a member's head or guard state changes after the preflight but before the batch PR merges, the batch merge checks the crew and batch PR, not each member's current state, so it still lands a member that is now held or red. If the head moves, the batch can merge the older snapshot and close the newer member PR, leaving its current changes unlanded.

Make member-head and guard validation atomic with the batch merge, and refuse the merge so the candidate can be rebuilt whenever a member changes.

Also at docs/merge-queue.md:86-88.

Prompt for AI agents
In `.agents/skills/ship-landing/SKILL.md` at lines 41-42:

**Changed members still land**

When a member's head or guard state changes after the preflight but before the batch PR merges, the batch merge checks the crew and batch PR, not each member's current state, so it still lands a member that is now held or red. If the head moves, the batch can merge the older snapshot and close the newer member PR, leaving its current changes unlanded.

Make member-head and guard validation atomic with the batch merge, and refuse the merge so the candidate can be rebuilt whenever a member changes.

Also at `docs/merge-queue.md:86-88`.

After a batch pull request that was refused or abandoned without merging, rebind the crew with `bin/fm-pr-check.sh <crew-task> <next-batch-url>` before merging the next one, or the merge refuses with `bound to <old>, not <new>`.
For a project that does not land through a batch pull request, merge the members in landing order instead, each on its own unchanged head.
In either shape, a member still red on its own head waits for a rerun of only its failed job or a current explicit captain waiver naming that check, and never lands red, whether inside a batch pull request or by its own merge.
If anything outside the batch lands on the default branch mid-batch, stop and put the unmerged members into a new candidate.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High · Stale-base proof can land

When the default branch advances after candidate CI passes but before the batch PR merges, the batch PR need not be up to date, and the instruction to stop when an outside landing is noticed does not serialize that check with merging. The merge can therefore land a combination that the candidate run did not prove.

Prevent the merge when the default branch has advanced since the candidate was tested, and rebuild and rerun proof against the new base.

Also at docs/merge-queue.md:33, docs/merge-queue.md:100, .agents/skills/ship-landing/SKILL.md:47.

Prompt for AI agents
In `.agents/skills/ship-landing/SKILL.md` at line 46:

**Stale-base proof can land**

When the default branch advances after candidate CI passes but before the batch PR merges, the batch PR need not be up to date, and the instruction to stop when an outside landing is noticed does not serialize that check with merging. The merge can therefore land a combination that the candidate run did not prove.

Prevent the merge when the default branch has advanced since the candidate was tested, and rebuild and rerun proof against the new base.

Also at `docs/merge-queue.md:33`, `docs/merge-queue.md:100`, `.agents/skills/ship-landing/SKILL.md:47`.

Comment thread .agents/skills/ship-landing/SKILL.md Resolved
Comment thread .agents/skills/ship-landing/SKILL.md Resolved
Comment thread .agents/skills/ship-landing/SKILL.md Resolved
Comment thread .agents/skills/ship-landing/SKILL.md Resolved
Comment thread docs/merge-queue.md Resolved
Comment thread bin/fm-brief.sh
# Landing crew: the merge-queue contract. docs/merge-queue.md owns the build,
# lease, and cleanup mechanics; this text owns only what the crew may do.
if [ "$KIND" = landing ]; then
cat > "$BRIEF" <<EOF

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Interrupted scaffold blocks retry

When the scaffold process is interrupted while writing the landing-crew brief, the landing brief is written directly to its final path. If the process stops during the heredoc, the partial file remains, and a retry refuses because the brief already exists, leaving the task with no usable scaffold until someone repairs or removes the file.

Write the complete brief to a temporary file in the task directory and atomically publish it only after generation succeeds.

Prompt for AI agents
In `bin/fm-brief.sh` at line 745:

**Interrupted scaffold blocks retry**

When the scaffold process is interrupted while writing the landing-crew brief, the landing brief is written directly to its final path. If the process stops during the heredoc, the partial file remains, and a retry refuses because the brief already exists, leaving the task with no usable scaffold until someone repairs or removes the file.

Write the complete brief to a temporary file in the task directory and atomically publish it only after generation succeeds.

In either shape, a member still red on its own head waits for a rerun of only its failed job or a current explicit captain waiver naming that check, and never lands red, whether inside a batch pull request or by its own merge.
If anything outside the batch lands on the default branch mid-batch, stop and put the unmerged members into a new candidate.
6. Close out: after a batch pull request squash-merges, close each member pull request with `Landed on main in batch PR #<n> (<sha>)`, because the forge still shows every member open; skip this when the project merges with merge commits, since the forge then marks the members merged.
Tear down each member's task once its pull request is merged or closed as landed, and never the crew on a batch pull request's merged notification, which is informational; only the crew's own `done:` line and report end it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Landed members cannot be torn down

When a batch PR squash-merges and its member PRs are closed as landed, fm-teardown.sh treats a closed-but-unmerged member PR as not merged, so the member task’s normal cleanup refuses even though the batch PR landed its changes. The member task remains active after the procedure says it can be torn down.

Teach teardown to accept an explicit, validated batch-landing record for a closed member PR, or keep member tasks until teardown can prove their work landed another way.

Also at docs/merge-queue.md:94.

Prompt for AI agents
In `.agents/skills/ship-landing/SKILL.md` at line 48:

**Landed members cannot be torn down**

When a batch PR squash-merges and its member PRs are closed as landed, `fm-teardown.sh` treats a closed-but-unmerged member PR as not merged, so the member task’s normal cleanup refuses even though the batch PR landed its changes. The member task remains active after the procedure says it can be torn down.

Teach teardown to accept an explicit, validated batch-landing record for a closed member PR, or keep member tasks until teardown can prove their work landed another way.

Also at `docs/merge-queue.md:94`.

Comment thread AGENTS.md Resolved
@twilwa

twilwa commented Oct 20, 2026

Copy link
Copy Markdown
Owner Author

Local full-suite evidence

The full local suite was run on this branch before the pipeline, and the complete record is in the operator's private evidence file data/fm-merge-queue-policy/test-evidence.md.

  • Full run of all 258 scripts (runner auto scheduler, four workers for proven-isolated scripts, unproven scripts serial, CPU-capped user scope): 37 failed, 36 gate-skipped.
  • Serial rerun of those 37: 5 passed, 32 still fail.
  • The four of the 32 that reference a changed file (fm-pr-merge, fm-test-run, fm-live-lab, fm-control-relaunch) fail identically on the base commit d447e08, so they are pre-existing.
  • The other 28 touch no changed file and fail for host-environment reasons on the runner machine: about 20 live Herdr tests cannot provision an isolated lab session, ruby is absent for the YAML contract tests, a node shim has no version, a pi API-key check, and watcher and second-mate timing checks.
  • The tests for the changed surface pass: tests/fm-brief.test.sh (including the two new landing-crew tests), tests/fm-brief-test-scope.test.sh, bin/fm-doc-audience-check.sh, and bin/fm-lint.sh.

Recheck a member's head before closing it as landed and close it in its
own repository, revalidate the candidate base and member guards as the last
step before the batch merge, complete the batch PR's review ledger, admit
the full run at the action that starts it, make close-out resumable, treat
an already-deleted candidate branch as cleaned up, and allow the refresh a
forge requires for an up-to-date branch.
@twilwa twilwa changed the title feat(bin): add in-house merge queue policy and landing-crew briefs feat(bin): add in-house merge queue with landing-crew briefs Oct 20, 2026
twilwa and others added 2 commits October 20, 2026 10:51
… flake in tests/fm-startup-network.test.sh. This PR didn't cause it: the PR changes only docs, bin/fm-brief.sh, a comment and the landing case in bin/fm-dod-lib.sh, and tests/fm-brief.test.sh, none of which this test exercises. The same assertion ("summary did not retain and report its capped deadline") also failed on main in run 38196263317 on 2026-10-12. Invariant: the test may assert on the persisted .home-summary-refresh.log only after the summary parent has had time to write it. `fm-startup-network.sh wait` returns as soon as the network result is published. The best-effort summary parent writes its "N-second deadline" line through a `--_log-failure` child, bounded at 2s, only after its own timeout fires. That timeout is capped to the same 5s stage budget, so on a loaded runner the test can grep the log before the line exists. Fix (test-only, tests/fm-startup-network.test.sh, test_summary_is_authorized_and_bounded): before the existing assert_grep, poll for the log line for up to 10s, using the same loop style the test already uses. I first tried waiting for the worker to exit and rejected it, because the worker can block up to 120s in await_delivery while the test shell's harvest claim is outstanding. No production code changed, and this is the only assertion on that log. Verification: I added a temporary 1s sleep to the log-failure path of bin/fm-home-summary-refresh.sh, which stays inside the 2s bound. With it, the old test failed with the exact CI message and the new test passed. I then reverted the sleep. The full tests/fm-startup-network.test.sh passes with "all assertions passed". The only shellcheck output is info-level SC1091/SC2153 notes on lines this fix didn't touch
tests/fm-supervision-host.test.sh alone ran 1296-1788 s in Behavior
portable serial 2 (and 1662 s on main) against the lane's 30-minute cap.
Move the shared fixture, stub engine, and helpers into
tests/supervision-host-helpers.sh, keep the run list through
test_report_without_acknowledgement_hands_the_wake_to_main in the original
script, and run the rest from tests/fm-supervision-host-late.test.sh.
Every case and function body is unchanged; the two run lists together are
the original one. bin/fm-test-run.sh names the new script in the afk
family and the supervision __script__ selection, and replaces the stale
789123 ms hint with 900000 ms placeholders for each half so the packer
puts them on different shards.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@twilwa

twilwa commented Oct 20, 2026

Copy link
Copy Markdown
Owner Author

Final review disposition at b794b2b

Every review item on this PR has a recorded disposition at head b794b2b140df6ea059701b93d96bf1e862ecfe51.

Addressed (12 inline threads):

  • Close-out re-reads each member and closes only one whose head still equals the head the batch carried, in its own repository via -R <owner>/<repo> (docs/merge-queue.md:100-101, ship-landing step 6). This covers the Critical finding and its Codex twin.
  • The member checks and the base-equals-default-head check run as the last step before the merge command. They are stated as non-atomic and are repeated after any delay (docs/merge-queue.md:90-93, ship-landing step 5).
  • Full runs are recounted immediately before the batch PR is opened, because opening it starts the admitted run (docs/merge-queue.md:75).
  • The batch PR's review ledger is completed before merging (docs/merge-queue.md:89).
  • Close-out also covers rebase merges and is resumable (docs/merge-queue.md:99-104).
  • A candidate branch that the forge has already deleted counts as deleted (docs/merge-queue.md:113).
  • The no-refresh rule exempts forges that require an up-to-date branch, and those projects stay outside the queue (AGENTS.md, docs/merge-queue.md:121).

Rejected (2 inline threads):

  • Interrupted scaffold write: every brief kind in bin/fm-brief.sh writes its brief with the same direct heredoc, so atomic writes belong in a separate fix across all kinds.
  • Closed members cannot be torn down: bin/fm-teardown.sh counts work reachable from any remote-tracking branch as landed, and closing a PR keeps its branch.

Summaries (2 review submissions and 3 top-level comments): none of these asks for a change beyond the inline threads above.

Validation: no-mistakes run 01M5C49NTYG8BH66TND8NV2K5D used model claude-opus-5-5, ran without a rebase, and reached checks passed on this head.

CI-step commits after review approval at c7f38502:

  • 4ceb5c65 is a test-only timing fix in tests/fm-startup-network.test.sh.
  • b794b2b1 splits tests/fm-supervision-host.test.sh into two portable-serial scripts. The two scripts run the same 73 cases, and no original line was lost. The 30-minute shard limit and the workflow are unchanged.
    • The original script alone took 1049-1788 s of shard 2's 30-minute limit, on main too.
    • Shard 2 now finishes in about 10 minutes and shard 3 in 21 minutes.

@twilwa
twilwa merged commit 79423d8 into main Oct 20, 2026
22 checks passed
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