Repository navigation
fix(bin): honor a slow-but-healthy pre-lock migration scan in the watcher arm - #33
Merged
Merged
Conversation
…cher arm bin/fm-watch.sh's pre-lock PR-check migration scan can run well past ten seconds under a large fleet, during which the watcher holds no lock and the arm's ARM_CONFIRM_DEFAULT=10 confirmation window had nothing but a flat timeout to go on, killing genuinely healthy starts. fm-watch.sh now touches a dedicated state/.watch-starting-beat marker right before that scan; it is deliberately never state/.last-watcher-beat, since a process that has not taken the lock yet may never become the watcher, and touching the authoritative beacon early could make the autoarm supervision model read "healthy" with none present. fm-watch-arm.sh's confirmation wait grants one bounded STARTUP_GRACE extension (default 60s) on that marker's evidence, raises ARM_CONFIRM_DEFAULT to 60s non-Windows, and records each cycle's startup_scan_secs/startup_lock_secs in the lifecycle ledger. Also fixes a pre-existing race in fm-watch-arm.test.sh's rearm-resurface case (a one-shot liveness sample racing normal process exit/reaping) that the added overhead made more likely to hit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Under a large fleet, the watcher's pre-lock PR-check migration scan (
bin/fm-pr-check-migrate.sh --checks-safe) can run well past ten seconds — measured at 15s against ~30 registered checks — beforebin/fm-watch.shever acquires its singleton lock. Until now the arm (bin/fm-watch-arm.sh) had a flat 10-second confirmation timeout and no evidence at all during that window (lock_before=pid:nonethe whole time), so it killed genuinely healthy starts mid-scan.Why it matters: this repeatedly took supervision down under load — every arm launch ended
reason=confirmation-timeout, the Stop auto-arm reported "auto-arm FAILED", and the fleet went unsupervised until someone noticed and re-armed manually.Change
bin/fm-watch.shstate/.watch-starting-beatmarker right before the pre-lock migration scan; recordsstartup-scan-secs/startup-lock-secsinto the lock directory for the arm to fold into its ledgerbin/fm-watch-arm.shARM_CONFIRM_DEFAULTto 60s (non-Windows); grants one boundedSTARTUP_GRACEextension (default 60s) to a forked child that is alive and has touched the new marker; recordsstartup_scan_secs/startup_lock_secsinstate/.watch-cycle-exits.logdocs/watcher-continuity.mdtests/fm-watch-arm.test.shCONFIRM_TIMEOUT; also fixes a pre-existing race in an existing test (see Validation)The new marker is deliberately never
state/.last-watcher-beat, the shared, authoritative liveness beacon every other guard trusts. A process that has not taken the lock yet may never become the watcher at all (a failed migration scan exits before ever trying), so touching the shared beacon early could make Claude's/Cursor's autoarm supervision model read "healthy" with no watcher present. The new marker is read by nothing but the arm's own confirmation-wait extension.Validation
tests/fm-watch-arm.test.sh(15/15, including the new test): confirmed the arm now honors a simulated 12s pre-lock scan againstFM_ARM_CONFIRM_TIMEOUT=3, well below the old 10s default — proving the new marker, not just the raised default, is what the confirmation wait actually honors.tests/fm-watcher-lock.test.sh,tests/fm-watch-recovery-loop.test.sh,tests/fm-pi-watch-extension.test.sh,tests/fm-watch-triage.test.sh: all green (142 assertions total across the five files).bin/fm-lint.sh(shellcheck) andbin/fm-doc-audience-check.sh: clean.While validating,
tests/fm-watch-arm.test.sh's rearm-resurface case started failing intermittently: a one-shotsleep 0.25+ liveness sample was racing a normal, fast process exit/reap, and the small added overhead of the new code made that race easier to hit. Fixed by polling for up to 2s instead of sampling once; confirmed the underlying behavior (the arm surfacing recovery + exiting) was already correct.Separately,
tests/fm-watch-checkpoint.test.shfails intermittently (~1 in 5-8 runs) on both this branch and unmodifiedmain— reproduced independently against a cleanmainworktree. Pre-existing, unrelated to this change, not touched here.Out of scope
fm-pr-check-migrate.shwhen nothing has changed since the last scan (the actual root cause of the repeated 15s cost) — left out. That script is extremely heavily tested for fail-closed security properties (~3400 lines of tests), and a change to its hot-path validation logic deserves its own focused review rather than riding along with an arm-timeout fix.fm-watch-checkpoint.test.shflake noted above.