Repository navigation
fix(bin): name Claude successor-gap banner and harden auto-arm - #18
Merged
Merged
Conversation
…o-arm The Claude PRIMARY watcher runs only between turns. After a clean actionable close, a handling turn longer than the beacon grace lets the beacon go stale, and fm-guard printed WATCHER DOWN with a repair line that told the operator to check hook registration. That is misleading when the last epoch is a successful rewake: nothing is broken, the successor just has not started because the turn is still running. - fm-guard: when the auto-arm model shows a successful rewake epoch and a stale beacon, name a design-induced supervision gap after a successful rewake and drop the hook-registration repair. Keep saying supervision is genuinely absent during the gap; do not call it a false alarm or harmless. Only the auto-arm model reaches this path. - fm-claude-stop-autoarm: add HUP/INT/TERM parent traps that record an interrupted epoch outcome and remove the abandoned arm-output file before dying, covering the exit-143 process-group kill that previously left a dangling epoch and stranded output files. - fm-watch-arm: add source, epoch, session, and termination-cause fields to each lifecycle-ledger row, appended after successor so existing parsers are unaffected. The auto-arm hook marks its cycles source=autoarm; every other arm defaults to manual. Every other harness keeps its supervision behavior unchanged; the ledger field additions are additive only.
|
Warning Review limit reachedNext included review available in 6 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (8)
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 |
EvanAgee
added a commit
that referenced
this pull request
Sep 22, 2026
Re-architects Claude's Stop-owned supervision onto successor-first ordering, the same shape Pi and OpenCode already use. The former between-turns auto-arm made the watcher one-shot: it delivered one wake and exited, and the successor armed only at the NEXT Stop. Any handling turn longer than the beacon grace therefore ran with no live watcher, so the beacon went stale and supervision was genuinely absent even though nothing had crashed. Two cooperating Stop hooks replace it: - bin/fm-claude-watch-coordinator.sh (async) admits one owner per session generation (state/.claude-coordinator.lock, role coordinator) and keeps exactly one arm/watcher cycle alive by driving the real bin/fm-watch-arm.sh as a tracked background child. After an actionable close it reads the queue high-water mark, arms and verifies a fresh successor, and only then publishes an atomic state/.claude-ready-to-notify record binding that mark, the recovery generation, the predecessor arm pid, the verified successor pid and identity, the coordinator generation, and the session owner. After a bounded successor-timeout streak with no healthy watcher it stands down. - bin/fm-claude-watch-notifier.sh (asyncRewake) keeps the former auto-arm's scope, identity, AFK, need, stale-session-lock recovery, and single-flight gates, and parks until it can exit 2 on a ready record whose ready_seq is past its own high-water mark, still belongs to this session and coordinator generation, and covers at least one durable unacked queue row. It surfaces a typed degraded-supervision failure rather than exiting 0 into a still-needed-but-unsurfaced state, and drives the same failure-episode progression the turn-end guard reads. bin/fm-claude-stop-autoarm.sh and its two suites are gone; the notifier is its successor, and .claude/settings.json registers the coordinator and the notifier alongside the turn-end guard. Root-specific decisions recorded in the port: - The notifier adopts the root's generation-claim contract in bin/fm-wake-lib.sh (fm_autoarm_claim_open/fm_autoarm_claim_next plus the epoch ledger) instead of the fork's plain owner lock, because the root explicitly forbids holding a mutex across a blocking step and a parked hook can block for hours. Claims are open while their outcome is arming or parked, which keeps the turn-end guard's recovery proof unchanged, and fm_lock_set_role gains the coordinator role. - A coordinator lock alone never satisfies the turn-end guard: a coordinator cannot exit 2, so its state stays diagnostic evidence. - The notifier commits its rewake epoch with the session-lock pid only; the fork's recovery-generation binding existed for the between-turns model, and the coordinator now keeps the beacon fresh instead. Tests carried over and adapted: tests/fm-claude-watch-coordinator.test.sh drives the real arm and watcher and proves a verified successor owns the lock before the ready record is published, one stable watcher holds a fresh beacon across a turn longer than grace, an actionable close re-arms and re-publishes, and a coordinator lock never satisfies the guard. tests/fm-claude-watch-notifier.test.sh covers the parked/rewake/failed progression, the unacked-queue rewake gate, single-flight, and host-timeout translation. The ancestry, cursor, guard, and instructions suites were re-pointed at the two hooks, and the fork's prime-seen helper is replaced by the root's own production owner (tests/wake-helpers.sh). Refs #19 Refs #18 ## What I walked Everything below ran in a throwaway home under this worktree (`$PWD/.walk-home`, a plain git checkout carrying a copy of `bin/`, so the scope predicate accepts it), with `FM_HOME`/`FM_ROOT_OVERRIDE`/`FM_STATE_OVERRIDE`/`FM_CONFIG_OVERRIDE` pointing at it; the live home and the trial home were never touched. The scratch home held one in-flight task (`state/task.meta` + `state/task.status`), a fake Claude session (a `bash` symlink named `claude`) that owns `state/.lock` and fires both hooks from inside its own process tree the way `.claude/settings.json` does, and fast knobs (`FM_POLL=1`, `FM_GUARD_GRACE=6`). 1. `bash session.sh` (the fake session) then `cat .walk-home/state/.lock` -> `session lock: 78208`. 2. Waiting on `state/.watch.lock/pid`: ``` watcher pid: 79305 alive: yes coordinator lock role: coordinator t=1s watcher pid=79305 alive=yes beacon_age=1s (grace 6s) t=2s watcher pid=79305 alive=yes beacon_age=2s (grace 6s) t=3s watcher pid=none alive=no beacon_age=3s (grace 6s) t=4s watcher pid=88427 alive=yes beacon_age=4s (grace 6s) t=5s watcher pid=88427 alive=yes beacon_age=1s (grace 6s) ready-to-notify record: ready_seq=2 recovery_generation=85049.1790074216.uOltZZ predecessor_arm_pid=79156 successor_watch_pid=88427 ``` and one cycle-ledger row per cycle: `arm_pid=79156 watcher_pid=79305 origin=started ... reason=actionable-signal ... lock_after=pid:none|identity:none successor=started:88427`. The t=3s line is the arm's own actionable close: that cycle delivered a wake and exited, and `successor=started:88427` in the same row shows the coordinator had already armed and verified the next watcher, which is the successor-first ordering this port exists for. No model arm command was issued at any point. 3. Writing a real actionable status (`printf 'blocked: needs a decision [key=walk]\n' > state/task.status`) made the parked notifier wake: ``` notifier exit: 2 notifier stderr: firstmate watcher wake - one supervision event needs a handling turn now. ... The watcher coordinator owns continuity: a verified successor is already supervising the fleet - do NOT run bin/fm-watch-arm.sh after an ordinary wake. epoch after the wake: rewake durable queue row: 1790074216|1|signal|task.status|signal: .../state/task.status ``` and the drain presented that row with its `WAKE_ACK_REQUIRED --ack-through 2` line. 4. `printf '{"session_id":"walk","stop_hook_active":true}\n' | bin/fm-turnend-guard.sh --claude` -> `guard exit: 0` (the live successor allowed the stop). 5. A heartbeat row appended to the durable queue, then `bin/fm-wake-drain.sh`: ``` ANCHOR (durable truth re-read on this heartbeat; survives context compaction): standing steers (data/captain.md ## Working style): stand up before you sit down open decisions: 1 | in-flight tasks: 1 ``` with `odometer: pid=78208 started_epoch=1790074223 wakes=2` and `last-anchor stamped: yes`. Test evidence on this branch: `tests/fm-claude-watch-coordinator.test.sh` (10/10), `tests/fm-claude-watch-notifier.test.sh` (18/18), `tests/fm-session-lock-ancestry.test.sh`, `tests/fm-turnend-guard.test.sh`, `tests/fm-cursor-primary.test.sh` (Cursor stand-down for both hooks), `tests/fm-guard-stale-banner.test.sh`, `tests/fm-supervision-instructions.test.sh`, `tests/fm-daemon.test.sh` (after the wedge-lib extraction), `tests/fm-watcher-beat-alarm.test.sh` (14/14), and `tests/fm-wake-drain-anchor.test.sh` (8/8) all pass. `shellcheck -x` is clean on every touched `bin/*.sh`. ## Port record What the root already had, adopted rather than re-implemented: - The generation-claim single-flight contract in `bin/fm-wake-lib.sh` (`fm_autoarm_claim_open`/`fm_autoarm_claim_next`/`fm_autoarm_write_owned` and the `state/.claude-autoarm-epoch` ledger). The fork's notifier held a plain `state/.claude-autoarm.lock` with role `notifier` for its whole park; the root explicitly forbids holding a mutex across a blocking step, and a parked hook can block for hours, so the ported notifier claims a generation instead and its parked claim is the open claim the turn-end guard already reads (`fm_autoarm_claim_open` now accepts outcome `parked`). - The root's turn-end guard, its failure-episode machinery, and its `fm_session_lock_owned_by_self` identity verdict: unchanged in behavior. The port only reworded its user-facing lines and documented that a `coordinator` lock never satisfies it. - The root's newer watcher, drain, classify, and session-lock code: kept as the base. The fork's versions of `fm-watch.sh`, `fm-wake-drain.sh`, and `fm-classify-lib.sh` were NOT wholesale-imported; only this feature's seams were added to the root's files (the anchor re-read branch, the drain's anchor call, the instructions' anti-drift duties, the knob loader). - The root's stricter per-backend absence proof for a `missing` endpoint in `bin/fm-control.sh`: kept, and it is why ride #11 is dropped (see below). What changed from the fork's version, and why: - Rewake commit shape: the fork bound a rewake to the session-lock pid AND the recovery generation. The ported notifier commits the session-lock pid only, because that binding existed for the between-turns model where the beacon could legitimately go stale mid-turn; the coordinator now keeps the beacon fresh, so a stale mid-turn beacon with no live watcher is a genuinely loud coordinator miss. - `fm_lock_set_role` accepts `coordinator|notifier`; only `coordinator` is used by the ported hooks (the notifier owns the ledger, not the lock). - `tests/fm-claude-watch-notifier.test.sh` carries one adapted assertion: its parent-TERM case asserted that the dying hook releases the owner lock from an EXIT trap. That property belongs to the fork's lock-holding design; the ported design asserts the invariant that matters instead - the kill leaves no LIVE owner lock (a process killed inside a lock's critical section always leaves a reclaimable dead-owner record, which is what `fm-wake-lib.sh`'s steal path recovers), and the ledger still ends at `interrupted`. - `tests/fm-claude-watch-coordinator.test.sh`'s `prime_seen` helper now calls the root's production priming owner (`prime_status_seen` from `tests/wake-helpers.sh`) instead of hand-writing the fork's seen-marker shape. - `tests/fm-session-lock-ancestry.test.sh`'s end-to-end layer fires the notifier against a seeded ready-to-notify record (`$FM_HOME/seed-ready.sh`, installed by the fixture) rather than the deleted auto-arm's arm fixture, and its phase helpers dropped the arm-count assertions that belonged to the removed stub. - Docs were reconciled inside this port's own scope: `docs/configuration.md`'s Claude supervision knob lines, the new odometer and supervision-env sections, and the new `docs/scripts.md` rows. The rest of that file belongs to C3's reconciliation per the spec's conflict map. Deleted as superseded: `bin/fm-claude-stop-autoarm.sh`, `tests/fm-claude-stop-autoarm.test.sh`, and `tests/fm-claude-stop-autoarm-live-e2e.test.sh`, replaced by the coordinator, the notifier, and their two suites. Dropped, with reasons: - Ride #11 (herdr husk relaunch): the root already implements a stricter per-backend absence proof for a missing endpoint than the fork's `dead|missing` shortcut in `bin/fm-control.sh` (its own header, lines 34-59, and the `missing` branch at 485-533), and its herdr backend already owns `fm_backend_herdr_tab_is_husk` and in-place husk replacement. Porting the fork's version would weaken that contract, so the ticket's "the root already has it" path applies. - Rides #119 (stalled-validation wake) and #120 (tmux relaunch after endpoint loss): the root has no equivalent, so they cannot be dropped as already present. #119 is a feature-sized port across `fm-nm-run-lib.sh`, `fm-classify-lib.sh`, `fm-crew-state.sh`, `fm-watch.sh`, and `fm-supervise-daemon.sh` with roughly 2000 lines of tests, larger than everything on this branch. #120's surface on the root is two raw `tmux display-message -p -t <target> '#{pane_id}'` endpoint reads (`bin/fm-crew-state.sh`, `bin/fm-backend.sh`) that bypass the backend's named-window check, but no live failure has been reproduced on the root and the endpoint-liveness path must not change without one. Firstmate decided `[key=rides-scope]` option 1 on 2026-09-22: this branch lands as-is, and #119 (first), then #120 and #11, become their own port ticket after C1 lands.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Intent
Ship the SAFE, low-risk hardening of the Claude PRIMARY watcher supervision (the immediate-hardening list endorsed by an adversarial review). This is the safe track only; the larger coordinator/notifier redesign is a separate task and is deliberately NOT done here. Every change is Claude-specific and must NOT alter Pi, OpenCode, OMP, Codex, Grok, Cursor, or Kimi supervision behavior.
Context: on Claude the PRIMARY watcher runs only between turns (one-shot). After a clean actionable close, if the handling turn runs longer than the 300s beacon grace the beacon goes stale and fm-guard prints 'WATCHER DOWN - SUPERVISION IS OFF' with a repair line telling the operator to inspect hook registration. That repair advice is misleading when the last auto-arm epoch outcome is a successful 'rewake': nothing is broken, the successor cycle simply has not started because the handling turn is still running.
Changes:
Tests added: guard-stale-banner tests assert the banner text switches on epoch outcome (design-gap wording for a rewake epoch, ordinary wording otherwise, and the persistent model ignoring a stray rewake epoch); an autoarm test simulates a TERM to the parent process group and asserts the interrupted epoch outcome plus removal of the abandoned output file; watch-arm tests assert the new ledger fields appear with correct values, that a manual arm defaults to source=manual/epoch=none, and that the original twelve fields remain parseable in order (additive, non-breaking). Every other harness's supervision behavior stays byte/behavior-equivalent.
Note: on this dev host, the pre-existing autoarm test 'failure must exhaust exactly two bounded arm attempts' fails identically on unmodified HEAD (an ambient-environment quirk unrelated to this change); it was not introduced by this work.
What Changed
rewakenow prints a WATCHER DOWN banner that names a design-induced supervision gap and tells the operator to check the Stop hook only if the handling turn has already ended; Cursor and other models keep the ordinary stale-beacon / hook-registration wording.fm-claude-stop-autoarm.shnow traps HUP/INT/TERM, records aninterruptedepoch, and removes the abandoned.claude-autoarm-output.*file so a mid-cycle process-group kill no longer leaves a dangling arming epoch.successor(source,epoch,session,cause); auto-arm cycles setsource=autoarm, other arms default tosource=manual/epoch=none, and successor back-fill is field-position-agnostic.Risk Assessment
✅ Low: The Claude-only harness gate and softened successor-gap copy close the prior Cursor bleed and hook-health misdiagnosis without changing other harness banner paths, and the remaining auto-arm trap and additive ledger work stay bounded.
Testing
Ran the banner suite and the new auto-arm TERM plus watch-arm ledger cases, then reproduced the operator surfaces with the real binaries: Claude rewake prints the design-gap WATCHER DOWN banner without the hook-registration repair line, Cursor and persistent keep their ordinary banners, a mid-cycle TERM records outcome=interrupted and deletes the abandoned output file, and ledger rows append source/epoch/session/cause after the original twelve fields. No graphical UI is involved, so the evidence is those CLI banners and persisted state files rather than screenshots. All targeted checks passed.
Evidence: Live fm-guard banners: Claude rewake gap vs ordinary Claude/Cursor/persistent wording
Source: Live fm-guard banners: Claude rewake gap vs ordinary Claude/Cursor/persistent wording
Claude rewake: WATCHER DOWN - SUPERVISION IS OFF / a design-induced supervision gap after a successful rewake / Supervision IS absent during this gap; it is not harmless / check the Stop hook / no hook-registration line. Claude arming and Cursor leftover rewake keep 'no watcher has a fresh beacon' plus hook-registration repair. Persistent stray rewake keeps 'no live watcher process holds this home lock'.Evidence: Auto-arm parent TERM: interrupted epoch and cleaned output file
Source: Auto-arm parent TERM: interrupted epoch and cleaned output file
Evidence: Persisted epoch after process-group TERM
Source: Persisted epoch after process-group TERM
epoch=2 owner_pid=67166 outcome=interrupted updated_at=1787588645Evidence: Lifecycle ledger rows from real autoarm and manual arms
Source: Lifecycle ledger rows from real autoarm and manual arms
Evidence: Autoarm-sourced .watch-cycle-exits.log row (16 tab fields, source=autoarm epoch=41 session=4242)
Source: Autoarm-sourced .watch-cycle-exits.log row (16 tab fields, source=autoarm epoch=41 session=4242)
Evidence: Manual .watch-cycle-exits.log row (source=manual epoch=none)
Source: Manual .watch-cycle-exits.log row (source=manual epoch=none)
Evidence: fm-guard stale-banner test transcript
Source: fm-guard stale-banner test transcript
Evidence: Auto-arm TERM test transcript
Source: Auto-arm TERM test transcript
Evidence: Watch-arm ledger test transcript
Source: Watch-arm ledger test transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 1 issue found → auto-fixed ✅
bin/fm-guard.sh:224- The design-gap banner keys only on model=autoarm plus leftover outcome=rewake. That is not the same as “this rewake’s handling turn is still open.” Concrete Claude path: hook writes outcome=rewake and exits 2; handling turn ends; the next Stop never claims arming (unregistered, inert, or killed before write_epoch arming). Beacon is already stale. The next guarded command still sees rewake and prints “The Stop-owned auto-arm is working… nothing needs repair” and “It ends on its own when the handling turn ends.” That is the original hook-failure case the dropped repair line existed for. Same leftover token also fires that Claude Stop-auto-arm copy on Cursor, because fm_supervision_model maps cursor to autoarm — contradicting “Every change is Claude-specific and must NOT alter … Cursor … supervision behavior” and “The Stop-owned auto-arm is working.” The earliest existing boundary that stops the Cursor bleed is harness=claude (fm-harness.sh), not the shared autoarm model. Leftover rewake alone cannot prove the hook is fine; confirm whether that misdiagnosis is accepted containment.🔧 Fix: Scope successor-gap banner to Claude only
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
bash tests/fm-guard-stale-banner.test.sh(full banner suite, including Claude rewake-gap, Cursor leftover rewake, non-rewake autoarm, persistent stray epoch, and Pi/OMP/extension routing)focusedtest_parent_term_records_interrupted_and_cleans_outputfromtests/fm-claude-stop-autoarm.test.shfocusedtest_lifecycle_ledger_records_additive_source_epoch_session_causeandtest_lifecycle_ledger_defaults_manual_source_without_epochfromtests/fm-watch-arm.test.shlivebin/fm-guard.shagainst Claude/rewake, Claude/arming, Cursor/rewake, and persistent/rewake fixture homeslive process-group TERM ofbin/fm-claude-stop-autoarm.shmid-cycle, then inspected.claude-autoarm-epoch, abandoned output files, and owner locklivebin/fm-watch-arm.shautoarm-sourced and manual cycles, then parsed.watch-cycle-exits.logfield orderconfirmedGRACE=${FM_GUARD_GRACE:-300}is unchanged inbin/fm-guard.sh,bin/fm-watch-arm.sh, andbin/fm-claude-stop-autoarm.sh✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.