Skip to content

fix(bin): close the Claude auto-arm failure episode when supervision recovers - #5772

Open
Courtneyezra wants to merge 1 commit into
kunchenguid:mainfrom
Courtneyezra:fm/fm-autoarm-failure-latch-never-clears
Open

Courtneyezra wants to merge 1 commit into
kunchenguid:mainfrom
Courtneyezra:fm/fm-autoarm-failure-latch-never-clears

Conversation

@Courtneyezra

Copy link
Copy Markdown
Contributor

The fault

The last-resort auto-arm FAILED notice is deduplicated once per failure episode by state/.claude-autoarm-failure-notified.

An episode closed when a live identity-matched watcher with a fresh beacon was verified, but not when the supervision need ended altogether - and that is the stronger proof of health, because nothing remains for the mechanism to be failing at. An episode opened before the fleet went quiet therefore outlived the condition it described and latched for the life of the home. The next genuine exhausted-failure episode - the one where supervision is down and nothing is recovering it - passed silently.

Second consequence: the same marker gated the turn-end guard's budget reset ([ -e "$FAILURE_NOTICE" ] || budget_reset), so a latched episode also left the bounded block budget permanently unreset, while the budget accounting downstream kept reading the marker as a live unresolved episode.

Reproduced before the fix

An episode's three records, with the fleet then torn down so supervision is definitively not needed:

guard rc=0 out=[]
STILL PRESENT: .claude-autoarm-failure-notified
STILL PRESENT: .claude-autoarm-failure-alarmed
STILL PRESENT: .turnend-claude-blocks

The guard correctly allows the stop - there is nothing to supervise - and correctly leaves no output, but the episode never closes.

The change

  • bin/fm-turnend-guard.sh - the marker-gated budget reset becomes a full episode close. Best-effort by design: the absent supervision need already decides this stop, so a contended close must not block the turn's end, unlike allow_supervised_stop where supervision is still needed and an unproven close must still block. Both sites now go through one named close_failure_episode.
  • bin/fm-claude-stop-autoarm.sh - closes the episode from its post-loop need-vanished path, where it still holds its generation. The earlier pre-claim need_supervision || exit 0 deliberately does not, because the hook holds no generation there and must not mutate shared auto-arm state unowned; the synchronous guard owns that close.
  • bin/fm-wake-lib.sh - fm_failure_episode_reset already owned the record set but documented neither the set nor the conditions that close an episode. It now does, and the two scripts plus docs/turnend-guard.md and docs/watcher-continuity.md point at it instead of restating it.

state/.claude-autoarm-failure-alarmed was left alone, deliberately

Its meaning was established before touching it: it records that this episode's one attended fail-open was consumed, and it is read to suppress a second attended alarm and any later automatic continuation within the same unresolved episode. It is therefore episode-scoped by construction, and clearing it independently would let a second attended alarm fire inside one episode - exactly what the bound exists to prevent. Its single closer, the episode close, is the correct one. Its lifecycle is correct as it stands; the defect was never in this record, only in the episode failing to close.

Tests

The existing cases assert the marker is preserved across a run. That is right for one hook invocation - deduplication within an episode is the marker's whole purpose - and it is wrong as the whole contract, which is why the fault survived. Those cases are kept unchanged, and each suite gains the missing one: after recovery is verified the marker is gone, and a subsequent failure emits its notice again.

Each new test was confirmed to fail against the unfixed scripts, so neither is vacuous:

new test against unfixed code
tests/fm-turnend-guard.test.sh::test_hook_claude_mode_ended_supervision_need_closes_failure_episode not ok - the ended supervision need left the failure notice marker
tests/fm-claude-stop-autoarm.test.sh::test_vanished_need_closes_the_failure_episode not ok - the vanished supervision need left the failure notice marker

Both assert the full episode record set, not just the notice marker, and both assert the second notice fires after the close - while still asserting it does not repeat within one episode, so the second-notice assertion cannot pass vacuously.

Evidence

Every measurement below was taken against this branch's final tree (commit 6d716182), on Linux, hermetically - real processes, no harness, no fleet state touched. Suites were re-run after the last code edit; nothing was measured against an intermediate tree.

Test suites

Selected as every tests/*.test.sh that exercises bin/fm-turnend-guard.sh or bin/fm-claude-stop-autoarm.sh, run individually with bash tests/<name>.test.sh:

suite passed failed
fm-turnend-guard.test.sh 90 0
fm-claude-stop-autoarm.test.sh 54 0
fm-pi-watch-extension.test.sh 51 0
fm-guard-stale-banner.test.sh 34 0
fm-cursor-primary.test.sh 30 0
fm-sessionstart-nudge.test.sh 23 0
fm-session-lock-ancestry.test.sh 16 0
fm-omp-harness.test.sh 14 0
fm-supervision-instructions.test.sh 12 0
total 324 0

Two further suites in that set reported capability skips rather than results, on this machine only: fm-pi-windows-shell-invocation.test.sh (skip: native Windows Node required) and fm-pi-codex-native.test.sh (skip: native Pi adapter not installed). Neither was exercised here; CI covers what it can.

Case counts rose by exactly one per changed suite, which is the two new tests and no accidental loss: fm-turnend-guard.test.sh 89 -> 90, fm-claude-stop-autoarm.test.sh 53 -> 54.

Lint and docs

bin/fm-lint.sh, the repo's single owner of the lint definition, in the changed-file mode that applies to a local branch:

fm-lint.sh: ShellCheck 0.11.0 (pinned 0.11.0)
fm-lint.sh: local changed-file mode; ShellCheck source following disabled
fm-lint-workflows.sh: actionlint 1.7.12 (pinned 1.7.12)
fm-lint-workflows.sh: 3 workflow files valid

bin/fm-doc-audience-check.sh:

fm-doc-audience-check: ok surfaces=109 local_links=657

Not covered here

This change is pure state-machine logic over files in state/, with no verdict drawn from anything a harness emits, so it is not a harness-dependent check and adds no live guard or per-harness verification record. The full-canonical-set lint mode was not run; it is the separate blocker this branch is routed around, and it is untouched.

Delivery

Raised as direct-PR without the no-mistakes pipeline, by explicit instruction of 26 Sep 2026, because that pipeline's lint step is the blocker being worked around. Nothing else queued behind it was touched, and the lint step itself was not modified.

…recovers

The last-resort "auto-arm FAILED" notice is deduplicated once per failure
episode by state/.claude-autoarm-failure-notified. An episode closed when a
live identity-matched watcher with a fresh beacon was verified, but NOT when
the supervision need ended altogether - and that is the stronger proof of
health, because nothing remains for the mechanism to be failing at. An episode
opened before the fleet went quiet therefore outlived the condition it
described and latched for the life of the home: the next genuine failure, the
one where supervision is down and nothing is recovering it, passed silently.

The same marker gated the turn-end guard's budget reset
(`[ -e "$FAILURE_NOTICE" ] || budget_reset`), so a latched episode also left
the bounded block budget permanently unreset and kept lines downstream reading
it as a live unresolved episode.

Close the episode on that condition instead, in both Stop-event participants:

- bin/fm-turnend-guard.sh replaces the marker-gated budget reset with a full
  episode close, best-effort because the absent need already decides the stop.
- bin/fm-claude-stop-autoarm.sh closes the episode from its post-loop
  need-vanished path, where it still holds its generation. The pre-claim
  need check deliberately does not, because the hook must not mutate shared
  auto-arm state unowned; the guard owns that close.

state/.claude-autoarm-failure-alarmed needed no change. It records that the
episode's one attended fail-open was consumed, so it is episode-scoped by
construction and clearing it on its own would let a second attended alarm fire
in the same episode. Its single closer, the episode close, is the correct one.

fm_failure_episode_reset in bin/fm-wake-lib.sh already owned the record set but
documented neither the set nor the closing conditions; it now does, and the two
scripts and docs point at it rather than restating it.

Tests: the existing cases assert the marker is PRESERVED across a run, which is
right for one hook invocation and is why this survived. Both are kept, and each
suite gains the missing case: after recovery is verified the marker is gone,
and a subsequent failure emits its notice again. Both new tests were confirmed
to fail against the unfixed scripts.
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