Skip to content

fix: reclaim orphaned watcher arms on the next park - #6335

Merged
kunchenguid merged 8 commits into
mainfrom
fm/fm-restart-orphan-watcher-arm-r1
Oct 2, 2026
Merged

kunchenguid merged 8 commits into
mainfrom
fm/fm-restart-orphan-watcher-arm-r1

Conversation

@kunchenguid

@kunchenguid kunchenguid commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Intent

"agree", to: do item 7 first, then items 1-3 together as one PR, leave 4-6 for later.
Item 7, as authorized: recheck that the orphaned pre-restart watcher arms persist in axi-a1, eddies-wallet-e1, mini-default, sshhip-h7; if they do, fix the root cause so a second-mate restart does not leave the old arm as an orphan owner with the new arm attaching and polling (a leak fix, its own PR; do not kill the live orphans by hand as the fix, though cleaning them up after the fix lands is fine through the guarded path).

Context (data/fm-poll-churn-post-update-measure-s1/report.md, finding 4): after the 2026-10-01 fleet update to 549e07f restarted every second mate, ps at 10:04Z showed two fm-watch-arm.sh processes in each of axi-a1, mini-default, sshhip-h7 and eddies-wallet-e1. The owner arm is an orphan (ppid 1) started about 04:28Z by the pre-restart park host and is still the parent of the live fm-watch.sh. The second arm is a child of the new park host running attach_and_wait (fm-watch-arm.sh about lines 378-400), calling fm_watcher_healthy (fm-wake-lib.sh about line 187: four $(cat ...), fm_pid_identity via ps, fm_path_age) then sleep "$ATTACH_POLL" (0.5 s) at about 1.67 Hz, forking 7.4-7.9 children/s each - about 100-170 process creations/s host-wide, 8-13% of the new idle floor. fmdev-f1 has a single arm under its park host, the pre-update topology; before the update every home had exactly one arm, a child of its park host. fm-watch-arm.sh did not change in 549e07f. The report did not test whether the orphan ends at the watcher's next natural turnover or whether the attached arm still delivers wakes correctly.

