Repository navigation
fix(watch): assert watcher liveness during wake drain - #101
Conversation
…drain The watcher supervision chain could silently lapse: re-arms were bundled at the tail of multi-command calls (where fm-watch-arm no-ops when a cycle is briefly still alive, so no fresh cycle got established), and text-only "holding" turns ran no supervision script, so fm-guard's liveness banner - which only fires when a guarded script runs - never triggered. AGENTS.md section 8: make the re-arm rules unambiguous - keep exactly one live cycle while work is in flight; re-arm after each FIRE (a completed arm task carrying a wake reason) and never churn on a healthy/started no-op; run fm-watch-arm standalone, never bundled; never end a turn blind, holds included. Existing material (singleton lock, beacon, guard banner, afk exception) is preserved. fm-wake-drain.sh: assert watcher liveness after draining by reusing fm-guard.sh's existing graced, beacon-based banner, so a lapse also surfaces on a plain drain-and-handle turn. Called after the queue is emptied so the guard never re-prints its own queued-wakes notice, and best-effort so it never changes the drain's exit status. The grace beacon keeps it silent right after a normal fire and warns only on a stale-beyond-grace lapse with work in flight. Watcher core (fm-watch.sh, lock, beacon-touch, wake-queue) untouched. tests: keep the worktree-tangle check inert across the drain-invoking suites (wake-helpers points FM_ROOT at a non-git dir, the same trick the direct fm-guard.sh tests use), and add a regression test asserting the drain warns on a lapse and stays silent right after a fire.
…liveness on drain (kunchenguid#101) (#12) Port two upstream fixes; both are harness-agnostic supervision/contract changes. kunchenguid#97 harden no-mistakes validation contract: - bin/fm-brief.sh: rewrite the ship brief's validation block - the pipeline owns every fix (incl. the fix for a real bug review finds in the crewmate's own code); respond, never self-implement/abort/re-run; process every return (backgrounding ok, never idle-wait for auto-advance); review findings always gate; avoid --yes (it auto-resolves ask-user with zero escalation). - AGENTS.md section 7: supervisor heuristic - judge a validating crewmate by the run step status (running/fixing/ci = working; awaiting_approval/fix_review = parked), not shell liveness, plus a self-fix-duplication red flag. - CONTRIBUTING.md: same crewmate-validation contract. kunchenguid#101 assert watcher liveness during wake drain: - bin/fm-wake-drain.sh: after draining, call fm-guard.sh (best-effort) so a lapsed supervision chain also surfaces on a plain drain-and-handle turn, not only when a guarded script runs. Graced/beacon-based, so silent right after a normal fire. - AGENTS.md section 8: unambiguous re-arm rules - keep exactly one live cycle, re-arm after each FIRE and never churn on a healthy/started no-op, run fm-watch-arm standalone (never bundled), never end a turn blind (holds included). - fm-guard.sh / fm-watch-arm.sh: comment clarifications; docs synced. - tests/fm-wake-queue.test.sh: pin FM_ROOT (drain now runs the tangle check) and add a regression test (drain warns on a lapse, silent after a fire). shellcheck clean; full suite green (96 checks).
|
Local run evidence for tests/fm-remote-secondmate-lifecycle-e2e.test.sh Diagnosis: reproduced on unchanged main at load ~10 on 12 cores. A timestamped trace of the spawn showed about 31s spent inside fm-remote-inherit-push.sh: 13 inherited items before data/captain-shared.md, each a full fm-on -> ssh -> remote entrypoint round trip, with no sleep or lock wait on the path. At load ~5 the spawn reached its blocked write after 1463 of the old 1500 x 0.02s polls. That is load-driven throughput exhausting a fixed poll count, not an ordering race or a bin/ bug. run1.logrun2.logrun3.logrun4-siblings.logRuns 1-3 are on the first commit (spawn wait only); run 4 is on the final head (sibling waits too). In every run the inheritance legs pass. Each run then stops at the separately ticketed watcher auto-relaunch bound, so the file never reaches the respawn sibling wait locally; CI ran the whole file green. |
…henguid#101) * fix(bin): hold a macOS sleep assertion for the watcher lifetime Per-run caffeinate gaps let the machine sleep mid-fleet-work. The lock-owning watcher now keeps caffeinate -dims bound to its pid for the whole process, so the assertion dies with the watcher and does not pile up across successors. * no-mistakes(review): drop display-wake flag from watcher lifetime caffeinate assertion * no-mistakes(ci): declare the caffeinate watcher test in shards and fork surface tests/fm-watch-caffeinate.test.sh joins the watcher-wake-lock family and portable serial shard 1 so the coverage guard's shard partition stays complete, and a watcher-sleep-assertion capability claims the fork-only test path so the declared-fork-surface gate passes. * fix(tests): reap background children from the real test shell on Linux BASHPID inside command substitution is the subshell, so pgrep never saw the suite's background jobs on bash 4+. * no-mistakes: apply CI fixes
Intent
Tighten firstmate's watcher re-arm discipline (AGENTS.md section 8) and add a wake-drain liveness assertion so the watcher supervision chain cannot silently lapse. Motivating incident: the watcher (bin/fm-watch.sh, armed via bin/fm-watch-arm.sh as a harness-tracked background task) died ~12 min undetected because re-arms were bundled at the tail of multi-command bashes (where fm-watch-arm silently no-ops when a cycle is briefly still alive, so no fresh cycle got established) and because text-only 'holding' turns ran no supervision script, so fm-guard.sh's liveness banner (which only fires when a supervision script runs) never triggered.
Three deliberate changes:
AGENTS.md section 8: reworded the re-arm discipline into four unambiguous bold-led rules - keep exactly one live cycle while work is in flight; re-arm after each FIRE (a completed arm task carrying a wake reason signal/stale/check/heartbeat) and do NOT churn on a healthy/started no-op; run fm-watch-arm standalone, never bundled in a multi-command bash; never end a turn blind, holds included. This intentionally REPLACES the old misleading 'Re-arming is the primary model: just run fm-watch-arm and let the singleton lock no-op' line that encouraged the churn. Existing correct material (singleton lock, beacon, guard banner, afk-daemon-owns-watcher exception) is preserved verbatim - a tightening, not a rewrite. Also added one line noting fm-wake-drain.sh now runs the same guard.
bin/fm-wake-drain.sh: added an assert_watcher_liveness() helper that REUSES fm-guard.sh's existing graced, beacon-based banner (no duplicated beacon math, per the task constraint) and called it on both success-exit paths. Deliberately called AFTER the queue is emptied so the guard never re-prints its own 'queued wakes pending' notice for the records this run just drained, and wrapped with '|| true' so a guard hiccup never changes the drain's exit status. Because the watcher touches its beacon every poll cycle, a normal fire leaves a recent beacon well inside FM_GUARD_GRACE so the drain stays silent right after a fire; it warns only on a genuine stale-beyond-grace lapse with work in flight. The watcher core (fm-watch.sh, the singleton lock, the beacon-touch, the wake-queue) is deliberately UNTOUCHED.
Tests: the drain's new guard call would otherwise emit a spurious WORKTREE TANGLE banner across the drain-invoking suites because FM_ROOT resolves to the feature-branch test checkout during validation, so tests/wake-helpers.sh now sets a default FM_ROOT_OVERRIDE to a fresh non-git dir to keep the tangle check inert (the same trick the direct fm-guard.sh tests already use); a per-call FM_ROOT_OVERRIDE still wins. Added a regression test (test_drain_asserts_watcher_liveness in tests/fm-wake-queue.test.sh) asserting the drain warns on a lapse and stays silent right after a fire. Verified locally: shellcheck clean, all behavior suites green, and a negative control confirmed the new test genuinely fails if the assertion is removed.
What Changed
AGENTS.mdand related docs so captain-facing instructions require one live cycle, standalone re-arms after fired wakes, and supervision before ending holding turns.bin/fm-wake-drain.shby reusingfm-guard.shafter queue drains without changing the drain exit status.Risk Assessment
✅ Low: Captain, the change is narrowly scoped to documentation, a successful-drain guard call that reuses existing liveness logic, and focused regression coverage; I did not find material risks in the changed paths.
Testing
I inspected the target diff, ran the focused wake-drain/watcher/daemon suites, ran the full behavior-test loop, captured a manual CLI transcript showing the WATCHER DOWN banner and fresh-beacon silence, verified the AGENTS.md re-arm rules and old line removal, and confirmed the worktree stayed clean with no transient build/test directories left behind.
Evidence: Manual fm-wake-drain liveness transcript
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.
git status --short --branchgit diff --stat fe3c867788fe389bbcaddbf9500c27cceb99504a..eb6897bb28b25df74b6dc2ab7d966904c16b9b25git diff --name-only fe3c867788fe389bbcaddbf9500c27cceb99504a..eb6897bb28b25df74b6dc2ab7d966904c16b9b25Reviewed base-to-target diffs forAGENTS.md,bin/fm-wake-drain.sh,tests/fm-wake-queue.test.sh, andtests/wake-helpers.sh.tests/fm-wake-queue.test.shtests/fm-watcher-lock.test.shtests/fm-daemon.test.shtests/fm-wake-daemon-lifecycle-e2e.test.shfor test_script in tests/*.test.sh; do "$test_script"; doneManualbin/fm-wake-drain.shcheck with an in-flight meta file and no watcher beacon, then with a fresh.last-watcher-beat, writing evidence to/var/folders/5x/4nqprlbx0518k3ybcb1sz6gr0000gn/T/no-mistakes-evidence/01KW31M8H57RN64KXEMCME7WZP.rg -n "Keep exactly one live cycle|Standalone, never bundled|Re-arm after each FIRE|No turn ends blind|fm-wake-drain.sh.*same guard" AGENTS.mdif rg -q "Re-arming is the primary model" AGENTS.md; then printf 'old misleading re-arm line still present\n' >&2; exit 1; figit status --shortfind . -maxdepth 2 -type d \( -name '.pytest_cache' -o -name 'node_modules' -o -name 'coverage' -o -name 'dist' -o -name 'build' \) -print✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.