Skip to content

fix(bin): retain Pi watcher predecessor to stop false down alarms - #5174

Merged
kunchenguid merged 3 commits into
kunchenguid:mainfrom
sdivanl:fm/fm-watcher-down-guard-false-alarm
Sep 22, 2026
Merged

kunchenguid merged 3 commits into
kunchenguid:mainfrom
sdivanl:fm/fm-watcher-down-guard-false-alarm

Conversation

@sdivanl

@sdivanl sdivanl commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Fix the recurring Firstmate supervision-monitoring dropouts without suppressing genuine outage alarms. Monitoring has repeatedly reported itself down while work is active, and several repairs genuinely had to start a replacement monitoring process, so this is not only a cosmetic warning.

What Changed

  • The Pi primary watcher now writes a generation id and active/handoff phase into its extension marker; on ordinary same-process replacement, session_shutdown flips the marker to handoff and keeps the established predecessor arm child alive until a distinct active successor generation commits its own tracked replacement arm, rather than tearing it down immediately.
  • fm_pi_extension_loaded takes an optional required phase, and fm_pi_extension_owns_supervision now requires the watcher marker to be active, so a handoff marker left behind by a generation whose replacement never loaded the extension can no longer satisfy the fresh-beacon tolerance and suppress a genuine outage diagnostic.
  • Generation ids are tracked on the replacement coordinator (surviving extension-module rebinds), omp keeps its documented teardown-and-rearm replacement shape, and the guard, session-start, and Pi extension suites plus continuity/supervision docs cover the retained predecessor, bounded retry, and the still-loud stopped-chain alarm.

Risk Assessment

✅ Low: The change is well-bounded: it adds a generation-bound active/handoff marker and retains the established Pi arm child across same-process replacement until the successor's --restart retires it, with the shell guard now rejecting handoff/legacy markers; I found no concrete reachable path producing a wrong result, suppressed genuine alarm, or false alarm, and the changed tests exercise the observable lifecycle and guard behavior.

Testing

I drove the changed Pi supervision surface against the real product. The opt-in live E2E (FM_PI_LIVE_E2E=1 FM_PI_LIVE_WATCH_ONLY=1 tests/fm-pi-primary-live-e2e.test.sh) ran a real Pi 0.86.1 session through three consecutive actionable watcher closes, confirming each restored a ledger-linked successor before wake handling with no turn-end-blind warning, then intentionally stopped the live chain and confirmed the guard still emitted WATCHER DOWN - SUPERVISION IS OFF. Because that E2E does not perform a same-process session replacement, I additionally ran a manual live /new scenario against real Pi in an isolated tmux socket/home: the extension marker moved generation=1 phase=active -> phase=handoff -> generation=2 phase=active, the predecessor arm stayed alive through the uncommitted handoff, a distinct live successor watcher committed, the predecessor retired, and the real guard raised no outage alarm. I also drove the real bin/fm-guard.sh against an isolated home holding a live session lock: a handoff-phase marker and a legacy 2-line marker each still produced the outage alarm, while a distinct active-generation marker was tolerated. The targeted deterministic suites for the extension, guard, and session-start all passed. The only surface I could not exercise live is the fm-session-start.sh diagnostic with a handoff marker, because a real Pi successor always reloads the tracked extension; that path is covered by tests/fm-session-start.test.sh. No UI surface is involved, so there is no screenshot artifact; evidence is the live CLI/guard transcripts.

  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
