Skip to content

fix(bin): name Claude successor-gap banner and harden auto-arm - #18

Merged
EvanAgee merged 4 commits into
mainfrom
fm/fm-watcher-hardening
Aug 24, 2026
Merged

EvanAgee merged 4 commits into
mainfrom
fm/fm-watcher-hardening

Conversation

@EvanAgee

Copy link
Copy Markdown
Owner

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:

  1. fm-guard.sh: when the supervision model is autoarm AND the latest .claude-autoarm-epoch outcome is 'rewake' AND the beacon is stale, the banner now names 'a design-induced supervision gap after a successful rewake' and drops the hook-registration repair line. Deliberate constraints honored: it does NOT call the gap a false alarm and does NOT call it harmless (the banner keeps the WATCHER DOWN header and explicitly states supervision IS absent during the gap); it only stops telling the operator to repair a registration that is fine. Only the autoarm model reaches this path; persistent/extension models keep their existing banner even if a stray rewake epoch is on disk.
  2. fm-claude-stop-autoarm.sh: the parent hook previously had only an EXIT lock-release trap. Added HUP/INT/TERM traps that, when possible, append an 'interrupted' epoch outcome and remove the abandoned .claude-autoarm-output.* file before dying, covering the real exit-143 process-group kill (session teardown / hook timeout). SIGKILL stays unreportable by design. The turn-end guard reads 'interrupted' as 'auto-arm does not own recovery', so it falls through to a proper Stop-owned continuation.
  3. fm-watch-arm.sh: added four ADDITIVE lifecycle-ledger fields to each .watch-cycle-exits.log row (source=autoarm|manual from FM_WATCH_ARM_SOURCE, the auto-arm epoch sequence, the session-lock owner pid as session generation, and a compact termination cause). They are appended AFTER the existing 'successor' field so nothing that parses the original fields breaks; the successor back-fill logic was rewritten to be field-position-agnostic. The auto-arm hook marks its cycles source=autoarm; every other arm (Pi/OpenCode/OMP/Codex/Grok/Cursor/Kimi and manual) defaults to source=manual with epoch=none and unchanged behavior.
  4. FM_GUARD_GRACE was deliberately NOT raised (the review is explicit that only delays detection of real supervision absence).

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

  • On Claude auto-arm only, a stale beacon whose latest epoch is rewake now 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.sh now traps HUP/INT/TERM, records an interrupted epoch, and removes the abandoned .claude-autoarm-output.* file so a mid-cycle process-group kill no longer leaves a dangling arming epoch.
  • Watch-cycle ledger rows append four fields after successor (source, epoch, session, cause); auto-arm cycles set source=autoarm, other arms default to source=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'.

=== 1. Claude autoarm + outcome=rewake + stale beacon ===
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but a design-induced supervision gap after a successful rewake (last beat: never, grace 999s).
●  Supervision IS absent during this gap; it is not harmless. Expected if the handling turn is still running past grace after a successful rewake; if that turn has ended, the auto-arm hook may have failed to arm the successor - check it.
●  This is a supervision warning only; the guarded operation WILL still run.
●  If the handling turn has already ended, the auto-arm hook may have failed to arm the successor - check the Stop hook and whether it armed. Do not re-arm the watcher yourself while that turn is still running.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

=== 2. Claude autoarm + outcome=arming + stale beacon (ordinary) ===
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 999s).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
●  This is a supervision warning only; the guarded operation WILL still run.
●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

=== 3. Cursor autoarm + leftover rewake (must stay ordinary) ===
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 999s).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
●  This is a supervision warning only; the guarded operation WILL still run.
●  watcher supervision is owned by the stop-hook park; inspect the hook registration and watcher startup path before ending the turn.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

=== 4. Persistent model + stray rewake epoch ===
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher process holds this home lock (last beat: 0s ago).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
●  This is a supervision warning only; the guarded operation WILL still run.
●  repair a missing or failed watcher cycle with the Pi tool fm_watch_arm_pi, or restart Pi with -e /tmp/fm-hardening-demo/persistent-rewake/root/.pi/extensions/fm-primary-turnend-guard.ts -e /tmp/fm-hardening-demo/persistent-rewake/root/.pi/extensions/fm-primary-pi-watch.ts if the extensions are not loaded.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

=== 5. FM_GUARD_GRACE default still 300 ===
resolved_default_note=script_uses_${FM_GUARD_GRACE:-300}

=== 5. FM_GUARD_GRACE default still 300 (resolved from source) ===
bin/fm-guard.sh: GRACE=${FM_GUARD_GRACE:-300}
bin/fm-watch-arm.sh: GRACE=${FM_GUARD_GRACE:-300}
bin/fm-claude-stop-autoarm.sh: GRACE=${FM_GUARD_GRACE:-300}
diff vs base: no FM_GUARD_GRACE edits in bin/
Evidence: Auto-arm parent TERM: interrupted epoch and cleaned output file

Source: Auto-arm parent TERM: interrupted epoch and cleaned output file

=== BEFORE TERM ===
leader_pid=67166
arm_live=-rw-r--r--@ 1 evanagee  staff  0 Aug 24 11:24 /var/folders/k4/bmrhcryx7ld7c_w81zly9mh40000gn/T//fm-hardening-term-demo.DFWcO1/home/state/arm-live
epoch_before:
epoch=1 owner_pid=67166 outcome=arming updated_at=1787588644
output files before:
/var/folders/k4/bmrhcryx7ld7c_w81zly9mh40000gn/T//fm-hardening-term-demo.DFWcO1/home/state/.claude-autoarm-output.lgKj3q
.
..
.claude-autoarm-epoch
.claude-autoarm-output.lgKj3q
.claude-autoarm.lock
.claude-autoarm.lock.owner.wGDJQ1
.lock
arm-live
arm-ran
task.meta

=== MID-CYCLE (arm live, about to TERM the process group) ===
epoch_mid:
epoch=1 owner_pid=67166 outcome=arming updated_at=1787588644
state listing:
.
..
.claude-autoarm-epoch
.claude-autoarm-output.lgKj3q
.claude-autoarm.lock
.claude-autoarm.lock.owner.wGDJQ1
.lock
arm-live
arm-ran
task.meta

=== AFTER TERM ===
outcome=interrupted
epoch_after:
epoch=2 owner_pid=67166 outcome=interrupted updated_at=1787588645
abandoned output files:
owner lock present? NO
state listing:
.
..
.claude-autoarm-epoch
.lock
arm-live
arm-ran
task.meta
Evidence: Persisted epoch after process-group TERM

Source: Persisted epoch after process-group TERM

epoch=2 owner_pid=67166 outcome=interrupted updated_at=1787588645

epoch=2 owner_pid=67166 outcome=interrupted updated_at=1787588645
Evidence: Lifecycle ledger rows from real autoarm and manual arms

Source: Lifecycle ledger rows from real autoarm and manual arms

=== AUTOARM-SOURCED CYCLE ===
ledger:
arm_pid=81208	watcher_pid=80625	origin=attached	started_at=1787588665	ended_at=1787588674	exit_code=unknown	signal=unknown	reason=attached-delivered-wake	beacon_age=9	lock_before=pid:80625|identity:Mon Aug 24 11:24:24 2026     bash /Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M0T82CKQQKXTF0Z538QPZHQB/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none	source=autoarm	epoch=41	session=4242	cause=unknown

field split:
NF=16
  $1=arm_pid=81208
  $2=watcher_pid=80625
  $3=origin=attached
  $4=started_at=1787588665
  $5=ended_at=1787588674
  $6=exit_code=unknown
  $7=signal=unknown
  $8=reason=attached-delivered-wake
  $9=beacon_age=9
  $10=lock_before=pid:80625|identity:Mon Aug 24 11:24:24 2026     bash /Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M0T82CKQQKXTF0Z538QPZHQB/bin/fm-watch.sh
  $11=lock_after=pid:none|identity:none
  $12=successor=none
  $13=source=autoarm
  $14=epoch=41
  $15=session=4242
  $16=cause=unknown

=== MANUAL ARM DEFAULT ===
ledger:
arm_pid=86371	watcher_pid=85885	origin=attached	started_at=1787588675	ended_at=1787588684	exit_code=unknown	signal=unknown	reason=attached-delivered-wake	beacon_age=9	lock_before=pid:85885|identity:Mon Aug 24 11:24:34 2026     bash /Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M0T82CKQQKXTF0Z538QPZHQB/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none	source=manual	epoch=none	session=none	cause=unknown

field split:
NF=16
  $1=arm_pid=86371
  $2=watcher_pid=85885
  $3=origin=attached
  $4=started_at=1787588675
  $5=ended_at=1787588684
  $6=exit_code=unknown
  $7=signal=unknown
  $8=reason=attached-delivered-wake
  $9=beacon_age=9
  $10=lock_before=pid:85885|identity:Mon Aug 24 11:24:34 2026     bash /Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M0T82CKQQKXTF0Z538QPZHQB/bin/fm-watch.sh
  $11=lock_after=pid:none|identity:none
  $12=successor=none
  $13=source=manual
  $14=epoch=none
  $15=session=none
  $16=cause=unknown
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)

arm_pid=81208	watcher_pid=80625	origin=attached	started_at=1787588665	ended_at=1787588674	exit_code=unknown	signal=unknown	reason=attached-delivered-wake	beacon_age=9	lock_before=pid:80625|identity:Mon Aug 24 11:24:24 2026     bash /Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M0T82CKQQKXTF0Z538QPZHQB/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none	source=autoarm	epoch=41	session=4242	cause=unknown
Evidence: Manual .watch-cycle-exits.log row (source=manual epoch=none)

Source: Manual .watch-cycle-exits.log row (source=manual epoch=none)

arm_pid=86371	watcher_pid=85885	origin=attached	started_at=1787588675	ended_at=1787588684	exit_code=unknown	signal=unknown	reason=attached-delivered-wake	beacon_age=9	lock_before=pid:85885|identity:Mon Aug 24 11:24:34 2026     bash /Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M0T82CKQQKXTF0Z538QPZHQB/bin/fm-watch.sh	lock_after=pid:none|identity:none	successor=none	source=manual	epoch=none	session=none	cause=unknown
Evidence: fm-guard stale-banner test transcript

Source: fm-guard stale-banner test transcript

ok - fm-guard stale banner: first stale call prints the full actionable banner
ok - fm-guard stale banner: repeated same-episode calls print a concise reminder only
ok - fm-guard stale banner: Pi and pi-signed primaries route themselves to the extension model
ok - fm-guard stale banner: omp routes to its own extension model and markers
ok - fm-guard stale banner: extension-owned hand-off with a live session is healthy
ok - fm-guard stale banner: extension-owned empty lock is genuinely unheld
ok - fm-guard stale banner: held unhealthy extension locks stay loud
ok - fm-guard stale banner: extension model without ownership evidence stays loud
ok - fm-guard stale banner: every extension-ownership signal is load-bearing
ok - fm-guard stale banner: extension model still alarms on a genuinely stale beacon
ok - fm-guard stale banner: queued-wake warning survives the extension hand-off tolerance
ok - fm-guard stale banner: persistent primaries ignore Pi extension evidence
ok - fm-guard stale banner: extension model stays silent for a live watcher
ok - fm-guard stale banner: auto-arm fresh beacon without a live watcher is healthy
ok - fm-guard stale banner: auto-arm stale beacon alarms with the true reason
ok - fm-guard stale banner: Claude rewake gap names the design gap and a possible hook-arm failure
ok - fm-guard stale banner: Cursor keeps the ordinary banner for a leftover rewake
ok - fm-guard stale banner: a non-rewake auto-arm epoch keeps the ordinary banner
ok - fm-guard stale banner: persistent model ignores a stray rewake epoch
ok - fm-guard stale banner: auto-arm stale episode stays one episode across calls
ok - fm-guard stale banner: persistent no-watcher banner names the true reason
ok - fm-guard stale banner: a no-watcher episode survives a beacon mtime change
ok - fm-guard stale banner: a fresh beacon without a live watcher remains unhealthy
ok - fm-guard stale banner: X-mode polling without a live watcher remains unhealthy
ok - fm-guard stale banner: healthy recovery rearms the next stale episode
ok - fm-guard stale banner: concurrent same-episode calls claim exactly one full banner
ok - fm-guard stale banner: deduplication is isolated per FM_HOME
ok - fm-guard stale banner: queued-wake warning remains independent
ok - fm-guard stale banner: read-only before writable does not consume full banner
ok - fm-guard stale banner: read-only during episode observes without mutating marker
ok - fm-guard stale banner: healthy read-only does not clear marker
ok - fm-guard stale banner: read-only never mutates stale-banner state files
EXIT:0
Evidence: Auto-arm TERM test transcript

Source: Auto-arm TERM test transcript

ok - auto-arm: parent TERM records interrupted and cleans the abandoned output file
EXIT:0
Evidence: Watch-arm ledger test transcript

Source: Watch-arm ledger test transcript

ok - watch-arm: lifecycle ledger adds source/epoch/session/cause without breaking existing parsers
ok - watch-arm: a manual arm defaults source=manual with epoch=none
EXIT:0

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)
  • focused test_parent_term_records_interrupted_and_cleans_output from tests/fm-claude-stop-autoarm.test.sh
  • focused test_lifecycle_ledger_records_additive_source_epoch_session_cause and test_lifecycle_ledger_defaults_manual_source_without_epoch from tests/fm-watch-arm.test.sh
  • live bin/fm-guard.sh against Claude/rewake, Claude/arming, Cursor/rewake, and persistent/rewake fixture homes
  • live process-group TERM of bin/fm-claude-stop-autoarm.sh mid-cycle, then inspected .claude-autoarm-epoch, abandoned output files, and owner lock
  • live bin/fm-watch-arm.sh autoarm-sourced and manual cycles, then parsed .watch-cycle-exits.log field order
  • confirmed GRACE=${FM_GUARD_GRACE:-300} is unchanged in bin/fm-guard.sh, bin/fm-watch-arm.sh, and bin/fm-claude-stop-autoarm.sh
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

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

coderabbitai Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 6 minutes.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 77afd1dd-7f63-430f-9f60-d11228d16614

📥 Commits

Reviewing files that changed from the base of the PR and between c5e8228 and a5e14df.

📒 Files selected for processing (8)
  • bin/fm-claude-stop-autoarm.sh
  • bin/fm-guard.sh
  • bin/fm-watch-arm.sh
  • docs/turnend-guard.md
  • docs/watcher-continuity.md
  • tests/fm-claude-stop-autoarm.test.sh
  • tests/fm-guard-stale-banner.test.sh
  • tests/fm-watch-arm.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.

@EvanAgee EvanAgee added the agent-pr-watched An agent merge watch is armed on this PR label Aug 24, 2026
@EvanAgee
EvanAgee merged commit b1dcad9 into main Aug 24, 2026
14 checks passed
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-pr-watched An agent merge watch is armed on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant