Repository navigation
Conversation
740e74d to
fc65808
Compare
A blocked Claude Stop aborts the in-flight asyncRewake arm, so the guard's refusal starved the only mechanism that could restore a watcher. Prime --ensure-watcher before refusing: a session-detached watcher can still come up, the registered hook remains the rewake owner, and two consecutive refusals cannot be guaranteed by the first. The racing stale-heartbeat alarm is a separate lock-acquisition TOCTOU and is left unchanged.
A primed --ensure-watcher cycle started as a non-successor and discarded stdout and stderr, so leftover downtime was re-announced into a one-poll resurface and the wake or failed-start line had no consumer. Pass FM_WATCH_PREDECESSOR_ARM_PID so the arm starts a handling successor, and write that cycle's output to state/.claude-autoarm-prime.out so a later Stop can still recover.
Priming before the cooperative wait made every ordinary Claude Stop start a handling successor, which consumed pending downtime and skipped the once-per-generation rearm-resurface. Move --ensure-watcher to immediately before the refusal so a blocked Stop still leaves a detached successor, while an allowed Stop leaves the ordinary asyncRewake cycle as a non-successor.
Rebasing this branch onto main picked up kunchenguid#3946, which made bin/fm-claude-stop-autoarm.sh derive its grace from the poll cadence (max(300, FM_POLL + 60)) and pass that resolved value to every bin/fm-watch-arm.sh invocation, because the wrapper's own default is a flat 300s and would otherwise reject a healthy long-poll watcher as stale. The two branches conflict semantically rather than textually: this branch adds a third fm-watch-arm.sh invocation - the --ensure-watcher priming fork - and it called the wrapper bare, so on a long-poll home the primed cycle would judge staleness with 300s while the hook that forked it had just judged the same beacon with the derived value. That reintroduces the spurious "lock held by live pid but heartbeat is stale" refusal on the one path whose whole job is to restore a watcher. Hand the primed fork the same FM_GUARD_GRACE="$GRACE" the retry loop already passes, and cover it: the new test drives --ensure-watcher with FM_POLL=900 and FM_GUARD_GRACE unset and asserts the detached arm sees 960. It reports "got: unset" without this change. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…e priming exception
…. It is a genuine defect introduced by this PR: the change added refusal-path priming (the guard forks `fm-claude-stop-autoarm.sh --ensure-watcher`, which detaches a `fm-watch-arm.sh` recovery cycle, immediately before the final `block_stop`), but the banner sentence still asserted "so nothing owns recovery and restoring supervision is on you" — false on exactly the refusal that just detached a cycle, and an invitation to arm a second watcher over a recovery already under way. Fix (smallest root-cause change, removal of the unknowable clause rather than a second wording or a conditional branch, both of which this branch's history already tried and rejected): - bin/fm-turnend-guard.sh:247 — banner now reads "The Stop-owned auto-arm did not claim this home, so no generation claim owns recovery for this Stop." True on every refusal: priming deliberately takes no generation claim, and both `block_stop` sites in --claude mode are reached only after `autoarm_owns_recovery` returned false. The banner's instruction is left to the repair line below it, which for Claude says to inspect the Stop-owned recovery path rather than replace it. - bin/fm-turnend-guard.sh priming comment updated to state the banner stops at the missing generation claim so it never denies a recovery this Stop just started. - tests/fm-turnend-guard.test.sh — one assertion added to `test_hook_claude_mode_refused_stop_cannot_guarantee_a_second_refusal`, on the first refusal (the one that detaches the cycle the rest of the case proves claims the home lock). Verified it fails against the old wording ("not ok - ... (missing: 'no generation claim owns recovery for this Stop')") and passes against the new. - docs/turnend-guard.md — banner paragraph and regression-coverage line updated. - docs/verification/supervision.md — new evidence entry recording the pre-fix reproduction, the post-fix isolated run, and the full four-suite run. Verification on the final tree: `bin/fm-test-run.sh tests/fm-claude-stop-autoarm.test.sh tests/fm-guard-stale-banner.test.sh tests/fm-turnend-guard.test.sh tests/fm-supervision-instructions.test.sh` → FM_TEST_SUMMARY total=4 failed=0 skipped_gate=0, exit 0; `bin/fm-lint.sh` exit 0; `bin/fm-doc-audience-check.sh` exit 0 (surfaces=97 local_links=357). Changes are left uncommitted in the worktree; no gate/push/PR action was taken
692fabc to
7a1422d
Compare
|
Handing this over for review. It is rebased onto current The one red check is "PR must be raised via no-mistakes", and it is red for a reason Reproduced on v1.64.0 and again on v1.72.0. The same install runs fine against another Because the pipeline could not run, the rebase was pushed directly, which is precisely what One correction to the record on this PR: an earlier run here was reported with Nothing here needs action from me that I can take — clearing that check needs either a fix |
… work is spent Refs kunchenguid#4018 Limits, stated as limits: - It closes nothing. Every forge call is a read, including in the opt-in --sweep mode: no issue is closed, labelled, or commented on, and no backlog is read or written. It is the evidence half of the claim problem, not the loop closure the triage also leaves open. - A fix that cites the issue number nowhere - no PR body, branch, or title, no commit message, and no --symbol the caller supplies - stays invisible to every check. bin/fm-issue-claim.sh runs five read-only checks per issue and prints an inspectable verdict (open, claimed, partially-covered, fixed-on-main, or unknown): timeline cross-references, maintainer triage stamps (OWNER, MEMBER, or COLLABORATOR only; the existing-pr target PR is read for its current state), the complete open-PR corpus fetched by paginated REST and checked against the search API total, the issue author's fork branches (resolved to the PR each heads), and main history since the issue opened (commit messages citing the issue, plus optional caller --symbol pickaxe searches). Issue numbers match only as whole numbers, so 4018 never matches 40181, and a foreign owner/repo#N is not a citation. A failed or rate-limited read, a short or unverified corpus, or a history ref that cannot be searched yields unknown or an explicit disclosure, never open. One corpus is shared across every issue in a run and can be saved and reused across runs with its completeness verdict and age. --sweep is opt-in and report-only: one disposition line per issue (close-candidate, leave-open, no-action, undetermined) with link candidates, judged only from durable evidence and never from titles, branches, PR checks, reviews, or mergeability. An issue with a live PR stamped existing-pr is always leave-open, and merged evidence with incomplete coverage is undetermined rather than a close candidate. Live proof against kunchenguid/firstmate, 2026-09-23, history ref origin/main@9296f9b9, open-PR corpus 1261/1261: - kunchenguid#4927 claimed, reproduced: PR kunchenguid#4943 and PR kunchenguid#4955 (timeline, corpus, fork, and the maintainer existing-pr stamp on kunchenguid#4955), plus kunchenguid#4026 named by the earlier stamp and still open. - kunchenguid#3370 fixed-on-main, reproduced: commit baede47 (kunchenguid#4656), found only by the history check with --symbol 3370:rerecord_device, issue still open. - kunchenguid#4412 partially-covered, reproduced: PR kunchenguid#4775 merged (landed as 9bc051f) and PR kunchenguid#4832 open. - kunchenguid#4466 open, reproduced, with every check complete. - Reporter's cases in one --sweep: kunchenguid#3966 claimed by PR kunchenguid#3977 and kunchenguid#3942 claimed by PR kunchenguid#3978 (leave-open); kunchenguid#3928 (PR kunchenguid#3946) and kunchenguid#3926 (PR kunchenguid#3944) show fixed-on-main and have since been closed on the forge (no-action).
Intent
The captain authorised fixing the supervision defects that keep interrupting his fleet, and this is
one of them. It is the defect that has cost the most working time: over a single day it repeatedly
refused every turn end in the supervising session, and the only operator remedy found was restarting
that session.
WHAT GOES WRONG
The Stop boundary registers two hooks in order,
bin/fm-turnend-guard.sh --claudefirst andbin/fm-claude-stop-autoarm.sh(asyncRewake) second. The guard refuses a stop when no live watcherholds the home lock. The arm only runs when a turn actually ends. So once the watcher has exited and
the guard starts refusing, the arm can never run, which guarantees the next refusal. The two hooks
deadlock each other.
Observed 2026-09-06 05:00-05:40: every turn end refused with "TURN WOULD END BLIND - SUPERVISION IS
OFF ... The Stop-owned auto-arm did not claim this home either".
state/.claude-autoarm-epochstayedfrozen at
epoch=165 owner_pid=41746 outcome=rewake updated_at=1788664081for over forty minutes,while
state/.turnend-claude-blocksstayedcount=1 epoch=165and its bounded fail-open neveradvanced, because it is pinned to an epoch that cannot change.
Entry condition: the watcher exits normally after delivering an actionable wake. Everything else was
healthy. The session lock was held by a live harness pid, hook registration was correct and complete,
no autoarm failure-notified or failure-alarmed markers existed, and
state/.watch-triage.logshowedthe watcher absorbing four parked tasks correctly before each exit.
WHY IT CANNOT BE REPAIRED FROM INSIDE THE SESSION, established by three attempts:
bin/fm-watch-arm.shrestores a watcher that beats, but it is one-shot. It exits at its nextactionable close and the deadlock returns.
exited, and the deadlock returned. The duration varies; the outcome does not.
bin/fm-claude-stop-autoarm.shdirectly exits 0 immediately, prints nothing, and does NOTadvance the epoch or claim the home. The arm appears to require the harness Stop invocation
context, so the owner cannot be made to claim from an ordinary tool call.
The chain can therefore only re-engage from a genuine harness Stop event, which the guard is
preventing.
TWO VARIANTS, AND WHY A FIX KEYED ON EPOCH STALENESS ALONE IS WRONG
A second episode the same day, 07:30-09:00 in the same home, recovered on its own several times
instead of locking up, so the deadlock is intermittent. In that window the epoch ADVANCED (166 failed
to 167 rewake) rather than freezing. A frozen epoch is one presentation of this defect, not its
definition.
That window also showed a third symptom: the arm can fail while a live watcher process holds the
singleton lock with a heartbeat stale past the 300s grace. It reports "lock held by live pid but
heartbeat is stale for s; inspect or stop that watcher before re-arming", then "watcher cycle
exited 1 without an actionable reason". Reproduced twice with different pids about an hour apart.
Both times the named pid no longer existed by the time the handling turn ran
psagainst it, thebeacon was fresh well inside the 300s grace, and the drain printed no watcher-down banner. So the arm
and the real state are racing: the arm reports a broken mechanism while supervision is in fact alive.
These alarms are largely spurious and must be verified before being acted on.
CONTRIBUTING LOAD WORTH RULING OUT AS A CAUSE
Through that window the watcher was re-absorbing two captain-held parked tasks roughly every
seventeen seconds for hours, because their wait was never declared in their status. Once each worker
appended its own
paused:line the churn stopped and the recheck moved to the intended long cadence.Whether that churn was driving the collapses is untested, but the two coincided closely.
What Changed
bin/fm-turnend-guard.shnow primesbin/fm-claude-stop-autoarm.sh --ensure-watcheron the refusal path only, placed below the attended fail-open and immediately before the finalblock_stop, so a refused Stop no longer aborts the only process that could restore a watcher. The new--ensure-watchermode inbin/fm-claude-stop-autoarm.shreuses the existing identity, AFK, and need gates, then setsid-detachesbin/fm-watch-arm.shas a handling successor (FM_WATCH_PREDECESSOR_ARM_PID) carrying the guard's derivedFM_GUARD_GRACE, takes no generation claim, and discards the cycle's stdout sostate/.watch-cycle-exits.logstays its single record.blocked-stopargument: a Stop that reaches the refusal now advances the count even when the auto-arm epoch has not changed, so a frozen epoch can no longer pinstate/.turnend-claude-blocksatcount=1and starve the bounded fail-open. The Claude refusal banner collapses to one unconditional sentence that reports the missing auto-arm claim without asserting anything about the detached cycle.--ensure-watchercases totests/fm-claude-stop-autoarm.test.sh(detached start without a claim, AFK and session-lock inertness, refused-cycle ledger row, derived grace) and six guard cases totests/fm-turnend-guard.test.sh(ordinary Stop does not prime, frozen/advancing/no-progress refusal variants, fail-open allows without priming, frozen epoch still reaches the fail-open); replaces GNU-onlytouch -d @<epoch>in the three away-mode grace cases with a portableset_mtimehelper, and records the contract and verification runs indocs/turnend-guard.md,docs/watcher-continuity.md, anddocs/verification/supervision.md.Risk Assessment
Testing
I ran the two smallest relevant suites (fm-turnend-guard, fm-claude-stop-autoarm) and then demonstrated the intent the way an operator experiences it: a reproducer stands up real Firstmate homes carrying the real bin/ tree of the branch base and of the branch head, seeded with the recorded 2026-09-06 state (task in flight, no watcher, epoch frozen at 165 rewake, blocks count=1 epoch=165), and fires genuine fm-turnend-guard.sh --claude Stop hooks under a harness process owning state/.lock, without the sibling asyncRewake arm — exactly what Claude Code does when a Stop is blocked. At base, three turn ends in a row refuse, no watcher ever appears, the ledger stays empty and the block count stays pinned at 1; at head the first refusal forks a real fm-watch-arm.sh/fm-watch.sh that takes the home lock, the count advances 1→2, the auto-arm epoch is left byte-identical (no generation claim), and the next Stop is allowed silently. The same before/after holds for the advancing-epoch variant (166 failed → 167 rewake), where head also leaves the allowed handoff Stop unprimed. Running the head test file against the base bin/ tree fails at the first priming assertion, so the added tests are true regressions. The first suite run surfaced one failure unrelated to this change — a pre-existing away-mode case using GNU-only
touch -d @epochon a BSD-touch host, which also made two neighbouring cases assert nothing; I fixed it with the repo's existing portable set_mtime idiom and re-ran, after which both suites are green (139 ok, 0 failures). No screenshots apply: the end-user surface here is the Stop-hook CLI transcript and the persisted state files, both captured verbatim.Evidence: End-to-end before/after transcript of the deadlock (both variants)
Source: End-to-end before/after transcript of the deadlock (both variants)
Evidence: Reproducer that produced the transcript
Source: Reproducer that produced the transcript
Evidence: Evidence index (marks two earlier-round artifacts superseded)
Source: Evidence index (marks two earlier-round artifacts superseded)
Evidence: Key excerpt: same seeded incident state, base vs head
Evidence: New coverage fails against the base bin/ tree (regression proof)
Pipeline
Updates from git push no-mistakes
... (51 earlier update rounds omitted to keep the PR body within GitHub's 65536-char limit; full history is in the run log.)
Stating the trade-off honestly so you can decide rather than me: the un-primed wording ("recovery is NOT already under way") is a genuinely stronger act-now signal than the primed one, so collapsing to a single sentence does lose a real distinction. The narrower forms are either (a) keep only the original wording and drop the whole contract, or (b) print the neutral "no generation claim owns recovery yet" unconditionally, which is true whether or not a cycle was detached and also needs no exit status. Recommending removal of the component rather than hardening it; this is deliberate authored content you have shaped across several rounds, so it is your call.
bin/fm-turnend-guard.sh:298- A blocked Stop still fails to advance state/.turnend-claude-blocks when autoarm_owns_recovery already accounted the same epoch earlier in that same Stop without incrementing, and docs/turnend-guard.md:129 now asserts the opposite. (Raised in round 9 and deferred by your "leave them for a later response"; code unchanged.)Concrete state: session S, tasks in flight, no watcher, state/.claude-autoarm-failure-notified present, state/.claude-autoarm-epoch =
epoch=42 owner_pid=<dead> outcome=failed updated_at=Twith mtime T, and state/.turnend-claude-blocks =session=S count=1 epoch=42from the previous Stop. A Stop at T+3: thefailedbranch of autoarm_owns_recovery (:367-372) sees age 3 < EPOCH_FRESH (15) and the notice present, so it calls budget_account_current_epoch with no argument. Inside, blocked=0 and old_epoch == current_epoch == 42, so :297-299 takes the no-op branch and COUNT stays 1 - yet :327 still sets BUDGET_ACCOUNTED=1. BUDGET_INITIALIZED_FAILURE is 0 (the file exists and the session matches), so the branch falls through, the guard refuses, and at :509budget_account_current_epoch blocked-stopfinds old_epoch == current_epoch and BUDGET_ACCOUNTED == 1 and skips the increment as well. The Stop is a consecutive block that advanced nothing. Thefailed-suppressedbranch at :374-379 has the identical shape.docs/turnend-guard.md:129 states "a Stop that reaches the refusal with no epoch progress still advances the count", which this sequence contradicts.
Impact is bounded, which is why this is info rather than a repeat of the 2026-09-06 pin: the epoch file's mtime ages past EPOCH_FRESH within 15 seconds and nothing refreshes it without a new generation, so accounting resumes on the next Stop; the cost is at most one extra blocked Stop before the attended fail-open, far below Claude's 8-block override. The observed 2026-09-06 incident (outcome=rewake, no notice) never reaches the accounting call at all and is fixed correctly by this change.
Remedy: set BUDGET_ACCOUNTED only when COUNT was actually incremented, rather than whenever accounting ran, and leave docs/turnend-guard.md:129 as written.
bin/fm-claude-stop-autoarm.sh:84- The --ensure-watcher header block states a fact about the shipped banner that stopped being true two commits ago, and it is the stated justification for the whole exit-status contract above it.Line 84-85 reads "The guard's refusal banner tells the model a recovery cycle is in flight only on the 0, so that claim can never outrun the fork." Commit 1474acb removed the printf at bin/fm-turnend-guard.sh:256 that made that claim. The banner the guard now prints on PRIMED_RECOVERY=1 is only "The Stop-owned auto-arm did not claim this home, so no generation claim owns recovery yet." - it does not tell the model a recovery cycle is in flight, and docs/turnend-guard.md:104 explicitly records that it "deliberately says nothing about the detached start's prospects".
A maintainer reading this header concludes the guard announces an in-flight recovery on exit 0 and may either rely on that announcement or reintroduce it. Correct the sentence to say what the exit status is actually keyed to - which of the two missing-claim wordings the banner selects - or drop it entirely if the wording split is removed per the simplification finding above.
tests/fm-turnend-guard.test.sh:31- The new file-level trap overrides EXIT, INT, and TERM but leaves HUP and QUIT pointing at the handler in tests/lib.sh, which removes the temp root without stopping the real detached cycle the new case starts.tests/lib.sh:177-181 installs handlers for EXIT, INT, TERM, HUP, and QUIT. tests/fm-turnend-guard.test.sh:31-33 replaces only the first three with turnend_guard_cleanup, so
trap 'fm_test_cleanup; exit 129' HUPand the QUIT equivalent survive from the lib and never call stop_real_primed_cycle.Concrete sequence: test_hook_claude_mode_ordinary_stop_does_not_prime has set PRIMED_CYCLE_HOME and is in its positive-control phase, so a real bin/fm-watch-arm.sh and bin/fm-watch.sh copied by install_real_watch_stack are running against the fixture home. The terminal hangs up (SIGHUP) or the user sends SIGQUIT. The lib handler runs fm_test_cleanup, which rm -rf's the fixture directory, and exits - while the primed cycle keeps running against the deleted tree. It does not receive the signal itself, because the priming path deliberately setsid's it into its own session (bin/fm-claude-stop-autoarm.sh:215), which is exactly the property the production change relies on.
Remedy: add the two missing lines next to :32-33,
trap 'turnend_guard_cleanup; exit 129' HUPandtrap 'turnend_guard_cleanup; exit 131' QUIT, matching the exit codes tests/lib.sh already uses.🔧 Fix: collapse the refusal banner to one unconditional sentence
2 warnings still open:
bin/fm-turnend-guard.sh:491- Priming is placed abovebudget_account_current_epoch blocked-stop || block_stop, exactly as instructed, but that line is not the refusal.terminal_fail_openruns afterwards and can ALLOW the same Stop, so a primed handling successor still lands on an allowed Stop - the outcome the recorded decision required be confined to refusals.Concrete sequence: session S, tasks in flight, no watcher,
state/.claude-autoarm-failure-notifiedpresent, epochoutcome=failed-suppressedaged pastFM_CLAUDE_AUTOARM_EPOCH_FRESH,state/.turnend-claude-blocksatcount=3 epoch=E, no.afk, noFAILURE_ALARM, andstate/.watcher-downholdingpending:downtime:<gen>.autoarm_owns_recoveryreturns 1 (stale epoch takes no accounting branch), so line 491 primes a detached arm withFM_WATCH_PREDECESSOR_ARM_PIDset. Line 501 raises COUNT to 4.terminal_fail_openthen passes every gate (4 > 3,failure_episode_verifiedtrue, no alarm, no open claim), writesFAILURE_ALARM, and returns 0, so line 515 exits 0 - the Stop is ALLOWED. Claude therefore does not cancel the registered asyncRewake sibling; it arms, finds the primed watcher already holdingstate/.watch.lock, and attaches (bin/fm-watch-arm.sh:438). That watcher is running withFM_WATCH_HANDLING_SUCCESSOR=1(bin/fm-watch-arm.sh:481-482), sofm_recovery_marker_arm_checkstill flips the marker toannounced:downtime:<gen>(bin/fm-watch.sh:1635) whileWATCHER_RECOVERY_PENDINGis forced to 0 (:1639-1640) andresurface_after_downtimereturns immediately for the whole cycle (:1757-1763). The once-per-generation re-presentation of the unacknowledged downtime episode never fires, with no error anywhere.terminal_fail_openreturning 2 reaches the same place through line 517, and there the priming call can also change the verdict of the Stop that started it: if the primed watcher wins the lock before the health re-check at :419, that check reports healthy,fm_failure_episode_resetruns, and the loud attended fail-open is skipped entirely.This contradicts the invariant the change asserts in three places - bin/fm-turnend-guard.sh:83 and :477 ("Priming is refusal-path only", "Prime recovery only on the refusal path") and docs/turnend-guard.md:98.
Remedy needs your call because it moves the block you explicitly placed: either relocate priming to immediately before the final
block_stopat line 518 (true refusal-path only, at the cost of the fail-open decision no longer seeing a cycle this Stop started), or keep the placement and correct the three invariant statements to say priming runs on the terminal path, which usually but not always refuses.tests/fm-claude-stop-autoarm.test.sh:1354- Removing the--ensure-watcherexit-status contract in d8e407d left two inertness tests asserting nothing that can fail. Their only remaining evidence is a filesystem check evaluated one statement after the hook returns, but priming is asynchronous by construction, so both would pass with the gate they exist to prove deleted.test_ensure_watcher_inert_when_afkpreviously assertedexpect_code 1- which only the non-forking gates produced - and now assertsexpect_code 0, the value every path returns. The surviving assertion at :1354 is[ ! -e "$dir/state/.watch.lock/pid" ]. If the[ -e "$STATE/.afk" ] && exit 0gate at bin/fm-claude-stop-autoarm.sh:152 were removed, the hook would fork through python3, execbin/fm-watch-arm.sh, and only then reach the fixture watcher that creates the lock dir - hundreds of milliseconds later. The file's own positive control proves the timing:test_ensure_watcher_starts_detached_watcher_without_claimneeds a 50-iteration, 5-second poll loop to observe that same lock appear.test_ensure_watcher_inert_without_session_lock(:1264-1265) has the identical shape against the session-lock gate at :142-149.This also removed the last non-racy proof of away-mode priming inertness: d8e407d deleted
test_hook_claude_mode_away_refusal_claims_no_primed_start, which checkedprimed_cycle_pidsand the lock through the guard's real refusal path. The same pattern exists at tests/fm-turnend-guard.test.sh:2092, where the allowed handoff Stop'sprimed_cycle_pidscheck runs immediately rather than over a window.Remedy is mechanical: give each of the three a bounded observation window instead of a single instantaneous check, matching what
test_hook_claude_mode_ordinary_stop_does_not_primealready does at tests/fm-turnend-guard.test.sh:1927-1939 (watch for ~1s and fail on the first trace that appears), and in the autoarm suite watch for the arm process as well as the lock so the check is not blind to a fork whose watcher has not started yet.🔧 Fix: prime only on the true refusal, below the fail-open
4 infos still open:
bin/fm-turnend-guard.sh:479- Relocating the priming block in 915761e opened one refusal path that no longer primes.budget_account_current_epoch blocked-stop || block_stoprefuses directly on the||branch, and that branch is now ABOVE the priming block at :497 - before the move (d8e407d) priming ran first, so this same refusal did prime.Reachable sequence: the registered asyncRewake sibling fires on the same Stop and calls
fm_failure_episode_reset(bin/fm-wake-lib.sh:1205-1207), which takesstate/.turnend-claude-blocks.lock. If it holds that lock at the moment the guard reaches :272,fm_lock_try_acquirereturns 1,budget_account_current_epochreturns 1, and the guard refuses with no detached cycle started - the one outcome the change exists to prevent. The same happens if theprintf/mv -fof the budget file fails (:308-313).It is self-healing rather than a durable deadlock:
fm_lock_try_acquiresteals a lock whose holder is dead (bin/fm-wake-lib.sh:913-930), so the next Stop primes normally. Remedy is mechanical - factor the priming block at :497-521 into a function and call it from both refusal sites, e.g.budget_account_current_epoch blocked-stop || { prime_recovery; block_stop; }- and does not move the block back aboveterminal_fail_open.tests/fm-turnend-guard.test.sh:2145- Two of the three assertions intest_hook_claude_mode_fail_open_allows_without_priming_a_cyclecannot fail, and they claim coverage the same change argues elsewhere is impossible with a stub.The case uses
write_gated_watch_fixture(:1955), whose fm-watch.sh spins onstate/release-watch- which this case never creates - and which never callsfm_recovery_marker_arm_check. So[ ! -e "$dir/state/.watch.lock/pid" ](:2145) is unreachable even if priming ran, and thepending:downtime:failopen.1.aaamarker check (:2146-2149) is unreachable for the same reason. The change states this itself atinstall_real_watch_stack(:1830-1834): "A stub watcher cannot perform it, so 'the downtime episode is still unconsumed' is only a real assertion over the real watcher."The case still catches its regression through
primed_cycle_pids(:2143), which matches the detached arm as soon as it execs - and docs/verification/supervision.md:462 records exactly that, "the forked arm and watcher pids named in its message". So the test is not broken; its stated coverage is wider than what it proves. Smallest honest remedy: drop the two assertions that cannot fail, or switch this case toinstall_real_watch_stackso they mean what the comment at :2120-2125 says.tests/fm-turnend-guard.test.sh:2116- The new test was inserted between an existing comment and the function it documents, so the comment now heads the wrong case.Lines 2116-2119 ("The 2026-09-06 budget half of the same deadlock: state/.turnend-claude-blocks stayed count=1 epoch=165 for forty minutes ... A frozen auto-arm epoch must not pin the bound.") described
test_hook_claude_mode_frozen_epoch_still_reaches_the_bounded_fail_open, which is now at :2153. It reads as a preamble totest_hook_claude_mode_fail_open_allows_without_priming_a_cycle(:2126), which is about priming placement and not about the pinned count at all. Move lines 2116-2119 down to immediately above :2153, leaving the new comment at :2120-2125 with its own case.tests/fm-turnend-guard.test.sh:33- The new file-level trap overrides EXIT, INT, and TERM but leaves HUP and QUIT pointing at the handler in tests/lib.sh, which removes the temp root without stopping the real detached cycle the new case starts.tests/lib.sh:177-181 installs handlers for EXIT, INT, TERM, HUP, and QUIT. tests/fm-turnend-guard.test.sh:31-33 replaces only the first three with
turnend_guard_cleanup, sotrap 'fm_test_cleanup; exit 129' HUPand the QUIT equivalent survive from the lib and never callstop_real_primed_cycle.Concrete sequence:
test_hook_claude_mode_ordinary_stop_does_not_primehas setPRIMED_CYCLE_HOMEand is in its positive-control phase, so a real bin/fm-watch-arm.sh and bin/fm-watch.sh copied byinstall_real_watch_stackare running against the fixture home. The terminal hangs up (SIGHUP) or the user sends SIGQUIT. The lib handler runsfm_test_cleanup, which rm -rf's the fixture directory, and exits - while the primed cycle keeps running against the deleted tree. It does not receive the signal itself, because the priming path deliberately setsid's it into its own session (bin/fm-claude-stop-autoarm.sh:196-208), which is exactly the property the production change relies on.Remedy: add the two missing lines next to :32-33,
trap 'turnend_guard_cleanup; exit 129' HUPandtrap 'turnend_guard_cleanup; exit 131' QUIT, matching the exit codes tests/lib.sh already uses. (Raised in round 10 and never selected by a human; still present at branch head.)✅ No issues found.
bash tests/fm-turnend-guard.test.sh— full guard suite including the six new--claudecases (ordinary stop does not prime, frozen-epoch/advancing-epoch/no-epoch-progress refusal variants, away-mode refusal claims no primed start, frozen epoch still reaches the bounded fail-open)bash tests/fm-claude-stop-autoarm.test.sh— full auto-arm suite including the four new--ensure-watchercases (detaches a watcher with no generation claim, records a refused primed cycle in the lifecycle ledger, inert without a session lock, inert while away mode owns supervision)Manual end-to-end incident replay against realbin/at base 6d396da vs HEAD e823344 over real Claude Stop boundaries:bash ~/.no-mistakes/evidence/01M1XBNK8V52GE36GK363C65BD/turnend-deadlock-e2e.sh <worktree> 6d396daManual end-to-end banner-honesty check at HEAD across a primeable home, an away-mode home, and a home whosestate/.locknames a live foreign claude-shaped pid:bash ~/.no-mistakes/evidence/01M1XBNK8V52GE36GK363C65BD/banner-honesty-e2e.sh <worktree>Verified the primed cycle is genuinely detached and live (ps -o pid=,ppid=,args=on the process holdingstate/.watch.lock) and that a primed cycle blocked by a wedged stale-beacon holder still writes itsstate/.watch-cycle-exits.logrow naming that holderℹ️
tests/fm-turnend-guard.test.sh:2204- Working-tree change made by this test phase: tests/fm-turnend-guard.test.sh gained the repo's existing portableset_mtimehelper (copied in shape from tests/fm-inactive-reconcile.test.sh) and its threetouch -d "@$beat"call sites now use it.touch -d @<epoch>is GNU-only; on this macOS host BSD touch rejects it, left the beacon fresh, and made test_hook_away_daemon_blocks_beacon_older_than_poll_derived_grace fail while two neighbouring poll-derived-grace cases passed vacuously. This is unrelated to the deadlock fix and pre-exists the branch base; it is a host-portability fix, not a behaviour change, and it lands in this PR's diff.ℹ️ Two evidence artifacts from earlier rounds of this run are stale and will be linked from the PR: banner-honesty-e2e.txt (captured at e823344) and turnend-deadlock-e2e.txt (captured against base 6d396da) both show the refusal-banner line "This refusal primed a detached watcher start that survives it ...", which d8e407d removed when the banner collapsed to one unconditional sentence. They also predate 915761e moving priming below the attended fail-open. I left them in place and added README-evidence.md to the evidence directory marking them superseded and naming deadlock-before-after.txt as the head-accurate transcript; deleting them is the user's call.
bin/fm-test-run.sh tests/fm-turnend-guard.test.sh tests/fm-claude-stop-autoarm.test.sh— 139 ok, FM_TEST_SUMMARY total=2 failed=0 skipped_gate=0End-to-end before/after reproduction of the 2026-09-06 incident with real homes and real Stop hooks:deadlock-repro.sh <checkout> b84e0e362face25f3dd8945297a3df1320d7668c(frozen epoch 165 rewake, and advancing epoch 166 failed -> 167 rewake), transcript capturedRegression check that the new coverage fails before the fix: copied the base-commitbin/fm-turnend-guard.shandbin/fm-claude-stop-autoarm.shinto the worktree, ranbash tests/fm-turnend-guard.test.sh(first priming assertion fails:not ok - the watcher primed by the refused control stop never beat), then restored withgit checkout -- bin/Diagnosed the initialtest_hook_away_daemon_blocks_beacon_older_than_poll_derived_gracefailure to BSD touch (touch -d "@1700000000"→out of range or illegal time specification), applied the repo's portableset_mtimeidiom intests/fm-turnend-guard.test.sh, and re-ran the suite (bin/fm-test-run.sh tests/fm-turnend-guard.test.sh→ 93 ok, exit 0)Verified no primed watcher/arm processes and no temp homes were left behind after each repro run (ps -eo pid,command | grep fm-deadlock-repro), and that the worktree carries only the intentional test change (git status --porcelain)🔧 **Document** - 1 issue found → auto-fixed (2) ✅
docs/verification/supervision.md:386- Judgment call left for the phase that actually runs the suites: docs/verification/supervision.md records dated evidence entries for the two closest precedents to this change - the 2026-08-02 Claude auto-arm false-failure, guard-predicate, and bounded fail-open correction (line 356) and the 2026-08-04 model-aware pull-guard correction (line 372) - each with the exact commands (bin/fm-lint.sh, bin/fm-doc-audience-check.sh, bin/fm-test-run.sh over the four isolated supervision suites) and observed output. This deadlock fix is the same class of guard/auto-arm correction and has no such entry. I did not add one: an honest entry needs a real lint, doc-check, and suite run with captured output, which belongs to the validation phase rather than the documentation phase, and inventing a date or a FM_TEST_SUMMARY line would make the file lie. The deterministic proof itself is already recorded in docs/turnend-guard.md "Regression coverage" and docs/watcher-continuity.md, so nothing is undocumented - the open question is only whether this change also warrants a dated maintainer-verification record alongside its two precedents.🔧 Fix: record 2026-09-08 deadlock-fix verification evidence
✅ Re-checked - no issues remain.
docs/verification/supervision.md:416- The working tree carries an uncommitted change to tests/fm-turnend-guard.test.sh (beyond the stated target commit 915761e) that replaces the GNU-onlytouch -d "@<epoch>"calls in the three away-mode poll-derived-grace cases with a portableset_mtimehelper. That is exactly the host-portability failure this verification entry narrates at length. Two present-tense claims in the entry become false the moment that change is committed: line 416 says the failure "remains open against tests/fm-turnend-guard.test.sh rather than against this correction", and line 460 says the observedtouch -dfailure "is still the only observation of that case". I did not edit them. The historical narration of the 2026-09-08 run stays true either way, but an honest update needs a real full-script run of tests/fm-turnend-guard.test.sh on the tree that carries the helper, and inventing an FM_TEST_SUMMARY line or a secondokblock would make this evidence file lie - the same reason Round 1 of this step left the entry to a phase that actually runs the suites. Decision needed: either the test fix is dropped (entry is already correct), or it lands and someone re-runsbin/fm-test-run.sh tests/fm-claude-stop-autoarm.test.sh tests/fm-guard-stale-banner.test.sh tests/fm-turnend-guard.test.sh tests/fm-supervision-instructions.test.shso lines 414-417 and 460 can be replaced with observed output.docs/turnend-guard.md:97- Line 97 states that when the wait produces no recovery proof the guard "primes bin/fm-claude-stop-autoarm.sh --ensure-watcher immediately before refusing". After 915761e moved the priming call below terminal_fail_open, one Claude-path refusal no longer primes:budget_account_current_epoch blocked-stop || block_stop(bin/fm-turnend-guard.sh:479) refuses directly when fm_lock_try_acquire on state/.turnend-claude-blocks.lock fails, and that block_stop returns before the priming block at :513. Before the relocation that refusal did prime. The consequence is bounded and self-correcting - the budget lock is a micro-mutex held across a few file operations, and the next Stop primes normally - so it is not a fifth unbounded entry condition alongside the four the doc enumerates. I did not add a qualifier to line 97 because the recorded round-11 decision instructs that the surrounding invariant statements be re-read and confirmed rather than rewritten, and I would rather surface the imprecision than edit against that instruction. Your call whether the doc should name the exception or the code should prime on that path too.🔧 Fix: record the passing full-script re-run; name the priming exception
✅ Re-checked - no issues remain.
🔧 **Lint** - 1 issue found ✅
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
✅ No issues found.