Decisions and constraints from the earlier validation of this PR, which stand: the take-over restores the acknowledged recovery episode only when the taken-over arm's cycle-ledger row for that exact arm and watcher shows signal=TERM, waited for within a short bound; a missing row or any other signal deliberately leaves the downtime for the fresh cycle's ordinary recovery wake (one extra recovery wake is the accepted safe direction, never a hidden failure). The --restart first-cycle branch used by the OpenCode and omp hosts predates this PR (#5941) and stays out of scope as a documented follow-up, as does the supervision-host-off Stop-hook handling successor. No watcher, signal-trap, or polling-cadence change; no shared sleep abstraction.

This update: the PR was closed by accident and reopened for a merge decision. Current origin/main, which now contains #6338 (the Pi 1.0.0 Calm test fix that cleared an unrelated red check), was merged into this branch with an ordinary merge commit - no rebase, no amend, no force-push - so the pipeline publishes the update and fresh CI runs. Landing timing is coordinated with the main firstmate.

What Changed

  • Persist detached successor arm identities and take over their watcher cycles on the next non---restart park; retain interrupted takeovers for retry and stop successors that cannot be recorded.
  • Restore acknowledged recovery state only after bounded confirmation of TERM for the exact arm/watcher pair and no intervening wake append; otherwise preserve recovery and delivered wakes.
  • Add regression coverage for takeover ownership, interruption, persistence failure, queued work, and watcher self-exit; document unchanged --restart and host-off Stop-hook paths.

Risk Assessment

✅ Low: The takeover and persistence changes are bounded, preserve the authorized recovery fallback, and introduce no substantiated material defects.

Testing

Focused baseline checks and seven live lifecycle scenarios passed. The pre-fix negative control reproduced acknowledgement erasure. Product transcripts, topology, persisted state, and ledgers were captured; all disposable resources were removed without touching the live fleet.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Restart the primary after a main-only close; the next park replaces the orphan with a host-owned cycle and delivers the next decision ✅ pass live live-topology.log; live-after-restart.txt
Interrupt a takeover while its marker lock is held; a later park retries using the retained successor identity ✅ pass live live-interruption.log
Make the successor-record destination a writable directory; the close remains unchanged and the unrecorded successor is cleaned up ✅ pass live live-record-failure.log; live-record-failure.txt; live-record-rearmed.txt
Request takeover using a process that does not own the watcher; the arm attaches without stopping that watcher ✅ pass live live-watch-scenarios.log
Take over a cycle with work still queued; the fresh cycle surfaces that work ✅ pass live live-watch-scenarios.log
Let the old watcher fail after the handover snapshot but before TERM; genuine downtime produces a recovery wake ✅ pass live live-watch-scenarios.log; self-exit-negative-control.log
Prevent the owner from recording its TERM row; takeover proceeds but conservatively surfaces recovery ✅ pass live live-missing-row.log
Evidence: Restart replaces the orphan owner and preserves acknowledgement

Source: Restart replaces the orphan owner and preserves acknowledgement

Before primary restart:
  PID  PPID ARGS
91946     1 bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch-arm.sh
91986 91946 bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh

left record: 91946	Thu Oct  1 14:09:57 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch-arm.sh

recovery: acked:handling:56763.1790888997.CrEpp7

After primary restart, before park:
  PID  PPID ARGS
91946     1 bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch-arm.sh
91986 91946 bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh

After restarted primary parks:
  PID  PPID ARGS
66732 66716 bash bin/fm-supervision-host.sh park
67145 66732 bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch-arm.sh --take-over 91946
68273 67145 bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh

host record: host	66732	Thu Oct  1 14:12:25 2026     bash bin/fm-supervision-host.sh park
arm	67145	Thu Oct  1 14:12:25 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch-arm.sh --take-over 91946

recovery: acked:handling:56763.1790888997.CrEpp7

host ledger: 1790888907	start	gen=host-3491-1790888907	primary=claude
1790888910	to-main	the supervision session could not take this wake: the dialog mirror could not be read; this wake is yours
1790888960	start	gen=host-56093-1790888960	primary=claude
1790888997	pass-through	attended	main-only	signal: ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/.l/state/demo.status
1790889145	start	gen=host-66732-1790889145	primary=claude
1790889145	take-over	arm=91946

cycle ledger: arm_pid=3840	watcher_pid=3883	origin=started	started_at=1790888907	ended_at=1790888908	exit_code=0	signal=none	reason=actionable-signal	beacon_age=1	lock_before=pid:3883|identity:Thu Oct  1 14:08:27 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:6472
arm_pid=6439	watcher_pid=6472	origin=started	started_at=1790888908	ended_at=1790888910	exit_code=143	signal=TERM	reason=arm-interrupted	beacon_age=1	lock_before=pid:6472|identity:Thu Oct  1 14:08:28 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=56634	watcher_pid=56763	origin=started	started_at=1790888960	ended_at=1790888997	exit_code=0	signal=none	reason=actionable-signal	beacon_age=1	lock_before=pid:56763|identity:Thu Oct  1 14:09:20 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:91986
arm_pid=91946	watcher_pid=91986	origin=started	started_at=1790888997	ended_at=1790889145	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=0	lock_before=pid:91986|identity:Thu Oct  1 14:09:57 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=67145	watcher_pid=91986	origin=attached	started_at=1790889145	ended_at=1790889145	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=0	lock_before=pid:91986|identity:Thu Oct  1 14:09:57 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:68273

Observed: previous orphan arm exited; fresh watcher belongs to new host arm; acknowledgement retained, no recovery close.
Evidence: Real Claude reports the next decision close after restart

Source: Real Claude reports the next decision close after restart


⏺ Running the corrected command (no trailing argument), leaving it running.

  Ran 1 shell command

⏺ The corrected park command is running in the background. I'll leave it running and take no other actions, reporting
  its line only if it closes.

✻ Worked for 7s · done 2:12 PM

⏺ Background command "Run supervision host in park mode" completed (exit code 0)

⏺ The park command closed. Let me read its output line to report it.

  Read 1 file

⏺ The park command closed cleanly (exit code 0). Reporting its line as instructed - not acting on it and not stopping
  any successor:

  watcher: started pid=68273 (beacon fresh)
  signal: ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/.l/state/demo.status

  [exited with code 0]

  The supervision host started a watcher (pid=68273, beacon fresh), then exited at code 0 after a signal event on
  demo.status. Per your instruction I'm reporting this line only - not acting on the signal and not stopping any
  successor.

✻ Churned for 8s · done 2:13 PM

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
❯ restart it
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
  Opus 4.8 ctx window   ▉               63.1k / 1.0M
  ⏵⏵ auto mode on (shift+tab to cycle) · ← for agents
Evidence: Interrupted takeover retains its record and succeeds on retry

Source: Interrupted takeover retains its record and succeeds on retry

Held recovery-marker lock during takeover; interrupted lab host 81907 with TERM; left arm 50979 watcher 51140
Host cleanup retained byte-identical successor record and old arm/watcher remain alive.
1790888907	start	gen=host-3491-1790888907	primary=claude
1790888910	to-main	the supervision session could not take this wake: the dialog mirror could not be read; this wake is yours
1790888960	start	gen=host-56093-1790888960	primary=claude
1790888997	pass-through	attended	main-only	signal: ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/.l/state/demo.status
1790889145	start	gen=host-66732-1790889145	primary=claude
1790889145	take-over	arm=91946
1790889182	pass-through	attended	main-only	signal: ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/.l/state/demo.status
1790889282	start	gen=host-81907-1790889282	primary=claude
1790889282	take-over	arm=50979

Next park retries takeover: old arm gone, watcher parent is host-owned arm, acknowledged episode unchanged.
  PID  PPID ARGS
41930 41922 bash bin/fm-supervision-host.sh park
42344 41930 bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch-arm.sh --take-over 50979
43507 42344 bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh

1790888907	start	gen=host-3491-1790888907	primary=claude
1790888910	to-main	the supervision session could not take this wake: the dialog mirror could not be read; this wake is yours
1790888960	start	gen=host-56093-1790888960	primary=claude
1790888997	pass-through	attended	main-only	signal: ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/.l/state/demo.status
1790889145	start	gen=host-66732-1790889145	primary=claude
1790889145	take-over	arm=91946
1790889182	pass-through	attended	main-only	signal: ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/.l/state/demo.status
1790889282	start	gen=host-81907-1790889282	primary=claude
1790889282	take-over	arm=50979
1790889337	start	gen=host-41930-1790889337	primary=claude
1790889337	take-over	arm=50979

arm_pid=3840	watcher_pid=3883	origin=started	started_at=1790888907	ended_at=1790888908	exit_code=0	signal=none	reason=actionable-signal	beacon_age=1	lock_before=pid:3883|identity:Thu Oct  1 14:08:27 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:6472
arm_pid=6439	watcher_pid=6472	origin=started	started_at=1790888908	ended_at=1790888910	exit_code=143	signal=TERM	reason=arm-interrupted	beacon_age=1	lock_before=pid:6472|identity:Thu Oct  1 14:08:28 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=56634	watcher_pid=56763	origin=started	started_at=1790888960	ended_at=1790888997	exit_code=0	signal=none	reason=actionable-signal	beacon_age=1	lock_before=pid:56763|identity:Thu Oct  1 14:09:20 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:91986
arm_pid=91946	watcher_pid=91986	origin=started	started_at=1790888997	ended_at=1790889145	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=0	lock_before=pid:91986|identity:Thu Oct  1 14:09:57 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=67145	watcher_pid=91986	origin=attached	started_at=1790889145	ended_at=1790889145	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=0	lock_before=pid:91986|identity:Thu Oct  1 14:09:57 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:68273
arm_pid=67145	watcher_pid=68273	origin=started	started_at=1790889145	ended_at=1790889181	exit_code=0	signal=none	reason=actionable-signal	beacon_age=1	lock_before=pid:68273|identity:Thu Oct  1 14:12:25 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:51140
arm_pid=82196	watcher_pid=51140	origin=attached	started_at=1790889282	ended_at=1790889298	exit_code=143	signal=TERM	reason=arm-interrupted	beacon_age=2	lock_before=pid:51140|identity:Thu Oct  1 14:13:02 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:51140|identity:Thu Oct  1 14:13:02 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	successor=none
arm_pid=50979	watcher_pid=51140	origin=started	started_at=1790889182	ended_at=1790889337	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=1	lock_before=pid:51140|identity:Thu Oct  1 14:13:02 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=42344	watcher_pid=51140	origin=attached	started_at=1790889337	ended_at=1790889338	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=2	lock_before=pid:51140|identity:Thu Oct  1 14:13:02 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:43507
Evidence: Directory destination retains cleanup ownership and allows fresh rearm

Source: Directory destination retains cleanup ownership and allows fresh rearm

Writable directory at left-record destination: close passes through unchanged, successor-unrecorded logged, directory empty, all recorded lab arms/watchers exited.
1790888907	start	gen=host-3491-1790888907	primary=claude
1790888910	to-main	the supervision session could not take this wake: the dialog mirror could not be read; this wake is yours
1790888960	start	gen=host-56093-1790888960	primary=claude
1790888997	pass-through	attended	main-only	signal: ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/.l/state/demo.status
1790889145	start	gen=host-66732-1790889145	primary=claude
1790889145	take-over	arm=91946
1790889182	pass-through	attended	main-only	signal: ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/.l/state/demo.status
1790889282	start	gen=host-81907-1790889282	primary=claude
1790889282	take-over	arm=50979
1790889337	start	gen=host-41930-1790889337	primary=claude
1790889337	take-over	arm=50979
1790889353	pass-through	attended	main-only	signal: ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/.l/state/demo.status
1790889354	pass-through	successor-unrecorded	signal: ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/.l/state/demo.status

arm_pid=3840	watcher_pid=3883	origin=started	started_at=1790888907	ended_at=1790888908	exit_code=0	signal=none	reason=actionable-signal	beacon_age=1	lock_before=pid:3883|identity:Thu Oct  1 14:08:27 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:6472
arm_pid=6439	watcher_pid=6472	origin=started	started_at=1790888908	ended_at=1790888910	exit_code=143	signal=TERM	reason=arm-interrupted	beacon_age=1	lock_before=pid:6472|identity:Thu Oct  1 14:08:28 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=56634	watcher_pid=56763	origin=started	started_at=1790888960	ended_at=1790888997	exit_code=0	signal=none	reason=actionable-signal	beacon_age=1	lock_before=pid:56763|identity:Thu Oct  1 14:09:20 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:91986
arm_pid=91946	watcher_pid=91986	origin=started	started_at=1790888997	ended_at=1790889145	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=0	lock_before=pid:91986|identity:Thu Oct  1 14:09:57 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=67145	watcher_pid=91986	origin=attached	started_at=1790889145	ended_at=1790889145	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=0	lock_before=pid:91986|identity:Thu Oct  1 14:09:57 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:68273
arm_pid=67145	watcher_pid=68273	origin=started	started_at=1790889145	ended_at=1790889181	exit_code=0	signal=none	reason=actionable-signal	beacon_age=1	lock_before=pid:68273|identity:Thu Oct  1 14:12:25 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:51140
arm_pid=82196	watcher_pid=51140	origin=attached	started_at=1790889282	ended_at=1790889298	exit_code=143	signal=TERM	reason=arm-interrupted	beacon_age=2	lock_before=pid:51140|identity:Thu Oct  1 14:13:02 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:51140|identity:Thu Oct  1 14:13:02 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	successor=none
arm_pid=50979	watcher_pid=51140	origin=started	started_at=1790889182	ended_at=1790889337	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=1	lock_before=pid:51140|identity:Thu Oct  1 14:13:02 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=42344	watcher_pid=51140	origin=attached	started_at=1790889337	ended_at=1790889338	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=2	lock_before=pid:51140|identity:Thu Oct  1 14:13:02 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:43507
arm_pid=42344	watcher_pid=43507	origin=started	started_at=1790889338	ended_at=1790889353	exit_code=0	signal=none	reason=actionable-signal	beacon_age=1	lock_before=pid:43507|identity:Thu Oct  1 14:15:38 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:65865
arm_pid=65813	watcher_pid=65865	origin=started	started_at=1790889353	ended_at=1790889354	exit_code=143	signal=TERM	reason=arm-interrupted	beacon_age=0	lock_before=pid:65865|identity:Thu Oct  1 14:15:53 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none


After handling close, next park owns fresh cycle with no left record:
  PID  PPID ARGS
77811 77807 bash bin/fm-supervision-host.sh park
78052 77811 bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch-arm.sh
78109 78052 bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh

recovery: acked:handling:43507.1790889352.xg5vg3

host	77811	Thu Oct  1 14:17:52 2026     bash bin/fm-supervision-host.sh park
arm	78052	Thu Oct  1 14:17:53 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch-arm.sh
Evidence: Real watcher ownership guard, queued work, and self-exit recovery

Source: Real watcher ownership guard, queued work, and self-exit recovery

ok - watch-arm: --take-over attaches to a cycle the named arm does not own and leaves it running

REAL PRODUCT STATE take-over-not-owner after test_take_over_attaches_to_a_cycle_the_named_arm_does_not_own

--- arm.out ---
watcher: attached pid=3678 (beacon 0s)

--- watch.out ---

--- .watcher-down ---
pending:downtime:3678.1790889401.TZOz0R

--- .watch-cycle-exits.log ---
arm_pid=4263	watcher_pid=3678	origin=attached	started_at=1790889399	ended_at=1790889401	exit_code=143	signal=TERM	reason=arm-interrupted	beacon_age=2	lock_before=pid:3678|identity:Thu Oct  1 14:16:39 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
ok - watch-arm: --take-over owns a fresh cycle without a recovery wake and still surfaces queued work

REAL PRODUCT STATE take-over-not-owner after test_take_over_owns_a_fresh_cycle_and_keeps_queued_work_surfacing

--- arm.out ---
watcher: attached pid=3678 (beacon 0s)

--- watch.out ---

--- .watcher-down ---
pending:downtime:3678.1790889401.TZOz0R

--- .watch-cycle-exits.log ---
arm_pid=4263	watcher_pid=3678	origin=attached	started_at=1790889399	ended_at=1790889401	exit_code=143	signal=TERM	reason=arm-interrupted	beacon_age=2	lock_before=pid:3678|identity:Thu Oct  1 14:16:39 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none

REAL PRODUCT STATE take-over-owner after test_take_over_owns_a_fresh_cycle_and_keeps_queued_work_surfacing

--- arm.out ---
check: rearm-resurface

--- owner.out ---
watcher: started pid=6207 (beacon fresh)
watcher: FAILED - watcher cycle exited 143 without an actionable reason

--- owner2.out ---
watcher: started pid=12320 (beacon fresh) recovery-generation=8418.1790889406.ZN3CBg
watcher: FAILED - watcher cycle exited 143 without an actionable reason

--- .watcher-down ---
announced:downtime:13033.1790889407.iHEEMm

--- .watch-cycle-exits.log ---
arm_pid=6187	watcher_pid=6207	origin=started	started_at=1790889401	ended_at=1790889402	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=1	lock_before=pid:6207|identity:Thu Oct  1 14:16:41 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=7876	watcher_pid=6207	origin=attached	started_at=1790889402	ended_at=1790889402	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=1	lock_before=pid:6207|identity:Thu Oct  1 14:16:41 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:8418
arm_pid=7876	watcher_pid=8418	origin=started	started_at=1790889402	ended_at=1790889406	exit_code=143	signal=TERM	reason=arm-interrupted	beacon_age=1	lock_before=pid:8418|identity:Thu Oct  1 14:16:42 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=12252	watcher_pid=12320	origin=started	started_at=1790889406	ended_at=1790889407	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=1	lock_before=pid:12320|identity:Thu Oct  1 14:16:46 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=13204	watcher_pid=12320	origin=attached	started_at=1790889407	ended_at=1790889407	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=1	lock_before=pid:12320|identity:Thu Oct  1 14:16:46 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=13204	watcher_pid=14108	origin=started	started_at=1790889407	ended_at=1790889408	exit_code=0	signal=none	reason=actionable-check	beacon_age=1	lock_before=pid:none|identity:none	lock_after=pid:none|identity:none	successor=none

--- .wake-queue ---
1790889407	2	signal	take-over	signal: fixture still queued for main
watcher: secondmate liveness check failed
ok - watch-arm: takeover preserves self-exit downtime and surfaces a recovery wake

REAL PRODUCT STATE take-over-not-owner after test_take_over_preserves_downtime_from_watcher_self_exit

--- arm.out ---
watcher: attached pid=3678 (beacon 0s)

--- watch.out ---

--- .watcher-down ---
pending:downtime:3678.1790889401.TZOz0R

--- .watch-cycle-exits.log ---
arm_pid=4263	watcher_pid=3678	origin=attached	started_at=1790889399	ended_at=1790889401	exit_code=143	signal=TERM	reason=arm-interrupted	beacon_age=2	lock_before=pid:3678|identity:Thu Oct  1 14:16:39 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none

REAL PRODUCT STATE take-over-owner after test_take_over_preserves_downtime_from_watcher_self_exit

--- arm.out ---
check: rearm-resurface

--- owner.out ---
watcher: started pid=6207 (beacon fresh)
watcher: FAILED - watcher cycle exited 143 without an actionable reason

--- owner2.out ---
watcher: started pid=12320 (beacon fresh) recovery-generation=8418.1790889406.ZN3CBg
watcher: FAILED - watcher cycle exited 143 without an actionable reason

--- .watcher-down ---
announced:downtime:13033.1790889407.iHEEMm

--- .watch-cycle-exits.log ---
arm_pid=6187	watcher_pid=6207	origin=started	started_at=1790889401	ended_at=1790889402	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=1	lock_before=pid:6207|identity:Thu Oct  1 14:16:41 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=7876	watcher_pid=6207	origin=attached	started_at=1790889402	ended_at=1790889402	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=1	lock_before=pid:6207|identity:Thu Oct  1 14:16:41 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:8418
arm_pid=7876	watcher_pid=8418	origin=started	started_at=1790889402	ended_at=1790889406	exit_code=143	signal=TERM	reason=arm-interrupted	beacon_age=1	lock_before=pid:8418|identity:Thu Oct  1 14:16:42 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=12252	watcher_pid=12320	origin=started	started_at=1790889406	ended_at=1790889407	exit_code=143	signal=TERM	reason=signal-exit	beacon_age=1	lock_before=pid:12320|identity:Thu Oct  1 14:16:46 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=13204	watcher_pid=12320	origin=attached	started_at=1790889407	ended_at=1790889407	exit_code=unknown	signal=unknown	reason=taken-over	beacon_age=1	lock_before=pid:12320|identity:Thu Oct  1 14:16:46 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=13204	watcher_pid=14108	origin=started	started_at=1790889407	ended_at=1790889408	exit_code=0	signal=none	reason=actionable-check	beacon_age=1	lock_before=pid:none|identity:none	lock_after=pid:none|identity:none	successor=none

--- .wake-queue ---
1790889407	2	signal	take-over	signal: fixture still queued for main

REAL PRODUCT STATE take-over-self-exit after test_take_over_preserves_downtime_from_watcher_self_exit

--- arm.out ---
watcher: started pid=18856 (beacon fresh)
check: rearm-resurface

--- owner.out ---
watcher: started pid=14941 (beacon fresh)
watcher: FAILED - watcher cycle exited 1 without an actionable reason

--- .watcher-down ---
announced:downtime:14941.1790889411.6xxRM9

--- .watch-cycle-exits.log ---
arm_pid=14913	watcher_pid=14941	origin=started	started_at=1790889408	ended_at=1790889411	exit_code=1	signal=none	reason=nonzero-exit	beacon_age=0	lock_before=pid:14941|identity:Thu Oct  1 14:16:48 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none
arm_pid=16882	watcher_pid=14941	origin=attached	started_at=1790889409	ended_at=1790889411	exit_code=unknown	signal=unknown	reason=taken-over-unconfirmed-stop	beacon_age=0	lock_before=pid:14941|identity:Thu Oct  1 14:16:48 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=started:18856
arm_pid=16882	watcher_pid=18856	origin=started	started_at=1790889411	ended_at=1790889412	exit_code=0	signal=none	reason=actionable-check	beacon_age=0	lock_before=pid:18856|identity:Thu Oct  1 14:16:51 2026     bash ~/.no-mistakes/worktrees/52b07e9083e7/01M3WMCNX8QFSJCB7Q3K5VB23W/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none

--- .wake-queue ---
Evidence: Missing owner ledger row leaves recovery visible

Source: Missing owner ledger row leaves recovery visible

Missing owner row deliberately induced with real ledger-lock contention. Old owner and watcher exited; fresh cycle reports recovery rather than restoring acknowledgement.
Before: acked:handling:56538.1790889545.Y89EBD
After: announced:downtime:55820.1790889546.bQIG6M
watcher: started pid=55820 (beacon fresh)
watcher: FAILED - watcher cycle exited 143 without an actionable reason
watcher: started pid=69430 (beacon fresh)
check: rearm-resurface
Evidence: Pre-fix negative control reproduces hidden downtime

Source: Pre-fix negative control reproduces hidden downtime

watcher: secondmate liveness check failed
not ok - takeover restored the old acknowledgement
Evidence: Disposable lab teardown

Source: Disposable lab teardown

Private fm-lab tmux server stopped. All recorded arms and watchers in disposable validation homes have exited. No live fleet sessions were touched.

Evidence and trade-offs

Recheck (read-only, 2026-10-01 17:33Z)

  • axi-a1, eddies-wallet-e1, mini-default, and sshhip-h7 each showed a single arm, a child of a park host started 11:59-12:10Z.
    Their host ledgers show the orphans ended at the park boundary (boundary after 27001s, 11:59-12:10Z), which stops the home's watcher; they had lived about 7.5 h since the 04:28-04:40Z restart-persist pass-throughs (pass-through attended main-only signal: .../parent-replies.status).
  • The control home fmdev-f1 showed the same topology live: an orphan arm (ppid 1) owning the watcher plus the park host's attached arm, re-created by every attended main-only pass-through in its host ledger.
    So the leak recurs on every such close and on every second-mate restart, rather than being a one-off of the 549e07f update.

Root cause

  • Since fix: keep remote reply listeners and watcher cycles running #5941 (2026-09-27), an attended main-only pass-through starts a successor watcher cycle, disowns it, and exits so the Claude Stop hook can exit 2 and wake main.
    The successor arm is reparented to init and stays in the exited hook's process group, which nothing stops.
  • The next park host's first arm found that healthy watcher and attached to it (attach_and_wait, polling every 0.5 s) instead of owning it, and nothing ever reclaimed ownership before the watcher's next close or the 27000 s park boundary.
  • A second-mate restart always hits this: the persist request sent before the restart is a main-only close in the mate, and a quiet mate may see no further close for hours.

Fix

  • The host records the successor it leaves for main (state/.supervision-host-left, pid and identity), and the next host's activation consumes that record.
    The pipeline's review rounds hardened that record: it persists until the recorded arm is gone or has a different identity, so a later host retries an interrupted take-over; the write is atomic and read back before the host exits; and when the write fails the host keeps the successor tracked and stops it at cleanup rather than leaving an unrecorded orphan.
  • While that arm still runs under its identity, the host's first cycle runs fm-watch-arm.sh --take-over <arm>.
    Only when the healthy watcher is that arm's own child, it stops the watcher by its locked identity, reports a reason the cycle delivered before the stop landed, and otherwise owns a fresh cycle.
  • The stopped watcher publishes downtime like any close; the taking arm undoes that publication over an acknowledged episode when no wake was appended in between (handover-restore, docs/watcher-continuity.md "Generation reuse"), so the handover wakes nobody and hides no queued work.
  • That undo applies only when the taken-over arm, which waits on its watcher, recorded that exact watcher ending by the take-over's TERM in the cycle ledger (state/.watch-cycle-exits.log, waited for within a short bound).
    A watcher that failed on its own just before the stop records signal=none, so its downtime stays and the fresh cycle surfaces it as an ordinary recovery wake (Greptile review finding; a missing record costs one extra recovery wake, never a hidden one).
  • The watcher, signal traps, and attached-arm cadence are unchanged; a cycle the named arm does not own, or one that outlives the stop, is attached to exactly as before.

Regression test and counterfactual

  • tests/fm-supervision-host.test.sh test_next_park_takes_over_the_cycle_a_pass_through_left_for_main drives the real Stop hook, host, arm, and watcher through a main-only pass-through, main's drain and acknowledgement, and a session restart.
    Before the fix it fails with exactly the fleet topology (one arm with ppid 1 owning the watcher, one attached arm under the new host); after the fix it passes, with one arm owned by the host, no wake to main, the episode still acknowledged, and the next close delivered.
  • With the downtime undo disabled, the same test fails with check: rearm-resurface waking main on every takeover.
  • tests/fm-watch-arm.test.sh covers the ownership guard, a fresh cycle without a recovery wake, and queued work still resurfacing; tests/fm-wake-queue.test.sh covers that the undo applies only to the stop's own publication.
  • test_take_over_preserves_downtime_from_watcher_self_exit makes the owned watcher fail on its own between the take-over's snapshot and its stop.
    Before the confirmed-stop check it fails (takeover restored the old acknowledgement); after it, it passes with check: rearm-resurface, while the ordinary take-over test and the host regression above still pass with no wake.

Herdr lab before and after

A disposable primary home ran a fake Claude second mate in an isolated Herdr lab pane, firing the real Stop hook in its own process group; the restart killed the session and its current hook group outright (the fleet's cycle log has no record for the old park at the real restart) and started a new session in the same pane.

  • Unfixed (HEAD): after the restart the orphan arm (ppid 1, in the first hook's dead process group) still owned the watcher, and the restarted session's park had an attached arm polling it.
    The next close was still delivered through the attached arm, which answers the report's open question about wake delivery.
  • Fixed: the old session's next park took the cycle over, so one arm owned the watcher before the restart.
    After the restart, the restarted session's park ended with one arm, its own child, owning the watcher, and the next close was delivered.

Trade-off: one recovery wake per second-mate restart

  • Before this change, the orphan carried the old watcher across a second-mate restart, which is the leak itself.
  • Now the watcher belongs to the session's own park, so a restart that kills the session's hook group kills that watcher too, and the restarted mate gets one check: rearm-resurface recovery wake before its next park owns a fresh cycle.
  • That is the ordinary recovery path for a watcher that died with its session, and it is how restarts behaved before fix: keep remote reply listeners and watcher cycles running #5941; it costs one short main turn per restart (restarts happen at fleet updates), against an attached poller forking about 25-40 processes per second per home for up to 7.5 h.
  • Continuity through main's handling turn after a main-only close is unchanged: the left successor still covers that turn, and only the next park replaces it.

Follow-up, not in this PR

  • Homes that opt out of the supervision host (config/supervision-host-off) still use the Claude Stop hook's own detached handling successor (start_handling_successor in bin/fm-claude-stop-autoarm.sh), and the next Stop's foreground arm attaches to it the same way.
    That variant is unfixed here and should get the same take-over in a separate change.
  • Hosts whose owner relaunches them with park --restart (the OpenCode plugin and omp) start their first cycle with fm-watch-arm.sh --restart, which stops a successor left by a main-only pass-through without the take-over's acknowledgement-preserving handover, so that stop can surface a recovery wake.
    That branch predates this PR (it has stopped the left successor's watcher since fix: keep remote reply listeners and watcher cycles running #5941; this PR only adds the take-over branch after it), and those hosts never attach to the successor, so they do not have the orphan-plus-attached-poller leak fixed here.
    The successor record those hosts write is dropped at the next activation once the stopped successor has exited.
    Giving that restart the same handover is a separate change.

Landing

This changes supervision machinery that every live home runs, so landing timing is coordinated with the main firstmate; the live orphans are cleaned up through the guarded path after it lands, not by hand as part of this fix.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 7 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Restart the primary after a main-only close; the next park replaces the orphan with a host-owned cycle and delivers the next decision ✅ pass live live-topology.log; live-after-restart.txt
Interrupt a takeover while its marker lock is held; a later park retries using the retained successor identity ✅ pass live live-interruption.log
Make the successor-record destination a writable directory; the close remains unchanged and the unrecorded successor is cleaned up ✅ pass live live-record-failure.log; live-record-failure.txt; live-record-rearmed.txt
Request takeover using a process that does not own the watcher; the arm attaches without stopping that watcher ✅ pass live live-watch-scenarios.log
Take over a cycle with work still queued; the fresh cycle surfaces that work ✅ pass live live-watch-scenarios.log
Let the old watcher fail after the handover snapshot but before TERM; genuine downtime produces a recovery wake ✅ pass live live-watch-scenarios.log; self-exit-negative-control.log
Prevent the owner from recording its TERM row; takeover proceeds but conservatively surfaces recovery ✅ pass live live-missing-row.log
  • Ran selected executable regressions from tests/fm-watch-arm.test.sh, tests/fm-supervision-host.test.sh, and tests/fm-wake-queue.test.sh through temporary focused drivers.
  • Started real claude on the disposable home's private fm-lab tmux socket; drove bin/fm-lock.sh, bin/fm-supervision-host.sh park, and generation-bound wake acknowledgements.
  • Restarted the lab primary and inspected persisted ownership records, process parentage, recovery markers, cycle ledgers, and subsequent decision delivery.
  • Held the recovery-marker lock, interrupted the lab host with TERM, released the lock, and drove another park.
  • Introduced a writable directory at the successor-record destination; verified cleanup and the next fresh park.
  • Drove real watcher-arm interfaces without mock tmux or crew-state implementations for non-owner attachment, queued work, watcher self-exit, and missing owner-ledger evidence.
  • Ran the self-exit regression against 99601828^; it failed with takeover restored the old acknowledgement, while the current implementation passed.
  • Stopped the private tmux server, verified recorded lab processes exited, removed disposable homes and temporary drivers, and confirmed a clean worktree.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

An attended main-only pass-through leaves a successor watcher cycle
running through main's handling turn. The session's next park attached
to that cycle instead of owning it, so the successor's arm, orphaned by
its host's exit, kept owning the watcher while the new park's arm polled
it twice a second until the next close or the park boundary, hours later
in a quiet second mate. A second-mate restart hit this every time, since
its persist request is a main-only close.

The host now records the successor it leaves for main, and the next
host's first cycle runs bin/fm-watch-arm.sh --take-over on it: when that
arm still owns the healthy watcher, the new arm stops it, reports a
reason the cycle delivered first, and otherwise owns a fresh cycle. The
stop's own downtime publication is undone over an acknowledged episode
when no wake was appended in between, so the handover wakes nobody.
@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •