Skip to content

fix(watch): keep the watcher liveness beacon fresh across long cycles - #8371

Open
kesslerio wants to merge 25 commits into
kunchenguid:mainfrom
kesslerio:fix/watcher-beacon-progress
Open

kesslerio wants to merge 25 commits into
kunchenguid:mainfrom
kesslerio:fix/watcher-beacon-progress

Conversation

@kesslerio

@kesslerio kesslerio commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

What Changed

  • bin/fm-watch.sh now refreshes state/.last-watcher-beat between the units of a long supervision cycle (pending-reply records, stale windows, heartbeat scan, check sweep) instead of only at cycle boundaries, so a home with a deep backlog or slow checks no longer reads as a dead supervisor; child display sweeps report through a separate .last-watcher-progress marker that only the live watcher propagates, and .watch-cycle is now the distinct per-cycle boundary marker.
  • Every beacon reader (fm-guard.sh, fm-watch-arm.sh, the turn-end guards and their Cursor/Antigravity wrappers, the Claude Stop auto-arm hook, the supervision host and hand-back, fm-inbox.sh, fm-afk-return.sh, and the shared fm_watcher_healthy/fm_watcher_supervision_verdict/fm_supervision_status predicates) resolves freshness through the new fm_beacon_grace in bin/fm-wake-lib.sh, so an explicit FM_GUARD_GRACE wins and otherwise the poll-derived default applies consistently; armed and directly launched watchers also share one config/watch.env + config/x-mode.env loader.
  • Opt-in display sweeps (Herdr groups, Rex marks) run as managed process groups that a stop tears down, and fm_nm_bounded gives each no-mistakes query its own group so a cancelled sweep kills its query descendants while a single query's timeout still stays query-local and returns 124.
  • Docs (turnend-guard.md, watcher-continuity.md, configuration.md, the operational home layout skill) record the cycle-progress contract, the new markers, and the shared grace derivation.

Risk Assessment

⚠️ Medium: The changes affect watcher liveness and subprocess cancellation across several paths, but static review found no substantiated new defects.

Testing