With supervision armed in a real Pi session, issuing /new retains the predecessor arm through a handoff generation, commits a distinct active successor with a live watcher, and raises no supervision-d… ✅ pass live ~/.no-mistakes/evidence/01M32J37994HCXQ8EAXFWKD1WC/pi-new-replacement-live.log (real Pi 0.86.1 in a private tmux socket and isolated FM_HOME; owner went generation=1 phase=active -> phase=ha…
Three consecutive actionable watcher closes in a live Pi session each restore a ledger-linked successor before the wake is handled, with no turn-end-blind warning and no model re-arm ✅ pass live ~/.no-mistakes/evidence/01M32J37994HCXQ8EAXFWKD1WC/pi-live-watch-only-e2e.log and FM_PI_LIVE_E2E=1 FM_PI_LIVE_WATCH_ONLY=1 bash tests/fm-pi-primary-live-e2e.test.sh
Intentionally stopping the live Pi arm/watcher chain still raises the genuine outage alarm after the grace period ✅ pass live Same live E2E: after replacing the isolated arm command with an intentional failure and stopping the live chain, bin/fm-guard.sh still printed WATCHER DOWN - SUPERVISION IS OFF; see pi-live-watch-…
A Pi watcher marker left in the handoff phase, or a legacy marker without a generation, cannot vouch for an unheld watcher: the real guard still alarms, while a distinct active-generation marker is to… ✅ pass live ~/.no-mistakes/evidence/01M32J37994HCXQ8EAXFWKD1WC/guard-handoff-marker-live.log (real bin/fm-guard.sh: handoff -> WATCHER DOWN, active -> no output, legacy 2-line -> WATCHER DOWN)
Running bin/fm-session-start.sh with a Pi watcher marker left in handoff prints PI_WATCH_EXTENSION: not loaded ⏸️ untested no A real Pi successor session always auto-loads the tracked extension, so the 'replacement extension absent, marker frozen in handoff' state cannot be produced in a live Pi session without patching Pi.…
Evidence: Live Pi /new replacement transcript (real Pi 0.86.1)

Source: Live Pi /new replacement transcript (real Pi 0.86.1)

startup: watcher=4780 arm=4742 owner='generation=1 phase=active' == sending /new == after /new: owner='generation=2 phase=active' saw_handoff=1 pred_alive_during=1 samples=11 successor: watcher=6206 arm=6184 guard output after /new: == sending /quit == ok - real Pi 0.86.1 live /new replacement retained the predecessor under a handoff generation, committed a distinct active successor with a live watcher, and raised no supervision-dropout alarm

== setting up isolated lab ~/.no-mistakes/worktrees/bfc710bdae80/01M32J37994HCXQ8EAXFWKD1WC/.pi-new-live.4665 ==
startup: watcher=4780 arm=4742 owner='generation=1 phase=active'
== sending /new ==
after /new: owner='generation=2 phase=active' saw_handoff=1 pred_alive_during=1 samples=11
successor: watcher=6206 arm=6184
guard output after /new:

== sending /quit ==
ok - real Pi 0.86.1 live /new replacement retained the predecessor under a handoff generation, committed a distinct active successor with a live watcher, and raised no supervision-dropout alarm
Evidence: Live Pi watch-only E2E result (real Pi 0.86.1)

Source: Live Pi watch-only E2E result (real Pi 0.86.1)

ok - Pi 0.86.1 live E2E covered repeated successor handoffs and a genuine stopped-chain alarm

ok - Pi 0.86.1 live E2E covered repeated successor handoffs and a genuine stopped-chain alarm
Evidence: Live adversarial guard marker-phase transcript

Source: Live adversarial guard marker-phase transcript

--- handoff marker (expect alarm) --- WATCHER DOWN - SUPERVISION IS OFF --- active marker (expect tolerance) --- (no output) --- legacy marker (expect alarm) --- WATCHER DOWN - SUPERVISION IS OFF ok - real fm-guard.sh rejects handoff and legacy markers as outage evidence, tolerates only a distinct active generation

--- handoff marker (expect alarm) ---
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 0s ago).
●  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.
●  repair a missing or failed watcher cycle with the Pi tool fm_watch_arm_pi, or restart Pi with -e /tmp/fm-guard-handoff.wDKuQN/root/.pi/extensions/fm-primary-turnend-guard.ts -e /tmp/fm-guard-handoff.wDKuQN/root/.pi/extensions/fm-primary-pi-watch.ts if the extensions are not loaded.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
--- active marker (expect tolerance) ---

