Skip to content

fix(bin): honor a slow-but-healthy pre-lock migration scan in the watcher arm - #33

Merged
alandomio merged 1 commit into
mainfrom
fm/fm-arm-confirm-timeout
Sep 26, 2026
Merged

alandomio merged 1 commit into
mainfrom
fm/fm-arm-confirm-timeout

Conversation

@alandomio

Copy link
Copy Markdown
Owner

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 — before bin/fm-watch.sh ever 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:none the 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
File Change
bin/fm-watch.sh Touches a dedicated state/.watch-starting-beat marker right before the pre-lock migration scan; records startup-scan-secs/startup-lock-secs into the lock directory for the arm to fold into its ledger
bin/fm-watch-arm.sh Raises ARM_CONFIRM_DEFAULT to 60s (non-Windows); grants one bounded STARTUP_GRACE extension (default 60s) to a forked child that is alive and has touched the new marker; records startup_scan_secs/startup_lock_secs in state/.watch-cycle-exits.log
docs/watcher-continuity.md Documents the new confirmation predicate and ledger fields
tests/fm-watch-arm.test.sh New test simulating a 12s pre-lock scan against a deliberately tight CONFIRM_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 against FM_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) and bin/fm-doc-audience-check.sh: clean.
  • Manually reproduced the original failure end to end (a simulated slow scan against the pre-fix code killed the watcher at the old timeout) and confirmed the fix resolves it.

While validating, tests/fm-watch-arm.test.sh's rearm-resurface case started failing intermittently: a one-shot sleep 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.sh fails intermittently (~1 in 5-8 runs) on both this branch and unmodified main — reproduced independently against a clean main worktree. Pre-existing, unrelated to this change, not touched here.

Out of scope
  • Skipping re-hashing in fm-pr-check-migrate.sh when 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.
  • The pre-existing fm-watch-checkpoint.test.sh flake noted above.

…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.
@alandomio
alandomio merged commit 3a64094 into main Sep 26, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant