Skip to content

fix(bin): keep the supervision host's successor watcher alive after the Stop hook's group is torn down - #6787

Merged
kunchenguid merged 4 commits into
kunchenguid:mainfrom
menidi:fm/fm-watch-resurface-loop
Oct 8, 2026
Merged

kunchenguid merged 4 commits into
kunchenguid:mainfrom
menidi:fm/fm-watch-resurface-loop

Conversation

@menidi

@menidi menidi commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Have a worker investigate and fix it in the firstmate repo, as a public contribution: fork the repo to the captain's account and open a PR upstream, which the upstream maintainers merge.

"It" is this loop, as reported: about every 30 seconds the primary Claude firstmate session gets an empty check: rearm-resurface wake with nothing behind it (six between 18:21 and 18:26 on 2026-10-07, on a home with the supervision host on and two live workers). From the watcher logs: a few seconds after each firstmate turn ends, the handling-successor watcher that should keep running receives TERM (cycle exit reason=signal-exit, exit 143, about 17s after it started), the Stop hook's attached arm then ends with attached-cycle-ended, and the next started watcher finds the downtime marker and immediately announces check: rearm-resurface, which wakes the session again. No work is lost; real wakes still arrive. Recent upstream change #6762 (let TERM stop a watcher blocked in a pane capture on bash 3.2) is a suspect, not a confirmed cause. Upstream has related open reports, including #6320 (no-op wake turns spend tokens), #4446 (watcher recovery loop on Pi and Codex primaries) and #2251.

What Changed

  • bin/fm-supervision-host.sh: when the host leaves a successor watcher running for main (a main-only pass-through, or a close that turns main-only at its turn), start_arm now launches it in its own process group (set -m), with stdin from /dev/null. This matches start_handling_successor in fm-claude-stop-autoarm.sh. Before this, Claude's teardown of the hook's process group after the exit-2 rewake TERMed the successor. The watcher then recorded downtime, and the next park announced an empty check: rearm-resurface, which woke main again about every 30 seconds.
  • tests/fm-supervision-host.test.sh: the hook-session fixture can now run the Stop hook in its own process group and record its pgid. Two new tests TERM that group, one after a pass-through close and one after an at-turn main-only hand-back, and check that the successor watcher is still alive.
  • docs/supervision-host.md: says that the successor left for main runs in its own process group, so the harness tearing down the hook's group doesn't stop it.

🤖 Generated with Claude Code

Risk Assessment

⚠️ Medium: The change is small and follows the hook's existing own-group pattern, but a sibling path (attended-during-turn, lines 1124/1141) still leaves a successor in the hook's group, and the root-cause mechanism is asserted rather than reproduced against a live Claude session.

Testing

I ran the two new regression tests and four neighbouring host+hook tests on their own. All pass on the fix, and both new tests fail on the base host script. I then drove a real Claude 2.1.292 primary with the supervision host in a disposable lab home. On the fix, a main-only pass-through left its successor in its own process group. That successor outlived the Stop hook, main drained and acked the wake, and the next park took it over with no check: rearm-resurface. On base, the successor shared the hook's group as diagnosed, but Claude never terminated that group in two runs, so the reported loop could not be reproduced live. A ~5s rearm-resurface loop seen early was a lab artifact: the lab main had been told to run no tools, so it never acked the wake. The loop stopped once main drained and acked. This change has no UI, so there are no screenshots; the evidence is CLI logs, process-group samples and pane captures.

  • Live validation: ✅ go - 3 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Main-only pass-through on a live Claude primary: the successor watcher runs in its own process group and outlives the Stop hook ✅ pass live lab-fixed-supervision-host.log, lab-fixed-watch-cycle-exits.log, lab-run-summary.md: successor arm 19176 in pgid 19176 while the hook's group was 98048; hook group gone at t+45s with the successor sti…