--- legacy marker (expect alarm) ---
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 0s ago).
●  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.
●  repair a missing or failed watcher cycle with the Pi tool fm_watch_arm_pi, or restart Pi with -e /tmp/fm-guard-handoff.wDKuQN/root/.pi/extensions/fm-primary-turnend-guard.ts -e /tmp/fm-guard-handoff.wDKuQN/root/.pi/extensions/fm-primary-pi-watch.ts if the extensions are not loaded.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ok - real fm-guard.sh rejects handoff and legacy markers as outage evidence, tolerates only a distinct active generation

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
With supervision armed in a real Pi session, issuing /new retains the predecessor arm through a handoff generation, commits a distinct active successor with a live watcher, and raises no supervision-d… ✅ pass live ~/.no-mistakes/evidence/01M32J37994HCXQ8EAXFWKD1WC/pi-new-replacement-live.log (real Pi 0.86.1 in a private tmux socket and isolated FM_HOME; owner went generation=1 phase=active -> phase=ha…
Three consecutive actionable watcher closes in a live Pi session each restore a ledger-linked successor before the wake is handled, with no turn-end-blind warning and no model re-arm ✅ pass live ~/.no-mistakes/evidence/01M32J37994HCXQ8EAXFWKD1WC/pi-live-watch-only-e2e.log and FM_PI_LIVE_E2E=1 FM_PI_LIVE_WATCH_ONLY=1 bash tests/fm-pi-primary-live-e2e.test.sh
Intentionally stopping the live Pi arm/watcher chain still raises the genuine outage alarm after the grace period ✅ pass live Same live E2E: after replacing the isolated arm command with an intentional failure and stopping the live chain, bin/fm-guard.sh still printed WATCHER DOWN - SUPERVISION IS OFF; see pi-live-watch-…
A Pi watcher marker left in the handoff phase, or a legacy marker without a generation, cannot vouch for an unheld watcher: the real guard still alarms, while a distinct active-generation marker is to… ✅ pass live ~/.no-mistakes/evidence/01M32J37994HCXQ8EAXFWKD1WC/guard-handoff-marker-live.log (real bin/fm-guard.sh: handoff -> WATCHER DOWN, active -> no output, legacy 2-line -> WATCHER DOWN)
Running bin/fm-session-start.sh with a Pi watcher marker left in handoff prints PI_WATCH_EXTENSION: not loaded ⏸️ untested no A real Pi successor session always auto-loads the tracked extension, so the 'replacement extension absent, marker frozen in handoff' state cannot be produced in a live Pi session without patching Pi.…
  • bash tests/fm-pi-watch-extension.test.sh (50 assertions, including Pi actionable output waits for predecessor close before successor restoration, Pi session transitions auto-arm through a generation owner across /new /resume /fork/reload, stale callbacks, and quit, Pi replacement handoff tokens stay unique across fresh modules, Pi replacement persistence failure keeps its predecessor until a successor commits)
  • bash tests/fm-guard-stale-banner.test.sh (including the extension-ownership cases handoff-watch-generation and legacy-watch-marker)
  • bash tests/fm-session-start.test.sh (including session start rejects a Pi watcher generation left in handoff)
  • FM_PI_LIVE_E2E=1 FM_PI_LIVE_WATCH_ONLY=1 bash tests/fm-pi-primary-live-e2e.test.sh against real Pi 0.86.1 with the tracked extension
  • Manual live drive /tmp/fm-pi-new-live.sh: real Pi in a private tmux socket and isolated FM_HOME, /new sent during armed supervision, sampled marker phase and arm PIDs
  • Manual live adversarial drive /tmp/fm-guard-handoff-live.sh: real bin/fm-guard.sh against an isolated home with handoff, active, and legacy Pi watcher markers
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: stamped waiting-author.

HEAD b6c56acdfca35553986b16bd10332c84380dce5c. Attestation MATCH. workflow-zero yes. MERGEABLE.

contract-class: restore — tip restores the existing Pi supervision continuity path (no false WATCHER DOWN during ordinary same-process /new replacement) by retaining the predecessor arm under a handoff generation until a distinct active successor commits; omp keeps teardown-and-rearm (scoped). Guard still alarms on handoff/legacy markers. Not a new always-on surface.

VISION: One captain/interface aligns (honest supervision alarms, fewer false outages); Authority aligns (no consent widen); Scripts/judgment aligns (extension + shell guard); Restart aligns (generation/handoff markers durable); Delegation aligns (continuity spine); Fleet/vendor aligns (Pi adapter; omp deliberately different); Scope aligns (supervision mechanics, not workshop). Align: deepens confidence looking away.

CI: NM green (35638624001). CI run 35638624043 — Stock macOS Bash snapshot compatibility FAILED: stock Bash 3.2 failed to parse tests/fm-pi-watch-extension.test.sh (annotations on check 106462193595). Lint 1 also reported exit 143 while the run was still in progress. Other shards still pending/partial. Please fix the Bash 3.2 parse error in that test file and push; then we can re-evaluate for auto-merge once green + MATCH.

Overlaps files with open #5172 (.pi/extensions/fm-primary-pi-watch.ts, bin/fm-wake-lib.sh, omp watch, watcher-continuity docs, pi-watch tests) — land order may need a rebase of the loser after the first merges.

Firstmate-flag: no (author/CI blockers remain).

…e-caused. (ci-3, genuine) Stock macOS Bash snapshot compatibility: `tests/fm-pi-watch-extension.test.sh` failed the macOS Bash 3.2 `bash -n` parse sweep with `line 4265: unexpected EOF while looking for matching '`. I built GNU Bash 3.2.0 from source locally and reproduced it. Root cause: the PR added a comment containing an apostrophe (`// Replacement shutdown deliberately retains module 2's established arm until`) inside a quoted here-document (`<<'EOF'`) nested inside a `$(...)` command substitution. Bash 3.2 has a parser bug (fixed in later bash) where an unmatched single quote inside such a here-doc body is treated as opening a shell quote and never closed, aborting the whole file parse. The base commit parses cleanly under Bash 3.2, confirming this PR introduced the break. Minimal fix: reworded the comment to remove the apostrophe (`... retains the established module-2 arm until`), preserving meaning. Verified `bin/fm-lint.sh --list-files` (the 6 changed shell files) now all pass `/tmp/bash-3.2/bash -n`; Bash 5 also parses. (ci-1, infrastructure) Behavior portable serial 8: GitHub API shows the `Run portable serial shard 8` step conclusion=success; only `Upload portable serial shard 8 timing artifact` failed with `Failed to FinalizeArtifact ... (403) Forbidden`. This is a transient artifact-service/cancellation failure, not a test or code failure. No change. (ci-2, infrastructure) Lint 1: fetched the job log via the GitHub API; it ends with `##[error]The runner has received a shutdown signal...` then exit 143. The step was cancelled mid-run, not a ShellCheck finding. Independently ran `bin/fm-lint.sh --partition 1of2 --telemetry ...` locally with pinned ShellCheck 0.11.0 and actionlint 1.7.12: exited rc=0 (no findings). No change. The only code change is the apostrophe removal in tests/fm-pi-watch-extension.test.sh; no other files modified
@sdivanl

sdivanl commented Sep 22, 2026

Copy link
Copy Markdown
Contributor Author

Bash 3.2 parse error in tests/fm-pi-watch-extension.test.sh is fixed and pushed.

Head: e776dea156228d5edabefaa64943a51b62b6eadc

All 19 checks pass at that head, including Stock macOS Bash snapshot compatibility, which was the lane that failed at b6c56acd. Ready for re-evaluation.

@kunchenguid
kunchenguid merged commit 3fcbc6c into kunchenguid:main Sep 22, 2026
19 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @sdivanl — really appreciate you taking the time on this.

Pre-merge recheck at HEAD e776dea156228d5edabefaa64943a51b62b6eadc: attestation MATCH; workflow-zero yes; all 19 tip checks green (NM 35643169919, CI 35643169916 including Stock macOS Bash snapshot). Bash 3.2 parse fix confirmed.

contract-class: restore — restores existing Pi supervision continuity (no false WATCHER DOWN on ordinary same-process /new replacement) by retaining the predecessor arm under a handoff generation until a distinct active successor commits; omp stays teardown-and-rearm (scoped). Guard still alarms on handoff/legacy markers.

VISION: One captain/interface aligns (honest supervision alarms); Authority aligns; Scripts/judgment aligns (extension + shell guard); Restart aligns (generation/handoff durable); Delegation aligns (continuity spine); Fleet/vendor aligns (Pi adapter; omp deliberately different); Scope aligns. Align.

Overlaps files with open #5172 / #3986 — left on their queues (not superseded wholesale).

sandeepsalwan1 added a commit to sandeepsalwan1/mac-setup that referenced this pull request Sep 22, 2026
Summary:
- Record FirstMate's watcher continuity fix.
- Refresh the vendored Lavish skill from its reviewed upstream commit.

Testing:
- ./tests/check.sh

Related:
- kunchenguid/firstmate#5174
- kunchenguid/lavish-axi@a3b3987
BohnBawerick added a commit to BohnBawerick/firstmate that referenced this pull request Sep 23, 2026