Skip to content

fix(watch): account a delivering attached close as success - #8

Merged
knowttl merged 1 commit into
mainfrom
fm/fm-fix-watch-arm-close-accounting
Jul 27, 2026
Merged

knowttl merged 1 commit into
mainfrom
fm/fm-fix-watch-arm-close-accounting

Conversation

@knowttl

@knowttl knowttl commented Jul 27, 2026

Copy link
Copy Markdown
Owner

What was wrong

Under wake-heavy load, an arm attached to another arm's watcher printed
watcher: FAILED - cycle ended without an actionable reason and exited 1 every time
that watcher closed after successfully delivering its wake.

Confirmed from the main home's own lifecycle ledger (state/.watch-cycle-exits.log),
where the pattern repeats: a started arm records reason=actionable-signal exit_code=0,
and the arm that attached ~4s later records reason=attached-cycle-ended successor=none
about 12 seconds afterward (the successor confirmation window):

arm_pid=3342652 watcher_pid=3342685 origin=started  ... exit_code=0 reason=actionable-signal
arm_pid=3344281 watcher_pid=3342685 origin=attached ... reason=attached-cycle-ended successor=none

Root cause: an attached arm can only observe the singleton lock disappearing. The wake
reason goes to the stdout of the arm that owns that watcher as a child, so a successful
delivering close was indistinguishable from a dead cycle.

That false alarm was also self-sustaining: the Claude auto-arm translates watcher: FAILED
into a banner telling the model supervision is down and to re-arm by hand, which is what put
two competing arms in one home in the first place.

Compounding symptom, same window

The turn-end guard blocked 4 turns with "The Stop-owned auto-arm did not claim this home either"
while wakes were flowing normally. Measured on this machine (2026-07-27, loaded):

$ fm_harness_ancestry_pid   # old implementation
ancestry ms: 3257 / 2496 / 2663 / 3173

The auto-arm must resolve session-lock ancestry before it may claim a home, and
bin/fm-turnend-guard.sh --claude allows a stop only if that claim lands inside
FM_CLAUDE_AUTOARM_SYNC_WAIT_MS (800ms). The walk forked ps, basename, and grep on
every hop (up to ~40 forks), so under load the guard blocked turns whose auto-arm was
working normally. The two symptoms share the incident, not the code path; both are fixed.

The fix

  • bin/fm-push-transition-lib.sh: wake() publishes an identity-bound receipt
    (state/.watch-cycle-delivery: watcher pid, fm_pid_identity, timestamp, reason) as it
    delivers.
  • bin/fm-watch-arm.sh: when an attached chain ends, a receipt matching the exact
    attached pid, the lock identity captured at attach, and a delivery no older than that
    cycle
    closes the arm successfully with watcher: closed pid=<N> (wake delivered by its owning arm) plus the delivered reason, so every adapter notifies exactly as it does for
    an owned actionable close. Anything else - no receipt, stale, foreign, or recycled pid -
    still emits the typed failure and exits nonzero. Successor attach is still tried first, so
    the Pi/OpenCode "start the successor before delivering" ordering is unchanged.
  • bin/fm-session-lock-lib.sh: ancestry resolution reads /proc with no forks and falls
    back to a single ps snapshot on hosts without it. 18-40ms after the change, with the
    /proc and ps paths resolving the identical harness pid.

Cross-adapter check: the arm-layer change is additive to a path that previously only ever
failed, and the new line is classified by the same ^(signal:|stale:|check:|heartbeat)
grep every adapter already uses (claude Stop-owned, grok background-notify, codex
checkpoint, opencode/pi extensions). No adapter file changed.

docs/watcher-continuity.md updated because the arm-layer cycle contract itself gained a
terminal outcome; docs/turnend-guard.md gained one line naming the claim-latency
constraint its 800ms window depends on.

Local verification

GitHub Actions is billing-disabled fleet-wide, so local runs are the gate.

$ bin/fm-lint.sh
fm-lint.sh: ShellCheck 0.11.0 (pinned 0.11.0)          rc=0

$ bash tests/fm-watcher-lock.test.sh                   rc=0   ok=30  not ok=0
$ bash tests/fm-claude-stop-autoarm.test.sh            rc=0   ok=19  not ok=0
$ bash tests/fm-turnend-guard.test.sh                  rc=0   ok=50  not ok=0
$ bash tests/fm-guard-stale-banner.test.sh             rc=0
$ bash tests/fm-supervision-events.test.sh             rc=0
$ bash tests/fm-backend-herdr-eventwait-smoke.test.sh  rc=0
$ bash tests/fm-watch-checkpoint.test.sh               rc=0
$ bash tests/fm-documentation-audiences.test.sh        rc=0
$ bash tests/fm-instruction-owners.test.sh             rc=0

New regression coverage:

  • tests/fm-watcher-lock.test.sh - a real seed watcher delivers a real wake while a second
    arm is attached: the attached arm exits 0, reports the delivering close, repeats the
    reason, and logs reason=attached-cycle-delivered.
  • tests/fm-watcher-lock.test.sh - a receipt with the correct pid and identity but an old
    timestamp still yields watcher: FAILED and a nonzero exit, so real failure detection is
    not weakened. The pre-existing kill-the-seed cases cover the no-receipt failure.
  • tests/fm-claude-stop-autoarm.test.sh - a delivering close translates to an ordinary wake
    rewake (exit 2, outcome=rewake), never the supervision-down alarm.
  • tests/fm-claude-stop-autoarm.test.sh - ancestry resolves with ps stubbed to fail
    outright (proving the fork-free /proc path) and still resolves the same pid through the
    ps fallback with /proc unavailable. Verified to fail against the old implementation.

Pre-existing failures, unrelated and reproduced identically on origin/main
(checked out bin tests docs from origin/main and re-ran):

  • tests/fm-watch-triage.test.sh - "dead-agent declared pause flooded stale wakes across
    six unchanged polls" (awk: cannot open .../state/.wake-queue).
  • tests/fm-pi-watch-extension.test.sh - "OpenCode watch plugin must arm only when this
    session owns the fleet lock: expected exit 0, got 1".

Under wake-heavy load an arm attached to another arm's watcher reported
"watcher: FAILED - cycle ended without an actionable reason" and exited 1
every time that watcher closed after successfully delivering its wake. The
attached arm can only observe the lock disappearing: the reason line goes to
the stdout of the arm that owns the watcher as a child.

The watcher now publishes an identity-bound receipt as it delivers a wake, and
the arm accounts a close as successful only when the receipt names the exact
attached pid, the lock identity captured at attach, and a delivery no older
than that cycle. It then repeats the delivered reason so the adapter notifies
exactly as it does for an owned actionable close. Any other outcome, including
a stale, foreign, or recycled-pid receipt, still reports the typed failure and
exits nonzero.

The same incident window showed the Claude turn-end guard blocking turns whose
auto-arm was working normally. The auto-arm resolves session-lock ancestry
before it may claim a home, and that walk cost 2.5-3.3s on a loaded machine
against the guard's 800ms cooperative window, because it forked ps, basename,
and grep on every hop. Ancestry now reads /proc with no forks at all and falls
back to a single ps snapshot elsewhere: 18-40ms on the same machine, with both
paths resolving the identical harness pid.
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.

2 participants