Repository navigation
fix(bin): evict a watcher whose beacon stalls past a hard bound instead of refusing every re-arm - #5594
Conversation
…tead of refusing every re-arm A fleet watcher that is alive but whose liveness beacon has gone stale could never be replaced: every re-arm was refused because the lock holder was a live pid, and the holder was never evicted because it was not dead. Add FM_WATCHER_STALL_BOUND (default 3x the stale grace): below it the refusal is unchanged; at or past it the arm re-verifies the holder against the lock's recorded identity, sends TERM, waits boundedly, and takes the lock the normal way, ledgering a stalled-holder-replaced row. A holder that survives TERM keeps the old refusal. Fixes kunchenguid#4400
|
Speaking as Kun's firstmate: Verdict: Diff reviewed ( VISION: aligns — One captain one interface: yes (homes stay supervised without captain hand-restart). Authority explicit: yes (env override only; default restores intended recovery). Scripts vs agents: yes. Restart non-event: yes (stalled holder no longer bricks re-arm). Delegation with spine: yes. Fleet outlives vendor: n/a (watcher core). Scope: yes. Closing: peace of mind that a wedged mid-cycle watcher cannot refuse every replacement forever. Safe review; CI/NM green; MERGEABLE/CLEAN. Squash-merging as restore. |
|
Speaking as Kun's firstmate: this is merged. Thank you @karotkriss — really appreciate you taking the time on this. |
… + stall eviction Header comment conflict only after kunchenguid#5594; retain both the stalled-holder eviction docs from main and this PR's per-poll home/state/code-root exit.
…ad of refusing every re-arm (kunchenguid#5594) * fix(bin): replace a watcher whose beacon stalls past a hard bound instead of refusing every re-arm A fleet watcher that is alive but whose liveness beacon has gone stale could never be replaced: every re-arm was refused because the lock holder was a live pid, and the holder was never evicted because it was not dead. Add FM_WATCHER_STALL_BOUND (default 3x the stale grace): below it the refusal is unchanged; at or past it the arm re-verifies the holder against the lock's recorded identity, sends TERM, waits boundedly, and takes the lock the normal way, ledgering a stalled-holder-replaced row. A holder that survives TERM keeps the old refusal. Fixes kunchenguid#4400 * no-mistakes(test): poll for replacement message to fix watcher-lock test flake * no-mistakes(document): document FM_WATCHER_STALL_BOUND in config inventory
…ad of refusing every re-arm (kunchenguid#5594) * fix(bin): replace a watcher whose beacon stalls past a hard bound instead of refusing every re-arm A fleet watcher that is alive but whose liveness beacon has gone stale could never be replaced: every re-arm was refused because the lock holder was a live pid, and the holder was never evicted because it was not dead. Add FM_WATCHER_STALL_BOUND (default 3x the stale grace): below it the refusal is unchanged; at or past it the arm re-verifies the holder against the lock's recorded identity, sends TERM, waits boundedly, and takes the lock the normal way, ledgering a stalled-holder-replaced row. A holder that survives TERM keeps the old refusal. Fixes kunchenguid#4400 * no-mistakes(test): poll for replacement message to fix watcher-lock test flake * no-mistakes(document): document FM_WATCHER_STALL_BOUND in config inventory
…ad of refusing every re-arm (kunchenguid#5594) * fix(bin): replace a watcher whose beacon stalls past a hard bound instead of refusing every re-arm A fleet watcher that is alive but whose liveness beacon has gone stale could never be replaced: every re-arm was refused because the lock holder was a live pid, and the holder was never evicted because it was not dead. Add FM_WATCHER_STALL_BOUND (default 3x the stale grace): below it the refusal is unchanged; at or past it the arm re-verifies the holder against the lock's recorded identity, sends TERM, waits boundedly, and takes the lock the normal way, ledgering a stalled-holder-replaced row. A holder that survives TERM keeps the old refusal. Fixes kunchenguid#4400 * no-mistakes(test): poll for replacement message to fix watcher-lock test flake * no-mistakes(document): document FM_WATCHER_STALL_BOUND in config inventory
Intent
Fixes #4400
A fleet watcher that is alive but whose liveness beacon has gone stale can never be replaced: every re-arm is refused because the lock holder is a live pid, and the holder is never evicted because it is not dead. Observed on 2026-09-24: one poll cycle ran for 1 h 48 min without touching the beacon and no replacement started, so nothing was polled for that time, and 74 re-arm attempts the same day each died within a second against a live-but-stale holder while the home stayed unsupervised. When the holder's beacon is stale past a hard bound well beyond the ordinary grace, the re-arm should replace that holder rather than refuse.
What Changed
bin/fm-watch.sh: addedevict_stalled_holderand a retry loop aroundfm_lock_try_acquireso a re-arm now evicts a live lock holder (identity-verifiedTERM, once per arm) whose beacon is stale past the new hard boundFM_WATCHER_STALL_BOUND(default 3xFM_WATCHER_STALE_GRACE) and starts in its place, printingwatcher: replaced stalled pid <N> ...; a beacon stale only past the ordinary grace still gets the existing refusal, and a holder that survivesTERMkeeps the refusal and nonzero exit.bin/fm-watch-arm.sh: when the started child reports it replaced a stalled holder, ledger astalled-holder-replacedcycle row and reopen the cycle so its normal close row follows.docs/configuration.mdanddocs/turnend-guard.md: documentedFM_WATCHER_STALL_BOUNDand the eviction ceiling on the stale-beacon refusal.tests/fm-watcher-lock.test.sh: addedtest_live_stalled_watch_lock_is_replaced_past_hard_bound, asserting a beacon under the bound stays refused while one past it evicts and replaces the holder.Risk Assessment
✅ Low: A small, well-bounded fix that closes the live-but-stale watcher deadlock exactly as the intent specifies; the new eviction is identity-verified, TERM-only with a bounded wait, single-shot per arm, and falls back to the unchanged refusal, with behavioral test coverage.
Testing
Drove the real fm-watch.sh binary through its regression test end-to-end. The past-hard-bound eviction/replacement and the under-bound refusal both pass live, the reported deadlock reproduces on the pre-fix binary and is gone after the fix, and the flaky replacement-message grep is now poll-synchronized (10/10 clean). No screenshot applies - this is a process-lifecycle shell change with no rendered UI surface; evidence is the CLI transcript of the watcher acquiring/refusing the singleton lock. Worktree left clean.
git show b42d4fa:bin/fm-watch.sh; it fails with the ticket's exact refusal message, proving fail-before / pass-afterEvidence: stall-replace test 10x (no flake)
Source: stall-replace test 10x (no flake)
Evidence: regression: new test fails on pre-fix fm-watch.sh
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
🔧 **Test** - 1 issue found → auto-fixed ✅
tests/fm-watcher-lock.test.sh:215- test_live_stalled_watch_lock_is_replaced_past_hard_bound in tests/fm-watcher-lock.test.sh raced the watcher's post-acquire echo: it synchronized on the lock-pid file but asserted the 'watcher: replaced stalled pid ...' stdout line, which is printed only after the lock is acquired, so a single grep read an empty file ~1 in 3 runs. Fixed by polling for the message before asserting; 8/8 runs clean after. Product behavior was correct throughout.Isolated run oftest_live_stale_watch_lock_is_actionableandtest_live_stalled_watch_lock_is_replaced_past_hard_boundfrom tests/fm-watcher-lock.test.sh, 8 consecutive runs after the fix (all pass)Manual live drive ofbin/fm-watch.shwith a real fake lock holder: beacon past hard bound -> holder evicted, replacement acquires lock, prints 'watcher: replaced stalled pid ... past hard bound 3s'Manual live drive: holder withtrap '' TERMpast the hard bound -> exit 1, refusal on stderr, holder still aliveManual live drive: lock pid-identity set to a non-matching value -> exit 1, refusal, holder never signalled🔧 Fix applied.
✅ Re-checked - no issues remain.
git show b42d4fa:bin/fm-watch.sh; it fails with the ticket's exact refusal message, proving fail-before / pass-afterRantest_live_stalled_watch_lock_is_replaced_past_hard_bound10x in a loop against the fixed bin/fm-watch.sh - 10/10 pass, no flakeRan the same test againstgit show b42d4fa:bin/fm-watch.sh(pre-fix) - fails with the exact deadlock refusal from the ticket, confirming the regression reproduces before the fixThe test's first invocation (FM_WATCHER_STALL_BOUND=9999999999) drives the under-bound boundary: holder stale past grace is still refused and left un-signalled✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.