Repository navigation
fix(bin): close the Claude auto-arm failure episode when supervision recovers - #5772
Open
Courtneyezra wants to merge 1 commit into
Open
Courtneyezra wants to merge 1 commit into
Courtneyezra wants to merge 1 commit into
Conversation
…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.
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.
The fault
The last-resort
auto-arm FAILEDnotice is deduplicated once per failure episode bystate/.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:
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, unlikeallow_supervised_stopwhere supervision is still needed and an unproven close must still block. Both sites now go through one namedclose_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-claimneed_supervision || exit 0deliberately 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_resetalready owned the record set but documented neither the set nor the conditions that close an episode. It now does, and the two scripts plusdocs/turnend-guard.mdanddocs/watcher-continuity.mdpoint at it instead of restating it.state/.claude-autoarm-failure-alarmedwas left alone, deliberatelyIts 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:
tests/fm-turnend-guard.test.sh::test_hook_claude_mode_ended_supervision_need_closes_failure_episodenot ok - the ended supervision need left the failure notice markertests/fm-claude-stop-autoarm.test.sh::test_vanished_need_closes_the_failure_episodenot ok - the vanished supervision need left the failure notice markerBoth 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.shthat exercisesbin/fm-turnend-guard.shorbin/fm-claude-stop-autoarm.sh, run individually withbash tests/<name>.test.sh:fm-turnend-guard.test.shfm-claude-stop-autoarm.test.shfm-pi-watch-extension.test.shfm-guard-stale-banner.test.shfm-cursor-primary.test.shfm-sessionstart-nudge.test.shfm-session-lock-ancestry.test.shfm-omp-harness.test.shfm-supervision-instructions.test.shTwo 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) andfm-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.sh89 -> 90,fm-claude-stop-autoarm.test.sh53 -> 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:bin/fm-doc-audience-check.sh: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-PRwithout theno-mistakespipeline, 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.