Repository navigation
fix(watcher): re-arm on quiet close and surface cycle exit classification - #47
Conversation
…ming it
A harness stop that kills the Claude Stop auto-arm takes the watcher with it.
bin/fm-watch-arm.sh's TERM handler kills its watcher child, records
reason=arm-interrupted successor=none, and exits by design - no handoff. That
left supervision dead with nothing scheduled to notice, three times in one
night.
Nothing detected it because both available signals lie in this case:
- The liveness beacon is touched every poll, so a watcher killed while
healthy leaves a beacon 3-13s old - indistinguishable from a live one.
- The arm's benign "watcher: idle" line asserts "adapter re-arm owns
continuity". On a Claude primary that adapter is fm-claude-stop-autoarm.sh
itself, which took the quiet-close branch, wrote outcome=clean, and exited
0 - handing continuity to itself and then quitting.
The lifecycle ledger classified it correctly the whole time. Nothing read it:
before this change no production script opened state/.watch-cycle-exits.log.
Fix, in two parts:
1. The Stop auto-arm now VERIFIES the deferral it receives. After a quiet
close it rechecks supervision need, then fm_watcher_healthy (live lock +
identity match + fresh beacon), and re-arms in its own harness-owned
foreground tree when no live watcher answers. Bounded by
FM_AUTOARM_MAX_REARMS (default 20); an exhausted budget or an already-queued
wake escalates to an exit-2 rewake carrying a continuity-LOST banner. Exit 0
is now reserved for provably-fine states: no need, AFK, or a verified live
watcher.
Deliberately NOT a detached successor: bin/fm-watch-arm.sh's header forbids
it, and it would convert a loud supervision-down alarm into a silent
"beacon fresh, nobody listening" - letting the turn-end guard allow a blind
stop.
2. bin/fm-watch-cycle-lib.sh reads the ledger, and both supervision-down
banners (fm-guard.sh WATCHER DOWN, fm-turnend-guard.sh TURN WOULD END BLIND)
print its classification. That covers every harness, not just Claude.
The reader never cites successor=: only an adapter passing
FM_WATCH_PREDECESSOR_ARM_PID (the OpenCode plugin, the Pi extension)
back-fills it, so it reads "none" on a Claude primary even when a healthy
successor took over. Treating that field as evidence would assert
supervision was lost on data that cannot support the claim.
Tests: tests/fm-watch-cycle-lib.test.sh is new (parsing =-bearing values,
cleared state after a failed read, the exact arm-interrupted predicate, the
refusal to quote successor=). tests/fm-claude-stop-autoarm.test.sh replaces the
old clean-close test - which encoded the defect - with four covering silent
exit behind a verified live watcher, re-arm when none answers, restored
continuity without a rewake, and the queued-wake escalation.
Closes robots-iuhj.
|
Warning Review limit reached
Next review available in: 39 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (11)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…tion (#47) * fix(watch): verify continuity after a quiet arm close instead of assuming it A harness stop that kills the Claude Stop auto-arm takes the watcher with it. bin/fm-watch-arm.sh's TERM handler kills its watcher child, records reason=arm-interrupted successor=none, and exits by design - no handoff. That left supervision dead with nothing scheduled to notice, three times in one night. Nothing detected it because both available signals lie in this case: - The liveness beacon is touched every poll, so a watcher killed while healthy leaves a beacon 3-13s old - indistinguishable from a live one. - The arm's benign "watcher: idle" line asserts "adapter re-arm owns continuity". On a Claude primary that adapter is fm-claude-stop-autoarm.sh itself, which took the quiet-close branch, wrote outcome=clean, and exited 0 - handing continuity to itself and then quitting. The lifecycle ledger classified it correctly the whole time. Nothing read it: before this change no production script opened state/.watch-cycle-exits.log. Fix, in two parts: 1. The Stop auto-arm now VERIFIES the deferral it receives. After a quiet close it rechecks supervision need, then fm_watcher_healthy (live lock + identity match + fresh beacon), and re-arms in its own harness-owned foreground tree when no live watcher answers. Bounded by FM_AUTOARM_MAX_REARMS (default 20); an exhausted budget or an already-queued wake escalates to an exit-2 rewake carrying a continuity-LOST banner. Exit 0 is now reserved for provably-fine states: no need, AFK, or a verified live watcher. Deliberately NOT a detached successor: bin/fm-watch-arm.sh's header forbids it, and it would convert a loud supervision-down alarm into a silent "beacon fresh, nobody listening" - letting the turn-end guard allow a blind stop. 2. bin/fm-watch-cycle-lib.sh reads the ledger, and both supervision-down banners (fm-guard.sh WATCHER DOWN, fm-turnend-guard.sh TURN WOULD END BLIND) print its classification. That covers every harness, not just Claude. The reader never cites successor=: only an adapter passing FM_WATCH_PREDECESSOR_ARM_PID (the OpenCode plugin, the Pi extension) back-fills it, so it reads "none" on a Claude primary even when a healthy successor took over. Treating that field as evidence would assert supervision was lost on data that cannot support the claim. Tests: tests/fm-watch-cycle-lib.test.sh is new (parsing =-bearing values, cleared state after a failed read, the exact arm-interrupted predicate, the refusal to quote successor=). tests/fm-claude-stop-autoarm.test.sh replaces the old clean-close test - which encoded the defect - with four covering silent exit behind a verified live watcher, re-arm when none answers, restored continuity without a rewake, and the queued-wake escalation. Closes robots-iuhj. * no-mistakes(review): Add missing newline after cycle_evidence printf in two guards * no-mistakes(document): add fm-watch-cycle-lib.sh to scripts.md toolbelt table
…tion (#47) * fix(watch): verify continuity after a quiet arm close instead of assuming it A harness stop that kills the Claude Stop auto-arm takes the watcher with it. bin/fm-watch-arm.sh's TERM handler kills its watcher child, records reason=arm-interrupted successor=none, and exits by design - no handoff. That left supervision dead with nothing scheduled to notice, three times in one night. Nothing detected it because both available signals lie in this case: - The liveness beacon is touched every poll, so a watcher killed while healthy leaves a beacon 3-13s old - indistinguishable from a live one. - The arm's benign "watcher: idle" line asserts "adapter re-arm owns continuity". On a Claude primary that adapter is fm-claude-stop-autoarm.sh itself, which took the quiet-close branch, wrote outcome=clean, and exited 0 - handing continuity to itself and then quitting. The lifecycle ledger classified it correctly the whole time. Nothing read it: before this change no production script opened state/.watch-cycle-exits.log. Fix, in two parts: 1. The Stop auto-arm now VERIFIES the deferral it receives. After a quiet close it rechecks supervision need, then fm_watcher_healthy (live lock + identity match + fresh beacon), and re-arms in its own harness-owned foreground tree when no live watcher answers. Bounded by FM_AUTOARM_MAX_REARMS (default 20); an exhausted budget or an already-queued wake escalates to an exit-2 rewake carrying a continuity-LOST banner. Exit 0 is now reserved for provably-fine states: no need, AFK, or a verified live watcher. Deliberately NOT a detached successor: bin/fm-watch-arm.sh's header forbids it, and it would convert a loud supervision-down alarm into a silent "beacon fresh, nobody listening" - letting the turn-end guard allow a blind stop. 2. bin/fm-watch-cycle-lib.sh reads the ledger, and both supervision-down banners (fm-guard.sh WATCHER DOWN, fm-turnend-guard.sh TURN WOULD END BLIND) print its classification. That covers every harness, not just Claude. The reader never cites successor=: only an adapter passing FM_WATCH_PREDECESSOR_ARM_PID (the OpenCode plugin, the Pi extension) back-fills it, so it reads "none" on a Claude primary even when a healthy successor took over. Treating that field as evidence would assert supervision was lost on data that cannot support the claim. Tests: tests/fm-watch-cycle-lib.test.sh is new (parsing =-bearing values, cleared state after a failed read, the exact arm-interrupted predicate, the refusal to quote successor=). tests/fm-claude-stop-autoarm.test.sh replaces the old clean-close test - which encoded the defect - with four covering silent exit behind a verified live watcher, re-arm when none answers, restored continuity without a rewake, and the queued-wake escalation. Closes robots-iuhj. * no-mistakes(review): Add missing newline after cycle_evidence printf in two guards * no-mistakes(document): add fm-watch-cycle-lib.sh to scripts.md toolbelt table
What Changed
Extracted
bin/fm-watch-cycle-lib.sh: a new shared reader for the watcher lifecycle ledger (state/.watch-cycle-exits.log) that classifies why a cycle ended (fm_cycle_last_row,fm_cycle_last_was_interrupted,fm_cycle_last_ended_supervision,fm_cycle_describe) without relying onsuccessor=(not back-filled on Claude primaries) orbeacon_age=(stays fresh for a watcher that was killed while healthy).Fixed supervision gap in
bin/fm-claude-stop-autoarm.sh: replaced the single arm invocation with a re-arm loop; after a quiet close the hook now callsfm_watcher_healthyto verify a live successor actually took over, re-arms in its own foreground process tree when none did (up toFM_AUTOARM_MAX_REARMS, default 20), and escalates to an explicitcontinuity-lostexit-2 rewake rather than exiting silently — closing thearm-interrupted(harness-kill) path where a terminated arm left a still-fresh beacon and nothing scheduled to restart supervision.Surfaced cycle exit evidence in supervision-down banners:
bin/fm-guard.shandbin/fm-turnend-guard.shnow sourcefm-watch-cycle-lib.shand printfm_cycle_describeinside their supervision-down output, distinguishing a harness-killed arm from a crashed watcher in every banner across all harness types.Risk Assessment
✅ Low: The fix-round commit is a minimal, correct one-character addition of
\nto twoprintfformat strings, exactly addressing the missing-newline findings from round 1 with no other changes.Testing
Ran all three targeted test suites: 8/8 fm-watch-cycle-lib tests verified the new ledger reader (field parsing, = in values, absent/malformed ledger, stale-value clearing, predicate exactness, describe output); 20/20 autoarm tests including four new continuity cases (quiet close with live watcher exits 0, quiet close with no successor re-arms then alarms, successful re-arm exits 0, queued wake after quiet close rewakes immediately); 51/51 turnend-guard tests including the new cycle-evidence banner integration. No failures.
Evidence: fm-watch-cycle-lib test output
Evidence: fm-claude-stop-autoarm test output
Pipeline
Updates from git push no-mistakes
⏭️ **intent** - skipped
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed ✅
bin/fm-guard.sh:197- Command substitution$(fm_cycle_describe ...)strips the trailing newline thatfm_cycle_describeemits. The subsequentprintf '● %s'(no\nformat) then leaves no newline before the next banner line, soprintf '● This read-only session...'orprintf '● Trust the emitted supervision...'runs onto the same visual line as the cycle evidence. Fix: change'● %s'to'● %s\n'here (same fix needed at fm-turnend-guard.sh:175).bin/fm-turnend-guard.sh:175- Same missing-newline defect as fm-guard.sh:197.cycle_evidence=$(fm_cycle_describe ...)strips the trailing\n, andprintf '● %s'emits no newline, so the followingprintf '● The Stop-owned auto-arm...'orprintf '● %s\n' "$reason"concatenates onto the cycle-evidence line. Fix: change'● %s'to'● %s\n'.🔧 Fix: Add missing newline after cycle_evidence printf in two guards
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-watch-cycle-lib.test.shbash tests/fm-claude-stop-autoarm.test.shbash tests/fm-turnend-guard.test.sh✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.