Ran the branch's three real-process shell suites (beacon progress, bounded-query ownership, wedge cap), then drove the product end-to-end in a disposable marked lab home created and destroyed in the same turn: the real watch-arm, watcher, and guard. The arm still loads config/watch.env after the CONFIG assignment removal and attaches to a 700s beacon under the configured 1200s grace; the guard judges the same configured grace in both directions; a live watcher's long check sweep keeps its beacon fresh so a progressing cycle raises no false WATCHER DOWN; and a SIGSTOP-frozen watcher correctly ages out and warns. No UI surface is involved, so no screenshots were captured.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
After the CONFIG assignment removal, bin/fm-watch-arm.sh started with only FM_HOME in a marked lab home loads config/watch.env and attaches to a live identity-matched holder whose beacon is 700s old w… ✅ pass live live-lab-scenarios.log section A: watcher: attached pid=1460132 (beacon 700s) and fm_beacon_grace in lab home = 1200
bin/fm-guard.sh judges freshness against the home-configured grace: silent for a 700s beacon with config/watch.env grace 1200, and raises WATCHER DOWN naming 'grace 60s' for a 100s beacon after the fi… ✅ pass live live-lab-scenarios.log section A2 plus live-A2-guard-1200.log (0 bytes) and live-A2-guard-60.log (banner 'last beat: 100s ago, grace 60s')
A real watcher running an 8-check sweep longer than its 8s grace keeps its liveness beacon refreshed from inside the cycle, so bin/fm-guard.sh stays silent while the cycle is still progressing past th… ✅ pass live live-lab-scenarios.log section B: cycle_age 9-12s with beacon_age 1-2s, guard during the working sweep -> 0 WATCHER DOWN lines, output bytes=0
Adversarial: a watcher SIGSTOPped mid-sweep cannot refresh its beacon, so after 13s it exceeds its 8s grace and bin/fm-guard.sh raises WATCHER DOWN ✅ pass live live-lab-scenarios.log section C: frozen watcher pid=1460990 beacon_age=13s, guard raised 1 WATCHER DOWN with grace 8s
An expired no-mistakes query run through the real bounded-query boundary stops its descendants when the watcher cancels the display group, preserves stdout and exit status, and lets the next query run ✅ pass live test-nm-bounded.log: 3 ok (status and resolver query descendants stop on display cancellation, owned and standalone bounded queries preserve stdout and status, `expired queries close descendant ou…
The whole beacon contract holds in real processes: refresh is throttled and inert outside a watcher, child sweeps update only the progress marker, every sweep and terminal-wait branch refreshes progre… ✅ pass live test-beacon-progress.log: 18 ok, FM_TEST_COMPLETE, exit 0 (real bin/fm-watch.sh, bin/fm-guard.sh, bin/fm-watch-arm.sh processes in isolated homes)
Evidence: Live lab-home run of watch-arm, watcher, and guard (scenarios A, A2, B, C)

Source: Live lab-home run of watch-arm, watcher, and guard (scenarios A, A2, B, C)

=== A: arm loads home watch.env and attaches to a 700s beacon under configured grace 1200 === holder live pid=1460132 beacon_age=700s fm_beacon_grace in lab home = 1200 watcher: attached pid=1460132 (beacon 700s) === A2: guard reads the configured grace (silent at 700s, warns at 100s with grace 60) === guard with home grace=1200, live holder, beacon 700s -> 0 WATCHER DOWN lines, output bytes=0 guard with home grace=60, live holder, beacon 100s -> 1 WATCHER DOWN lines WATCHER DOWN - SUPERVISION IS OFF (last beat: 100s ago, grace 60s) === B: real watcher's 16s check sweep keeps the beacon fresh under grace 8 === sample: cycle_age=9s beacon_age=1s sample: cycle_age=12s beacon_age=2s (grace 8s) guard during the working sweep -> 0 WATCHER DOWN lines, output bytes=0 === C: SIGSTOP the working watcher mid-sweep === frozen watcher pid=1460990 beacon_age=13s guard on the frozen watcher -> 1 WATCHER DOWN lines

lab=/tmp/fm-lab.sqKaD1

=== A: arm loads home watch.env and attaches to a 700s beacon under configured grace 1200 ===
holder live pid=1460132 beacon_age=700s
fm_beacon_grace in lab home = 1200
watcher: attached pid=1460132 (beacon 700s)

=== A2: the guard reads the same configured grace (silent at 700s, warns at 100s with grace 60) ===
guard with home grace=1200, live holder, beacon 700s -> 0 WATCHER DOWN lines, output bytes=0
guard with home grace=60, live holder, beacon 100s -> 1 WATCHER DOWN lines
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: 100s ago, grace 60s).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.

=== B: a real watcher's 16s check sweep keeps the beacon fresh under grace 8; guard stays silent ===
watcher pid=1460990 lock=1460990
sample: cycle_age=0s beacon_age=0s (8 checks registered)
sample: cycle_age=3s beacon_age=1s (8 checks registered)
sample: cycle_age=6s beacon_age=2s (8 checks registered)
sample: cycle_age=9s beacon_age=1s (8 checks registered)
sample: cycle_age=12s beacon_age=2s (8 checks registered)
cycle_age=12s beacon_age=2s (grace 8s)
guard during the working sweep -> 0 WATCHER DOWN lines, output bytes=0

=== C: SIGSTOP the same working watcher mid-sweep; the guard raises WATCHER DOWN ===
frozen watcher pid=1460990 beacon_age=13s
guard on the frozen watcher -> 1 WATCHER DOWN lines
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: 13s ago, grace 8s).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
●  This is a supervision warning only; the guarded operation WILL still run.

lab teardown: rm -rf /tmp/fm-lab.sqKaD1
Evidence: Beacon-progress real-process suite (18 ok)

Source: Beacon-progress real-process suite (18 ok)

1..15
ok - a progress tick refreshes the watcher beacon and throttles tight loops
ok - progress refresh is inert outside a watcher, so no library invents liveness
ok - crew classification refreshes watcher progress and preserves standalone verdicts
ok - the shared beacon grace derives from the poll cadence and honours an explicit override
ok - readers resolve home cadence and Relay precedence without leaking configuration
ok - every terminal wait refreshes progress and direct watchers load home settings
ok - standalone supervision predicates share the poll-derived grace
ok - progress refresh keeps a fixed cadence regardless of unused interval inputs
ok - a live watcher mid-sweep refreshes its beacon, so a long cycle never reads as dead
ok - the pull guard stays silent while a live watcher works through a long sweep
ok - a successor attaches to a working cycle instead of refusing or replacing it
ok - a stalled beacon still raises the banner, judged with the explicit grace
ok - an explicit FM_WATCHER_STALL_BOUND keeps a merely slow holder in place
ok - a genuinely stalled holder is still evicted and replaced past the hard bound
ok - an explicit FM_GUARD_GRACE wins over the derived default in both directions
ok - explicit short and long FM_HEARTBEAT cadences govern scheduled heartbeats
ok - child processes update the progress marker and cannot touch the beacon directly
ok - a watcher frozen with SIGSTOP during a display sweep trips the guard
FM_TEST_COMPLETE

real	0m26.863s
user	0m4.050s
sys	0m4.213s
exit=0
Evidence: Bounded-query ownership suite (3 ok)

Source: Bounded-query ownership suite (3 ok)

1..3
ok - status and resolver query descendants stop on display cancellation
ok - owned and standalone bounded queries preserve stdout and status
ok - expired queries close descendant output and allow the next query
FM_TEST_COMPLETE

real	0m3.592s
user	0m0.128s
sys	0m0.135s
exit=0
Evidence: Live scenario driver script used for the lab-home run

Source: Live scenario driver script used for the lab-home run

#!/usr/bin/env bash
# live-lab-scenarios.sh - drive the real watcher, arm, and guard in a disposable
# marked lab home (bin/fm-lab-home.sh), per the firstmate live-validation runbook.
# Evidence only; never touches the operator's home or default tmux server.
set -u

ROOT={run-worktree}
EV=~/.no-mistakes/evidence/01M77TT015RB584XQG5V31A01V
CLEAN_ENV=(env -u NO_MISTAKES_GATE -u FM_GATE_REFUSE_BYPASS -u FM_ROOT_OVERRIDE
  -u FM_STATE_OVERRIDE -u FM_DATA_OVERRIDE -u FM_CONFIG_OVERRIDE -u FM_PROJECTS_OVERRIDE
  -u FM_GUARD_GRACE -u FM_POLL -u FM_HEARTBEAT)

LAB=$(mktemp -d "${TMPDIR:-/tmp}/fm-lab.XXXXXX")
HOLDER_PID=
ARM_PID=
WATCH_PID=

cleanup() {
  local p
  for p in "$ARM_PID" "$WATCH_PID" "$HOLDER_PID"; do
    [ -n "$p" ] || continue
    kill -CONT "$p" 2>/dev/null || true
    kill -TERM "$p" 2>/dev/null || true
  done
  sleep 0.3
  for p in "$ARM_PID" "$WATCH_PID" "$HOLDER_PID"; do
    [ -n "$p" ] || continue
    kill -KILL "$p" 2>/dev/null || true
  done
  rm -rf "$LAB"
}
trap cleanup EXIT

step() { printf '\n=== %s ===\n' "$*"; }

"$ROOT/bin/fm-lab-home.sh" create "$LAB" >/dev/null || { echo "lab create failed"; exit 1; }
mkdir -p "$LAB/tmux" "$LAB/root"
printf 'lab=%s\n' "$LAB"

# ---------------------------------------------------------------- scenario A
# A live identity-matched holder with a 700s-old beacon: inside the home's
# configured FM_GUARD_GRACE=1200 but far past the legacy 300s default. The arm
# must load config/watch.env (the consolidation the change finishes) and attach;
# a reader that lost settings load would judge 700s stale.
step "A: arm loads home watch.env and attaches to a 700s beacon under configured grace 1200"
printf '%s\n' 'export FM_POLL=600' 'export FM_GUARD_GRACE=1200' > "$LAB/config/watch.env"
sleep 300 &
HOLDER_PID=$!
IDENTITY=$(bash -c '. "$1"; fm_pid_identity "$2"' _ "$ROOT/bin/fm-wake-lib.sh" "$HOLDER_PID")
mkdir -p "$LAB/state/.watch.lock"
printf '%s\n' "$HOLDER_PID" > "$LAB/state/.watch.lock/pid"
printf '%s\n' "$LAB" > "$LAB/state/.watch.lock/fm-home"
printf '%s\n' "$ROOT/bin/fm-watch.sh" > "$LAB/state/.watch.lock/watcher-path"
printf '%s\n' "$IDENTITY" > "$LAB/state/.watch.lock/pid-identity"
: > "$LAB/state/.last-watcher-beat"
touch -d @$(( $(date +%s) - 700 )) "$LAB/state/.last-watcher-beat"
printf 'holder live pid=%s beacon_age=%ss\n' "$HOLDER_PID" "$(( $(date +%s) - $(stat -c %Y "$LAB/state/.last-watcher-beat") ))"
printf 'fm_beacon_grace in lab home = %s\n' \
  "$("${CLEAN_ENV[@]}" FM_HOME="$LAB" bash -c '. "$1"; fm_beacon_grace' _ "$ROOT/bin/fm-wake-lib.sh" 2>&1)"
"${CLEAN_ENV[@]}" FM_HOME="$LAB" "$ROOT/bin/fm-watch-arm.sh" > "$EV/live-A-arm.log" 2>&1 &
ARM_PID=$!
i=0
while [ "$i" -lt 60 ]; do
  grep -q '^watcher: attached' "$EV/live-A-arm.log" 2>/dev/null && break
  sleep 0.25; i=$((i + 1))
done
cat "$EV/live-A-arm.log"
kill -TERM "$ARM_PID" "$HOLDER_PID" 2>/dev/null || true
HOLDER_PID= ; ARM_PID=
sleep 0.3
rm -rf "$LAB/state/.watch.lock"

step "A2: the guard reads the same configured grace (silent at 700s, warns at 100s with grace 60)"
# A live identity-matched holder whose beacon is old: the guard judges freshness
# against the home-configured grace, not a flat default.
printf '%s\n' 'export FM_POLL=600' 'export FM_GUARD_GRACE=1200' > "$LAB/config/watch.env"
printf 'kind=ship\n' > "$LAB/state/task.meta"
sleep 300 &
HOLDER_PID=$!
IDENTITY=$(bash -c '. "$1"; fm_pid_identity "$2"' _ "$ROOT/bin/fm-wake-lib.sh" "$HOLDER_PID")
mkdir -p "$LAB/state/.watch.lock"
printf '%s\n' "$HOLDER_PID" > "$LAB/state/.watch.lock/pid"
printf '%s\n' "$LAB" > "$LAB/state/.watch.lock/fm-home"
printf '%s\n' "$ROOT/bin/fm-watch.sh" > "$LAB/state/.watch.lock/watcher-path"
printf '%s\n' "$IDENTITY" > "$LAB/state/.watch.lock/pid-identity"
: > "$LAB/state/.last-watcher-beat"
touch -d @$(( $(date +%s) - 700 )) "$LAB/state/.last-watcher-beat"
"${CLEAN_ENV[@]}" FM_HOME="$LAB" FM_ROOT_OVERRIDE="$LAB/root" FM_POLL=15 \
  FM_SUPERVISION_MODEL=persistent "$ROOT/bin/fm-guard.sh" > "$EV/live-A2-guard-1200.log" 2>&1
printf 'guard with home grace=1200, live holder, beacon 700s -> %s WATCHER DOWN lines, output bytes=%s\n' \
  "$(grep -c 'WATCHER DOWN' "$EV/live-A2-guard-1200.log" || true)" "$(wc -c < "$EV/live-A2-guard-1200.log")"
printf '%s\n' 'export FM_POLL=600' 'export FM_GUARD_GRACE=60' > "$LAB/config/watch.env"
touch -d @$(( $(date +%s) - 100 )) "$LAB/state/.last-watcher-beat"
"${CLEAN_ENV[@]}" FM_HOME="$LAB" FM_ROOT_OVERRIDE="$LAB/root" FM_POLL=15 \
  FM_SUPERVISION_MODEL=persistent "$ROOT/bin/fm-guard.sh" > "$EV/live-A2-guard-60.log" 2>&1
printf 'guard with home grace=60, live holder, beacon 100s -> %s WATCHER DOWN lines\n' \
  "$(grep -c 'WATCHER DOWN' "$EV/live-A2-guard-60.log" || true)"
grep -m1 -A2 'WATCHER DOWN' "$EV/live-A2-guard-60.log" || true
kill -TERM "$HOLDER_PID" 2>/dev/null || true
HOLDER_PID=
rm -rf "$LAB/state/.watch.lock"

# ---------------------------------------------------------------- scenario B
# A real watcher whose single check sweep runs longer than the 8s grace it was
# given: the beacon must stay fresh from inside the sweep while a check child is
# genuinely running, so the guard raises no false alarm.
step "B: a real watcher's 16s check sweep keeps the beacon fresh under grace 8; guard stays silent"
rm -f "$LAB"/state/slow-*.check.sh "$LAB"/state/slow-*.check.json
printf '%s\n' 'export FM_POLL=1' 'export FM_GUARD_GRACE=8' 'export FM_SIGNAL_GRACE=1' \
  'export FM_CHECK_INTERVAL=1' 'export FM_CHECK_TIMEOUT=30' 'export FM_HEARTBEAT=999999' \
  > "$LAB/config/watch.env"
i=0
while [ "$i" -lt 8 ]; do
  i=$((i + 1))
  printf '#!/usr/bin/env bash\nsleep 2\nexit 0\n' > "$LAB/state/slow-$i.check.sh"
  chmod 0700 "$LAB/state/slow-$i.check.sh"
  "${CLEAN_ENV[@]}" FM_HOME="$LAB" "$ROOT/bin/fm-check-register.sh" "slow-$i" >/dev/null \
    || echo "register slow-$i failed"
done
"${CLEAN_ENV[@]}" FM_HOME="$LAB" "$ROOT/bin/fm-watch.sh" > "$EV/live-B-watch.log" 2>&1 &
WATCH_PID=$!
i=0
while [ "$i" -lt 100 ]; do
  [ "$(cat "$LAB/state/.watch.lock/pid" 2>/dev/null || true)" = "$WATCH_PID" ] \
    && [ -e "$LAB/state/.last-watcher-beat" ] && [ -e "$LAB/state/.watch-cycle" ] && break
  sleep 0.1; i=$((i + 1))
done
printf 'watcher pid=%s lock=%s\n' "$WATCH_PID" "$(cat "$LAB/state/.watch.lock/pid" 2>/dev/null || true)"
CYCLE_START=$(stat -c %Y "$LAB/state/.watch-cycle")
# The cycle runs its registered check sweep before the terminal wait: sample the
# beacon while that one cycle is already older than the 8s grace.
samples=0
while :; do
  now=$(date +%s); age=$(( now - CYCLE_START ))
  printf 'sample: cycle_age=%ss beacon_age=%ss (%s checks registered)\n' "$age" \
    "$(( now - $(stat -c %Y "$LAB/state/.last-watcher-beat" 2>/dev/null || echo "$now") ))" \
    "$(ls "$LAB"/state/slow-*.check.sh 2>/dev/null | wc -l)"
  [ "$age" -ge 12 ] && break
  sleep 3; samples=$(( samples + 1 ))
  [ "$samples" -gt 8 ] && break
done
BEACON_AGE=$(( $(date +%s) - $(stat -c %Y "$LAB/state/.last-watcher-beat") ))
printf 'cycle_age=%ss beacon_age=%ss (grace 8s)\n' "$(( $(date +%s) - CYCLE_START ))" "$BEACON_AGE"
"${CLEAN_ENV[@]}" FM_HOME="$LAB" FM_ROOT_OVERRIDE="$LAB/root" FM_POLL=15 \
  FM_SUPERVISION_MODEL=persistent "$ROOT/bin/fm-guard.sh" > "$EV/live-B-guard.log" 2>&1
printf 'guard during the working sweep -> %s WATCHER DOWN lines, output bytes=%s\n' \
  "$(grep -c 'WATCHER DOWN' "$EV/live-B-guard.log" || true)" "$(wc -c < "$EV/live-B-guard.log")"

# ---------------------------------------------------------------- scenario C
# Adversarial: freeze the same real watcher mid-sweep. A frozen parent cannot
# make progress, so the beacon must age and the guard must raise the alarm even
# though its check children keep running.
step "C: SIGSTOP the same working watcher mid-sweep; the guard raises WATCHER DOWN"
kill -STOP "$WATCH_PID"
sleep 11
BEACON_AGE=$(( $(date +%s) - $(stat -c %Y "$LAB/state/.last-watcher-beat") ))
printf 'frozen watcher pid=%s beacon_age=%ss\n' "$WATCH_PID" "$BEACON_AGE"
"${CLEAN_ENV[@]}" FM_HOME="$LAB" FM_ROOT_OVERRIDE="$LAB/root" FM_POLL=15 \
  FM_SUPERVISION_MODEL=persistent "$ROOT/bin/fm-guard.sh" > "$EV/live-C-guard.log" 2>&1
printf 'guard on the frozen watcher -> %s WATCHER DOWN lines\n' \
  "$(grep -c 'WATCHER DOWN' "$EV/live-C-guard.log" || true)"
grep -m1 -A3 'WATCHER DOWN' "$EV/live-C-guard.log" || true
kill -CONT "$WATCH_PID" 2>/dev/null || true
kill -TERM "$WATCH_PID" 2>/dev/null || true
sleep 0.5
kill -KILL "$WATCH_PID" 2>/dev/null || true
WATCH_PID=
printf '\nlab teardown: rm -rf %s\n' "$LAB"

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed (4) ✅
  • ⚠️ bin/fm-watch.sh:4181 - The new background display sweeps record only FM_ACTIVE_CHECK_PID, leaving FM_ACTIVE_CHECK_PGID empty. If the watcher receives TERM while Herdr is reporting metadata or Rex is reading validation status, watcher_cleanup kills the helper shell but leaves its subprocesses running, then releases the watcher lock. A successor can therefore start while predecessor-owned operations remain active. Both launches need the existing managed process-group ownership and cleanup: bin/fm-watch.sh:4181 (Herdr) and :4193 (Rex), consumed by fm_active_check_stop at :3368.
  • ⚠️ tests/fm-watch-beacon-progress.test.sh:544 - This test stops as soon as .last-heartbeat exists, but watcher startup unconditionally creates that file at bin/fm-watch.sh:4042 before any heartbeat runs. Ignoring FM_HEARTBEAT entirely would still pass both the wait at :544 and assertion at :549. Use the documented heartbeat cadence as the oracle: wait for a scheduled heartbeat to advance the marker or produce its idle-heartbeat streak, and verify that a long configured interval does not advance it during the same observation window.

🔧 Fix applied.
2 warnings still open:

  • ⚠️ bin/fm-watch.sh:4181 - The new background display sweeps record only FM_ACTIVE_CHECK_PID, leaving FM_ACTIVE_CHECK_PGID empty. If the watcher receives TERM while Herdr is reporting metadata or Rex is reading validation status, watcher_cleanup kills the helper shell but leaves its subprocesses running, then releases the watcher lock. A successor can therefore start while predecessor-owned operations remain active. Both launches need the existing managed process-group ownership and cleanup: bin/fm-watch.sh:4181 (Herdr) and :4193 (Rex), consumed by fm_active_check_stop at :3368.
  • ⚠️ bin/fm-watch.sh:3527 - Round 1's process-group fix leaves the Rex validation-read path outside cleanup ownership. With Rex marks enabled and an expired progress cache, fm-rex-marks.sh:249 calls fm_nm_bounded, whose timeout/gtimeout branches create a separate process group (bin/fm-nm-run-lib.sh:32–33); its Perl fallback explicitly does likewise (:34). Sending TERM to the watcher during that read kills the display helper's group but leaves the query running while watcher_cleanup releases the singleton lock. The optional home-resolver call uses the same escaping boundary (:61). This remains reachable through bin/fm-watch.sh:4211 and bin/fm-rex-marks.sh:305. Propagate cancellation through the shared bounded-query boundary and wait for its owned descendants before releasing the watcher lock.

🔧 Fix applied.
1 error still open:

  • 🚨 bin/fm-nm-run-lib.sh:27 - Round 2's ownership fix breaks per-query timeout isolation. With a shell resolver that starts a slow child and waits (the shape already used by the new fixture), --foreground terminates only the resolver; its child retains stdout, so the command substitution at bin/fm-nm-run-lib.sh:66 can remain blocked beyond five seconds and stall the watcher. Both timeout backends at bin/fm-nm-run-lib.sh:34 and bin/fm-nm-run-lib.sh:35 are affected. Conversely, the Perl backend at bin/fm-nm-run-lib.sh:36 sends TERM to the entire display group, including itself and the display shell: one expired query aborts all remaining tasks instead of returning a bounded failure. These paths are enabled by bin/fm-watch.sh:3525 and reached through bin/fm-rex-marks.sh:249. Preserve query-local timeout cleanup and failure returns at fm_nm_bounded while retaining watcher cancellation ownership.

🔧 Fix applied.
✅ Re-checked - no issues remain.

  • ⚠️ tests/fm-nm-bounded-owned.test.sh:13 - The ownership-fix rounds introduced fixtures that require GNU timeout despite supporting gtimeout and Perl fallbacks. On macOS with only gtimeout or Perl, command -v timeout returns empty, generating exec &#39;&#39; &#34;$@&#34;; this shim shadows the working fallback and queries never start. The same defect occurs at tests/fm-nm-bounded-owned.test.sh:93. Resolve an available timeout/gtimeout executable before creating the shim; when neither exists, skip GNU backend emulation while retaining Perl coverage.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 5 of 5 scenarios driven live against the product
Scenario Result Live Evidence
An operator whose lab home sets FM_POLL=600 in config/watch.env runs the real arm against a live watcher with a 320s-old beacon and sees watcher: attached pid=... (beacon 320s) instead of a stale-he… ✅ pass live ~/.no-mistakes/evidence/01M77TT015RB584XQG5V31A01V/live-arm-settings-run.log (S1 section)
An operator adds export FM_GUARD_GRACE=60 to the same config/watch.env and re-arms: on the same 320s beacon the arm no longer attaches but reports `watcher: replaced stalled pid ... (beacon 320s pas… ✅ pass live ~/.no-mistakes/evidence/01M77TT015RB584XQG5V31A01V/live-arm-settings-run.log (S2 section)
Adversarial control: a lab home without config/watch.env, at the identical 320s beacon age, attaches only when the arm's own environment supplies FM_POLL=600 and is otherwise refused with `heartbeat i… ✅ pass live ~/.no-mistakes/evidence/01M77TT015RB584XQG5V31A01V/live-arm-settings-run.log (S3a/S3b sections) and live-s3b-arm.log
A home that declares its grace only in the Relay cadence file config/x-mode.env (watch.env declares just FM_POLL=600) gets that grace applied: the arm replaces a 320s stalled holder rather than attach… ✅ pass live ~/.no-mistakes/evidence/01M77TT015RB584XQG5V31A01V/live-arm-xmode-run.log
A real arm-launched watcher working a sweep several times longer than its grace keeps its liveness beacon fresh (max age stays under the grace, with multiple beacon touches inside one cycle) ✅ pass live ~/.no-mistakes/evidence/01M77TT015RB584XQG5V31A01V/live-beacon-progress-run.log
  • bash tests/fm-nm-bounded-owned.test.sh (3/3 ok)
  • bash tests/fm-watch-beacon-progress.test.sh (15/15 ok, 27s)
  • bash tests/fm-watch-wedge-cap.test.sh (all cases ok, 4m56s)
  • bash tests/fm-watch-arm.test.sh (41 ok / 0 not ok when I stopped it incomplete to stay inside the time budget; no TAP plan, so not counted as a pass)
  • Live lab scenario 1: lab home with config/watch.env exporting FM_POLL=600, real arm-started watcher, beacon backdated to 320s, second real arm -> watcher: attached pid=... (beacon 320s)
  • Live lab scenario 2: same home with export FM_GUARD_GRACE=60 added, same 320s beacon -> watcher: replaced stalled pid ... (beacon 320s past hard bound 180s), no attach
  • Live lab scenario 3 control: lab home with no config/watch.env; a 320s beacon attaches only when the arm's own environment supplies FM_POLL=600, and is refused (heartbeat is stale for 320s (&gt;300s)) without it
  • Live lab scenario 4: config/watch.env FM_POLL=600 plus config/x-mode.env FM_GUARD_GRACE=60 -> arm replaced the 320s stalled holder, proving the second file is sourced
  • Live lab scenario 5: real arm-launched watcher with five 2s checks, grace 4s -> max beacon age 2s with 7 distinct beacon touches while the same lock pid owned one 12s cycle
  • grep audit of bin/fm-watch-arm.sh after the live runs: no remaining CONFIG reference; arm runs cleanly under set -u
  • git status --porcelain in the worktree: empty (no test artifacts left behind); all /tmp/fm-lab.* homes removed and all watcher processes stopped

✅ No issues found.

  • Live validation: ✅ go - 6 of 6 scenarios driven live against the product
Scenario Result Live Evidence
After the CONFIG assignment removal, bin/fm-watch-arm.sh started with only FM_HOME in a marked lab home loads config/watch.env and attaches to a live identity-matched holder whose beacon is 700s old w… ✅ pass live live-lab-scenarios.log section A: watcher: attached pid=1460132 (beacon 700s) and fm_beacon_grace in lab home = 1200
bin/fm-guard.sh judges freshness against the home-configured grace: silent for a 700s beacon with config/watch.env grace 1200, and raises WATCHER DOWN naming 'grace 60s' for a 100s beacon after the fi… ✅ pass live live-lab-scenarios.log section A2 plus live-A2-guard-1200.log (0 bytes) and live-A2-guard-60.log (banner 'last beat: 100s ago, grace 60s')
A real watcher running an 8-check sweep longer than its 8s grace keeps its liveness beacon refreshed from inside the cycle, so bin/fm-guard.sh stays silent while the cycle is still progressing past th… ✅ pass live live-lab-scenarios.log section B: cycle_age 9-12s with beacon_age 1-2s, guard during the working sweep -&gt; 0 WATCHER DOWN lines, output bytes=0
Adversarial: a watcher SIGSTOPped mid-sweep cannot refresh its beacon, so after 13s it exceeds its 8s grace and bin/fm-guard.sh raises WATCHER DOWN ✅ pass live live-lab-scenarios.log section C: frozen watcher pid=1460990 beacon_age=13s, guard raised 1 WATCHER DOWN with grace 8s
An expired no-mistakes query run through the real bounded-query boundary stops its descendants when the watcher cancels the display group, preserves stdout and exit status, and lets the next query run ✅ pass live test-nm-bounded.log: 3 ok (status and resolver query descendants stop on display cancellation, owned and standalone bounded queries preserve stdout and status, `expired queries close descendant ou…
The whole beacon contract holds in real processes: refresh is throttled and inert outside a watcher, child sweeps update only the progress marker, every sweep and terminal-wait branch refreshes progre… ✅ pass live test-beacon-progress.log: 18 ok, FM_TEST_COMPLETE, exit 0 (real bin/fm-watch.sh, bin/fm-guard.sh, bin/fm-watch-arm.sh processes in isolated homes)
  • bash tests/fm-watch-beacon-progress.test.sh (18 real-process cases: throttle/inertness, crew+secondmate+check+terminal-wait progress refresh, home cadence and Relay precedence, stalled-holder banner and eviction, frozen watcher during a display sweep) -> FM_TEST_COMPLETE, exit 0
  • bash tests/fm-nm-bounded-owned.test.sh (real timeout/gtimeout/Perl bounded queries: owned and standalone descendants stop on display cancellation, stdout/status preserved, expired query frees the next) -> exit 0
  • bash tests/fm-watch-wedge-cap.test.sh (changed wedge-cap coverage) -> 23 ok, exit 0
  • bash ~/.no-mistakes/evidence/01M77TT015RB584XQG5V31A01V/live-lab-scenarios.sh (lab minted with bin/fm-lab-home.sh create, torn down in the same run): bin/fm-watch-arm.sh attaches to a live 700s beacon under home FM_GUARD_GRACE=1200; bin/fm-guard.sh silent at 700s/1200 and warns WATCHER DOWN 'grace 60s' at 100s/60; a real watcher's 12s+ check sweep keeps beacon_age 1-2s under grace 8 with guard silent; SIGSTOP mid-sweep ages the beacon to 13s and the guard raises WATCHER DOWN
🔧 **Document** - 1 issue found → no changes applied ✅
  • 🚨 bin/fm-test-run.sh:973 - The branch adds tests/fm-nm-bounded-owned.test.sh to the portable serial lane with no duration hint, so bin/fm-test-run.sh --check-coverage now reports 45 of 299 unhinted scripts (15.05%) against its 15% limit and exits 1; the base state passed at 44/298. Fixing it needs a hint line in the single shared table (beside tests/fm-watch-beacon-progress.test.sh 45000) plus a provenance entry in docs/fm-test-portable-shards.md; local samples here were 3000-4000 ms. That is test-harness configuration, not documentation, so this phase could not apply it without changing executable behavior.

🔧 No changes applied.
1 error still open:

  • 🚨 bin/fm-test-run.sh:973 - Carried over unresolved from the previous round and still reproducible: bin/fm-test-run.sh --check-coverage exits 1 with 45 of 299 unhinted portable-serial scripts (15.05% against a 15% limit) because this branch adds tests/fm-nm-bounded-owned.test.sh with no measured duration hint. This document phase cannot close it: the repair is harness configuration, not documentation - a tests/fm-nm-bounded-owned.test.sh &lt;ms&gt; row beside tests/fm-watch-beacon-progress.test.sh 45000 in portable_serial_weight_hints, plus its provenance sentence in docs/fm-test-portable-shards.md. Editing the runner's hint table would change executable harness behavior (shard packing and the guard's own verdict), which this phase must not do. Two local samples here were 3-4 s (bash tests/fm-nm-bounded-owned.test.sh, exit 0 both times), so a CI-scaled hint around 8000-9000 ms fits the existing provisional-hint convention. I deliberately did not add the docs provenance line alone, because it would document a hint the table does not contain.

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues remain from this review.

Reviews (7) · Last reviewed commit: "no-mistakes(document): docs: fix hint pr..." · Reviewed by Greptile

Comment thread bin/fm-watch.sh Resolved
@kesslerio kesslerio changed the title fix(bin): keep the watcher beacon fresh across long cycle sweeps fix(watch): keep the liveness beacon fresh as a cycle makes progress Nov 12, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @kesslerio. I read the full diff against latest main 47df77f3. The problem is real: a watcher that is still working through a long cycle shouldn't read as down, and its successor arm shouldn't refuse it. Having one fm_beacon_grace entry point instead of a flat 300 s in each reader also tidies up what main's own docs list as stragglers. The no-mistakes check passes, the attestation binds 5826e0f7 with no skipped steps, and the coverage guard and repo invariants pass.

One thing is waiting on you: Greptile's open P1 (Frozen watcher looks healthy). Exporting FM_WATCH_BEACON_PATH lets bin/fm-rex-marks.sh (a separate process, via sync_task) keep refreshing the beacon while the watcher itself is stopped. fm_watcher_healthy still accepts the stopped pid, so the guards stay quiet and replacement is delayed. Your new docs/turnend-guard.md section says "no helper process can make a wedged watcher look healthy", so this contradicts the PR's own contract. It is also the one scenario your pipeline didn't drive live (Rex mark-sync). Either tie child refreshes to the watcher's own progress, for example by refreshing only from the watcher process between child calls, or show why the child can't outlive a stopped parent. Add a test that freezes the watcher during a display sweep, and resolve the thread. After that, I'll queue the full suite. The "Full suite" check without the label isn't something you need to act on.

contract-class: new-default. On main, the beacon is touched once per cycle, and the guard, arm and turn-end readers use a flat 300 s. With this PR, every home's beacon becomes a mid-cycle progress signal refreshed by the cycle's sweeps, with a new state/.watch-cycle marker for cycle counting. With the default FM_POLL the grace is still 300 s, but what "fresh" means changes for every home. So once the full suite is green, this goes to the captain for a decision rather than auto-merging.

VISION: One captain aligns in purpose (no false "watcher down"), but a frozen watcher must not look healthy ("never hide a failure") · Authority neutral · Scripts aligns (deterministic throttle, one grace entry point) · Restart aligns in purpose, cannot tell while the P1 is open · Delegation cannot tell (supervision liveness) · Vendor neutral · Scope aligns.

@kesslerio kesslerio changed the title fix(watch): keep the liveness beacon fresh as a cycle makes progress fix(bin): keep the watcher liveness beacon fresh across long cycles Nov 12, 2026
@kunchenguid kunchenguid added the full-ci Maintainer go-ahead: run the full CI suite on this outside pull request label Nov 12, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @kesslerio. The P1 is fixed on 05abb9ea. Child sweeps (Rex marks, Herdr groups) now touch a separate state/.last-watcher-progress marker. Only the watcher process copies that progress to the beacon, and it does so between child calls. So a SIGSTOPped watcher's beacon still goes stale and the guard raises WATCHER DOWN. test_frozen_watcher_during_display_sweep_trips_guard shows that, and so does your live run (11/11, including the pre-fix mutation check). The thread is resolved, and Greptile re-reviewed this head at 5/5.

Checks on this head: no-mistakes passes, and the attestation binds 05abb9ea with no skipped steps. The coverage guard and repo invariants pass. There are no workflow, CI-config, credential or checksum changes. It still merges cleanly with main a9ae3c0c.

I've queued the full suite. Status: waiting on CI, not on you.

contract-class: new-default (unchanged from my last note). Every home's beacon becomes a mid-cycle progress signal, and the readers move from a flat 300 s to fm_beacon_grace. If the full suite is green, this goes to the captain for a decision rather than auto-merging.

The turn-end guard, the pull warning, and the arm that replaces a stalled
watcher all judge one liveness beacon with a flat 300-second grace, but a
single poll cycle walks the pending-reply sweep, the per-window stale loop,
the per-status heartbeat scan, and the per-check sweep with a subprocess per
unit. On a home with a deep pending-reply backlog one cycle ran past 590s with
the beacon untouched while the watcher was genuinely working (another ran
1997s and delivered an actionable check at the end), so a live cycle raised the
watcher-down banner and a successor refused that same live holder as stale
until the 3x stall bound - the false alarm and the blocked replacement were the
same failure.

Cycle sweeps now refresh the beacon between units through
fm_watch_beacon_progress: a throttled, fork-free touch that acts only when a
live watcher exported its beacon path, so a working cycle stays fresh while a
genuinely wedged one stops advancing and ages exactly as before. Counting
completed cycles moves to its own state/.watch-cycle marker, because the beacon
is now a progress signal rather than a cycle tick.

Every beacon reader derives its grace from the poll cadence through
fm_beacon_grace (an explicit FM_GUARD_GRACE, else max(300, FM_POLL+60)), so the
guard, the arm, and the watcher's own re-arm agree on what fresh means.
FM_GUARD_GRACE, FM_HEARTBEAT, and FM_WATCHER_STALL_BOUND still win as explicit
overrides, and the banner keeps naming the grace it judged.
turnend-guard.md owns the liveness contract, so it now states that the beacon
tracks cycle progress, what that does and does not guarantee, and that
state/.watch-cycle is the cycle boundary. Its grace section names the one
shared derivation and every reader instead of listing readers that fall back to
a bare 300 seconds. watcher-continuity.md and configuration.md stop claiming the
flat default.
…ite tests/fm-watch-beacon-progress.test.sh had no portable-serial duration hint, so the coverage guard measured 45/298 unhinted (15.1%) against its 15% limit and failed. Added a provisional 45000 ms hint in the single shared table in bin/fm-test-run.sh, based on two local runner samples (18426/18470 ms) scaled for CI, and recorded its provenance in docs/fm-test-portable-shards.md. The guard now reports serial_unhinted=44 of 298 (14.8%) and exits 0. The Full suite verdict failure is not independently code-caused: the failing run was a labeled event with a non-full-ci label, so every behavior lane was skipped, repo invariants passed, and the coverage guard was the only failed needed job. The remaining Full suite gate is the maintainer full-ci label. Verified: bin/fm-test-run.sh --check-coverage passes; the beacon progress suite passes all 13 tests; the changed fm-watch-wedge-cap suite passes; and the runner's hint-coverage and packing-boundary tests pass. Local-only failures in unrelated harness tests came from this NixOS/container host (pty reparenting, missing ruby), not from the change
@kesslerio
kesslerio force-pushed the fix/watcher-beacon-progress branch from 05abb9e to 1ab9157 Compare November 12, 2026 13:18
@kesslerio kesslerio changed the title fix(bin): keep the watcher liveness beacon fresh across long cycles fix(bin): keep the watcher beacon fresh while a cycle progresses Nov 12, 2026
Comment thread tests/fm-nm-bounded-owned.test.sh Resolved
…: 1. Test coverage guard and Behavior portable parallel 2 (same root cause): tests/fm-test-run.test.sh runs bin/fm-test-run.sh --check-coverage, which found 45 of 299 portable serial scripts unhinted (>15%) because the PR added tests/fm-nm-bounded-owned.test.sh without a duration hint. Once hinted realistically, the serial packing model also exceeded its 1,200,000 ms budget because the provisional 45000 ms hint for tests/fm-watch-beacon-progress.test.sh was an overestimate. I added the completed passing Ubuntu FM_TEST_END durations from CI run 43226301857: 3712 ms for fm-nm-bounded-owned and 30149 ms for fm-watch-beacon-progress (replacing the provisional 45000 ms), and recorded provenance in docs/fm-test-portable-shards.md. bin/fm-test-run.sh --check-coverage now reports 44/299 unhinted and serial_max_ms=1198795 <= 1200000. 2. Lint 1: new source lines could not be followed under --external-sources, producing SC1091/SC2153 in tests/fm-nm-bounded-owned.test.sh and SC1091 in bin/fm-supervision-lib.sh. Added shellcheck source directives for tests/lib.sh and bin/fm-wake-lib.sh. 3. Full suite is the dependent aggregator and failed only because the lanes above failed; fixing them resolves it with no separate code change. Local verification: bin/fm-test-run.sh --check-coverage passes; explicit ShellCheck and bin/fm-lint.sh --partition 1of2 pass; changed files in partition 2 report reason=ok; tests/fm-nm-bounded-owned.test.sh and tests/fm-watch-beacon-progress.test.sh pass; the coverage tests in tests/fm-test-run.test.sh pass. A later, unrelated tests/fm-session-lock-ancestry.test.sh case fails on this host because it expects orphans to be reparented to PID 1, which this container does not do; it is not in the changed area and does not affect the CI fix
@kesslerio kesslerio changed the title fix(bin): keep the watcher beacon fresh while a cycle progresses fix(watch): keep the watcher liveness beacon fresh across long cycles Nov 12, 2026
@kunchenguid kunchenguid added full-ci Maintainer go-ahead: run the full CI suite on this outside pull request and removed full-ci Maintainer go-ahead: run the full CI suite on this outside pull request labels Nov 12, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @kesslerio. I re-read the change on the new head e85b5c26, rebased onto main a9ae3c0c, so it is 0 behind. It has grown since 05abb9ea. fm_nm_bounded now runs each no-mistakes query in its own process group and propagates HUP/INT/TERM cancellation (the perl fallback now kills only its child). The Herdr/Rex display sweeps run as managed process groups. fm-watch-arm.sh and the watcher share one watch.env/x-mode.env loader. tests/fm-nm-bounded-owned.test.sh is new. Greptile re-reviewed this head at 5/5, both threads are resolved, the no-mistakes check passes, the attestation binds e85b5c26 with no skipped steps, live is go (6 of 6), and there are no workflow, CI-config, credential or checksum changes.

The labelled run on this head (43241299800) passed every Behavior lane and Lint 1. Lint 2 was cancelled at the 30-minute cap after all 304 files finished with rc=0. That's a CI capacity problem, not this PR, so I've re-queued the full suite. Status: waiting on CI, not on you.

contract-class: new-default (unchanged). If the suite is green, this goes to the captain for a decision, with the wider no-mistakes-query scope noted on the card.

@kesslerio kesslerio closed this Nov 13, 2026
@kesslerio kesslerio reopened this Nov 13, 2026
@kesslerio kesslerio closed this Nov 13, 2026
@kesslerio kesslerio reopened this Nov 13, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: the full suite is green on e85b5c26 (run 43380694686, all 22 jobs pass), and every other gate still holds. The head hasn't changed since my last note, and your close and reopen only retriggered CI. The no-mistakes attestation binds this head with no skipped steps, live is go (6 of 6), Greptile is 5/5 with both threads resolved, and it merges cleanly with current main 07409e73.

Status: with the captain for a decision. This isn't waiting on you, @kesslerio. Contract class (my own read): new-default. The beacon refresh, the process-group handling in fm_nm_bounded and the display sweeps, and the shared settings loader all change the unconfigured watcher path, so Kun makes the merge-or-leave call instead of an auto-merge. The card calls out the wider fm_nm_bounded scope. There's nothing more for you to do here unless he asks.

@kesslerio

Copy link
Copy Markdown
Contributor Author

Gentle nudge @kunchenguid — this one is fully green (24/24, full labelled suite on e85b5c26) and parked at the new-default flag for your merge-or-leave call. For the wider queue: #7607, #7613, #8019, #6753 and the rest of the open set are all mergeable or green awaiting the same decision batch — several have been at that gate since Nov 9. No rush implied; just confirming nothing on our side is holding them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-ci Maintainer go-ahead: run the full CI suite on this outside pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants