Skip to content

fix(watcher): re-arm on quiet close and surface cycle exit classification - #47

Merged
trillium merged 3 commits into
mainfrom
robots-iuhj/arm-interrupted-successor
Aug 5, 2026
Merged

trillium merged 3 commits into
mainfrom
robots-iuhj/arm-interrupted-successor

Conversation

@trillium

@trillium trillium commented Aug 5, 2026

Copy link
Copy Markdown
Owner

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 on successor= (not back-filled on Claude primaries) or beacon_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 calls fm_watcher_healthy to verify a live successor actually took over, re-arms in its own foreground process tree when none did (up to FM_AUTOARM_MAX_REARMS, default 20), and escalates to an explicit continuity-lost exit-2 rewake rather than exiting silently — closing the arm-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.sh and bin/fm-turnend-guard.sh now source fm-watch-cycle-lib.sh and print fm_cycle_describe inside 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 \n to two printf format 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
ok - cycle-lib: reads the last record, not an earlier one
ok - cycle-lib: values containing = do not corrupt fields parsed after them
ok - cycle-lib: an absent or malformed ledger reports nothing rather than guessing
ok - cycle-lib: a failed read clears every field instead of leaking the previous one
ok - cycle-lib: only a signalled arm counts as an interrupted cycle
ok - cycle-lib: actionable wakes are separated from cycles that ended supervision
ok - cycle-lib: an interrupted cycle is described as a kill, not a clean end
ok - cycle-lib: the evidence line never cites the unreliable successor field
Evidence: fm-claude-stop-autoarm test output
ok - auto-arm: inert in a linked child worktree even when in-flight
ok - auto-arm: inert with no session lock
ok - auto-arm: a demonstrably dead recorded session owner is reclaimed through fm-lock.sh before arming
ok - auto-arm: inert without arm, rewake, or lock replacement when another live harness owns the home
ok - auto-arm: inert while AFK owns supervision
ok - auto-arm: stale-owner recovery leaves the AFK and supervision-need gates unchanged
ok - auto-arm: resolves the outermost pid of a nested contiguous claude ancestry (bg-spare chain)
ok - auto-arm: inert with nothing in flight and no X-mode need
ok - auto-arm: actionable close translates to exactly one exit-2 rewake with reason
ok - auto-arm: watcher: FAILED translates to an exit-2 alarm rewake
ok - auto-arm: quiet close with a verified live watcher exits silently with a clean epoch
ok - auto-arm: a quiet close with no live successor re-arms, then alarms instead of dying silently
ok - auto-arm: a re-arm that re-establishes a healthy watcher closes silently
ok - auto-arm: a queued wake after a quiet close rewakes instead of re-arming
ok - auto-arm: X-mode poll need arms the cycle even with no tasks in flight
ok - auto-arm: concurrent firings admit one owner and one rewake translation
ok - auto-arm: need vanishing mid-cycle closes without a rewake
ok - auto-arm: mid-cycle AFK hands triage to the daemon with no rewake
ok - auto-arm: active in a marked secondmate home
ok - fm-lock: shared session-lock lib preserves the status path

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 that fm_cycle_describe emits. The subsequent printf '● %s' (no \n format) then leaves no newline before the next banner line, so printf '● This read-only session...' or printf '● 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, and printf '● %s' emits no newline, so the following printf '● The Stop-owned auto-arm...' or printf '● %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.sh
  • bash tests/fm-claude-stop-autoarm.test.sh
  • bash tests/fm-turnend-guard.test.sh
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…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.
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@trillium, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 2b32404c-c992-44f8-bf78-59968f8c406b

📥 Commits

Reviewing files that changed from the base of the PR and between 0aa21d3 and a505e53.

📒 Files selected for processing (11)
  • bin/fm-claude-stop-autoarm.sh
  • bin/fm-guard.sh
  • bin/fm-turnend-guard.sh
  • bin/fm-watch-cycle-lib.sh
  • docs/architecture.md
  • docs/configuration.md
  • docs/scripts.md
  • docs/watcher-continuity.md
  • tests/fm-claude-stop-autoarm.test.sh
  • tests/fm-turnend-guard.test.sh
  • tests/fm-watch-cycle-lib.test.sh

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@trillium
trillium merged commit 4cf593a into main Aug 5, 2026
10 checks passed
@trillium
trillium deleted the robots-iuhj/arm-interrupted-successor branch August 5, 2026 08:48
trillium added a commit that referenced this pull request Aug 6, 2026
…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
trillium added a commit that referenced this pull request Aug 6, 2026
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant