Repository navigation
fix: reclaim orphaned watcher arms on the next park - #6335
Merged
Merged
Conversation
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.
…oritative documentation
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
--restartpark; retain interrupted takeovers for retry and stop successors that cannot be recorded.--restartand 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.
Evidence: Restart replaces the orphan owner and preserves acknowledgement
Source: Restart replaces the orphan owner and preserves acknowledgement
Evidence: Real Claude reports the next decision close after restart
Source: Real Claude reports the next decision close after restart
Evidence: Interrupted takeover retains its record and succeeds on retry
Source: Interrupted takeover retains its record and succeeds on retry
Evidence: Directory destination retains cleanup ownership and allows fresh rearm
Source: Directory destination retains cleanup ownership and allows fresh rearm
Evidence: Real watcher ownership guard, queued work, and self-exit recovery
Source: Real watcher ownership guard, queued work, and self-exit recovery
Evidence: Missing owner ledger row leaves recovery visible
Source: Missing owner ledger row leaves recovery visible
Evidence: Pre-fix negative control reproduces hidden downtime
Source: Pre-fix negative control reproduces hidden downtime
Evidence: Disposable lab teardown
Source: Disposable lab teardown
Evidence and trade-offs
Recheck (read-only, 2026-10-01 17:33Z)
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).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
The successor arm is reparented to init and stays in the exited hook's process group, which nothing stops.
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.Fix
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.
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.
handover-restore,docs/watcher-continuity.md"Generation reuse"), so the handover wakes nobody and hides no queued work.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).Regression test and counterfactual
tests/fm-supervision-host.test.shtest_next_park_takes_over_the_cycle_a_pass_through_left_for_maindrives 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.
check: rearm-resurfacewaking main on every takeover.tests/fm-watch-arm.test.shcovers the ownership guard, a fresh cycle without a recovery wake, and queued work still resurfacing;tests/fm-wake-queue.test.shcovers that the undo applies only to the stop's own publication.test_take_over_preserves_downtime_from_watcher_self_exitmakes 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 withcheck: 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.
The next close was still delivered through the attached arm, which answers the report's open question about wake delivery.
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
check: rearm-resurfacerecovery wake before its next park owns a fresh cycle.Follow-up, not in this PR
config/supervision-host-off) still use the Claude Stop hook's own detached handling successor (start_handling_successorinbin/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.
park --restart(the OpenCode plugin and omp) start their first cycle withfm-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.
Ran selected executable regressions fromtests/fm-watch-arm.test.sh,tests/fm-supervision-host.test.sh, andtests/fm-wake-queue.test.shthrough temporary focused drivers.Started realclaudeon the disposable home's privatefm-labtmux socket; drovebin/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 against99601828^; it failed withtakeover 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.