Skip to content

fix: preserve Pi watcher supervision across reloads - #553

Closed
korallis wants to merge 6 commits into
kunchenguid:mainfrom
korallis:fm/pi-watch-active-k9
Closed

korallis wants to merge 6 commits into
kunchenguid:mainfrom
korallis:fm/pi-watch-active-k9

Conversation

@korallis

Copy link
Copy Markdown
Contributor

Intent

Fix the Firstmate Pi primary watcher tool disappearing after /reload when a later-loaded extension resets the active tool list. Keep only fm_watch_arm_pi active alongside the current selected safety allowlist, without reactivating unrelated tools or weakening plan/review/validation restrictions, and avoid delayed callbacks that use stale extension APIs. Preserve the human command, tool API, attached process wake delivery, and clean shutdown. Treat restart exit 143 as benign only after the canonical home-scoped health predicate verifies a different watcher with a fresh beacon, while retaining genuine failure reporting. Add deterministic and isolated live reload coverage and record exact empirical evidence in the Pi supervision documentation.

What Changed

  • Captain, keep only fm_watch_arm_pi active alongside Pi’s current safety allowlist after reloads and later tool-surface resets.
  • Transfer watcher restart outcomes safely between extension generations, suppressing exit 143 only when a different healthy watcher is verified and retaining genuine failure delivery.
  • Add deterministic lifecycle tests, isolated Workflow Suite live-reload coverage, and documented empirical evidence.

Risk Assessment

✅ Low: The change is well-bounded, preserves the selected tool allowlist, avoids stale Pi API calls after shutdown, and safely scopes restart handoff handling.

Testing

Completed 1 recorded test check.

  • Outcome: ⚠️ 1 error across 1 run (12m23s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed (4) ✅
  • 🚨 .pi/extensions/fm-primary-pi-watch.ts:183 - The required criterion says to “avoid delayed callbacks that use stale extension APIs.” After session shutdown, this handler waits up to five seconds for replacement health and may then call sendWake() through the old captured pi.sendUserMessage API. If that API is invalidated during reload, genuine exit-143 failure reporting is silently lost by the catch block. Move verification and failure delivery to the current extension generation or otherwise avoid using the unloaded API.
  • ⚠️ tests/fm-pi-primary-live-e2e.test.sh:124 - The live test copies the user's long-lived Pi auth file beneath the repository in an unignored .pi-live-e2e.* directory. An abrupt termination can leave credentials exposed to git status or accidental staging. Use a restrictive temporary directory outside the source tree or avoid materializing the credential under the repository.

🔧 Fix: Captain, preserve Pi reload wake delivery safely
1 error still open:

  • 🚨 .pi/extensions/fm-primary-pi-watch.ts:310 - reportPriorRestart() runs unconditionally without verifying session-lock ownership. A read-only Pi session sharing the same FM_HOME can consume and delete the owning session's restart handoff, contradicting the requirement to retain genuine exit-143 failure reporting. Gate handoff processing and deletion against the existing ownership predicate.

🔧 Fix: Captain, gate Pi restart handoffs by session ownership
1 error still open:

  • 🚨 .pi/extensions/fm-primary-pi-watch.ts:201 - The required criterion says exit 143 is benign only after verifying a different watcher. If reload occurs before the arm child records .watch.lock/pid, previousPid is empty; this check then accepts any briefly healthy PID, including the old watcher still shutting down, as “different.” Do not suppress exit 143 unless a valid prior watcher PID was captured and the canonical predicate returns another PID.

🔧 Fix: Captain, require valid prior Pi watcher PID
3 errors still open:

  • 🚨 .pi/extensions/fm-primary-pi-watch.ts:270 - The requirement says to keep fm_watch_arm_pi active “alongside the current selected safety allowlist.” Restoration runs only during resources_discover, which Pi emits at startup/reload. Workflow Suite calls setActiveTools(...) during later plan/review/validation transitions, so the watcher tool disappears again until another reload. Reassert it after runtime tool-surface changes without restoring any unrelated tools.
  • 🚨 .pi/extensions/fm-primary-pi-watch.ts:202 - The fixed, unversioned handoff file can be cleared or overwritten by an older generation's delayed health check during a rapid second reload. That can delete the newer reload's handoff and contradict the requirement to retain genuine failure reporting. Add generation ownership/CAS and clear only the exact handoff originally read.
  • 🚨 .pi/extensions/fm-primary-pi-watch.ts:197 - If reload writes complete:false but the prior child never records its close result, every subsequent generation waits five seconds and returns without reporting or clearing the handoff. Treat an owned handoff that remains incomplete at the deadline as an actionable failure so genuine shutdown failures are retained.

🔧 Fix: Captain, preserve Pi watcher runtime and restart handoffs
✅ 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 17, 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#553 at 584d92af.

@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-17, 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.

@redeye1011

Copy link
Copy Markdown

Live proof on production, 2026-10-27 ~18:25 UTC.

Fixed. Closing.

I signed in on /el as the QA instant operator and searched the visible text for the English status words Active, Confirmed, Cancelled, Completed, Pending and Inactive. None appear:

  • /el/operator-dashboard/fleet: the fleet badge now reads Ενεργό (it used to read "Active").
  • /el/operator-dashboard/bookings: the badges read Ακυρώθηκε and Εκκρεμεί.
  • /el/operator-dashboard: no English status words.

StatusBadge now falls back to the statusBadge translation (#624). Earlier comments already showed verification, legal contract, settings and availability in Greek.

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.

3 participants