You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix: preserve Claude watcher continuity across Stop hooks - #997
Ship the existing A2 design for Claude tokenless Stop-owned auto-arm continuity in firstmate (scout reports data/fm-claude-stop-autoarm-a2 and fm-secondmate-supervision-continuity-gap-a1 are the authoritative design; A2 wins where they differ). Goal: Claude primaries (main home and marked secondmate homes) get watcher continuity owned by a tracked Stop asyncRewake hook instead of model memory, closing the proven multi-hour blind-window incident class. Deliberate decisions: bin/fm-claude-stop-autoarm.sh fires on every Stop with timeout 28800 (600s default forbidden), claims one home-scoped single-flight owner (Claude does not dedupe async hooks), foregrounds bin/fm-watch-arm.sh with no shell ampersand, and translates one actionable close or typed watcher failure into exactly one exit-2 rewake per event epoch; it gates on primary scope, session-lock identity via the new shared bin/fm-session-lock-lib.sh (extracted from fm-lock.sh), AFK ownership (never rewakes during away mode, including mid-cycle transitions), and in-flight-or-X-mode need. The synchronous turn-end guard's new --claude mode ignores stop_hook_active (true on every post-continuation stop, which caused the 2026-07-21 incident), waits up to 800ms for health/claim/fresh rewake epoch, and re-blocks only on genuine auto-arm failure with a budget of 3 (below Claude's 8-block cap) then a degraded allow with systemMessage; codex keeps the old one-block behavior byte-identical and Pi/OpenCode/Grok are untouched. The continuity PreToolUse gate and durable wake queue are preserved; only its guidance text and the Claude supervision protocol docs changed to name the Stop-owned re-arm, with manual background arms reserved for auto-arm failure. Explicitly out of scope: external pane injection, Agent SDK rewriting, Herdr coupling, delayed-verifier expansion, unrelated supervision refactors. Contract revalidated live on Claude Code 2.1.218 in a disposable lab and product live E2Es on 2.1.219. This PR requires the captain's explicit merge approval even though the project otherwise has standing yolo authority - do not merge, stop at a green PR.
What Changed
Add a tracked Claude Stop asyncRewake hook that single-flights watcher ownership, respects primary-session identity and AFK state, and rewakes once for actionable watcher events.
Add a Claude-specific turn-end guard path that coordinates with auto-arm claims and fresh rewake epochs, covers task and X-mode supervision, and degrades safely after a bounded retry budget.
Extract shared session-lock and supervision predicates, update Claude continuity guidance, and add unit and live E2E coverage while preserving existing behavior for other harnesses.
Risk Assessment
✅ Low: The prior runtime defect is fixed at the shared supervision-need boundary, the unsupported verification claims were removed, and the complete branch now conforms to the stated A2 behavior without additional material source risks.
Testing
Intent and diff inspection, five focused automated test scripts, a fixture-driven Claude Stop-hook E2E, and a base-versus-target Codex byte-compatibility check all passed. Evidence is captured as CLI transcripts because this change has no graphical UI surface; the credentialed live Claude E2E was not repeated during this targeted local phase.
Evidence: Claude Stop auto-arm E2E transcript
=== Claude Stop asyncRewake: actionable watcher close ===
hook_exit=2
persisted_epoch: epoch=2 owner_pid=<pid> outcome=rewake updated_at=<unix-time>
=== Cooperative guard: same fresh rewake epoch ===
guard_output=<silent>
guard_exit=0
=== Incident counterfactual: loop flag true, no watcher/claim/fresh epoch ===
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
● TURN WOULD END BLIND - SUPERVISION IS OFF
● 1 task(s) in flight, but no live watcher holds this home lock (last beat: never).
● The Stop-owned auto-arm did not claim this home either, so recovery is NOT already under way.
● repair missing watcher supervision according to the session-start block for this harness; do not use shell &.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
guard_exit=2
=== Codex default-mode compatibility: base vs target ===
blind-stop exit: base=2 target=2
blind-stop stdout byte-identical: yes
blind-stop stderr byte-identical: yes
second-stop loop-guard exit: base=0 target=0
second-stop stdout byte-identical: yes
second-stop stderr byte-identical: yes
User-visible first blind-stop banner:
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
● TURN WOULD END BLIND - SUPERVISION IS OFF
● <count> task(s) in flight, but no live watcher holds this home lock (last beat: never).
● repair missing watcher supervision according to the session-start block for this harness; do not use shell &.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
🚨 bin/fm-turnend-guard.sh:127 - X-mode-only homes bypass the Claude auto-arm failure backstop. The auto-arm treats either in-flight metadata or state/x-watch.check.sh as supervision need, but the guard exits whenever FM_SUP_IN_FLIGHT is zero. If X mode is active with no tasks and the auto-arm fails to claim or launch, the Stop is allowed and relay polling remains down indefinitely. Define the need predicate at the shared supervision boundary and use it in both scripts.
⚠️docs/turnend-guard.md:82 - This line claims the maintained verification record includes the 2026-07-24 Claude asyncRewake revalidation, but docs/verification/supervision.md is unchanged and still documents Claude 2.1.204/2.1.214 with the old background-completion behavior. Record the asserted 2.1.218/2.1.219 commands and results there, or remove the unsupported claim here and the equivalent claim in docs/watcher-continuity.md.
🔧 Fix: Fix Claude X-mode auto-arm continuity backstop
1 warning still open:
⚠️docs/verification/supervision.md:77 - The 2.1.218 contract-lab entry lists six empirical conclusions but still omits the exact commands and observed output supporting them. The maintained verification record requires reproducible commands and output, and only the later 2.1.219 product E2Es provide those details. Add the lab commands/results from the authoritative evidence, or keep these unsupported details in private PR evidence instead.
🔧 Fix: Remove unsupported Claude contract-lab verification claims
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
Inspected 861b1f8a342b819729a1f43a8413f5040c1ce4fb..ec325a07796b89edc8ac2c58b9495b844a75c521 against the supplied intent.
tests/fm-claude-stop-autoarm.test.sh
tests/fm-turnend-guard.test.sh
tests/fm-continuity-pretool-check.test.sh
tests/fm-supervision-instructions.test.sh
tests/fm-watcher-lock.test.sh
Fixture-driven invocation of bin/fm-claude-stop-autoarm.sh, followed by bin/fm-turnend-guard.sh --claude with and without a fresh rewake epoch.
Compared base and target default-mode bin/fm-turnend-guard.sh exit codes, stdout, and stderr using cmp -s.
git status --short after testing confirmed no working-tree artifacts.
Intent
Ship the existing A2 design for Claude tokenless Stop-owned auto-arm continuity in firstmate (scout reports data/fm-claude-stop-autoarm-a2 and fm-secondmate-supervision-continuity-gap-a1 are the authoritative design; A2 wins where they differ). Goal: Claude primaries (main home and marked secondmate homes) get watcher continuity owned by a tracked Stop asyncRewake hook instead of model memory, closing the proven multi-hour blind-window incident class. Deliberate decisions: bin/fm-claude-stop-autoarm.sh fires on every Stop with timeout 28800 (600s default forbidden), claims one home-scoped single-flight owner (Claude does not dedupe async hooks), foregrounds bin/fm-watch-arm.sh with no shell ampersand, and translates one actionable close or typed watcher failure into exactly one exit-2 rewake per event epoch; it gates on primary scope, session-lock identity via the new shared bin/fm-session-lock-lib.sh (extracted from fm-lock.sh), AFK ownership (never rewakes during away mode, including mid-cycle transitions), and in-flight-or-X-mode need. The synchronous turn-end guard's new --claude mode ignores stop_hook_active (true on every post-continuation stop, which caused the 2026-07-21 incident), waits up to 800ms for health/claim/fresh rewake epoch, and re-blocks only on genuine auto-arm failure with a budget of 3 (below Claude's 8-block cap) then a degraded allow with systemMessage; codex keeps the old one-block behavior byte-identical and Pi/OpenCode/Grok are untouched. The continuity PreToolUse gate and durable wake queue are preserved; only its guidance text and the Claude supervision protocol docs changed to name the Stop-owned re-arm, with manual background arms reserved for auto-arm failure. Explicitly out of scope: external pane injection, Agent SDK rewriting, Herdr coupling, delayed-verifier expansion, unrelated supervision refactors. Contract revalidated live on Claude Code 2.1.218 in a disposable lab and product live E2Es on 2.1.219. This PR requires the captain's explicit merge approval even though the project otherwise has standing yolo authority - do not merge, stop at a green PR.
What Changed
asyncRewakehook that single-flights watcher ownership, respects primary-session identity and AFK state, and rewakes once for actionable watcher events.Risk Assessment
✅ Low: The prior runtime defect is fixed at the shared supervision-need boundary, the unsupported verification claims were removed, and the complete branch now conforms to the stated A2 behavior without additional material source risks.
Testing
Intent and diff inspection, five focused automated test scripts, a fixture-driven Claude Stop-hook E2E, and a base-versus-target Codex byte-compatibility check all passed. Evidence is captured as CLI transcripts because this change has no graphical UI surface; the credentialed live Claude E2E was not repeated during this targeted local phase.
Evidence: Claude Stop auto-arm E2E transcript
Evidence: Codex default-mode byte compatibility transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
🔧 **Rebase** - 2 issues found → auto-fixed ✅
docs/turnend-guard.md- merge conflict rebasing onto origin/maindocs/watcher-continuity.md- merge conflict rebasing onto origin/main🔧 Fix applied.
✅ Re-checked - no issues remain.
🔧 **Review** - 2 issues found → auto-fixed (2) ✅
bin/fm-turnend-guard.sh:127- X-mode-only homes bypass the Claude auto-arm failure backstop. The auto-arm treats either in-flight metadata orstate/x-watch.check.shas supervision need, but the guard exits wheneverFM_SUP_IN_FLIGHTis zero. If X mode is active with no tasks and the auto-arm fails to claim or launch, the Stop is allowed and relay polling remains down indefinitely. Define the need predicate at the shared supervision boundary and use it in both scripts.docs/turnend-guard.md:82- This line claims the maintained verification record includes the 2026-07-24 Claude asyncRewake revalidation, butdocs/verification/supervision.mdis unchanged and still documents Claude 2.1.204/2.1.214 with the old background-completion behavior. Record the asserted 2.1.218/2.1.219 commands and results there, or remove the unsupported claim here and the equivalent claim indocs/watcher-continuity.md.🔧 Fix: Fix Claude X-mode auto-arm continuity backstop
1 warning still open:
docs/verification/supervision.md:77- The 2.1.218 contract-lab entry lists six empirical conclusions but still omits the exact commands and observed output supporting them. The maintained verification record requires reproducible commands and output, and only the later 2.1.219 product E2Es provide those details. Add the lab commands/results from the authoritative evidence, or keep these unsupported details in private PR evidence instead.🔧 Fix: Remove unsupported Claude contract-lab verification claims
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
Inspected861b1f8a342b819729a1f43a8413f5040c1ce4fb..ec325a07796b89edc8ac2c58b9495b844a75c521against the supplied intent.tests/fm-claude-stop-autoarm.test.shtests/fm-turnend-guard.test.shtests/fm-continuity-pretool-check.test.shtests/fm-supervision-instructions.test.shtests/fm-watcher-lock.test.shFixture-driven invocation ofbin/fm-claude-stop-autoarm.sh, followed bybin/fm-turnend-guard.sh --claudewith and without a fresh rewake epoch.Compared base and target default-modebin/fm-turnend-guard.shexit codes, stdout, and stderr usingcmp -s.git status --shortafter testing confirmed no working-tree artifacts.✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.