Skip to content

fix(pi): harden primary watcher wedge recovery - #614

Closed
RajeshThallam wants to merge 14 commits into
kunchenguid:mainfrom
RajeshThallam:fm/pi-watch-wedge-s4
Closed

RajeshThallam wants to merge 14 commits into
kunchenguid:mainfrom
RajeshThallam:fm/pi-watch-wedge-s4

Conversation

@RajeshThallam

Copy link
Copy Markdown

Intent

Fix the Pi primary supervision false-health wedge reproduced on 2026-07-15, including the repeat child-4 recurrence with a 1,922-second stale beacon. Diagnose and fix the nested fm-watch.sh process-chain hang, and harden fm_watch_arm_pi so it reconciles process exit, stale beacons, canonical lock identity, inherited-pipe descendants, and repeated arm calls without duplicate watchers, broad pkill, layout mutation, or captain intervention. Preserve the Pi tool schema and clean-exit behavior, add deterministic watcher and real isolated Pi lifecycle coverage, record dated empirical evidence in the owning docs, and validate focused tests, strict Pi typecheck, lint, broader affected tests, PR, and CI.

What Changed

  • Hardened Pi primary watcher recovery so fm_watch_arm_pi revalidates health through the shared watcher lock and beacon state, reuses an in-flight startup child, and reaps owned detached watcher groups instead of treating a stale child reference as healthy.
  • Bounded bin/fm-watch.sh native event capability probes and waits, kept the watcher beacon advancing while those subprocesses run, and killed the exact timed-out process tree so hung backend calls cannot wedge the watcher behind inherited pipes.
  • Canonicalized watcher-path lock identity across aliased roots, added focused regression coverage for stale-beacon recovery, repeated arm calls, delayed-close descendants, and hung event probes, and updated the Pi supervision docs with the 2026-07-15 recurrence and verification notes.

Risk Assessment

✅ Low: The remaining diff is narrow, directly addresses the prior startup-retry race, and I did not find new material correctness or intent-conformance issues in the reviewed changes.

Testing

Completed 1 recorded test check.

  • Outcome: ⚠️ 1 error across 1 run (13m46s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed (3) ✅
  • 🚨 .pi/extensions/fm-primary-pi-watch.ts:166 - The required intent says to handle "repeated arm calls without duplicate watchers", but a second fm_watch_arm_pi call during the initial startup window will tear down the first arm cycle instead of reusing it. In .pi/extensions/fm-primary-pi-watch.ts, any existing child is treated as stale unless healthyWatcherPid() already resolves, so quick retries can keep killing a legitimate in-flight arm before it ever becomes healthy.
  • ⚠️ .pi/extensions/fm-primary-pi-watch.ts:204 - The new exact-group cleanup can still target the wrong processes after the arm shell exits. .pi/extensions/fm-primary-pi-watch.ts clears child on exit, but the old pid stays in ownedGroups until close; a later stopOwnedGroups() then sends kill -TERM/-KILL to that raw negative pid with no identity check. In a delayed-close window, PID reuse can make that process-group id belong to something unrelated.

🔧 Fix: Reuse starting watcher and reap exited groups
2 issues (1 error, 1 warning) still open:

  • 🚨 .pi/extensions/fm-primary-pi-watch.ts:197 - The intent explicitly requires repeated arm calls "without duplicate watchers", but there is still a startup race after the watcher lock is written and before the first beacon touch. In .pi/extensions/fm-primary-pi-watch.ts any non-empty ownedWatcherPid() forces stopArm(), while the watcher only writes .last-watcher-beat later in bin/fm-watch.sh. A second fm_watch_arm_pi call in that gap still kills the in-flight arm instead of reusing it.
  • ⚠️ tmp.pi-debug.dDetS6/repo/.pi/extensions/fm-primary-pi-watch.ts:1 - The current tree includes committed local debug artifacts under tmp.pi-debug*, including duplicate source files, fixture node_modules, and captured outputs such as tmp.pi-debug.dDetS6/repo/.pi/extensions/fm-primary-pi-watch.ts. These files are unrelated to the feature, add thousands of lines to the review scope, and will pollute repo-wide searches and future maintenance if merged.

🔧 Fix: Harden Pi watcher startup retry handling
1 error still open:

  • 🚨 .pi/extensions/fm-primary-pi-watch.ts:194 - The required intent says repeated arm calls must work "without duplicate watchers", but the new startup guard still depends on the old beat file being strictly older than the new child start time. In .pi/extensions/fm-primary-pi-watch.ts beatPredatesChildStart() uses <, and line 210 only reuses the in-flight child when that predicate is true. On a rapid re-arm or a filesystem with coarse mtime resolution, the previous cycle's .last-watcher-beat can land in the same timestamp tick as childStartedAt, making the extension tear down and restart the same startup child again.

🔧 Fix: Stabilize Pi watcher startup beat reuse
✅ Re-checked - no issues remain.

⚠️ **Test** - 1 error
  • 🚨 tests failed with exit code 1
  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid

kunchenguid commented Jul 16, 2026 •

Copy link
Copy Markdown
Owner

Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch.

When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again.

Noted for firstmate#614 at b15e53f6.

@kunchenguid

Copy link
Copy Markdown
Owner

Automated reminder: this PR still looks blocked on a rebase or merge conflict fix.

If you are still interested, please rebase onto the current base branch, resolve the conflict, and push.

If I do not hear back, I may close this as inactive.

@kunchenguid

Copy link
Copy Markdown
Owner

I am closing this because it has been waiting on a rebase or merge-conflict fix since 2026-07-16, and I have not seen a comment or push since then.

If you still want to keep working on this, please reopen it or open a new PR and mention this one.

Happy to take another look when there is an update.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants