Skip to content

fix(bin): keep the Claude turn-end guard waiting while a supervision-host auto-arm is starting - #68

Merged
peterOC26 merged 9 commits into
mainfrom
fm/fm-turnend-guard-host-false-blind-g1
Nov 15, 2026
Merged

peterOC26 merged 9 commits into
mainfrom
fm/fm-turnend-guard-host-false-blind-g1

Conversation

@peterOC26

@peterOC26 peterOC26 commented Nov 15, 2026 •

Copy link
Copy Markdown
Owner

Intent

Turn-end guard says supervision is off while the supervision host is re-arming

Resolution recorded by fm-captain-hold.
Decision digest: 5bdc02baef9afb174011b9518ace85ceccc9553f92fc3327f30be8528c439697
Resolution mode: released

Captain decision:
Captain 2026-11-15 (Jobs page note 1794703235-3uxISq): "The 11 firstmate fixes - do all of these". Start now instead of the staggered dates; Grok builds, DeepSeek checks, firstmate repo reviews one at a time (fleet 133), captain merges each.

Seen 3 times on 2026-11-09 (about 07:00Z, 07:09Z, 07:10Z): at the end of a long wake-handling turn, the Claude Stop guard (bin/fm-turnend-guard.sh --claude) prints "TURN WOULD END BLIND - SUPERVISION IS OFF ... last beat 69-428s ago ... the Stop-owned auto-arm did not claim this home", yet seconds later fm-supervision-host.sh park plus fm-watch-arm.sh/fm-watch.sh are live with a fresh beat. Supervision host is on for this home. Find whether the guard misses the host-owned arm path (false alarm) or there is a real gap between host cycles; fix the guard or the gap. Firstmate repo ship, upkeep side job (Grok + DeepSeek).

"The 11 firstmate fixes - do all of these" (2026-11-15)

What Changed

  • bin/fm-claude-stop-autoarm.sh now writes its pid to state/.claude-autoarm-starting before it sources any libraries. An EXIT trap removes the file, but only if it still holds this process's pid. This lets the synchronous Stop guard see an auto-arm that is running but has not made its claim yet.
  • bin/fm-turnend-guard.sh --claude still uses the short FM_CLAUDE_AUTOARM_SYNC_WAIT_MS wait. On a home where the supervision host is enabled, it now keeps waiting after that window for as long as the starting marker names a live process running fm-claude-stop-autoarm.sh. It stops waiting when the claim or epoch proof appears, when that process exits, or when FM_CLAUDE_AUTOARM_HOST_CLAIM_WAIT_MS (default 15000) has passed since the wait began. After the loop it checks recovery once more. In these cases it keeps the short wait and still shows the "supervision is off" banner: no marker, a symlinked or non-numeric marker, a dead or reused pid, and a home with the host turned off. The allow path is now a shared allow_autoarm_recovery helper.
  • Docs: docs/configuration.md documents the new setting, docs/turnend-guard.md describes the extended wait, and the operational home layout skill lists the new marker file. tests/fm-turnend-guard.test.sh adds tests for the extended wait and for each case that still blocks.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change is narrow. It extends the --claude claim wait only while a host-enabled home's starting marker names a live fm-claude-stop-autoarm.sh process, and an elapsed-time deadline caps that wait (default 15s). The round-4 fix added a recheck after the loop, so a rewake, claim, or healthy watcher that lands as the starter exits still allows the stop. The marker is published atomically and its owner-only release is correct. I found no reachable path that gives a wrong verdict.

Testing

I ran the targeted turnend-guard test file, which passed. I also drove the real Stop auto-arm and the real --claude guard together in disposable primary homes. On base, the real auto-arm published its arming claim, but the guard still printed the "TURN WOULD END BLIND ... Stop-owned auto-arm did not claim" banner. That is the reported false alarm, reproduced live. On the fixed HEAD, the same race allowed the stop silently every time, waiting about 700-870ms for the real claim. HEAD also used no continuation and left no starting marker behind. A home that opted out of the host still showed the banner, which matches the recorded decision. A genuinely missing auto-arm with a stale dead-pid marker still blocked in about 1.6s, not the 15s ceiling. The auto-arm does create a missing state/ dir, but base does the same: fm-wake-lib.sh makes it when sourced. The new marker publish correctly skipped it. Everything ran as real scripts in the hook-firing order. No real Claude TUI was run, because the gate worktree is a linked worktree where these hooks stay inert by design. The lab was torn down afterward.

  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Host-enabled home: Stop guard allows when the real auto-arm claims after the short window, with no false 'did not claim' banner (local disposable home, synthetic Stop payload) ✅ pass live live-real-hooks-host-claim-wait.txt: HEAD with the host on and a 0ms short window gave exit=0 and no output in 706ms and 869ms. The ledger shows outcome=arming, owned by the live auto-arm pid. No cont…
Regression reproduction: the base commit prints the false 'SUPERVISION IS OFF / auto-arm did not claim' banner in the same race ✅ pass live live-real-hooks-host-claim-wait.txt: on BASE 6d7e171 the guard gave exit=2 with the TURN WOULD END BLIND banner both times, while the epoch ledger showed outcome=arming from the live auto-arm.
Default 800ms window on a host-enabled home still allows the real auto-arm ✅ pass live live-real-hooks-host-claim-wait.txt: HEAD with the default window gave exit=0 and no output in 713ms.
Adversarial: auto-arm genuinely absent on a host-on home with a stale dead-pid starting marker still blocks with the banner and does not wait out the 15s host bound ✅ pass live live-real-guard-absent-autoarm.txt: exit=2 with the banner after 1653ms.
Home that opted out of the supervision host keeps the short window and the banner ✅ pass live live-real-hooks-host-claim-wait.txt: 'host OPTED OUT' run gave exit=2 with the banner in 731ms.
Auto-arm in a home without state/ does not publish a starting marker or add any new side effect ✅ pass live live-autoarm-no-state-side-effect-compare.txt and the bash -x trace: publish_starting_marker returned without writing anything. state/ is created on HEAD and on base by the existing mkdir in fm-wake-l…
Real Claude TUI primary in a lab home ends a long turn without the false banner ⏸️ untested no Starting claude from the gate worktree puts FM_ROOT in a linked worktree, and fm_primary_scope_matches deliberately keeps both hooks inert there. The race also depends on how long the auto-arm takes…
Evidence: Live HEAD vs base vs host-off guard decisions with the real auto-arm

Source: Live HEAD vs base vs host-off guard decisions with the real auto-arm

# host enabled check: on
=== HEAD (fix) host-on, short window 0ms, run 1: guard exit=0 elapsed=706ms
--- guard output:
<none>
--- epoch ledger: epoch=1 owner_pid=3345819 outcome=arming updated_at=1794735548
--- starting marker at guard exit: 3345819
--- continuation budget file: absent
--- starting marker after auto-arm exit: absent
=== HEAD (fix) host-on, short window 0ms, run 2: guard exit=0 elapsed=869ms
--- guard output:
<none>
--- epoch ledger: epoch=1 owner_pid=3346977 outcome=arming updated_at=1794735549
--- starting marker at guard exit: 3346977
--- continuation budget file: absent
--- starting marker after auto-arm exit: absent
=== HEAD (fix) host-on, default short window 800ms: guard exit=0 elapsed=713ms
--- guard output:
<none>
--- epoch ledger: epoch=1 owner_pid=3348092 outcome=arming updated_at=1794735551
--- starting marker at guard exit: 3348092
--- continuation budget file: absent
--- starting marker after auto-arm exit: absent
=== BASE 6d7e171 host-on, short window 0ms, run 1: guard exit=2 elapsed=715ms
--- guard output:
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  TURN WOULD END BLIND - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher holds this home lock (last beat: 400s ago).
●  The Stop-owned auto-arm did not claim this home either, so recovery is NOT already under way.
●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
--- epoch ledger: epoch=1 owner_pid=3348831 outcome=arming updated_at=1794735552
--- starting marker at guard exit: absent
--- continuation budget file: session=sess-lab
count=1
epoch=
--- starting marker after auto-arm exit: absent
=== BASE 6d7e171 host-on, short window 0ms, run 2: guard exit=2 elapsed=721ms
--- guard output:
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  TURN WOULD END BLIND - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher holds this home lock (last beat: 400s ago).
●  The Stop-owned auto-arm did not claim this home either, so recovery is NOT already under way.
●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
--- epoch ledger: epoch=1 owner_pid=3349856 outcome=arming updated_at=1794735553
--- starting marker at guard exit: absent
--- continuation budget file: absent
--- starting marker after auto-arm exit: absent
=== HEAD (fix) host OPTED OUT, short window 0ms: guard exit=2 elapsed=731ms
--- guard output:
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  TURN WOULD END BLIND - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher holds this home lock (last beat: 400s ago).
●  The Stop-owned auto-arm did not claim this home either, so recovery is NOT already under way.
●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
--- epoch ledger: epoch=1 owner_pid=3350733 outcome=arming updated_at=1794735554
--- starting marker at guard exit: 3350733
--- continuation budget file: absent
--- starting marker after auto-arm exit: absent
Evidence: Live guard blocks quickly with no auto-arm and a stale marker

Source: Live guard blocks quickly with no auto-arm and a stale marker

=== HEAD host-on, auto-arm genuinely absent + stale starting marker (dead pid 999999), default windows: guard exit=2 elapsed=1653ms
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  TURN WOULD END BLIND - SUPERVISION IS OFF
●  1 task(s) in flight, but no live watcher holds this home lock (last beat: 400s ago).
●  The Stop-owned auto-arm did not claim this home either, so recovery is NOT already under way.
●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Evidence: Auto-arm state/ creation is the same on HEAD and base

Source: Auto-arm state/ creation is the same on HEAD and base

HEAD exit=0 state: 
52:++ mkdir -p /tmp/fm-lab.GSd8xO/ns-HEAD/state
6d7e171 exit=0 state: 
46:++ mkdir -p /tmp/fm-lab.GSd8xO/ns-6d7e171/state
Evidence: Targeted turnend guard test log

Source: Targeted turnend guard test log

ok - fm_supervision_unhealthy: false with no state/*.meta at all
ok - fm_supervision_unhealthy: true with in-flight task and no beacon ever
ok - fm_supervision_unhealthy: true with in-flight task and a beacon far outside the grace window
ok - fm_supervision_unhealthy: false with in-flight task and a fresh beacon
ok - fm_supervision_status: FM_SUP_QUEUE_PENDING tracks state/.wake-queue
ok - fm_supervision_needed: X-mode relay poll needs supervision
ok - fm_supervision_unhealthy: source-only home needs supervision
ok - fm_supervision_needed: a registered custom check needs supervision with no task in flight
ok - fm_supervision_needed: a registered check whose bytes drifted still needs supervision
ok - fm_supervision_needed: false for a check.sh with no registration binding
ok - fm_supervision_needed: a task PR poll without a trust binding is not a registered custom check
ok - fm_supervision_status: the relay shim is not counted as a registered custom check
ok - fm-turnend-guard: silent no-op with nothing in flight
ok - fm-turnend-guard: blocks when a fresh beacon has no live watcher lock
ok - fm-turnend-guard: non-Claude path blocks a source-only home
ok - fm-turnend-guard: blocks on a dead watcher lock even when the beacon is fresh
ok - fm-turnend-guard: silent no-op with a live watcher lock and fresh beacon
ok - fm-turnend-guard: healthy non-Claude harness paths ignore Claude episode contention
ok - fm-turnend-guard: blocks on a live watcher lock with an ancient beacon
ok - fm-turnend-guard: blocks with the exact required reason in the primary when unhealthy
ok - fm-turnend-guard: blocks from active FM_HOME state, not only repo-root state
ok - fm-turnend-guard: X-mode repair reason sources the cadence config
ok - fm-turnend-guard: X-mode-only supervision remains guarded in default mode
ok - fm-turnend-guard: registered-check-only supervision is named in the block banner
ok - fm-turnend-guard: ignores stale repo-root state when FM_HOME is set
ok - fm-turnend-guard: uses FM_STATE_OVERRIDE ahead of FM_HOME/state
ok - fm-turnend-guard: stop_hook_active=true always allows the stop (never blocks twice in one turn)
ok - fm-turnend-guard: blocks a blind turn end in a secondmate's own home (.fm-secondmate-home no longer excludes it)
ok - fm-turnend-guard: idle-by-default - silent in a secondmate home with nothing in flight
ok - fm-turnend-guard: stop_hook_active=true allows the stop in a secondmate home (never blocks twice in one turn)
ok - fm-turnend-guard: secondmate deferred-death recovery - silent while watched, forces re-arm once the watcher exits
ok - fm-turnend-guard: inert in a secondmate's own child worktree (linked git worktree) even when unhealthy
ok - fm-turnend-guard: blocks a blind turn end in a treehouse-leased LINKED secondmate home (marker force-include)
ok - fm-turnend-guard: an invalid (empty) marker cannot spoof inclusion; linked worktree stays exempt
ok - fm-turnend-guard: a non-ASCII marker cannot spoof inclusion; linked worktree stays exempt
ok - fm-turnend-guard: inert in a crewmate/scout task worktree (linked git worktree) even when unhealthy
ok - fm-turnend-guard: fails open (never blocks) when jq is missing
ok - fm-turnend-guard: silent no-op on empty stdin
ok - fm-turnend-guard: runs well under the generous timing margin (0s)
ok - fm-turnend-guard-grok: forces one explicitly marked same-session resume when the shared predicate blocks
ok - fm-turnend-guard-grok: legacy environment loop guard prevents a nested resume loop
ok - fm-turnend-guard-grok: native false delegates blocking feedback with zero resume processes
ok - fm-turnend-guard-grok: native true remains bounded and starts no resume process
ok - fm-turnend-guard-grok: both spellings are typed and camelCase has deterministic precedence
ok - fm-turnend-guard-grok: malformed, invalidly typed, and missing-prerequisite payloads start neither path
ok - fm-turnend-guard-grok: missing jq and no-supervision-needed stops stay silent and bounded
ok - tracked .claude/settings.json entries: 7 inert under grok, the documented subagent exception still armed, all live under Claude
ok - .codex/hooks.json: Stop hook uses hook process root when payload cwd is outside
ok - .codex/hooks.json: Stop hook ignores nested git root guard scripts
ok - .codex Stop wrapper: clean success JSON, inherited PATH, unchanged errors and continuation without logout output
ok - .opencode primary plugin: guard path is anchored to worktree, not directory
ok - .pi primary extension: no-tool and multi-tool runs each inject exactly one guard follow-up
ok - .pi primary extension: delivery failure resets the logical-run latch
ok - .pi primary extension: a nested load keeps the live session's turn-end marker
ok - .pi primary extension: the turn-end guard reads a Windows-tagged session lock only on Windows
ok - fm-turnend-guard --claude: re-blocks a loop-guarded stop while unhealthy and unclaimed (incident regression)
ok - fm-turnend-guard --claude: X-mode-only homes re-block when auto-arm recovery is absent
ok - fm-turnend-guard --claude: a live arming epoch advances once and repeated observation is idempotent
ok - fm-turnend-guard --claude: repeated failed-to-arming races make bounded monotonic progress
ok - fm-turnend-guard --claude: terminal owner boundary excludes a concurrent start without deadlock
ok - fm-turnend-guard --claude: rechecks recovery when the starter exits
ok - fm-turnend-guard --claude: fresh rewake epoch prevents a duplicate continuation for the same event
ok - fm-turnend-guard --claude: an abandoned auto-arm claim no longer allows a blind stop (incident regression)
ok - fm-turnend-guard --claude: a claim whose pid was reused stops counting as recovery even while its entry reads arming
ok - fm-turnend-guard --claude: a hung owner frozen at arming with no watcher beat no longer allows a blind stop
ok - fm-turnend-guard --claude: a live open generation claim owns recovery with no lock held
ok - fm-turnend-guard --claude: a stuck generation claim no longer allows a blind stop
ok - fm-turnend-guard --claude: the terminal path clears an abandoned claim instead of stepping aside silently
ok - fm-turnend-guard --claude: fresh failed epochs preserve and advance monotonic fail-open progression
ok - fm-turnend-guard --claude: integrated fresh failures reach one bounded fail-open, stop continuation, and reset on recovery
ok - fm-turnend-guard --claude: an inert auto-arm's frozen epoch reaches one bounded fail-open and resets on recovery
ok - fm-turnend-guard --claude: a frozen unverified epoch spends the budget yet still blocks
ok - fm-turnend-guard --claude: reset contention preserves all episode state until retry
ok - fm-turnend-guard --claude: concurrent auto-arm and guard resets are idempotent and deadlock-free
ok - fm-turnend-guard --claude: the exhausted auto-arm commits the attended alarm once, then stays suppressed until recovery
ok - fm-turnend-guard --claude: a repeatedly lost host hand-back on a pending or announced handling marker reaches the attended alarm
ok - fm-turnend-guard --claude: interruption reaches the attended alarm and preserves its final rewake after commit
ok - fm-turnend-guard --claude: stale rewake epoch does not allow a blind stop
ok - fm-turnend-guard --claude: budget exhaustion alone cannot permit a blind stop
ok - fm-turnend-guard --claude: verified fail-open is loud, bounded, attended, and non-repeating
ok - fm-turnend-guard --claude: fail-open requires both exhausted retries and consumed notice
ok - fm-turnend-guard --claude: away ownership excludes the Stop-autoarm fail-open
ok - fm-turnend-guard --claude: positive watcher recovery resets failure episode state
ok - fm-turnend-guard --claude: bounded claim wait avoids a token-consuming forced continuation
ok - fm-turnend-guard --claude: a live supervision-host auto-arm still starting past the short window owns recovery
ok - fm-turnend-guard --claude: only a live matching supervision-host starter extends the claim wait
ok - fm-claude-stop-autoarm: publishes its starting marker before the claim and drops only its own
ok - fm-claude-stop-autoarm: early marker publication leaves missing state absent
ok - fm-turnend-guard --claude: secondmate home re-blocks unclaimed and allows auto-arm-claimed stops
ok - fm-turnend-guard: a live away-mode daemon satisfies supervision with no watcher holding the lock
ok - fm-turnend-guard: away-mode daemon ownership survives a leftover dead watcher lock
ok - fm-turnend-guard: away mode with no daemon and no watcher still blocks
ok - fm-turnend-guard: away mode blocks on a dead away-mode daemon
ok - fm-turnend-guard: away mode blocks on a pid-reused away-mode daemon lock
ok - fm-turnend-guard: away-mode daemon ownership never substitutes for a fresh beacon
ok - fm-turnend-guard: a daemon lock proves nothing while away mode is off
ok - fm-turnend-guard: away-mode beacon freshness uses the poll-derived grace, not the flat default
ok - fm-turnend-guard: a dead away-mode daemon still blocks under the poll-derived grace
ok - fm-turnend-guard: the poll-derived grace is bounded, not unlimited
ok - fm-turnend-guard: with away mode off, the poll-derived grace never applies
exit=0

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • ⚠️ bin/fm-claude-stop-autoarm.sh:237 - publish_starting_marker runs mkdir -p &#34;$STATE&#34; on every Stop, before the scope check at line 309. Before this change, the hook exited without writing anything in a checkout that is not a primary home. Now, every Claude Stop in a linked worktree of the firstmate repo (crewmate/scout worktrees, gate worktrees like this one) leaves behind a state/ directory that persists. It also briefly creates the starting marker and its lock directory there. That is a new side effect in scopes the hook is documented to ignore. The mkdir is also unnecessary for primary homes: fm-sessionstart-run.sh:93-99 already creates state/ for a primary root, and the guard stands down when state/ is missing (fm-turnend-guard.sh:214 via fm_primary_scope_matches). Fix: replace the mkdir with [ -d &#34;$STATE&#34; ] || return 0 so the marker is only published into a state dir that already exists.
  • ℹ️ bin/fm-turnend-guard.sh:592 - The longer claim wait only applies when fm_supervision_host_enabled is true. The slow pre-claim work in fm-claude-stop-autoarm.sh (sourcing six libraries, ps-based ancestry checks, fm-lock.sh, fm_supervision_needed, lines 260-399) is the same whether or not the home runs the supervision host. So a Claude home that opted out of the host can still hit the same false 'did not claim' banner when its claim lands after 800ms. The tests (host-off case) and docs show this restriction is deliberate and it matches the stated intent, which is about a host home. Asking only to confirm that non-host homes should keep the short window.
  • ℹ️ docs/configuration.md:3483 - The docs say the guard 'keeps waiting past FM_CLAUDE_AUTOARM_SYNC_WAIT_MS', which reads as extra time on top of the sync wait. The code (fm-turnend-guard.sh host_ticks = max(HOST_CLAIM_WAIT_MS, SYNC_WAIT_MS)/100, counted from the start of the loop) treats it as the total wait. The guard header comment also describes it as the total. Reword it as 'total milliseconds the --claude guard may wait (counted from the start of the claim wait, at least FM_CLAUDE_AUTOARM_SYNC_WAIT_MS) while ...'.
  • ℹ️ bin/fm-claude-stop-autoarm.sh:251 - release_starting_marker checks [ -f &#34;$STARTING_MARKER&#34; ] before taking the starting lock, then reads the file without silencing errors. Race: firing A sees B's marker, B removes it under the lock, then A's read &lt; &#34;$STARTING_MARKER&#34; fails. Bash then prints 'No such file or directory' to stderr from A's EXIT trap. If A is exiting 2, its stderr is the model-visible rewake banner, so that error line gets appended to the banner. Fix: add 2&gt;/dev/null to the redirect, or repeat the -f check after acquiring the lock.

🔧 Fix applied.
6 issues (2 warnings, 4 infos) still open:

  • ⚠️ bin/fm-claude-stop-autoarm.sh:237 - publish_starting_marker runs mkdir -p &#34;$STATE&#34; on every Stop, before the scope check at line 309. Before this change, the hook exited without writing anything in a checkout that is not a primary home. Now, every Claude Stop in a linked worktree of the firstmate repo (crewmate/scout worktrees, gate worktrees like this one) leaves behind a state/ directory that persists. It also briefly creates the starting marker and its lock directory there. That is a new side effect in scopes the hook is documented to ignore. The mkdir is also unnecessary for primary homes: fm-sessionstart-run.sh:93-99 already creates state/ for a primary root, and the guard stands down when state/ is missing (fm-turnend-guard.sh:214 via fm_primary_scope_matches). Fix: replace the mkdir with [ -d &#34;$STATE&#34; ] || return 0 so the marker is only published into a state dir that already exists.
  • ℹ️ bin/fm-turnend-guard.sh:592 - The longer claim wait only applies when fm_supervision_host_enabled is true. The slow pre-claim work in fm-claude-stop-autoarm.sh (sourcing six libraries, ps-based ancestry checks, fm-lock.sh, fm_supervision_needed, lines 260-399) is the same whether or not the home runs the supervision host. So a Claude home that opted out of the host can still hit the same false 'did not claim' banner when its claim lands after 800ms. The tests (host-off case) and docs show this restriction is deliberate and it matches the stated intent, which is about a host home. Asking only to confirm that non-host homes should keep the short window.
  • ℹ️ bin/fm-claude-stop-autoarm.sh:251 - release_starting_marker checks [ -f &#34;$STARTING_MARKER&#34; ] before taking the starting lock, then reads the file without silencing errors. Race: firing A sees B's marker, B removes it under the lock, then A's read &lt; &#34;$STARTING_MARKER&#34; fails. Bash then prints 'No such file or directory' to stderr from A's EXIT trap. If A is exiting 2, its stderr is the model-visible rewake banner, so that error line gets appended to the banner. Fix: add 2&gt;/dev/null to the redirect, or repeat the -f check after acquiring the lock.
  • ⚠️ bin/fm-claude-stop-autoarm.sh:184 - Simplification: the directory lock around the starting marker (starting_lock_remove / starting_lock_acquire / starting_lock_release, lines 184-232, plus its uses at 238/242 in publish_starting_marker and 250/256 in release_starting_marker) is about 50 lines of extra machinery. It has its own stale-holder recovery and re-entry handling. The intent only requires that the guard stop reporting a false 'did not claim' while a host auto-arm is still starting. The marker plus a compare-before-remove on exit already gives that. The lock only covers the microsecond window between release reading the marker and running rm, and that window matters only when two auto-arm firings overlap. Even in that case the guard rechecks the named pid's liveness and command, and the wait is bounded. The lock also does not fully deliver its guarantee: two waiters that both see the same dead holder can each run starting_lock_remove, and one of them can remove the other's freshly made lock. That defect sits inside this component, so the smallest fix is to remove it. Recommendation: remove the lock and keep the atomic tmp+mv publish and the read/compare/rm release. The existing 'drops only its own' test still covers that narrower form.
  • ℹ️ bin/fm-claude-stop-autoarm.sh:240 - Round 1's fix for review-4 changed the read redirects to 2&gt;/dev/null &lt;file. It left two write redirects in the older order, where &gt;file comes before 2&gt;/dev/null. Bash applies redirections left to right, so when the open fails, the error ('No such file or directory' or 'Permission denied') is printed to the hook's real stderr before 2>/dev/null takes effect. I checked this with printf x &gt; /nonexistent/f 2&gt;/dev/null. On an exit-2 path, that stderr is the model-visible rewake banner. Sites: bin/fm-claude-stop-autoarm.sh:240 (printf ... &gt; &#34;$tmp&#34; 2&gt;/dev/null in publish, for example when state/ exists but is not writable) and bin/fm-claude-stop-autoarm.sh:201 (the lock pid write; it fails if a concurrent stale-steal removes the lock directory just after mkdir). The EXIT trap can reach line 201 after the banner is printed. Fix: write these as 2&gt;/dev/null &gt; file. Line 201 goes away if the starting lock is removed as recommended above.
  • ℹ️ bin/fm-claude-stop-autoarm.sh:1 - The pipeline fix commit b608427 has a garbled subject: 'no-mistakes(review): Fix auto-arm marker handling and wait documentation quietly waiting... just kidding captain only above enough'. The trailing words are unrelated noise, the kind of thing fix: keep greetings out of no-mistakes commit subjects #66 ('keep greetings out of no-mistakes commit subjects') was meant to stop. This is not a code defect. Squash or reword the commit before merge so it does not land in main's history.

🔧 Fix applied.
3 issues (1 warning, 2 infos) still open:

  • ℹ️ bin/fm-turnend-guard.sh:592 - The longer claim wait only applies when fm_supervision_host_enabled is true. The slow pre-claim work in fm-claude-stop-autoarm.sh (sourcing six libraries, ps-based ancestry checks, fm-lock.sh, fm_supervision_needed, lines 260-399) is the same whether or not the home runs the supervision host. So a Claude home that opted out of the host can still hit the same false 'did not claim' banner when its claim lands after 800ms. The tests (host-off case) and docs show this restriction is deliberate and it matches the stated intent, which is about a host home. Asking only to confirm that non-host homes should keep the short window.
  • ℹ️ bin/fm-claude-stop-autoarm.sh:1 - The pipeline fix commit b608427 has a garbled subject: 'no-mistakes(review): Fix auto-arm marker handling and wait documentation quietly waiting... just kidding captain only above enough'. The trailing words are unrelated noise, the kind of thing fix: keep greetings out of no-mistakes commit subjects #66 ('keep greetings out of no-mistakes commit subjects') was meant to stop. This is not a code defect. Squash or reword the commit before merge so it does not land in main's history.
  • ⚠️ bin/fm-turnend-guard.sh:596 - The extended host wait limits loop iterations, not elapsed time. host_ticks = HOST_CLAIM_WAIT_MS/100, and each pass adds sleep 0.1 to the real cost of autoarm_owns_recovery and host_arm_pending. That cost is several forks per pass: cat of the watch lock pid, the ledger read, the epoch sed, fm_pid_identity, and the ps call in fm_proc_info. The old loop had the same drift, but it only ran 8 passes. Now it can run up to 150 passes while a live auto-arm is still starting (default 15000 ms). On Linux the real wait goes somewhat past 15s. On Git Bash/MSYS, which the repo supports and where each fork costs tens of milliseconds or more, 150 passes can take well over a minute. The --claude guard entry in .claude/settings.json:54 sets no timeout, so it gets Claude Code's default command-hook timeout. If the harness kills the guard there, the Stop ends with no banner and no block, which is the blind turn this guard exists to catch. It also contradicts the round-1 docs fix in docs/configuration.md:3483, which calls the value the 'total milliseconds the --claude guard may wait'. Fix: record a deadline once before the loop and break on elapsed time instead of on i &gt;= host_ticks. Use $SECONDS, or date +%s captured before the loop, because macOS bash 3.2 has no EPOCHREALTIME. The sync window can keep its tick count. The same tick-for-time assumption is the bound described in the header comment at bin/fm-turnend-guard.sh:82-90.

🔧 Fix applied.
4 issues (2 warnings, 2 infos) still open:

  • ℹ️ bin/fm-turnend-guard.sh:592 - The longer claim wait only applies when fm_supervision_host_enabled is true. The slow pre-claim work in fm-claude-stop-autoarm.sh (sourcing six libraries, ps-based ancestry checks, fm-lock.sh, fm_supervision_needed, lines 260-399) is the same whether or not the home runs the supervision host. So a Claude home that opted out of the host can still hit the same false 'did not claim' banner when its claim lands after 800ms. The tests (host-off case) and docs show this restriction is deliberate and it matches the stated intent, which is about a host home. Asking only to confirm that non-host homes should keep the short window.
  • ℹ️ bin/fm-claude-stop-autoarm.sh:1 - The pipeline fix commit b608427 has a garbled subject: 'no-mistakes(review): Fix auto-arm marker handling and wait documentation quietly waiting... just kidding captain only above enough'. The trailing words are unrelated noise, the kind of thing fix: keep greetings out of no-mistakes commit subjects #66 ('keep greetings out of no-mistakes commit subjects') was meant to stop. This is not a code defect. Squash or reword the commit before merge so it does not land in main's history.
  • ⚠️ bin/fm-turnend-guard.sh:596 - The extended host wait limits loop iterations, not elapsed time. host_ticks = HOST_CLAIM_WAIT_MS/100, and each pass adds sleep 0.1 to the real cost of autoarm_owns_recovery and host_arm_pending. That cost is several forks per pass: cat of the watch lock pid, the ledger read, the epoch sed, fm_pid_identity, and the ps call in fm_proc_info. The old loop had the same drift, but it only ran 8 passes. Now it can run up to 150 passes while a live auto-arm is still starting (default 15000 ms). On Linux the real wait goes somewhat past 15s. On Git Bash/MSYS, which the repo supports and where each fork costs tens of milliseconds or more, 150 passes can take well over a minute. The --claude guard entry in .claude/settings.json:54 sets no timeout, so it gets Claude Code's default command-hook timeout. If the harness kills the guard there, the Stop ends with no banner and no block, which is the blind turn this guard exists to catch. It also contradicts the round-1 docs fix in docs/configuration.md:3483, which calls the value the 'total milliseconds the --claude guard may wait'. Fix: record a deadline once before the loop and break on elapsed time instead of on i &gt;= host_ticks. Use $SECONDS, or date +%s captured before the loop, because macOS bash 3.2 has no EPOCHREALTIME. The sync window can keep its tick count. The same tick-for-time assumption is the bound described in the header comment at bin/fm-turnend-guard.sh:82-90.
  • ⚠️ bin/fm-turnend-guard.sh:596 - The rewritten claim-wait loop dropped the old post-loop autoarm_owns_recovery recheck. Each pass now runs autoarm_owns_recovery first and then host_arm_pending, and it breaks straight to the block path when the starter is no longer pending. The usual reason the starter stops pending is that the auto-arm just finished: it published its claim, armed, recorded outcome=rewake or made the watcher healthy, exited, and removed .claude-autoarm-starting. That kind of proof is still accepted after the process exits (lines 428 and 448-454). Concrete sequence on a host-enabled home after the sync window: (1) the pass's autoarm_owns_recovery sees no claim, no fresh epoch, and an unhealthy watcher; (2) while that call and its forks are still running, the auto-arm claims, finishes, writes outcome=rewake and exits; (3) host_arm_pending sees no marker or a dead pid and returns 1; (4) the loop breaks, budget_account_current_epoch block uses up one continuation, and the user gets the false 'Stop-owned auto-arm did not claim' banner. That is the exact symptom the intent asks to remove. The window is only as long as one autoarm_owns_recovery call, which is several forks: tens of ms on Linux and more on Git Bash/MSYS. A host-path auto-arm that hands off quickly can fit inside it. Before this change, the old code always ran one more ownership check after its loop. The round-3 elapsed-time fix kept the same break structure and did not change this. Fix: run one final ownership check before blocking, e.g. autoarm_owns_recovery &amp;&amp; allow_autoarm_recovery right after the loop. Alternatively, recheck ownership only when the break happened because host_arm_pending failed.

🔧 Fix applied.
2 infos still open:

  • ℹ️ bin/fm-turnend-guard.sh:592 - The longer claim wait only applies when fm_supervision_host_enabled is true. The slow pre-claim work in fm-claude-stop-autoarm.sh (sourcing six libraries, ps-based ancestry checks, fm-lock.sh, fm_supervision_needed, lines 260-399) is the same whether or not the home runs the supervision host. So a Claude home that opted out of the host can still hit the same false 'did not claim' banner when its claim lands after 800ms. The tests (host-off case) and docs show this restriction is deliberate and it matches the stated intent, which is about a host home. Asking only to confirm that non-host homes should keep the short window.
  • ℹ️ bin/fm-claude-stop-autoarm.sh:1 - The pipeline fix commit b608427 has a garbled subject: 'no-mistakes(review): Fix auto-arm marker handling and wait documentation quietly waiting... just kidding captain only above enough'. The trailing words are unrelated noise, the kind of thing fix: keep greetings out of no-mistakes commit subjects #66 ('keep greetings out of no-mistakes commit subjects') was meant to stop. This is not a code defect. Squash or reword the commit before merge so it does not land in main's history.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 6 of 7 scenarios driven live against the product
Scenario Result Live Evidence
Host-enabled home: Stop guard allows when the real auto-arm claims after the short window, with no false 'did not claim' banner (local disposable home, synthetic Stop payload) ✅ pass live live-real-hooks-host-claim-wait.txt: HEAD with the host on and a 0ms short window gave exit=0 and no output in 706ms and 869ms. The ledger shows outcome=arming, owned by the live auto-arm pid. No cont…
Regression reproduction: the base commit prints the false 'SUPERVISION IS OFF / auto-arm did not claim' banner in the same race ✅ pass live live-real-hooks-host-claim-wait.txt: on BASE 6d7e171 the guard gave exit=2 with the TURN WOULD END BLIND banner both times, while the epoch ledger showed outcome=arming from the live auto-arm.
Default 800ms window on a host-enabled home still allows the real auto-arm ✅ pass live live-real-hooks-host-claim-wait.txt: HEAD with the default window gave exit=0 and no output in 713ms.
Adversarial: auto-arm genuinely absent on a host-on home with a stale dead-pid starting marker still blocks with the banner and does not wait out the 15s host bound ✅ pass live live-real-guard-absent-autoarm.txt: exit=2 with the banner after 1653ms.
Home that opted out of the supervision host keeps the short window and the banner ✅ pass live live-real-hooks-host-claim-wait.txt: 'host OPTED OUT' run gave exit=2 with the banner in 731ms.
Auto-arm in a home without state/ does not publish a starting marker or add any new side effect ✅ pass live live-autoarm-no-state-side-effect-compare.txt and the bash -x trace: publish_starting_marker returned without writing anything. state/ is created on HEAD and on base by the existing mkdir in fm-wake-l…
Real Claude TUI primary in a lab home ends a long turn without the false banner ⏸️ untested no Starting claude from the gate worktree puts FM_ROOT in a linked worktree, and fm_primary_scope_matches deliberately keeps both hooks inert there. The race also depends on how long the auto-arm takes…
  • bash tests/fm-turnend-guard.test.sh (targeted file, exit 0; includes the new host-starter, starter-exit, marker-publish and missing-state cases)
  • Live: disposable plain-checkout primary homes extracted from HEAD and from base 6d7e171 with in-flight task state and a 400s-stale watcher beat. Inside each home, a parent process named claude holds state/.lock and starts the real bin/fm-claude-stop-autoarm.sh and the real bin/fm-turnend-guard.sh --claude concurrently on the same synthetic Stop payload.
  • Live A/B: on HEAD with the host on (the default) and FM_CLAUDE_AUTOARM_SYNC_WAIT_MS=0, twice; on HEAD with the default 800ms window; on base with the host on and a 0ms window, twice; on HEAD with config/supervision-host-off
  • Live adversarial: the real guard on a host-on HEAD home with no auto-arm running and a stale .claude-autoarm-starting marker naming dead pid 999999
  • Live side effect: ran the real auto-arm against an FM_HOME with no state/ on HEAD and on base, under a bash -x trace
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → auto-fixed ✅
  • ⚠️ linter found issues (exit code 1)

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Push** - passed

✅ No issues found.

The Claude Stop guard treated an in-flight host re-arm as supervision
being off when the generation claim landed after its 800ms window.
Keep waiting while that auto-arm's starting marker names a live
matching process, and still block when the arm is absent, dead, or
past the bound.
…ion quietly waiting... just kidding captain only above enough
…he two behavior failures don't come from this PR's code, and Full suite failed only because those other lanes did. - **Lint 2 (fixed):** ShellCheck reported SC2329 ("this function is never invoked") for the `sleep()` override at `tests/fm-turnend-guard.test.sh:2556`, in the host-starting-bound test. The function isn't dead: `export -f sleep` passes it to the guard process so each claim-wait pass runs slowly. ShellCheck can't see that, so I added a scoped `# shellcheck disable=SC2329` with a comment explaining the export. This is the same approach as the earlier SC2016 lint fix. No other file has the problem. Running `bin/fm-lint.sh` on the file with ShellCheck 0.11.0 and full extended analysis now passes. - **Behavior portable serial 6:** The failure was in `tests/fm-extension-binding.test.sh` ("recovered source orphan-second never handled its private result"). - **Behavior portable serial 16:** The failure was in `tests/fm-watcher-lock.test.sh` ("the successor never delivered its recovery wake and exited"). - Neither test file uses anything this PR changes: the turn-end guard, the Claude Stop auto-arm script, or the starting marker. - Both files pass locally with no failing tests, so these look like timing flakes on the CI runners. - **Full suite:** It's only a roll-up that fails when any other lane fails ("A full-suite job failed or was cancelled"). It should pass once the lanes above pass. `tests/fm-turnend-guard.test.sh` also passes in full locally. The change is left uncommitted in the worktree
@peterOC26
peterOC26 merged commit 412dbc5 into main Nov 15, 2026
30 checks passed
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