Repository navigation
fix(pi): harden primary watcher wedge recovery - #614
RajeshThallam wants to merge 14 commits into
Conversation
|
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 |
|
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. |
|
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. |
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
fm_watch_arm_pirevalidates 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.bin/fm-watch.shnative 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.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.
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 secondfm_watch_arm_picall 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 existingchildis treated as stale unlesshealthyWatcherPid()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.tsclearschildonexit, but the old pid stays inownedGroupsuntilclose; a laterstopOwnedGroups()then sendskill -TERM/-KILLto 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.tsany non-emptyownedWatcherPid()forcesstopArm(), while the watcher only writes.last-watcher-beatlater inbin/fm-watch.sh. A secondfm_watch_arm_picall 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 undertmp.pi-debug*, including duplicate source files, fixturenode_modules, and captured outputs such astmp.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.tsbeatPredatesChildStart()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-beatcan land in the same timestamp tick aschildStartedAt, making the extension tear down and restart the same startup child again.🔧 Fix: Stabilize Pi watcher startup beat reuse
✅ Re-checked - no issues remain.
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.