Skip to content

feat(bin): defer spawns beyond a declared per-project capacity, opt-in - #5343

Merged
kunchenguid merged 20 commits into
kunchenguid:mainfrom
tiago-peixoto:fm/upstream-4237-project-capacity-admission
Oct 7, 2026
Merged

kunchenguid merged 20 commits into
kunchenguid:mainfrom
tiago-peixoto:fm/upstream-4237-project-capacity-admission

Conversation

@tiago-peixoto

@tiago-peixoto tiago-peixoto commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fixes #4237.
Keep #5343 (issue #4237) mergeable: it turned CONFLICTING against upstream main on 2026-09-24 after being green. Accepted behavior to preserve: project-capacity admission as accepted in the existing pull request and its maintainer triage (opt-in class).

The accepted admission stays opt-in. Without config/project-capacity, dispatch stays uncapped. With a declaration, a spawn beyond the declared number prints one deferred line, exits 75, creates nothing, and leaves the backlog item queued. Relaunches and secondmates are not counted. Holders are counted across the root home and local secondmate homes, including other clones of the same origin, until a ready pull request is recorded or the task is cleaned up. A malformed or unreadable declaration refuses the spawn. Matching is by clone directory name. A project name may begin with # when that # is written against the rest of the name. A line that is only #, or that begins with # followed by whitespace, stays a comment.

Maintainer triage treats the change as opt-in once the always-loaded backlog contract re-evaluates queued work after every teardown and heartbeat, and also after a recorded PR-ready handoff only when config/project-capacity caps that project. The conditional dispatch line in section 7 stays as it is.

Added 2026-10-04: "on opensource, some of my PRs need resync with main. make sure that is done, and CI is fully green for maintainer, on all of our work." "make sure the work is moving, nudging maintainer, making sure PRs are green and ready for maintainer"

What Changed

  • bin/fm-spawn.sh now reads an optional config/project-capacity from the root Firstmate home through the new bin/fm-project-capacity-lib.sh. With no declaration, dispatch stays uncapped. When every declared place for the project is held, a fresh ship or scout spawn prints one deferred: line and exits 75 before it creates a brief, endpoint, worktree, record, or backlog move. A malformed or unreadable declaration, or a task record that cannot be read while counting, refuses the spawn with exit 1. A batch reports such a pair as batch: DEFERRED. Relaunches and --secondmate spawns are not counted.
  • Holders are counted under the shared project lock, which the spawn now also takes on the Orca backend whenever the declaration caps any project. The count covers the root home and every local secondmate home, including other clones of the same origin, until a ready PR is recorded or the task is cleaned up. The walk over local homes moved from bin/fm-teardown.sh into fm_local_firstmate_state_dirs in bin/fm-wake-lib.sh, so teardown and capacity admission share it.
  • AGENTS.md, docs/configuration.md ("Project capacity"), and the operational-home-layout skill document the file format, the # comment rules, and matching by clone directory name. The backlog contract now also re-evaluates queued work after a recorded PR-ready handoff when config/project-capacity caps that project. The branch adds tests/fm-project-capacity.test.sh, registers it in bin/fm-test-run.sh, and freezes the clock in one tests/fm-contributions.test.sh case so its one-second budget cannot expire before the first forge call.

Risk Assessment

✅ Low: The admission is opt-in, runs before any brief, worktree, record or backlog change, releases its lock through the existing exit trap and publication release, and matches every stated intent criterion; the traces I ran (declaration parsing, own-record skip, symlinked-home dedupe, batch exit codes, Orca lock path, teardown refactor) found no wrong result.

Testing

No baseline command ran before this step. I ran the targeted behavior test tests/fm-project-capacity.test.sh (16 cases, all passed, real fm-spawn with fake tmux and treehouse). I then built a disposable lab home with bin/fm-lab-home.sh, a throwaway project with a local bare origin, a second clone named '#repo', a registered local secondmate home, and a markdown backlog, and drove ten script-level scenarios through a real tmux pane on the private fm-lab socket. Worker launches used the documented raw launch command 'sleep 3600', so no paid worker agent ran; tmux windows, treehouse worktrees, task records and backlog moves were all real. Finally I started a real Claude primary (normal login) in the lab and drove three turns covering deferral, re-dispatch after teardown, and re-dispatch after a recorded PR-ready handoff. Two scenarios were not driven live and are reported as untested: a secondmate-kind record not holding a place, and two concurrent spawns racing for the last place. The automated behavior test covers both (cases only this project's ship and scout records hold places and concurrent spawns can never both take the last place in capacity-behavior-test.log), but that is not a live result. This is a CLI change with no rendered UI, so the evidence is CLI transcripts and a pane capture rather than screenshots. One fixture problem (the bare origin's default branch) was mine and fixed before the recorded run. Overall result: all thirteen live-driven scenarios passed, and two scenarios are untested live.

  • Live validation: ✅ go - 13 of 15 scenarios driven live against the product
Scenario Result Live Evidence
With no config/project-capacity, the captain spawns two workers on one project and both launch ✅ pass live live-lab-transcript.txt section S1: cap-a and cap-b both print spawned ... with exit 0; two task records, two tmux windows, two treehouse worktrees, both items under In flight
With heavy 2 declared and two holders, a third spawn prints one deferred line, exits 75, creates nothing, and its backlog item stays queued ✅ pass live live-lab-transcript.txt section S2: exit 75, exactly one line starting deferred: naming holders cap-a, cap-b; data/cap-c holds only brief.md; records, windows and worktrees unchanged; cap-c still un…
Adversarial: a malformed or unreadable declaration refuses the spawn instead of guessing a limit ✅ pass live live-lab-transcript.txt section S3: non-integer capacity, zero, duplicate project, nameless line, mode 000 file and a directory each give `error: spawn refused: the project capacity declaration is unr…
A line that is only #, or # followed by whitespace, stays a comment and does not change the cap ✅ pass live live-lab-transcript.txt section S4: with #, # heavy 9, an indented # ... line, #note-with-no-number and a blank line above heavy 2, the spawn is deferred at 2, not 9, and not refused
A project whose clone directory is named #repo is capped by the line #repo 2, matched by clone directory name ✅ pass live live-lab-transcript.txt section S5: spawn from <lab>/projects/#repo prints deferred: project #repo admits 2 worker(s) with exit 75; after changing the line to #repo 3 the same spawn is admitted
Holders in another clone of the same origin count against the cap ✅ pass live live-lab-transcript.txt sections S5 and S6: the '#repo' spawn is deferred by holders cap-a and cap-b running in the 'heavy' clone; with heavy 3, cap-c is deferred with holders cap-a, cap-b, cap-d…
A relaunch of a worker that already holds a place is not counted while the project is full ✅ pass live live-lab-transcript.txt section S7: with 3 of 3 places held, bin/fm-spawn.sh cap-a --relaunch exits 0 and the cap-a pane runs the agent command again
Cleaning up a task frees exactly one place ✅ pass live live-lab-transcript.txt section S8: after bin/fm-teardown.sh cap-d, cap-c is admitted and the next spawn cap-e is deferred with holders cap-a, cap-b, cap-c
Recording a ready pull request frees that worker's place ✅ pass live live-lab-transcript.txt section S9: the real bin/fm-pr-check.sh cap-b &lt;url&gt; writes pr= to cap-b's record, and the next spawn cap-e is admitted although cap-b's record and window still exist
The cap is shared between the root home and a local secondmate home, in both directions ✅ pass live live-lab-transcript.txt section S10: a spawn from the secondmate home, whose own config/ is empty, is deferred on the root's declaration with holders `cap-a in <root>, cap-c in <root>, cap-e in <root>…
A secondmate-kind record does not hold a place ⏸️ untested no The prior payload did not establish a live result for this scenario. It was not driven against the running product: the run did not provision and launch a real persistent secondmate in the lab home, w…
Two concurrent spawns cannot both take the last place ⏸️ untested no The prior payload did not establish a live result for this scenario. It was not driven against the running product: the race needs one spawn held inside the admission lock at a precise point, and real…
A real primary that gets a deferral leaves the item queued, not blocked, and says it will retry when a place frees ✅ pass live live-primary-transcript.txt first turn: the Claude primary runs bin/fm-spawn.sh, sees exit 75, reports the item still under Queued, not blocked, and names cleanup or a ready PR as the retry trigger
A real primary re-evaluates queued work after a teardown and dispatches the deferred item ✅ pass live live-primary-transcript.txt second turn: asked only to clean up cap-c and carry on, the primary runs teardown, cites its standing instruction to re-evaluate queued work after every cleanup, and spawns…
A real primary re-evaluates queued work after a recorded PR-ready handoff on a capped project ✅ pass live live-primary-transcript.txt third turn: after bin/fm-pr-check.sh cap-a the primary states Heavy has a declared capacity, so my standing instructions call for re-evaluating the queue now and spawns c…
Evidence: Live lab transcript: real fm-spawn, fm-teardown and fm-pr-check in a disposable lab home (scenarios S1-S10)

Source: Live lab transcript: real fm-spawn, fm-teardown and fm-pr-check in a disposable lab home (scenarios S1-S10)

## Lab: FM_HOME=/tmp/fm-lab.1AKLOV, real bin/fm-spawn.sh typed into a real tmux pane on the private fm-lab socket, real treehouse pool, real tasks-axi backlog.
## Worker launch command is the documented raw-launch escape hatch ('sleep 3600') so no paid agent runs.

\### S1 - no config/project-capacity: dispatch is uncapped
(config/ listed above; no project-capacity file)
(cap-a was already spawned the same way; its output is in live-s1a below)
fm-gate-refuse: gate agent lifecycle permitted only against lab home /tmp/fm-lab.1AKLOV
warning: /tmp/fm-lab.1AKLOV/data/cap-a/launch-brief.md records no ship branch; defaulting to legacy branch fm/cap-a
notice: cap-a ships mode=local-only while the standing posture for heavy is no-mistakes - less rigor than the captain's standing posture; proceed only on a current explicit captain instruction or an intake judgment you can state
spawned cap-a harness=sleep kind=ship mode=local-only yolo=off window=primary:fm-cap-a worktree=/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/1/heavy
[exit 0]
$ bin/fm-spawn.sh cap-b /tmp/fm-lab.1AKLOV/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
fm-gate-refuse: gate agent lifecycle permitted only against lab home /tmp/fm-lab.1AKLOV
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
●  This is a supervision warning only; the guarded operation WILL still run.
●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
warning: /tmp/fm-lab.1AKLOV/data/cap-b/launch-brief.md records no ship branch; defaulting to legacy branch fm/cap-b
notice: cap-b ships mode=local-only while the standing posture for heavy is no-mistakes - less rigor than the captain's standing posture; proceed only on a current explicit captain instruction or an intake judgment you can state
spawned cap-b harness=sleep kind=ship mode=local-only yolo=off window=primary:fm-cap-b worktree=/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/2/heavy
[exit 0]
--- state records:
cap-a.meta
cap-b.meta
--- tmux windows:
primary:bash bash ~/.no-mistakes/worktrees/5284051b2355/01M468TAJ5H4QA2XF5A86T06ZW
primary:fm-cap-a sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/1/heavy
primary:fm-cap-b sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/2/heavy
--- git worktrees:
/tmp/fm-lab.1AKLOV/projects/heavy                            47eeee2 [main]
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/1/heavy 47eeee2 (detached HEAD)
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/2/heavy 47eeee2 (detached HEAD)
--- backlog:
# Backlog

## In flight
- [ ] cap-b - item for cap-b (kind: ship) (since 2026-10-05)
- [ ] cap-a - item for cap-a (kind: ship) (since 2026-10-05)

## Queued
- [ ] cap-c - item for cap-c (kind: ship) (since 2026-10-05)
## Done

\### S2 - declare 'heavy 2' with both places held: spawn cap-c is deferred
config/project-capacity:
# heavy suite serves two workers
#
heavy 2
$ bin/fm-spawn.sh cap-c /tmp/fm-lab.1AKLOV/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
fm-gate-refuse: gate agent lifecycle permitted only against lab home /tmp/fm-lab.1AKLOV
WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
deferred: project heavy admits 2 worker(s) at once on this machine (/tmp/fm-lab.1AKLOV/config/project-capacity) and 2 already hold a place (cap-a, cap-b); task cap-c was not launched and its backlog item stays queued - dispatch it again once one of them records its ready PR or is cleaned up
[exit 75]
stderr line count: 3 ; lines starting 'deferred:': 1
brief.md
--- state records:
cap-a.meta
cap-b.meta
--- tmux windows:
primary:bash bash ~/.no-mistakes/worktrees/5284051b2355/01M468TAJ5H4QA2XF5A86T06ZW
primary:fm-cap-a sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/1/heavy
primary:fm-cap-b sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/2/heavy
--- git worktrees:
/tmp/fm-lab.1AKLOV/projects/heavy                            47eeee2 [main]
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/1/heavy 47eeee2 (detached HEAD)
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/2/heavy 47eeee2 (detached HEAD)
--- backlog:
# Backlog

## In flight
- [ ] cap-b - item for cap-b (kind: ship) (since 2026-10-05)
- [ ] cap-a - item for cap-a (kind: ship) (since 2026-10-05)

## Queued
- [ ] cap-c - item for cap-c (kind: ship) (since 2026-10-05)
## Done

\### S3 - a malformed or unreadable declaration refuses the spawn (both places still held by cap-a, cap-b)

#### capacity is not an integer
config/project-capacity:
  | heavy two
$ bin/fm-spawn.sh cap-c /tmp/fm-lab.1AKLOV/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
error: spawn refused: the project capacity declaration is unreadable (/tmp/fm-lab.1AKLOV/config/project-capacity line 1 gives heavy a capacity that is not a positive integer); fix it so the captain's worker limits are known (docs/configuration.md "Project capacity")
[exit 1]
after: cap-c record: 0, cap-c windows: 0, backlog row: - [ ] cap-c - item for cap-c (kind: ship) (since 2026-10-05) [section: ## Queued]

#### capacity of zero
config/project-capacity:
  | heavy 0
$ bin/fm-spawn.sh cap-c /tmp/fm-lab.1AKLOV/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
error: spawn refused: the project capacity declaration is unreadable (/tmp/fm-lab.1AKLOV/config/project-capacity line 1 gives heavy a capacity that is not a positive integer); fix it so the captain's worker limits are known (docs/configuration.md "Project capacity")
[exit 1]
after: cap-c record: 0, cap-c windows: 0, backlog row: - [ ] cap-c - item for cap-c (kind: ship) (since 2026-10-05) [section: ## Queued]

#### project named twice
config/project-capacity:
  | heavy 2
  | heavy 3
$ bin/fm-spawn.sh cap-c /tmp/fm-lab.1AKLOV/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
error: spawn refused: the project capacity declaration is unreadable (/tmp/fm-lab.1AKLOV/config/project-capacity line 2 names heavy a second time); fix it so the captain's worker limits are known (docs/configuration.md "Project capacity")
[exit 1]
after: cap-c record: 0, cap-c windows: 0, backlog row: - [ ] cap-c - item for cap-c (kind: ship) (since 2026-10-05) [section: ## Queued]

#### another project's line is malformed (line with no name)
config/project-capacity:
  | other 2
  | 7
$ bin/fm-spawn.sh cap-c /tmp/fm-lab.1AKLOV/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
error: spawn refused: the project capacity declaration is unreadable (/tmp/fm-lab.1AKLOV/config/project-capacity line 2 is not '<project-name> <capacity>'); fix it so the captain's worker limits are known (docs/configuration.md "Project capacity")
[exit 1]
after: cap-c record: 0, cap-c windows: 0, backlog row: - [ ] cap-c - item for cap-c (kind: ship) (since 2026-10-05) [section: ## Queued]

#### file is unreadable (mode 000)
config/project-capacity:
---------- 1 firstmate firstmate 8 Oct  5 16:57 /tmp/fm-lab.1AKLOV/config/project-capacity
$ bin/fm-spawn.sh cap-c /tmp/fm-lab.1AKLOV/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
error: spawn refused: the project capacity declaration is unreadable (/tmp/fm-lab.1AKLOV/config/project-capacity is not a readable regular file); fix it so the captain's worker limits are known (docs/configuration.md "Project capacity")
[exit 1]
after: cap-c record: 0, cap-c windows: 0, backlog row: - [ ] cap-c - item for cap-c (kind: ship) (sin

... [3878 bytes truncated] ...

] cap-d - item for cap-d (kind: ship) (since 2026-10-05)
- [ ] cap-b - item for cap-b (kind: ship) (since 2026-10-05)
- [ ] cap-a - item for cap-a (kind: ship) (since 2026-10-05)

## Queued
- [ ] cap-c - item for cap-c (kind: ship) (since 2026-10-05)
- [ ] cap-e - item for cap-e (kind: ship) (since 2026-10-05)
## Done

\### S6 - 'heavy 3' with three holders (cap-a, cap-b in 'heavy'; cap-d in the '#repo' clone of the same origin)
config/project-capacity:
  | heavy 3
$ bin/fm-spawn.sh cap-c /tmp/fm-lab.1AKLOV/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
deferred: project heavy admits 3 worker(s) at once on this machine (/tmp/fm-lab.1AKLOV/config/project-capacity) and 3 already hold a place (cap-a, cap-b, cap-d); task cap-c was not launched and its backlog item stays queued - dispatch it again once one of them records its ready PR or is cleaned up
[exit 75]

\### S7 - a relaunch of a worker that already holds a place is not counted (project still full)
cap-a pane after stopping its agent: fm-cap-a bash
$ bin/fm-spawn.sh cap-a --relaunch --harness 'sleep 3600'
warning: /tmp/fm-lab.1AKLOV/data/cap-a/launch-brief.md records no ship branch; defaulting to legacy branch fm/cap-a
notice: cap-a ships mode=local-only while the standing posture for heavy is no-mistakes - less rigor than the captain's standing posture; proceed only on a current explicit captain instruction or an intake judgment you can state
spawned cap-a harness=sleep kind=ship mode=local-only yolo=off window=primary:fm-cap-a worktree=/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/1/heavy
[exit 0]
cap-a pane after relaunch: fm-cap-a sleep

\### S8 - cleanup frees exactly one place
$ bin/fm-teardown.sh cap-d
teardown: reaping leaked worktree process(es) for cap-d: 493073 499040
teardown: force-killing leaked worktree process(es) for cap-d: 493073
A new version of treehouse is available: v2.3.0 → v3.1.2
Run "treehouse update" to update

🌳 Worktree returned to pool.
teardown cap-d complete (window primary:fm-cap-d, worktree /tmp/fm-lab.1AKLOV/treehouse/.treehouse/#repo-1ac586/1/#repo)
Backlog: cap-d is closed in /tmp/fm-lab.1AKLOV/data/backlog.md. Run bin/fm-tasks-axi.sh ready for dependency-cleared candidates, check date gates, and dispatch only work whose blockers are gone and date is due.
[exit 0]
records now: cap-a.meta cap-b.meta 
$ bin/fm-spawn.sh cap-c /tmp/fm-lab.1AKLOV/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
warning: /tmp/fm-lab.1AKLOV/data/cap-c/launch-brief.md records no ship branch; defaulting to legacy branch fm/cap-c
notice: cap-c ships mode=local-only while the standing posture for heavy is no-mistakes - less rigor than the captain's standing posture; proceed only on a current explicit captain instruction or an intake judgment you can state
spawned cap-c harness=sleep kind=ship mode=local-only yolo=off window=primary:fm-cap-c worktree=/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/3/heavy
[exit 0]
$ bin/fm-spawn.sh cap-e /tmp/fm-lab.1AKLOV/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
deferred: project heavy admits 3 worker(s) at once on this machine (/tmp/fm-lab.1AKLOV/config/project-capacity) and 3 already hold a place (cap-a, cap-b, cap-c); task cap-e was not launched and its backlog item stays queued - dispatch it again once one of them records its ready PR or is cleaned up
[exit 75]

\### S9 - a recorded ready PR frees exactly one place
$ bin/fm-pr-check.sh cap-b https://github.com/o/r/pull/7
armed: state/cap-b.check.sh
[exit 0]
cap-b record pr line: pr=https://github.com/o/r/pull/7
$ bin/fm-spawn.sh cap-e /tmp/fm-lab.1AKLOV/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
warning: /tmp/fm-lab.1AKLOV/data/cap-e/launch-brief.md records no ship branch; defaulting to legacy branch fm/cap-e
notice: cap-e ships mode=local-only while the standing posture for heavy is no-mistakes - less rigor than the captain's standing posture; proceed only on a current explicit captain instruction or an intake judgment you can state
spawned cap-e harness=sleep kind=ship mode=local-only yolo=off window=primary:fm-cap-e worktree=/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/4/heavy
[exit 0]

\### S10 - capacity is shared with a local secondmate home (/tmp/fm-lab.1AKLOV/mate, registered in the root's data/secondmates.md; its own config/ has no declaration)
mate config dir: (empty)
$ env FM_HOME=/tmp/fm-lab.1AKLOV/mate bin/fm-spawn.sh mate-1 /tmp/fm-lab.1AKLOV/mate/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
deferred: project heavy admits 3 worker(s) at once on this machine (/tmp/fm-lab.1AKLOV/config/project-capacity) and 3 already hold a place (cap-a in /tmp/fm-lab.1AKLOV, cap-c in /tmp/fm-lab.1AKLOV, cap-e in /tmp/fm-lab.1AKLOV); task mate-1 was not launched and its backlog item stays queued - dispatch it again once one of them records its ready PR or is cleaned up
[exit 75]
mate records: 0; mate backlog section of mate-1: ## Queued
$ bin/fm-teardown.sh cap-e
teardown: reaping leaked worktree process(es) for cap-e: 586093 595840
teardown: force-killing leaked worktree process(es) for cap-e: 586093

🌳 Worktree returned to pool.
teardown cap-e complete (window primary:fm-cap-e, worktree /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/4/heavy)
Backlog: cap-e is closed in /tmp/fm-lab.1AKLOV/data/backlog.md. Run bin/fm-tasks-axi.sh ready for dependency-cleared candidates, check date gates, and dispatch only work whose blockers are gone and date is due.
[exit 0]
$ env FM_HOME=/tmp/fm-lab.1AKLOV/mate bin/fm-spawn.sh mate-1 /tmp/fm-lab.1AKLOV/mate/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
warning: /tmp/fm-lab.1AKLOV/mate/data/mate-1/launch-brief.md records no ship branch; defaulting to legacy branch fm/mate-1
notice: mate-1 ships mode=local-only while the standing posture for heavy is no-mistakes - less rigor than the captain's standing posture; proceed only on a current explicit captain instruction or an intake judgment you can state
spawned mate-1 harness=sleep kind=ship mode=local-only yolo=off window=primary:fm-mate-1 worktree=/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/4/heavy
[exit 0]
(cap-e was closed by its teardown; a new queued item cap-f is dispatched from the root home)
$ bin/fm-spawn.sh cap-f /tmp/fm-lab.1AKLOV/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
deferred: project heavy admits 3 worker(s) at once on this machine (/tmp/fm-lab.1AKLOV/config/project-capacity) and 3 already hold a place (cap-a, cap-c, mate-1 in /tmp/fm-lab.1AKLOV/mate); task cap-f was not launched and its backlog item stays queued - dispatch it again once one of them records its ready PR or is cleaned up
[exit 75]

\### Final lab state
--- state records:
cap-a.meta
cap-b.meta
cap-c.meta
--- tmux windows:
primary:bash bash ~/.no-mistakes/worktrees/5284051b2355/01M468TAJ5H4QA2XF5A86T06ZW
primary:fm-cap-a sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/1/heavy
primary:fm-cap-b sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/2/heavy
primary:fm-cap-c sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/3/heavy
primary:fm-mate-1 sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/4/heavy
--- git worktrees:
/tmp/fm-lab.1AKLOV/projects/heavy                            47eeee2 [main]
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/1/heavy 47eeee2 (detached HEAD)
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/2/heavy 47eeee2 (detached HEAD)
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/3/heavy 47eeee2 (detached HEAD)
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/4/heavy 47eeee2 (detached HEAD)
--- backlog:
# Backlog

## In flight
- [ ] cap-c - item for cap-c (kind: ship) (since 2026-10-05)
- [ ] cap-b - item for cap-b (kind: ship) (since 2026-10-05)
- [ ] cap-a - item for cap-a (kind: ship) (since 2026-10-05)

## Queued
- [ ] cap-f - item for cap-f (kind: ship) (since 2026-10-05)
## Done
- [x] cap-e - item for cap-e (kind: ship) (done 2026-10-05)
  local main
- [x] cap-d - item for cap-d (kind: ship) (done 2026-10-05)
  local main
--- mate records:
mate-1.meta
Evidence: Real Claude primary in the lab: pane capture of three turns plus lab state

Source: Real Claude primary in the lab: pane capture of three turns plus lab state

## Real Claude primary (claude CLI, normal login) in the lab home on the private fm-lab tmux socket, session 'captain'. Pane capture:
 ▐▛███▛█   Claude Code v2.1.289
▝▜██████▀  Opus 5.5 · Claude Max
 ▝▝   ▝▝   ~/.no-mistakes/worktrees/5284051b2355/01M468TAJ5H4QA2XF5A86T06ZW
❯ Captain here. This is a disposable lab home (FM_HOME=/tmp/fm-lab.1AKLOV). Lab rule for this whole session: every worker launch uses --harness 'sleep 3600' with --mode local-only
  --yolo off, briefs are already written and must not be edited, and skip watcher repair. Item cap-f is queued in the backlog for project /tmp/fm-lab.1AKLOV/projects/heavy.
  Dispatch it now with bin/fm-spawn.sh, then tell me in three lines what happened, what state the backlog item is in, and when you will try it again.
● Bash(export FM_HOME=/tmp/fm-lab.1AKLOV; ls -la $FM_HOME $FM_HOME/data $FM_HOME/config $FM_HOME/state 2>&1 | head -60; cat $FM_HOME/data/backlog.md 2>&1 | head -40; c…)
  ⎿  /tmp/fm-lab.1AKLOV:
     total 12
     drwx------   11 firstmate firstmate    280 Oct  5 16:58 .
     … +126 lines (ctrl+o to expand)
  ⎿  Allowed by auto mode classifier
● Bash(export FM_HOME=/tmp/fm-lab.1AKLOV; bin/fm-spawn.sh cap-f /tmp/fm-lab.1AKLOV/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'; echo "EXIT=$?";…)
  ⎿  fm-gate-refuse: gate agent lifecycle permitted only against lab home /tmp/fm-lab.1AKLOV
     WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
     deferred: project heavy admits 3 worker(s) at once on this machine (/tmp/fm-lab.1AKLOV/config/project-capacity) and 3 already hold a place (cap-a, cap-c, mate-1 in /tmp/f
     … +17 lines (ctrl+o to expand)
  ⎿  Allowed by auto mode classifier
● Captain, the worker for cap-f did not start: project heavy allows 3 workers at once on this machine, and 3 already hold a place (cap-a, cap-c, and the second mate's worker
  mate-1), so bin/fm-spawn.sh deferred it with exit code 75.
  The cap-f backlog item is unchanged and still under Queued, not blocked - I read data/backlog.md after the run, and no cap-f worker record was created.
  I will dispatch cap-f again as soon as one of those three reports a ready branch or is cleaned up, and I re-check at every cleanup and fleet review; monitoring is down in this
  lab and I left it unrepaired per your rule, so that re-check happens on my next turn rather than by automatic notification.
✻ Cogitated for 17s · done 5:00 PM
❯ cap-c is finished and nothing in it needs keeping. Clean up cap-c with bin/fm-teardown.sh, then carry on as your standing instructions say.
● Skill(ship-landing)
  ⎿  Successfully loaded skill
● Bash(export FM_HOME=/tmp/fm-lab.1AKLOV; bin/fm-teardown.sh --help 2>&1 | head -40; echo ---; cat $FM_HOME/state/cap-c.meta)
  ⎿  fm-gate-refuse: gate agent lifecycle permitted only against lab home /tmp/fm-lab.1AKLOV
     error: teardown refused: task record is not a regular file at /tmp/fm-lab.1AKLOV/state/--help.meta
     ---
     … +13 lines (ctrl+o to expand)
  ⎿  Allowed by auto mode classifier
● Bash(export FM_HOME=/tmp/fm-lab.1AKLOV; bin/fm-teardown.sh cap-c; echo "EXIT=$?"; echo ---; cat $FM_HOME/data/backlog.md; ls $FM_HOME/state | grep cap-c)
  ⎿  fm-gate-refuse: gate agent lifecycle permitted only against lab home /tmp/fm-lab.1AKLOV
     WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
     teardown: reaping leaked worktree process(es) for cap-c: 549336 556179
     … +25 lines (ctrl+o to expand)
  ⎿  Allowed by auto mode classifier
● Standing instructions: re-evaluate queued work after every teardown. A place on heavy is now free, so cap-f goes again.
● Bash(export FM_HOME=/tmp/fm-lab.1AKLOV; bin/fm-spawn.sh cap-f /tmp/fm-lab.1AKLOV/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'; echo "EXIT=$?";…)
  ⎿  fm-gate-refuse: gate agent lifecycle permitted only against lab home /tmp/fm-lab.1AKLOV
     WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
     warning: /tmp/fm-lab.1AKLOV/data/cap-f/launch-brief.md records no ship branch; defaulting to legacy branch fm/cap-f
     … +34 lines (ctrl+o to expand)
  ⎿  Allowed by auto mode classifier
● Bash(export FM_HOME=/tmp/fm-lab.1AKLOV; bin/fm-tasks-axi.sh --help 2>&1 | head -30)
  ⎿  fm-tasks-axi.sh - run tasks-axi against THIS home's backlog from any working directory.
     Usage: fm-tasks-axi.sh [<tasks-axi command> [args...]]
     … +27 lines (ctrl+o to expand)
  ⎿  Allowed by auto mode classifier
● Bash(export FM_HOME=/tmp/fm-lab.1AKLOV; bin/fm-tasks-axi.sh update --help 2>&1 | head -25; bin/fm-tasks-axi.sh show cap-f 2>&1 | head -20)
  ⎿  usage: tasks-axi update <id> [flags]
     aliases: edit
     flags:
     … +25 lines (ctrl+o to expand)
  ⎿  Allowed by auto mode classifier
● Bash(export FM_HOME=/tmp/fm-lab.1AKLOV; bin/fm-tasks-axi.sh update cap-f --body "Delivery: local-only, yolo off. Deviation from the standing no-mistakes posture for…)
  ⎿  ok: updated cap-f (body)
     task:
       id: cap-f
     … +23 lines (ctrl+o to expand)
  ⎿  Allowed by auto mode classifier
● Captain, cap-c is cleaned up and the cap-f worker is now running on project heavy.
  - cap-c cleanup: bin/fm-teardown.sh cap-c exited 0 without any force flag, so its own landed-work check passed. It stopped two leftover processes, returned the isolated copy to
    the pool, and moved cap-c to Done in the backlog.
  - cap-f dispatch: my standing instructions say to re-evaluate queued work after every cleanup, and cap-c's place on heavy was now free. bin/fm-spawn.sh exited 0 this time and
    moved cap-f from Queued to In flight. The Queued section is now empty.
  - Delivery note: the launch warned that local-only is less rigor than heavy's standing no-mistakes setting. I proceeded on your lab rule and recorded that reason on the cap-f
    backlog item.
  - Branch warning: the launch also warned that cap-f's instructions name no branch, so it defaulted to fm/cap-f. I left the instructions unedited per your rule.
  Heavy is at its limit of 3 again, and nothing else is queued. Monitoring is still down and unrepaired per your lab rule, so I will not get automatic notifications from cap-a,
  cap-b or cap-f.
✻ Churned for 45s · done 5:01 PM
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯ Show me the current backlog and fleet state
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  ⏵⏵ auto mode on (shift+tab to cycle) · ← for agents

## Lab state after the primary's second turn
--- state records:
cap-a.meta
cap-b.meta
cap-f.meta
--- tmux windows:
captain:claude claude ~/.no-mistakes/worktrees/5284051b2355/01M468TAJ5H4QA2XF5A86T06ZW
captain:fm-cap-f sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/3/heavy
primary:bash bash ~/.no-mistakes/worktrees/5284051b2355/01M468TAJ5H4QA2XF5A86T06ZW
primary:fm-cap-a sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/1/heavy
primary:fm-cap-b sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/2/heavy
primary:fm-mate-1 sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/4/heavy
--- git worktrees:
/tmp/fm-lab.1AKLOV/projects/heavy                            47eeee2 [main]
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/1/heavy 47eeee2 (detached HEAD)
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/2/heavy 47eeee2 (detached HEAD)
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/3/heavy 47eeee2 (detached HEAD)
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/4/heavy 47eeee2 (detached HEAD)
--- backlog:
# Backlog

## In flight
- [ ] cap-f - item for cap-f (kind: ship) (since 2026-10-05)
  Delivery: local-only, yolo off. Deviation from the standing no-mistakes posture for heavy: explicit lab-session instruction that every worker launch uses local-only with yolo off.
- [ ] cap-b - item for cap-b (kind: ship) (since 2026-10-05)
- [ ] cap-a - item for cap-a (kind: ship) (since 2026-10-05)

## Queued
## Done
- [x] cap-c - item for cap-c (kind: ship) (done 2026-10-05)
  local main
- [x] cap-e - item for cap-e (kind: ship) (done 2026-10-05)
  local main
- [x] cap-d - item for cap-d (kind: ship) (done 2026-10-05)
  local main

## Third turn: a recorded PR-ready handoff on a capped project. Pane capture:
❯ Two things. I queued a new item cap-g for project heavy (brief already written). And worker cap-a just reported its pull request is ready: https://github.com/o/r/pull/9 - record
  that handoff with bin/fm-pr-check.sh cap-a and that URL (skip any forge verification, this is a lab). Then carry on as your standing instructions say.
● Bash(export FM_HOME=/tmp/fm-lab.1AKLOV; sed -n 1,60p bin/fm-pr-check.sh; echo ---; cat $FM_HOME/data/backlog.md; cat $FM_HOME/state/cap-a.meta; ls $FM_HOME/data/cap-…)
  ⎿  #!/usr/bin/env bash
     # Record a PR-ready task: store one validated canonical pr=<url> and the forge's
     # exact pr_head=<sha> when available, then atomically arm a static merge poll.
     … +89 lines (ctrl+o to expand)
  ⎿  Allowed by auto mode classifier
● Bash(export FM_HOME=/tmp/fm-lab.1AKLOV; bin/fm-pr-check.sh cap-a https://github.com/o/r/pull/9; echo "EXIT=$?"; cat $FM_HOME/state/cap-a.meta | grep -E '^pr')
  ⎿  WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
     armed: state/cap-a.check.sh
     EXIT=0
     … +2 lines (ctrl+o to expand)
  ⎿  Allowed by auto mode classifier
● The handoff is recorded. Heavy has a declared capacity, so my standing instructions call for re-evaluating the queue now: cap-a's recorded PR frees its place, and cap-g is the
  queued candidate.
● Bash(export FM_HOME=/tmp/fm-lab.1AKLOV; bin/fm-spawn.sh cap-g /tmp/fm-lab.1AKLOV/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'; rc=$?; echo "EXI…)
  ⎿  fm-gate-refuse: gate agent lifecycle permitted only against lab home /tmp/fm-lab.1AKLOV
     WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
     warning: /tmp/fm-lab.1AKLOV/data/cap-g/launch-brief.md records no ship branch; defaulting to legacy branch fm/cap-g
     … +26 lines (ctrl+o to expand)
  ⎿  Allowed by auto mode classifier
● Captain, cap-a's ready PR is recorded and the cap-g worker is now running on project heavy.
  - cap-a handoff: bin/fm-pr-check.sh cap-a exited 0 and stored https://github.com/o/r/pull/9 on cap-a's record, with merge monitoring registered for it. cap-a stays In flight in
    the backlog until that PR merges, and merging it needs your word.
  - cap-g dispatch: heavy has a declared limit of 3 workers, so my standing instructions call for re-evaluating the queue after a recorded ready PR. That record freed cap-a's
    place, bin/fm-spawn.sh exited 0, and cap-g moved from Queued to In flight. The Queued section is empty.
  - Same two warnings as cap-f: local-only is less rigor than heavy's standing no-mistakes setting, which I proceeded on under your lab rule and recorded on the cap-g item. The
    instructions name no branch, so it defaulted to fm/cap-g, and I left them unedited.
  Heavy is at its limit again. Monitoring is still down and unrepaired per your lab rule, so a merge of PR 9 will not notify me automatically.
✻ Worked for 24s · done 5:02 PM
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯ I queued cap-h for heavy, dispatch it now
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  ⏵⏵ auto mode on (shift+tab to cycle) · ← for agents

## Lab state after the third turn
--- state records:
cap-a.meta
cap-b.meta
cap-f.meta
cap-g.meta
--- tmux windows:
captain:claude claude ~/.no-mistakes/worktrees/5284051b2355/01M468TAJ5H4QA2XF5A86T06ZW
captain:fm-cap-f sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/3/heavy
captain:fm-cap-g sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/5/heavy
primary:bash bash ~/.no-mistakes/worktrees/5284051b2355/01M468TAJ5H4QA2XF5A86T06ZW
primary:fm-cap-a sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/1/heavy
primary:fm-cap-b sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/2/heavy
primary:fm-mate-1 sleep /tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/4/heavy
--- git worktrees:
/tmp/fm-lab.1AKLOV/projects/heavy                            47eeee2 [main]
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/1/heavy 47eeee2 (detached HEAD)
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/2/heavy 47eeee2 (detached HEAD)
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/3/heavy 47eeee2 (detached HEAD)
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/4/heavy 47eeee2 (detached HEAD)
/tmp/fm-lab.1AKLOV/treehouse/.treehouse/heavy-1ac586/5/heavy 47eeee2 (detached HEAD)
--- backlog:
# Backlog

## In flight
- [ ] cap-g - item for cap-g (kind: ship) (since 2026-10-05)
  Delivery: local-only, yolo off. Deviation from the standing no-mistakes posture for heavy: explicit lab-session instruction that every worker launch uses local-only with yolo off.
- [ ] cap-f - item for cap-f (kind: ship) (since 2026-10-05)
  Delivery: local-only, yolo off. Deviation from the standing no-mistakes posture for heavy: explicit lab-session instruction that every worker launch uses local-only with yolo off.
- [ ] cap-b - item for cap-b (kind: ship) (since 2026-10-05)
- [ ] cap-a - item for cap-a (kind: ship) (since 2026-10-05)

## Queued
## Done
- [x] cap-c - item for cap-c (kind: ship) (done 2026-10-05)
  local main
- [x] cap-e - item for cap-e (kind: ship) (done 2026-10-05)
  local main
- [x] cap-d - item for cap-d (kind: ship) (done 2026-10-05)
  local main
cap-a pr line: pr=https://github.com/o/r/pull/9
Evidence: Deferred spawn at capacity (live)
$ bin/fm-spawn.sh cap-c <lab>/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
deferred: project heavy admits 2 worker(s) at once on this machine (<lab>/config/project-capacity) and 2 already hold a place (cap-a, cap-b); task cap-c was not launched and its backlog item stays queued - dispatch it again once one of them records its ready PR or is cleaned up
[exit 75]
state records: cap-a.meta cap-b.meta | data/cap-c: brief.md only | backlog: cap-c under ## Queued
Evidence: Malformed declaration refuses (live)
config/project-capacity: heavy two
$ bin/fm-spawn.sh cap-c <lab>/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
error: spawn refused: the project capacity declaration is unreadable (<lab>/config/project-capacity line 1 gives heavy a capacity that is not a positive integer); fix it so the captain's worker limits are known (docs/configuration.md "Project capacity")
[exit 1]
Evidence: Shared cap across the root home and a local secondmate home (live)
$ env FM_HOME=<lab>/mate bin/fm-spawn.sh mate-1 <lab>/mate/projects/heavy --mode local-only --yolo off --harness 'sleep 3600'
deferred: project heavy admits 3 worker(s) at once on this machine (<lab>/config/project-capacity) and 3 already hold a place (cap-a in <lab>, cap-c in <lab>, cap-e in <lab>); task mate-1 was not launched and its backlog item stays queued - ...
[exit 75]

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ bin/fm-spawn.sh:3046 - Every fresh ship or scout spawn now resolves the root Firstmate home through fm_project_capacity_config_dir before it knows whether a declaration exists. On non-Orca backends this adds no new failure, because fm_treehouse_project_lock_path already resolved the same root at line 3059. On Orca it is new: an Orca spawn from a secondmate home whose parent binding is malformed or unreachable now exits 1 with "could not resolve the root Firstmate home that declares project capacity", even when no config/project-capacity exists anywhere. This is fail-closed and matches the intent that an unreadable declaration refuses the spawn, since the spawn cannot tell whether the root declares a cap. No change is needed; the note records the one path where a home without a declaration behaves differently from before.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 13 of 15 scenarios driven live against the product
Scenario Result Live Evidence
With no config/project-capacity, the captain spawns two workers on one project and both launch ✅ pass live live-lab-transcript.txt section S1: cap-a and cap-b both print spawned ... with exit 0; two task records, two tmux windows, two treehouse worktrees, both items under In flight
With heavy 2 declared and two holders, a third spawn prints one deferred line, exits 75, creates nothing, and its backlog item stays queued ✅ pass live live-lab-transcript.txt section S2: exit 75, exactly one line starting deferred: naming holders cap-a, cap-b; data/cap-c holds only brief.md; records, windows and worktrees unchanged; cap-c still un…
Adversarial: a malformed or unreadable declaration refuses the spawn instead of guessing a limit ✅ pass live live-lab-transcript.txt section S3: non-integer capacity, zero, duplicate project, nameless line, mode 000 file and a directory each give `error: spawn refused: the project capacity declaration is unr…
A line that is only #, or # followed by whitespace, stays a comment and does not change the cap ✅ pass live live-lab-transcript.txt section S4: with #, # heavy 9, an indented # ... line, #note-with-no-number and a blank line above heavy 2, the spawn is deferred at 2, not 9, and not refused
A project whose clone directory is named #repo is capped by the line #repo 2, matched by clone directory name ✅ pass live live-lab-transcript.txt section S5: spawn from <lab>/projects/#repo prints deferred: project #repo admits 2 worker(s) with exit 75; after changing the line to #repo 3 the same spawn is admitted
Holders in another clone of the same origin count against the cap ✅ pass live live-lab-transcript.txt sections S5 and S6: the '#repo' spawn is deferred by holders cap-a and cap-b running in the 'heavy' clone; with heavy 3, cap-c is deferred with holders cap-a, cap-b, cap-d…
A relaunch of a worker that already holds a place is not counted while the project is full ✅ pass live live-lab-transcript.txt section S7: with 3 of 3 places held, bin/fm-spawn.sh cap-a --relaunch exits 0 and the cap-a pane runs the agent command again
Cleaning up a task frees exactly one place ✅ pass live live-lab-transcript.txt section S8: after bin/fm-teardown.sh cap-d, cap-c is admitted and the next spawn cap-e is deferred with holders cap-a, cap-b, cap-c
Recording a ready pull request frees that worker's place ✅ pass live live-lab-transcript.txt section S9: the real bin/fm-pr-check.sh cap-b &lt;url&gt; writes pr= to cap-b's record, and the next spawn cap-e is admitted although cap-b's record and window still exist
The cap is shared between the root home and a local secondmate home, in both directions ✅ pass live live-lab-transcript.txt section S10: a spawn from the secondmate home, whose own config/ is empty, is deferred on the root's declaration with holders `cap-a in <root>, cap-c in <root>, cap-e in <root>…
A secondmate-kind record does not hold a place ⏸️ untested no The prior payload did not establish a live result for this scenario. It was not driven against the running product: the run did not provision and launch a real persistent secondmate in the lab home, w…
Two concurrent spawns cannot both take the last place ⏸️ untested no The prior payload did not establish a live result for this scenario. It was not driven against the running product: the race needs one spawn held inside the admission lock at a precise point, and real…
A real primary that gets a deferral leaves the item queued, not blocked, and says it will retry when a place frees ✅ pass live live-primary-transcript.txt first turn: the Claude primary runs bin/fm-spawn.sh, sees exit 75, reports the item still under Queued, not blocked, and names cleanup or a ready PR as the retry trigger
A real primary re-evaluates queued work after a teardown and dispatches the deferred item ✅ pass live live-primary-transcript.txt second turn: asked only to clean up cap-c and carry on, the primary runs teardown, cites its standing instruction to re-evaluate queued work after every cleanup, and spawns…
A real primary re-evaluates queued work after a recorded PR-ready handoff on a capped project ✅ pass live live-primary-transcript.txt third turn: after bin/fm-pr-check.sh cap-a the primary states Heavy has a declared capacity, so my standing instructions call for re-evaluating the queue now and spawns c…
  • bash tests/fm-project-capacity.test.sh - 16 behavior cases passed, exit 0
  • bin/fm-lab-home.sh create $LAB plus a private tmux server tmux -L fm-lab with FM_HOME=$LAB; all commands below were typed into that pane with send-keys
  • bin/fm-spawn.sh cap-a|cap-b &lt;lab&gt;/projects/heavy --mode local-only --yolo off --harness &#39;sleep 3600&#39; with no config/project-capacity - both launched, exit 0
  • bin/fm-spawn.sh cap-c ... with heavy 2 declared and two holders - one deferred: line, exit 75, no record, no window, no worktree, no launch brief, item still under Queued
  • bin/fm-spawn.sh cap-c ... against six bad declarations (heavy two, heavy 0, a project named twice, a line with no name, mode 000 file, a directory) - each refused with exit 1 and created nothing
  • bin/fm-spawn.sh cap-c ... with #, # heavy 9, #note-with-no-number, an indented # ... line and a blank line before heavy 2 - still deferred at 2
  • bin/fm-spawn.sh cap-d &#39;&lt;lab&gt;/projects/#repo&#39; ... with #repo 2 - deferred, naming holders cap-a and cap-b from the other clone; with #repo 3 - admitted
  • bin/fm-spawn.sh cap-c ... with heavy 3 - deferred, counting cap-d from the '#repo' clone as the third holder
  • bin/fm-spawn.sh cap-a --relaunch --harness &#39;sleep 3600&#39; while the project was full - relaunched, exit 0
  • bin/fm-teardown.sh cap-d then bin/fm-spawn.sh cap-c ... (admitted) then bin/fm-spawn.sh cap-e ... (deferred)
  • bin/fm-pr-check.sh cap-b https://github.com/o/r/pull/7 (recorded pr=) then bin/fm-spawn.sh cap-e ... (admitted)
  • env FM_HOME=&lt;lab&gt;/mate bin/fm-spawn.sh mate-1 &lt;lab&gt;/mate/projects/heavy ... from a registered local secondmate home - deferred on the root home's declaration and holders; admitted after bin/fm-teardown.sh cap-e; then root bin/fm-spawn.sh cap-f ... deferred naming mate-1 in &lt;lab&gt;/mate
  • Real claude primary in the lab (tmux session captain): asked to dispatch cap-f at full capacity, then to clean up cap-c, then to record cap-a's ready PR with cap-g queued
  • Teardown: tmux -L fm-lab kill-server, removed the lab directory, confirmed git status --short is empty
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Teardown's walk over the root home and its registered local secondmate homes
moves into bin/fm-wake-lib.sh as fm_local_firstmate_state_dirs, next to
fm_firstmate_root_home, so a second consumer can count task records across
this machine's homes without a copy. Teardown keeps its exact refusal wording
through a thin wrapper.
A project whose machine-local resource only serves a few workers at once had
no way to tell Firstmate so: every queued item was launched, and the surplus
workers spent full-context turns retrying the resource.

config/project-capacity in the root home now declares how many workers each
named project admits at once on this machine. bin/fm-spawn.sh counts the ship
and scout records on the same project origin across the root and its local
secondmate homes, skipping ones whose ready PR is recorded, while holding the
shared project lock through publication. A spawn with every place held exits 75
before any brief render, endpoint, worktree, record, or backlog move, so the
item stays queued; batches report it as deferred. Undeclared projects keep
today's uncapped dispatch, and an unreadable declaration refuses rather than
guessing the limit.

Refs kunchenguid#4237
Keep project-capacity admission beside main's worker-account pin so the existing pull request can merge.
@tiago-peixoto

Copy link
Copy Markdown
Contributor Author

Friendly nudge: head 9a63c565 is mergeable against current main and all CI checks pass. Happy to adjust anything if needed.

@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Adds machine-local worker spawn admission control by project capacity.

The PR appears safe to merge; no new actionable issue or outstanding previous finding remains.

Reviews (12) · Last reviewed commit: "docs: scope PR-ready re-evaluation to a ..."

Comment thread bin/fm-project-capacity-lib.sh Resolved
Comment thread bin/fm-project-capacity-lib.sh Resolved
Comment thread bin/fm-spawn.sh Resolved
Comment thread tests/fm-project-capacity.test.sh Resolved
…tests/fm-project-capacity.test.sh pass, and shellcheck at warning level is clean on the changed files. Each new test failed against the old code and passes now. - **ci-1 (spaced names):** a declaration line must give a name its capacity whenever the name is a valid clone directory name. `fm_project_capacity_lookup` now trims each line, skips blank lines and lines whose first non-blank character is `#`, and takes the last field as the capacity. Everything before that field is the name, so it may contain spaces. The old error cases still refuse: a single field is rejected, and trailing text leaves a last field that is not an integer. The library header and docs/configuration.md now say a name starting with `#` cannot be declared. New test `test_spaced_project_name_is_declared` declares `my heavy project 1` next to an indented comment line and gets a deferral. - **ci-2 (unreadable records):** the holder count must never silently leave out a holder. `fm_project_capacity_occupants` now refuses when a local home's state directory exists but cannot be read or listed, or when a `.meta` file cannot be read. The error names the path, and `fm-spawn.sh` shows it in its existing refusal message. New test `test_unreadable_holders_refuse_admission` covers an unreadable record in the root home and an unreadable state directory in a registered local secondmate home, then checks that the spawn is admitted once both are readable. The test is skipped when run as root. - **ci-3 (Orca lock):** any spawn that can become a holder for a capped project must take that project's lock. The lookup now also reports whether the declaration caps any project at all, and an Orca spawn takes the per-origin lock whenever it does. This covers every capped same-origin clone. It also covers some cases where no same-origin clone is capped, because a spawn cannot find clones under other directory names without searching for them. With no declaration file, Orca still skips the lock. The comments in the library and in the `fm-spawn.sh` header are updated. The Orca test now clones the origin as `project-2`, which has no declaration, and checks that its Orca spawn refuses while the lock is held and publishes no record. - **ci-4 (worktrees):** `assert_nothing_created` now also compares the project's `git worktree list` from before and after a deferred spawn. Both tests that call it take that snapshot first. Files changed: bin/fm-project-capacity-lib.sh, bin/fm-spawn.sh, docs/configuration.md, tests/fm-project-capacity.test.sh
A clone directory whose name begins with # was skipped as a comment, so that project stayed uncapped. A line is a declaration when the # is written against the rest of the name and the line ends with a capacity; a # followed by whitespace stays a comment.
…k past its memory cap. ShellCheck ran out of memory analyzing bin/fm-teardown.sh in CI (reason=memory, rc=251, peak about 8.39 GB). On current main the same file passes at about 7.29 GB. **Cause:** the new `fm_local_firstmate_state_dirs` function in bin/fm-wake-lib.sh had a conditional `. fm-secondmate-registry-lib.sh` with a `# shellcheck source=` directive inside the function. ShellCheck followed that source again, inside a function scope, wherever fm-wake-lib.sh is sourced, and bin/fm-teardown.sh is the heaviest root that sources it. Measured locally with `shellcheck --norc --external-sources bin/fm-teardown.sh`: - current main (fd325b1): 7.29 GB - main merged with this PR: 7.86 GB - the same merge without the in-function source: 7.27 GB **Rule this restores:** this change must not make any lint root heavier than it is on main. That function holds the only new nested source in the change. **Fix:** I removed the in-function source, which no caller needs. Both callers already load the registry library at top level before calling the function: - bin/fm-teardown.sh sources it directly. - bin/fm-spawn.sh, the only user of bin/fm-project-capacity-lib.sh, gets it through bin/fm-ff-lib.sh. I also documented the requirement in the function's comment and in the "Requires" note in bin/fm-project-capacity-lib.sh. No behaviour changes. **Verification:** - ShellCheck on head: bin/fm-teardown.sh peaks at 7.12 GB and bin/fm-spawn.sh at 6.68 GB, both with rc=0. bin/fm-wake-lib.sh and bin/fm-project-capacity-lib.sh lint clean. - tests/fm-project-capacity.test.sh, tests/fm-teardown.test.sh (102 ok) and tests/fm-teardown-endpoint-safety.test.sh all pass. Files changed: bin/fm-wake-lib.sh, bin/fm-project-capacity-lib.sh