Repository navigation
fix(bin): judge watcher beacon staleness on awake time across host sleep - #5768
bartwesthoff-fyrm wants to merge 3 commits into
Conversation
On macOS no process runs while the host sleeps, so a healthy watcher's beacon aged by the whole sleep and the first arm after a wake refused it as stale, or evicted it past the hard bound. The healthy-watcher check, the supervision verdict, the watcher's stale-holder refusal and eviction, and the away-mode guard now use fm_beacon_age, which subtracts the most recent host sleep after the last beat. A stall while the host is awake still crosses the grace and the hard bound unchanged.
|
Independent confirmation from a second home: same symptom, same cause. Setup: MacBook Pro (MacBookPro18,3), macOS 26.5.2, Claude-primary home on the herdr backend. The Stop-hook auto-arm repeatedly reported An investigation on 2026-09-28 matched each failure to
While awake, the beacon advanced every 95 to 113 seconds, and no bounded cycle component came close to the 300 s grace. We reached the same conclusion as this PR: liveness should be judged on awake time across host sleep, keeping wall-clock ages for report-only gaps. @bartwesthoff-fyrm, this now conflicts with |
Problem
In a Claude-primary home on the herdr backend, the fleet watcher (
bin/fm-watch.sh) repeatedly stopped touchingstate/.last-watcher-beatfor 7-10 minutes while its process stayed alive.The Stop-hook auto-arm then reported
lock held by live pid ... heartbeat is stale for 600s(later 465s) and failed after two attempts, and once the watcher exited entirely.Cause
The stalls are macOS system sleep, not a blocking poll step.
Every triage-log gap and failed auto-arm lines up with a
pmset -g logsleep and wake entry (Idle, Clamshell and Maintenance Sleep, with DarkWakes of about 45s).For example, the first gap (16:19:30-16:29:39) matches Idle Sleep at 16:19:45 and wake at 16:29:34.
No process runs while the host sleeps, so a healthy watcher's beacon ages by the whole sleep.
Judged on wall-clock age, the first arm after a wake (often a DarkWake) refused the healthy watcher as stale, or TERM-evicted it once the age passed the hard bound.
The herdr event wait (
bin/backends/herdr-eventwait.py) is not the cause: it is bounded bytime.monotonic, which does not advance during sleep on macOS, so it only ever blocks for POLL seconds of awake time.Fix
fm_beacon_ageinbin/fm-wake-lib.shreports the beacon's awake age: wall-clock age minus the part of the host's most recent sleep (kern.sleeptime/kern.waketimeon macOS) that falls after the last beat.Hosts that expose no sleep record keep wall-clock ages, and the probe errs toward stale when several sleeps fall between two beats.
fm_watcher_healthy, used by the arm and the Stop-hook auto-armfm_watcher_supervision_verdict, and the beacon age the supervision banner showsmax(300, FM_POLL+60)) and theFM_WATCHER_STALL_BOUNDeviction contract are unchanged: a watcher that stalls while the host is awake still crosses both.tests/lib.shpinsFM_HOST_SLEEP_WINDOW=''so fixtures that backdate the beacon are not skewed by a real sleep during the suite.bin/fm-watch.shcomment that said the beacon is touched again before the terminal wait; it is touched once per cycle.The watcher that exited after 18:27:31
This is the arm/successor chain, not the beacon, and this PR does not change it.
The watcher exited normally at 18:36:35 with an actionable wake (a declared-paused lane recheck).
Its successor re-arm waits on the primary's handling turn, which host sleep delayed until 19:17:14.
A genuinely wedged watcher is still recovered by the existing hard-bound eviction, now measured on awake time.
Testing
Regression tests (each fails on the base code and passes with the fix):
tests/fm-watcher-lock.test.shtest_live_holder_is_not_stale_across_host_sleep: a live holder whose beacon gap was host sleep is attached to and reads as healthy. The same beacon with no sleep, or with a sleep that ended long before, is still refused.tests/fm-claude-stop-autoarm.test.sh: a live generation claim and a live legacy owner paused by host sleep keep deferring. An awake-stale claim is still superseded.Live runs in a disposable lab home, with a real
bin/fm-watch.shholder and a second arm against a backdated beacon:watcher: already running pid 47552. Base arm:lock held by live pid 47552 but heartbeat is stale for 2400s (>660s), the reported failure.heartbeat is stale for 800s (>660s)replaced stalled pid 78807 (beacon 2400s past hard bound 1980s)bin/fm-guard.shbannerWATCHER DOWNwhen no sleep explains the gapfm_host_sleep_windowparses this host'skern.sleeptime/kern.waketimecorrectlytests/fm-watcher-lock.test.sh,tests/fm-claude-stop-autoarm.test.shandtests/fm-turnend-guard.test.shpass.tests/fm-procevent.test.shfailed locally on three runs, each at a different timing-sensitive case with host load between 25 and 63.This PR only changes how that file sources the libraries, and it will be tracked separately as a load-sensitive flake.
The Stop-hook auto-arm was covered by its test file, not driven live through a real Claude primary.