After main handles the pass-through wake, the next park takes the successor over quietly: no empty check: rearm-resurface wake ✅ pass live lab-fixed-supervision-host.log 1791392881..1791392889: take-over arm=19176, ledger reason=taken-over, a fresh watcher, no rearm-resurface, marker acked:handling
Regression: the hook's process group is terminated after the rewake, and the successor left for main (both pass-through and at-turn) survives it ⏸️ untested no The prior payload did not establish a live result. This was checked only with the repo's fixture harness: test_pass_through_successor_survives_the_hook_process_group_teardown and test_successor_left_a…
Reproduce the reported loop live on base code (Claude TERMs the successor in the hook's group, then the next cycle announces rearm-resurface) ⏸️ untested no I drove two base-code main-only pass-throughs on a real Claude 2.1.292 lab primary, with main turns of ~9s and ~14s. Claude did not terminate the hook's process group in either run (the successors sta…
Handled engine path unchanged: the host still retires its own-group successor itself when it hands a handled outcome to main ✅ pass live lab-all-watch-cycle-exits.log: successor arm 65027 ran in pgid 65027 (start_successor with ARM_OWN_GROUP=1) and was ended by the host (reason=arm-interrupted) on the engine-handled to-main at 17913924…
Close that turns main-only during the engine turn (handle_wake returns 2, detach_successor): the successor left for main is in its own group ⏸️ untested no The prior payload did not establish a live result. Driving this live needs the offer to flip to main-only exactly between the first offer and the turn-boundary offer inside one engine turn, and that r…
Evidence: Live lab run summary (fixed vs base, process groups, timeline)

Source: Live lab run summary (fixed vs base, process groups, timeline)

# Live lab: Claude 2.1.292 primary + supervision host (disposable fm-lab home)

Setup: `bin/fm-lab-home.sh create`, `config/supervision-host`, one fake task `demo` (meta + status, a `sleep` window `fm-demo` on the lab tmux socket), real `claude` started on `tmux -L fm-lab` from the run worktree with `FM_HOME=<lab>`.
Lab workarounds: a temporary gitignored `.fm-secondmate-home` in the worktree (linked worktrees fail the primary-scope check), and `state/.lock` written with the lab Claude pid (session start stands down inside a gate worktree). Both were removed at teardown.

## Fixed code (HEAD 96c0c99)
- 1791392881 `pass-through attended main-only signal: demo.status`. The successor arm 19176 ran in **pgid 19176**, and the hook's group was 98048.
- The hook group 98048 was gone by t+45s, while the successor arm/watcher 19176/19212 were still alive.
- Main drained and acked. 1791392889: the next park's `take-over arm=19176` produced `taken-over`, then a fresh watcher 22288. No `check: rearm-resurface` followed. The marker reads `acked:handling:*`.
- See lab-fixed-supervision-host.log, lab-fixed-watch-cycle-exits.log, and lab-fixed-primary-pane.txt.

## Lab artifact (not the reported bug)
While the lab main had been told to run no tools, it never ran `bin/fm-wake-drain.sh` or the ack. Each take-over restored `announced:downtime`, so a `check: rearm-resurface` came every ~5s. This is the durable re-handling the rewake text describes.
It stopped as soon as main drained and acked (lab-all-supervision-host.log, 1791392544..1791392723).

## Base code (ac0811c host script, swapped in by atomic rename)
- 1791393041 and 1791393269: main-only pass-throughs. Each successor (arm 45622, arm 76811) stayed in the **hook's pgid 47715**.
- In both runs (main turns of ~9s and ~14s), Claude did not tear down the hook's group. The next park took the successor over normally, and no rearm-resurface followed.
- So the root-cause trigger (Claude TERMing the hook's process group after the exit-2 rewake) did not reproduce on this Claude build in the lab. The red/green fixture test models it.
Evidence: Fixed code: supervision host log from the live lab

Source: Fixed code: supervision host log from the live lab

1791392442	start	gen=host-59772-1791392442	primary=claude
1791392489	handled	turn=host-59772-1791392442.1	posture=attended	rc=0	reports=1	error=0 cost=0.023215 conversation_cost=0.023215 input=8 cache_read=50016 cache_write=2209 output=436 turns=4	signal: /var/folders/m3/81qcpm653_19d59xvhm52h2m0000gn/T//fm-lab.SLyVh4/state/demo.status
1791392489	to-main	branch-outcome: the supervision session handled this wake and recorded captain outcomes for you (store rows 1); run bin/fm-wake-drain.sh, act on its BRANCH OUTCOMES section, and acknowledge them as it prints
1791392492	start	gen=host-71182-1791392492	primary=claude
1791392493	pass-through	attended	main-only	check: rearm-resurface
1791392496	start	gen=host-74481-1791392496	primary=claude
1791392496	take-over	arm=72886
1791392529	pass-through	attended	main-only	signal: /var/folders/m3/81qcpm653_19d59xvhm52h2m0000gn/T//fm-lab.SLyVh4/state/demo.status
1791392532	start	gen=host-83452-1791392532	primary=claude
1791392532	take-over	arm=81688
1791392534	pass-through	attended	main-only	check: rearm-resurface
1791392537	start	gen=host-88029-1791392537	primary=claude
1791392539	pass-through	attended	main-only	check: rearm-resurface
1791392542	start	gen=host-90611-1791392542	primary=claude
1791392542	take-over	arm=89145
1791392544	pass-through	attended	main-only	check: rearm-resurface
1791392547	start	gen=host-93155-1791392547	primary=claude
1791392547	take-over	arm=91909
1791392549	pass-through	attended	main-only	check: rearm-resurface
1791392552	start	gen=host-96087-1791392552	primary=claude
1791392552	take-over	arm=94396
1791392554	pass-through	attended	main-only	check: rearm-resurface
1791392557	start	gen=host-99608-1791392557	primary=claude
1791392557	take-over	arm=98327
1791392559	pass-through	attended	main-only	check: rearm-resurface
1791392562	start	gen=host-2807-1791392562	primary=claude
1791392562	take-over	arm=1417
1791392564	pass-through	attended	main-only	check: rearm-resurface
1791392567	start	gen=host-5517-1791392567	primary=claude
1791392567	take-over	arm=4204
1791392569	pass-through	attended	main-only	check: rearm-resurface
1791392572	start	gen=host-8207-1791392572	primary=claude
1791392572	take-over	arm=6796
1791392574	pass-through	attended	main-only	check: rearm-resurface
1791392577	start	gen=host-10728-1791392577	primary=claude
1791392577	take-over	arm=9491
1791392579	pass-through	attended	main-only	check: rearm-resurface
1791392583	start	gen=host-13255-1791392582	primary=claude
1791392583	take-over	arm=12032
1791392585	pass-through	attended	main-only	check: rearm-resurface
1791392587	start	gen=host-15644-1791392587	primary=claude
1791392587	take-over	arm=14471
1791392589	pass-through	attended	main-only	check: rearm-resurface
1791392592	start	gen=host-18581-1791392592	primary=claude
1791392592	take-over	arm=16966
1791392594	pass-through	attended	main-only	check: rearm-resurface
1791392597	start	gen=host-22044-1791392597	primary=claude
1791392597	take-over	arm=20077
1791392599	pass-through	attended	main-only	check: rearm-resurface
1791392602	start	gen=host-25482-1791392602	primary=claude
1791392602	take-over	arm=23766
1791392605	pass-through	attended	main-only	check: rearm-resurface
1791392608	start	gen=host-27936-1791392608	primary=claude
1791392608	take-over	arm=26716
1791392610	pass-through	attended	main-only	check: rearm-resurface
1791392613	start	gen=host-30395-1791392613	primary=claude
1791392613	take-over	arm=29181
1791392615	pass-through	attended	main-only	check: rearm-resurface
1791392618	start	gen=host-33597-1791392618	primary=claude
1791392618	take-over	arm=31835
1791392620	pass-through	attended	main-only	check: rearm-resurface
1791392623	start	gen=host-38060-1791392622	primary=claude
1791392623	take-over	arm=34985
1791392625	pass-through	attended	main-only	check: rearm-resurface
1791392628	start	gen=host-42180-1791392628	primary=claude
1791392628	take-over	arm=40095
1791392630	pass-through	attended	main-only	check: rearm-resurface
1791392633	start	gen=host-45155-1791392633	primary=claude
1791392633	take-over	arm=43709
1791392635	pass-through	attended	main-only	check: rearm-resurface
1791392638	start	gen=host-47590-1791392637	primary=claude
1791392638	take-over	arm=46394
1791392640	pass-through	attended	main-only	check: rearm-resurface
1791392643	start	gen=host-50328-1791392642	primary=claude
1791392643	take-over	arm=49112
1791392645	pass-through	attended	main-only	check: rearm-resurface
1791392648	start	gen=host-52922-1791392648	primary=claude
1791392648	take-over	arm=51712
1791392650	pass-through	attended	main-only	check: rearm-resurface
1791392653	start	gen=host-55491-1791392653	primary=claude
1791392653	take-over	arm=54160
1791392655	pass-through	attended	main-only	check: rearm-resurface
1791392658	start	gen=host-59053-1791392658	primary=claude
1791392658	take-over	arm=57357
1791392660	pass-through	attended	main-only	check: rearm-resurface
1791392663	start	gen=host-61919-1791392663	primary=claude
1791392663	take-over	arm=60397
1791392665	pass-through	attended	main-only	check: rearm-resurface
1791392668	start	gen=host-64386-1791392668	primary=claude
1791392668	take-over	arm=63175
1791392670	pass-through	attended	main-only	check: rearm-resurface
1791392673	start	gen=host-70350-1791392673	primary=claude
1791392673	take-over	arm=66713
1791392675	pass-through	attended	main-only	check: rearm-resurface
1791392679	start	gen=host-73856-1791392678	primary=claude
1791392679	take-over	arm=71708
1791392681	pass-through	attended	main-only	check: rearm-resurface
1791392684	start	gen=host-76901-1791392684	primary=claude
1791392684	take-over	arm=75411
1791392686	pass-through	attended	main-only	check: rearm-resurface
1791392688	start	gen=host-79696-1791392688	primary=claude
1791392688	take-over	arm=78171
1791392690	pass-through	attended	main-only	check: rearm-resurface
1791392693	start	gen=host-82330-1791392693	primary=claude
1791392693	take-over	arm=81099
1791392695	pass-through	attended	main-only	check: rearm-resurface
1791392698	start	gen=host-84895-1791392698	primary=claude
1791392698	take-over	arm=83615
1791392700	pass-through	attended	main-only	check: rearm-resurface
1791392703	start	gen=host-87314-1791392703	primary=claude
1791392703	take-over	arm=86083
1791392705	pass-through	attended	main-only	check: rearm-resurface
1791392708	start	gen=host-89840-1791392708	primary=claude
1791392708	take-over	arm=88587
1791392710	pass-through	attended	main-only	check: rearm-resurface
1791392714	start	gen=host-92519-1791392714	primary=claude
1791392714	take-over	arm=91130
1791392716	pass-through	attended	main-only	check: rearm-resurface
1791392723	start	gen=host-98389-1791392723	primary=claude
1791392723	take-over	arm=93869
1791392881	pass-through	attended	main-only	signal: /var/folders/m3/81qcpm653_19d59xvhm52h2m0000gn/T//fm-lab.SLyVh4/state/demo.status
1791392889	start	gen=host-21644-1791392889	primary=claude
1791392889	take-over	arm=19176
Evidence: Fixed code: watcher cycle-exit ledger from the live lab

Source: Fixed code: watcher cycle-exit ledger from the live lab

arm_pid=60346	watcher_pid=60394	origin=started	started_at=1791392442	ended_at=1791392474	exit_code=0	signal=none	reason=actionable-signal	beacon_age=31	lock_before=pid:60394|identity:Wed Oct  7 20:00:42 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:65061
arm_pid=65027	watcher_pid=65061	origin=started	started_at=1791392475	ended_at=1791392489	exit_code=143	signal=TERM	reason=arm-interrupted	beacon_age=14	lock_before=pid:65061|identity:Wed Oct  7 20:01:15 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=71377	watcher_pid=71419	origin=started	started_at=1791392492	ended_at=1791392493	exit_code=0	signal=none	reason=actionable-check	beacon_age=1	lock_before=pid:none|identity:none	lock_after=pid:none|identity:none	successor=started:72950
arm_pid=72886	watcher_pid=72950	origin=started	started_at=1791392493	ended_at=1791392497	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=3	lock_before=pid:72950|identity:Wed Oct  7 20:01:33 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=74675	watcher_pid=72950	origin=attached	started_at=1791392496	ended_at=1791392497	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=3	lock_before=pid:72950|identity:Wed Oct  7 20:01:33 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:75160
arm_pid=74675	watcher_pid=75160	origin=started	started_at=1791392497	ended_at=1791392529	exit_code=0	signal=none	reason=actionable-signal	beacon_age=32	lock_before=pid:75160|identity:Wed Oct  7 20:01:37 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:81732
arm_pid=81688	watcher_pid=81732	origin=started	started_at=1791392529	ended_at=1791392533	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=3	lock_before=pid:81732|identity:Wed Oct  7 20:02:09 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=83670	watcher_pid=81732	origin=attached	started_at=1791392532	ended_at=1791392533	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=3	lock_before=pid:81732|identity:Wed Oct  7 20:02:09 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:84093
arm_pid=83670	watcher_pid=84093	origin=started	started_at=1791392533	ended_at=1791392534	exit_code=0	signal=none	reason=actionable-check	beacon_age=1	lock_before=pid:84093|identity:Wed Oct  7 20:02:13 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:86358
arm_pid=86322	watcher_pid=86358	origin=started	started_at=1791392534	ended_at=1791392536	exit_code=0	signal=none	reason=actionable-stale	beacon_age=1	lock_before=pid:86358|identity:Wed Oct  7 20:02:14 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=88204	watcher_pid=88246	origin=started	started_at=1791392538	ended_at=1791392538	exit_code=0	signal=none	reason=actionable-check	beacon_age=0	lock_before=pid:none|identity:none	lock_after=pid:none|identity:none	successor=started:89179
arm_pid=89145	watcher_pid=89179	origin=started	started_at=1791392539	ended_at=1791392542	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=3	lock_before=pid:89179|identity:Wed Oct  7 20:02:19 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=90799	watcher_pid=89179	origin=attached	started_at=1791392542	ended_at=1791392542	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=3	lock_before=pid:89179|identity:Wed Oct  7 20:02:19 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:91248
arm_pid=90799	watcher_pid=91248	origin=started	started_at=1791392543	ended_at=1791392543	exit_code=0	signal=none	reason=actionable-check	beacon_age=0	lock_before=pid:91248|identity:Wed Oct  7 20:02:23 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:91943
arm_pid=91909	watcher_pid=91943	origin=started	started_at=1791392544	ended_at=1791392547	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=3	lock_before=pid:91943|identity:Wed Oct  7 20:02:24 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=93342	watcher_pid=91943	origin=attached	started_at=1791392547	ended_at=1791392548	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=4	lock_before=pid:91943|identity:Wed Oct  7 20:02:24 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:93728
arm_pid=93342	watcher_pid=93728	origin=started	started_at=1791392548	ended_at=1791392548	exit_code=0	signal=none	reason=actionable-check	beacon_age=0	lock_before=pid:93728|identity:Wed Oct  7 20:02:28 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:94445
arm_pid=94396	watcher_pid=94445	origin=started	started_at=1791392549	ended_at=1791392552	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=2	lock_before=pid:94445|identity:Wed Oct  7 20:02:29 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=96272	watcher_pid=94445	origin=attached	started_at=1791392552	ended_at=1791392553	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=3	lock_before=pid:94445|identity:Wed Oct  7 20:02:29 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:96801
arm_pid=96272	watcher_pid=96801	origin=started	started_at=1791392553	ended_at=1791392553	exit_code=0	signal=none	reason=actionable-check	beacon_age=0	lock_before=pid:96801|identity:Wed Oct  7 20:02:33 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:98381
arm_pid=98327	watcher_pid=98381	origin=started	started_at=1791392554	ended_at=1791392557	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=2	lock_before=pid:98381|identity:Wed Oct  7 20:02:34 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=99793	watcher_pid=98381	origin=attached	started_at=1791392557	ended_at=1791392557	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=2	lock_before=pid:98381|identity:Wed Oct  7 20:02:34 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:276
arm_pid=99793	watcher_pid=276	origin=started	started_at=1791392558	ended_at=1791392558	exit_code=0	signal=none	reason=actionable-check	beacon_age=0	lock_before=pid:276|identity:Wed Oct  7 20:02:38 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:1451
arm_pid=1417	watcher_pid=1451	origin=started	started_at=1791392559	ended_at=1791392562	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=3	lock_before=pid:1451|ident

... [25853 bytes truncated] ...

	ended_at=1791392685	exit_code=0	signal=none	reason=actionable-check	beacon_age=0	lock_before=pid:77489|identity:Wed Oct  7 20:04:44 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:78205
arm_pid=78171	watcher_pid=78205	origin=started	started_at=1791392686	ended_at=1791392689	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=3	lock_before=pid:78205|identity:Wed Oct  7 20:04:46 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=80045	watcher_pid=78205	origin=attached	started_at=1791392689	ended_at=1791392689	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=3	lock_before=pid:78205|identity:Wed Oct  7 20:04:46 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:80438
arm_pid=80045	watcher_pid=80438	origin=started	started_at=1791392689	ended_at=1791392690	exit_code=0	signal=none	reason=actionable-check	beacon_age=1	lock_before=pid:none|identity:none	lock_after=pid:none|identity:none	successor=started:81133
arm_pid=81099	watcher_pid=81133	origin=started	started_at=1791392691	ended_at=1791392693	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=2	lock_before=pid:81133|identity:Wed Oct  7 20:04:51 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=82515	watcher_pid=81133	origin=attached	started_at=1791392693	ended_at=1791392694	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=3	lock_before=pid:81133|identity:Wed Oct  7 20:04:51 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:82903
arm_pid=82515	watcher_pid=82903	origin=started	started_at=1791392694	ended_at=1791392694	exit_code=0	signal=none	reason=actionable-check	beacon_age=0	lock_before=pid:82903|identity:Wed Oct  7 20:04:54 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:83649
arm_pid=83615	watcher_pid=83649	origin=started	started_at=1791392695	ended_at=1791392698	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=3	lock_before=pid:83649|identity:Wed Oct  7 20:04:55 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=85080	watcher_pid=83649	origin=attached	started_at=1791392698	ended_at=1791392699	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=4	lock_before=pid:83649|identity:Wed Oct  7 20:04:55 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=85080	watcher_pid=85464	origin=started	started_at=1791392699	ended_at=1791392700	exit_code=0	signal=none	reason=actionable-check	beacon_age=1	lock_before=pid:none|identity:none	lock_after=pid:none|identity:none	successor=started:86117
arm_pid=86083	watcher_pid=86117	origin=started	started_at=1791392700	ended_at=1791392703	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=2	lock_before=pid:86117|identity:Wed Oct  7 20:05:00 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=87500	watcher_pid=86117	origin=attached	started_at=1791392703	ended_at=1791392703	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=2	lock_before=pid:86117|identity:Wed Oct  7 20:05:00 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:87903
arm_pid=87500	watcher_pid=87903	origin=started	started_at=1791392703	ended_at=1791392704	exit_code=0	signal=none	reason=actionable-check	beacon_age=0	lock_before=pid:none|identity:none	lock_after=pid:none|identity:none	successor=started:88621
arm_pid=88587	watcher_pid=88621	origin=started	started_at=1791392705	ended_at=1791392708	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=3	lock_before=pid:88621|identity:Wed Oct  7 20:05:05 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=90026	watcher_pid=88621	origin=attached	started_at=1791392708	ended_at=1791392708	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=3	lock_before=pid:88621|identity:Wed Oct  7 20:05:05 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:90419
arm_pid=90026	watcher_pid=90419	origin=started	started_at=1791392708	ended_at=1791392709	exit_code=0	signal=none	reason=actionable-check	beacon_age=0	lock_before=pid:90419|identity:Wed Oct  7 20:05:08 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:91188
arm_pid=91130	watcher_pid=91188	origin=started	started_at=1791392710	ended_at=1791392714	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=4	lock_before=pid:91188|identity:Wed Oct  7 20:05:10 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=92790	watcher_pid=91188	origin=attached	started_at=1791392714	ended_at=1791392714	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=4	lock_before=pid:91188|identity:Wed Oct  7 20:05:10 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:93173
arm_pid=92790	watcher_pid=93173	origin=started	started_at=1791392714	ended_at=1791392715	exit_code=0	signal=none	reason=actionable-check	beacon_age=0	lock_before=pid:93173|identity:Wed Oct  7 20:05:14 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:93905
arm_pid=93869	watcher_pid=93905	origin=started	started_at=1791392716	ended_at=1791392724	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=8	lock_before=pid:93905|identity:Wed Oct  7 20:05:16 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=98586	watcher_pid=93905	origin=attached	started_at=1791392724	ended_at=1791392724	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=8	lock_before=pid:93905|identity:Wed Oct  7 20:05:16 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:99093
arm_pid=98586	watcher_pid=99093	origin=started	started_at=1791392724	ended_at=1791392880	exit_code=0	signal=none	reason=actionable-signal	beacon_age=31	lock_before=pid:99093|identity:Wed Oct  7 20:05:24 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:19212
arm_pid=19176	watcher_pid=19212	origin=started	started_at=1791392881	ended_at=1791392889	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=8	lock_before=pid:19212|identity:Wed Oct  7 20:08:01 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=21829	watcher_pid=19212	origin=attached	started_at=1791392889	ended_at=1791392890	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=9	lock_before=pid:19212|identity:Wed Oct  7 20:08:01 2026     bash ~/.no-mistakes/worktrees/da9fc43a9fb8/01M4BJR0YAKXY2EEKTANYG1EYM/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:22288
Evidence: Fixed code: lab Claude primary pane

Source: Fixed code: lab Claude primary pane



⏺ ack

✻ Baked for 1s · done 8:04 PM

⏺ Stop hook feedback

⏺ ack

✻ Churned for 1s · done 8:05 PM

⏺ Stop hook feedback

⏺ ack

✻ Brewed for 1s · done 8:05 PM

❯ New rule for this lab test, superseding the earlier one: for every watcher wake or Stop hook feedback, run bin/fm-wake-drain.sh, then run the exact WAKE_ACK_REQUIRED --ack-through command it prints
  (if it prints one), and if it shows BRANCH OUTCOMES run the mark-processed command it names. Do not run anything else, do not arm watchers, then reply: ack

⏺ ack

✻ Cogitated for 3s · done 8:05 PM

⏺ Stop hook feedback

  Ran 1 shell command

⏺ Stop hook feedback

  Ran 2 shell commands

⏺ ack

✻ Worked for 9s · done 8:05 PM

⏺ Stop hook feedback

  Ran 2 shell commands

⏺ ack

✻ Cooked for 6s · done 8:08 PM

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯ 
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  da@Dimitriss-Mac-Studio 01M4BJR0YAKXY2EEKTANYG1EYM [Opus 5.5] | Ctx: 🟢 38% (76k/200k)
  ⏵⏵ auto mode on (shift+tab to cycle) · ← for agents
Evidence: Final lab primary pane

Source: Final lab primary pane


  Ran 2 shell commands

⏺ ack

✻ Worked for 9s · done 8:05 PM

⏺ Stop hook feedback

  Ran 2 shell commands

⏺ ack

✻ Cooked for 6s · done 8:08 PM

⏺ Stop hook feedback

  Ran 2 shell commands

⏺ ack

✻ Sautéed for 7s · done 8:09 PM

⏺ Stop hook feedback

  Ran 2 shell commands

⏺ ack

✻ Crunched for 6s · done 8:10 PM

❯ Lab rule update: for each wake, after the drain and ack, also run: sleep 30   (as its own Bash command), then reply: ack

⏺ ack

✻ Worked for 2s · done 8:13 PM

⏺ Stop hook feedback

  Ran 3 shell commands

⏺ ack. The sleep 30 didn't run: the tool blocks standalone sleep commands, and I didn't work around it.

✻ Cooked for 12s · done 8:14 PM

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯ 
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  da@Dimitriss-Mac-Studio 01M4BJR0YAKXY2EEKTANYG1EYM [Opus 5.5] | Ctx: 🟢 40% (80k/200k)
  ⏵⏵ auto mode on (shift+tab to cycle) · ← for agents
Evidence: New regression tests on the base host script (both not ok)

Source: New regression tests on the base host script (both not ok)

not ok - group teardown: the successor watcher (pid 32735) did not survive the hook's process group teardown
not ok - at-turn teardown: the successor watcher (pid 35808) did not survive the hook's process group teardown
Evidence: Fixed live run, key lines
1791392881 pass-through attended main-only signal: demo.status
successor arm 19176 pgid 19176 (hook pgid 98048); hook gone at t+45s, successor alive
1791392889 take-over arm=19176 -> attached reason=taken-over, successor=started:22288
no check: rearm-resurface afterwards; .watcher-down = acked:handling:*

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ⚠️ bin/fm-supervision-host.sh:1124 - The fix moves only one of the two successors the host leaves running for main into its own process group. The successor started at line 1124 (start_successor &#34;$CLOSED_ARM_PID&#34;, without ARM_OWN_GROUP=1) can also be left for main: when handle_wake returns 2, line 1141 calls detach_successor, restores downtime, and emits, and the Stop hook then exits 2. That happens when the close arrives under the away posture, so the attended block at 1086 is skipped, but the captain returns before handle_wake re-reads the posture (TURN_POSTURE=attended, attended_acceptor fails). The successor is still in the hook's process group, so the same group teardown stops it, publishes downtime, and the next park's fresh cycle announces an empty check: rearm-resurface. That is the invariant the commit claims to restore: a successor left for main must outlive the hook's group teardown. It costs one spurious wake per occurrence rather than a sustained loop, because the follow-on rearm-resurface close is main-only and goes through the fixed leave_successor_for_main path. Smallest fix at the shared boundary: give every successor its own group inside start_successor (or pass ARM_OWN_GROUP=1 at line 1124 too). Only successors run there, and the host retires its parked arm by pid (retire_arm), so a separate group changes nothing on the handled path. That also lets the ARM_OWN_GROUP env knob (lines 470/477/711) go away. Sites: bin/fm-supervision-host.sh:1124 (start without own group), :1141 (detach to main), :711 (the fixed sibling).
  • ℹ️ tests/fm-supervision-host.test.sh:1472 - The regression test models Claude's teardown as a TERM to the hook's process group right after the hook exits, and asserts only that the watcher survives. The reported live sequence puts the TERM about 17s after the successor started, a few seconds after main's next turn ends, with the next hook's arm ending as attached-cycle-ended. The test does not reproduce that timing, and it does not assert the user-visible outcome: the next park takes over without a check: rearm-resurface wake. The own-group change protects the successor whenever the group is torn down, so this is not a defect. But the root cause has not been confirmed against a live Claude session; confirm on the reporting home that the empty rearm-resurface wakes stop.

🔧 Fix applied.
1 info still open:

  • ℹ️ tests/fm-supervision-host.test.sh:1472 - The regression test models Claude's teardown as a TERM to the hook's process group right after the hook exits, and asserts only that the watcher survives. The reported live sequence puts the TERM about 17s after the successor started, a few seconds after main's next turn ends, with the next hook's arm ending as attached-cycle-ended. The test does not reproduce that timing, and it does not assert the user-visible outcome: the next park takes over without a check: rearm-resurface wake. The own-group change protects the successor whenever the group is torn down, so this is not a defect. But the root cause has not been confirmed against a live Claude session; confirm on the reporting home that the empty rearm-resurface wakes stop.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Main-only pass-through on a live Claude primary: the successor watcher runs in its own process group and outlives the Stop hook ✅ pass live lab-fixed-supervision-host.log, lab-fixed-watch-cycle-exits.log, lab-run-summary.md: successor arm 19176 in pgid 19176 while the hook's group was 98048; hook group gone at t+45s with the successor sti…
After main handles the pass-through wake, the next park takes the successor over quietly: no empty check: rearm-resurface wake ✅ pass live lab-fixed-supervision-host.log 1791392881..1791392889: take-over arm=19176, ledger reason=taken-over, a fresh watcher, no rearm-resurface, marker acked:handling
Regression: the hook's process group is terminated after the rewake, and the successor left for main (both pass-through and at-turn) survives it ⏸️ untested no The prior payload did not establish a live result. This was checked only with the repo's fixture harness: test_pass_through_successor_survives_the_hook_process_group_teardown and test_successor_left_a…
Reproduce the reported loop live on base code (Claude TERMs the successor in the hook's group, then the next cycle announces rearm-resurface) ⏸️ untested no I drove two base-code main-only pass-throughs on a real Claude 2.1.292 lab primary, with main turns of ~9s and ~14s. Claude did not terminate the hook's process group in either run (the successors sta…
Handled engine path unchanged: the host still retires its own-group successor itself when it hands a handled outcome to main ✅ pass live lab-all-watch-cycle-exits.log: successor arm 65027 ran in pgid 65027 (start_successor with ARM_OWN_GROUP=1) and was ended by the host (reason=arm-interrupted) on the engine-handled to-main at 17913924…
Close that turns main-only during the engine turn (handle_wake returns 2, detach_successor): the successor left for main is in its own group ⏸️ untested no The prior payload did not establish a live result. Driving this live needs the offer to flip to main-only exactly between the first offer and the turn-boundary offer inside one engine turn, and that r…
  • tests/fm-supervision-host.test.sh cases run in isolation (scratch copy, removed): test_pass_through_successor_survives_the_hook_process_group_teardown, test_successor_left_at_the_turn_survives_the_hook_process_group_teardown, test_claude_stop_hook_delivers_a_main_only_pass_through, test_claude_stop_hook_delivers_a_close_that_turns_main_only_at_its_turn, test_next_park_takes_over_the_cycle_a_pass_through_left_for_main, test_unrecorded_successor_is_stopped_rather_than_left_for_main: all 6 ok on HEAD
  • Red check: the same two new tests run with bin/fm-supervision-host.sh from ac0811c: both not ok - ... did not survive the hook&#39;s process group teardown
  • Live lab: bin/fm-lab-home.sh create + config/supervision-host, real claude on tmux -L fm-lab with FM_HOME=lab, fake task demo with a status file and an fm-demo window; main-only closes driven by appending needs-decision status lines; process groups sampled with ps -o pid,pgid; host log, cycle-exit ledger and recovery marker inspected
  • Live lab with the base host script swapped in by atomic rename (two runs, main turns of ~9s and ~14s) to look for the hook-group teardown
  • Teardown: tmux -L fm-lab kill-server, checked for leftover lab processes (none), rm -rf of the lab, removed the temporary .fm-secondmate-home marker and the scratch test file; git status clean
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

menidi added 4 commits October 7, 2026 18:50
…he hook's process group

The successor a main-only pass-through leaves for main shared the Stop hook's
process group, so the harness tearing that group down after the exit-2 rewake
stopped it. The stop published downtime and the next park's first cycle
announced an empty check: rearm-resurface, which woke main again in a loop.
Start that successor in a process group of its own, as the hook's own
handling successor already is.
…ests in tests/fm-supervision-host.test.sh now call the existing `stop_home_processes "$home"` just before `pass`. The tests are `test_successor_left_at_the_turn_survives_the_hook_process_group_teardown` and `test_pass_through_successor_survives_the_hook_process_group_teardown`. No production code and no other tests changed. The rule broken was that a test must not leave a home's watcher or arm processes running after it passes. These two were the only cases in the changed area that broke it. The other host+hook tests already stop their home, and `test_successor_close_during_main_turn_is_delivered_at_the_next_turn_end` leaves its watcher behind too, but it is an older test you said not to touch. The only reason anything was left over is that the successor's arm now sits in its own process group, outside the hook's teardown. `stop_home_processes` kills the watcher by the pid in its lock file, which stops it no matter which group it is in. **Checks run:** - I ran just these two tests from a scratch copy of the suite (since deleted). Both pass in about 13 seconds. - After each test, a process listing filtered to that test's home directory came back empty once the processes had about a second to exit after TERM. - `bash -n` on the test file passes. - `shellcheck` is not installed here, so I did not lint the file. - I did not run the full serial-2 suite locally. Whether it now finishes under its 30-minute limit will only show on the next CI run
@kunchenguid
kunchenguid merged commit 3c58ec8 into kunchenguid:main Oct 8, 2026
19 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: I read the whole diff of head 255b158c against main 329ad4ed and squash-merged it as 3c58ec8e.

What it does: when the supervision host leaves a successor watcher running for main (a main-only pass-through, or a close that turns main-only at its turn), start_arm now starts it in its own process group (ARM_OWN_GROUP=1 → set -m) with stdin from /dev/null. That's the same shape start_handling_successor in bin/fm-claude-stop-autoarm.sh already uses. The harness tearing down the Stop hook's group after the exit-2 rewake no longer TERMs that successor, so it can't record downtime and set off the empty check: rearm-resurface wake loop. The engine-handled path still retires its own successor by pid. Both new fixture tests TERM the hook's group and check that the watcher survives. They fail on the base script and pass on this head.

Security review before approving fork CI: no workflow or CI-script edits, no credential or network handling. It's a process-group flag and a stdin redirect. I approved this head's fork runs 37716912258 (Require no-mistakes) and 37716912263 (CI).

Contract-class: restore. The supervision host runs by default on a Claude primary, and docs/supervision-host.md already specifies that on a main-only pass-through the host "starts the successor watcher cycle and leaves it running". That successor was being stopped by the hook's group teardown. This keeps it alive with no new surface or wake class. Your body is upfront that the Claude-side group teardown didn't reproduce live in the lab. The change is protective either way, because the successor survives whether or not the group is torn down.

VISION.md, rule by rule

  • One captain, one interface: aligns. It removes a recurring empty wake that cost main a turn and tokens about every 30 seconds.
  • Authority is explicit and never inferred: aligns. No authority change.
  • Scripts own the mechanics, agents own the judgment: aligns. A process-group mechanic in the host script.
  • A restart is a non-event: aligns. The watcher left for main survives the hook's teardown, and the next park takes it over.
  • Delegation with a spine: aligns. Regression tests cover both hand-back paths.
  • The fleet outlives any vendor: aligns. It follows the existing harness-agnostic own-group pattern.
  • Scope: aligns. Command-layer supervision only. The always-loaded contract is untouched.

Gates: no-mistakes attestation bound to 255b158c and green, every CI check green including the timing aggregate, CLEAN/MERGEABLE.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @menidi — really appreciate you taking the time on this.

nathanjgaul-agile added a commit to nathanjgaul-agile/firstmate that referenced this pull request Oct 9, 2026
* feat(bin): defer spawns beyond a declared per-project capacity, opt-in (kunchenguid#5343)

* refactor(bin): share the local Firstmate home walk from the wake library

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.

* feat(bin): defer spawns beyond a project's declared machine capacity

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

* no-mistakes(review): Document that capacity matches the clone directory name

* no-mistakes(document): Rewrap stale fm-wake-lib root-home doc comment

* no-mistakes(review): Dedupe local state dirs by identity to avoid double-counting

* no-mistakes(document): Rewrap fm_local_firstmate_state_dirs error doc comment

* no-mistakes(ci): I fixed all four Greptile findings. All 14 tests in 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

* fix(bin): declare capacity for a project name that begins with #

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.

* no-mistakes(document): Rewrap project-capacity library header comment

* no-mistakes(ci): Lint 2 fails because this PR's code pushes ShellCheck 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

* fix(bin): release the Herdr session lock when reclaim finishes

A concurrent resume in another home waits five seconds for that lock.
Reclaim is the last presentation change on the recovery path, so holding
the lock through the launch tail made the waiter time out. The contributions
arm check also freezes its one-second clock, the same way the budget tests
do, because an unfrozen clock can tick past before the first forge read.

* no-mistakes(review): Keep Herdr session lock through launch handoff after reclaim

* no-mistakes(review): Skip the spawning task's own record in capacity count

* no-mistakes(review): Restore release test comment above its test

* docs: scope PR-ready re-evaluation to a declared project capacity

A ready pull request frees a place only when that project declares capacity, so the always-loaded backlog contract should re-evaluate on that handoff only in that case.

* fix(bin): name the Lavish read message count by the same label as its section (kunchenguid#6785)

fm-procevent-lavish.sh read labels tag=message rows SESSION-ENDING MESSAGE
only when session_ended is true and CAPTAIN MESSAGE otherwise, but the
count line always said session_ending_message_count. Several composer
messages on a still-open board were therefore counted as session-ending.

The count line now follows the same session_ended switch:
session_ending_message_count once the session ended, captain_message_count
otherwise. Message rows stay out of the annotation count, per triage.

Fixes kunchenguid#6743

* fix(herdr): make the presentation lock namespace per OS account (kunchenguid#6780)

The Herdr presentation lock namespace was the fixed machine-global
/tmp/firstmate-herdr-presentation, so on a host where two OS users run
Firstmate on Herdr the first account to create it owned it and every
teardown from the other account was refused with no way to clear it.

Suffix the namespace with the account uid. The owner-uid and mode-700
checks are unchanged, so a foreign-owned or wrong-mode name at this
account's path is still refused and never adopted, chowned, or removed.

Fixes kunchenguid#4716.

* Fix OpenCode arm plugin to decide with the shared supervision predicate (kunchenguid#6809)

The OpenCode session plugin's shouldArm kept its own copy of the need
test that only looked for in-flight task records, while the turn-end
guard decides with fm_supervision_needed in bin/fm-supervision-lib.sh,
which also counts registered process-event sources and trusted custom
checks. With an empty fleet but any registered source or check, the
guard blocked every turn end while the plugin declined to arm - a loop
the guard's own repair line could not resolve because it names the
plugin as the fix.

The plugin now delegates the decision to the shared predicate through
bash, keeping the local away-record decline and the x-mode.env arm
override. OpenCode plugin test fixtures now carry the real predicate
their arming path sources, and the arm suite gains six cases asserting
the plugin's decision against the shared verdict over the same
synthetic state directories.

Co-authored-by: Mia Sun <[email protected]>

* fix(bin): resolve a pending reply only from its own task's status line (kunchenguid#6792)

* fix(bin): resolve a pending reply only from its own task's status line

Remote reply ingestion handed every corr= token in a mate's payload to
fm_pending_reply_try_resolve together with that mate's own status log,
so one mate echoing another mate's token resolved the other request.
Honor a status-file override only when it is the record's own
parent_status, and match the corr= token as a whole word.

Fixes kunchenguid#6538

* no-mistakes(document): docs: scope remote reply settlement to the asked mate

* docs(skills): index the six missing agent-only skill triggers (kunchenguid#6784)

agent-skill-trigger-index claims to be the complete agent-only trigger
index but omitted operational-home-layout, session-start-recovery,
validation-supervision, ship-landing, scout-completion, and
away-quiet-supervision. Add each with its own description's trigger,
placed beside the related entries.

The decision-hold-lifecycle redirect stub stays out, per triage.

Fixes kunchenguid#6503

* test: make agent process fixtures compatible with multicall sleep (kunchenguid#6814)

* test: share a rename-safe agent stand-in across liveness suites

On Ubuntu 26.04, `sleep` is the uutils multicall binary, which refuses to
run when invoked through a symlink named after another utility. The Herdr
descendant process-walk tests built their agent-named process as a `pi`
symlink to the host `sleep`, so the process exited at once, its parent shell
was gone before the walk ran, and both cases read `unknown unreadable` and
failed on that host. The suite stops at its first failure, so every later
case went unrun. The Herdr control smoke test's `claude` symlink has the
same construction.

The tmux liveness suite already solved this with a host-compiled spinner and
a survival-checked `sleep` fallback. That builder moves into tests/lib.sh as
fm_agent_standin, and the tmux suite, both Herdr descendant cases, and the
Herdr control smoke test now use it. When no stand-in can survive a foreign
name, a case skips with the reason instead of failing.

tests/fm-test-fixtures.test.sh gains a portable regression with a fake
multicall `sleep`, so it bites on hosts whose own `sleep` is single-purpose.

* no-mistakes(document): Correct Herdr verification fixture reference

* ci: retrigger cancelled shard

* fix(bin): keep the supervision host's successor watcher alive after the Stop hook's group is torn down (kunchenguid#6787)

* fix(bin): keep the supervision host's pass-through successor out of the hook's process group

The successor a main-only pass-through leaves for main shared the Stop hook's
process group, so the harness tearing that group down after the exit-2 rewake
stopped it. The stop published downtime and the next park's first cycle
announced an empty check: rearm-resurface, which woke main again in a loop.
Start that successor in a process group of its own, as the hook's own
handling successor already is.

* no-mistakes(review): Give the at-turn successor left for main its own group

* no-mistakes(document): Document own-group successor for turn-start hand-back too

* no-mistakes(ci): I made the change you asked for: both new teardown tests in tests/fm-supervision-host.test.sh now call the existing `stop_home_processes "$home"` just before `pass`. The tests are `test_successor_left_at_the_turn_survives_the_hook_process_group_teardown` and `test_pass_through_successor_survives_the_hook_process_group_teardown`. No production code and no other tests changed. The rule broken was that a test must not leave a home's watcher or arm processes running after it passes. These two were the only cases in the changed area that broke it. The other host+hook tests already stop their home, and `test_successor_close_during_main_turn_is_delivered_at_the_next_turn_end` leaves its watcher behind too, but it is an older test you said not to touch. The only reason anything was left over is that the successor's arm now sits in its own process group, outside the hook's teardown. `stop_home_processes` kills the watcher by the pid in its lock file, which stops it no matter which group it is in. **Checks run:** - I ran just these two tests from a scratch copy of the suite (since deleted). Both pass in about 13 seconds. - After each test, a process listing filtered to that test's home directory came back empty once the processes had about a second to exit after TERM. - `bash -n` on the test file passes. - `shellcheck` is not installed here, so I did not lint the file. - I did not run the full serial-2 suite locally. Whether it now finishes under its 30-minute limit will only show on the next CI run

* test: make tmux Claude readiness checks independent of permission footers (kunchenguid#6823)

* test: use idle composer readiness for Claude tmux guards

* no-mistakes(test): Fix attended supervision test expectations and isolate worker state

* no-mistakes(document): Correct live guard coverage and readiness documentation

* no-mistakes(ci): Captain, fixed SC2100 by quoting the cursor-agent assignment in tests/fm-host-mirror-live-e2e.test.sh. Reproduced the failure before editing; pinned ShellCheck lint on both PR test files, bash syntax checks, and git diff --check now pass

* test: preserve attended successor close assertions

* no-mistakes(test): Fix attended live test watcher takeover expectations

* no-mistakes(document): Correct stale attended guard documentation

* Revert "no-mistakes(document): Correct stale attended guard documentation"

This reverts commit 8e59d89.

* Revert "no-mistakes(test): Fix attended live test watcher takeover expectations"

This reverts commit c0b8510.

* test(herdr): accept safe exit refusals and clean lab once (kunchenguid#6818)

* test: stabilize watcher lock race fixtures (kunchenguid#6887)

* test: order stale watcher-lock fixture races explicitly

* no-mistakes(review): Removed duplicate stale-steal reap call

* Rerun CI after the merge

---------

Co-authored-by: Tiago <[email protected]>
Co-authored-by: yairtech <[email protected]>
Co-authored-by: Asser AboElkhair <[email protected]>
Co-authored-by: dubiousenvelope <[email protected]>
Co-authored-by: Mia Sun <[email protected]>
Co-authored-by: Pedro Guimarães <[email protected]>
Co-authored-by: menidi <[email protected]>
Co-authored-by: YifuGu <[email protected]>