Skip to content

fix(bin): restore watcher downtime before main-only hand-back - #6588

Merged
kunchenguid merged 4 commits into
kunchenguid:mainfrom
zachlandes:fm/idle-after-run-stale-miss
Oct 22, 2026
Merged

kunchenguid merged 4 commits into
kunchenguid:mainfrom
zachlandes:fm/idle-after-run-stale-miss

Conversation

@zachlandes

@zachlandes zachlandes commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Intent

On a Claude primary running the supervision host, monitoring could go silent without anyone noticing. When the host handed a watcher close back to main while an earlier engine turn was still marked as handling, the recovery marker stayed at handling. The Stop hook then exited 0 instead of re-waking main, so main never handled the queued event, and nothing reported a failure. One home lost about seven hours of supervision this way and had to switch the host off.

This makes the main-only hand-back set the marker back to downtime after starting the successor, so the Stop hook re-wakes main as intended. If writing the marker fails, the host now reports an auto-arm failure instead of printing a close that can never be delivered. A failure you can see is recoverable; a silent success is not.

It deliberately changes nothing else about the marker protocol or the engine-turn ownership model. The fix is the smallest one that makes this path either deliver or fail loudly.

Prepared with AI assistance.

What Changed

  • bin/fm-supervision-host.sh now has the main-only attended pass-through set the recovery marker back to downtime after it starts the successor. Before this, an earlier engine turn could leave the marker reading handling, and the re-arm owner then held back a later close that belonged to main.
  • If that publish fails, leave_successor_for_main logs downtime-unrestored and returns 2. The host then prints watcher: FAILED - the main-only hand-back could not restore watcher downtime and exits nonzero, so the Stop hook reports an auto-arm failure. Before, it printed a close that could never be delivered.
  • Updated the host header and docs/supervision-host.md to describe the republish and the failure path. Added regressions to tests/fm-supervision-host.test.sh for both the restore and refuse cases after a handled turn. Also added attended and away controls that check a returned driver's stale event is ordered after the resolved hand-back.

Risk Assessment

✅ Low: The change narrowly restores deliverable downtime using the existing marker protocol and routes publication failures through existing owner failure handling.

Testing

I ran the four new scenarios against the real Stop hook, supervision host, watcher, wake drain and outcome store, using a disposable FM_HOME, a delayed stub engine and a fake idle Pi worker; all passed on HEAD. Against the pre-fix host, both hand-back cases failed: the hook exited 0 even though its banner asked for a handling turn, and the marker stayed pending:handling, which is the silent-miss path. The Claude Stop-hook and Cursor consumer suites still pass. I did not run a real Claude lab primary: this path needs one engine turn held open while a second task closes the successor, and a real Claude turn can't be paused deterministically. The scratch runners were removed and the bin file restored, so the worktree is clean.

  • Live validation: ✅ go - 4 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Main-only close during a handled engine turn: the Stop hook rewakes main (exit 2), the marker becomes downtime, main-owned rows stay queued, and the successor watcher stays alive ✅ pass live after-fix-new-scenarios.log (restore case); before-fix-handback-regression.log shows the same scenario failing pre-fix with exit 0 and pending:handling
Adversarial: the marker publish fails during the main-only hand-back, and main gets a committed failure notice (exit 2, outcome=failed) instead of a silent success ✅ pass live after-fix-new-scenarios.log (refuse case); pre-fix run got exit 0
Attended: a worker whose driver returns ('resolved') and then sits idle is stale-handled after its resolved signal ✅ pass live after-fix-new-scenarios.log (attended control)
Away: the same returned-driver idle worker is stale-handled while in away posture ✅ pass live after-fix-new-scenarios.log (away control)
Host consumers (Claude Stop hook, Cursor primary) still handle host output and failures correctly ⏸️ untested no The prior payload did not establish a live result: it recorded only the existing hermetic consumer suites (claude-stop-autoarm.log, cursor-primary.log, both rc=0), not a live primary session.
A real Claude lab primary hits the overlapping-turn hand-back ⏸️ untested no Reproducing this needs one real Claude engine turn held open before its drain while a second task closes the successor. A real Claude turn can't be paused deterministically from a lab tmux socket, so…
Evidence: New scenarios passing on the fix

Source: New scenarios passing on the fix

ok - host+hook: a main-only close after a handled turn restores inherited handling and rewakes main ok - host+hook: a refused inherited handling restore delivers a failure instead of silent success ok - host+hook: a driver returning to an idle worker is stale-handled while attended ok - host+hook: a driver returning to an idle worker is stale-handled while away

ok - host+hook: a main-only close after a handled turn restores inherited handling and rewakes main
ok - host+hook: a refused inherited handling restore delivers a failure instead of silent success
ok - host+hook: a driver returning to an idle worker is stale-handled while attended
ok - host+hook: a driver returning to an idle worker is stale-handled while away
Evidence: Bug reproduced on pre-fix host (silent exit 0 with marker left pending:handling)

Source: Bug reproduced on pre-fix host (silent exit 0 with marker left pending:handling)

not ok - inherited handling: the Stop hook must rewake main: firstmate watcher wake - one supervision event needs a handling turn now. ... pending:handling:61754.1791428813.Dq8bjQ: expected exit 2, got 0 not ok - restore refusal must notify main rather than exit silently: expected exit 2, got 0

not ok - inherited handling: the Stop hook must rewake main: firstmate watcher wake - one supervision event needs a handling turn now.
signal: /private/var/folders/4n/_bv20k5d26dgrq1t5y4l69940000gn/T/fm-supervision-host.xDj0ni/hook-inherited-handling-restore/state/beta.status
Run bin/fm-wake-drain.sh first, handle the wake, then run its exact WAKE_ACK_REQUIRED --ack-through command. Until that post-handling acknowledgement, interruption leaves the wake durable for idempotent re-handling. This Stop hook owns watcher continuity: when the handling turn ends, the next needed cycle arms automatically - do NOT run bin/fm-watch-arm.sh after an ordinary wake.
pending:handling:61754.1791428813.Dq8bjQ: expected exit 2, got 0
RESULT restore: FAILED
not ok - restore refusal must notify main rather than exit silently: expected exit 2, got 0
RESULT refuse: FAILED
Evidence: Claude Stop-hook consumer suite

Source: Claude Stop-hook consumer suite

ok - auto-arm: inert in a linked child worktree even when in-flight
ok - auto-arm: inert with no session lock
ok - auto-arm: a demonstrably dead recorded session owner is reclaimed through fm-lock.sh before arming
ok - auto-arm: inert without arm, rewake, or lock replacement when another live harness owns the home
ok - auto-arm: inert while AFK owns supervision
ok - auto-arm: stale-owner recovery leaves the AFK and supervision-need gates unchanged
ok - auto-arm: resolves the outermost pid of a nested contiguous claude ancestry (bg-spare chain)
ok - auto-arm: inert with nothing in flight and no X-mode need
ok - auto-arm: actionable close translates to exactly one exit-2 rewake with reason
ok - auto-arm: actionable close survives a healthy successor without duplicate delivery
ok - auto-arm: an attached cycle's end starts a handling successor named after the closed arm before the rewake
ok - auto-arm: an unconfirmed handling successor is reported in the rewake instead of blocking it
ok - auto-arm: bounded failure verification emits one automatic-mechanism alarm
ok - auto-arm: consecutive failures keep Stop-owned retry without repeating notice
ok - auto-arm: marker-write refusal defers delivery until one successor commits the notice
ok - auto-arm: unverified clean close exhausts retries and fails closed
ok - auto-arm: post-alarm actionable outcomes cannot continue or reset failure state
ok - auto-arm: benign cycle end with a live watcher and fresh beacon stays silent across the next cycle
ok - auto-arm: budget contention preserves the episode and forces a reset retry
ok - auto-arm: owner-mutex contention preserves successor episode state
ok - auto-arm: X-mode poll need arms the cycle even with no tasks in flight
ok - auto-arm: a registered custom check arms the cycle even with no tasks in flight
ok - auto-arm: concurrent firings admit one owner and one rewake translation
ok - auto-arm: TERM mid-arm commits a durable failure and exits 2 for rewake
ok - auto-arm: an abandoned owner claim is reclaimed so a lapsed cycle re-arms
ok - auto-arm: an abandoned-claim reclaim reaps a dead steal mutex without nesting
ok - auto-arm: a legacy owner still arming is never reclaimed while its watcher keeps beating
ok - auto-arm: a fresh legacy arming claim is never reclaimed while its startup window is still open
ok - auto-arm: a live claim the ledger does not name is never reclaimed
ok - auto-arm: a claim whose pid was reused is reclaimed even while its ledger entry still reads arming
ok - auto-arm: a reused-pid claim is reclaimed even with no ledger entry to prove it
ok - auto-arm: an identity-matched owner still arming is never reclaimed
ok - auto-arm: the guard's terminal-check claim is never reclaimed
ok - auto-arm: a stuck live legacy owner is retired via TERM and its lock reclaimed
ok - auto-arm: a SIGSTOPped legacy owner is reclaimed with TERM pending and dies on continue
ok - auto-arm: a live open generation claim defers concurrent firings with no lock held
ok - auto-arm: a hung generation owner with no watcher beat is superseded so re-arming self-heals
ok - auto-arm: an identityless arming ledger never defers the gate (reused-pid loophole closed)
ok - auto-arm: a superseded owner never re-invokes the arm and leaves its successor's claim untouched
ok - auto-arm: a superseded owner goes silent - one supersession episode, one translation, no held mutex
ok - auto-arm: need vanishing mid-cycle closes without a rewake
ok - auto-arm: mid-cycle AFK hands triage to the daemon with no rewake
ok - auto-arm: active in a marked secondmate home
ok - auto-arm: a long FM_POLL with FM_GUARD_GRACE unset reaches fm-watch-arm.sh with the derived grace
ok - auto-arm: config/supervision-host-off keeps the hook on the arm exactly as before
ok - auto-arm: a Claude home without config/supervision-host runs the host by default
ok - auto-arm: an opted-in home runs the host bound to its generation, and a host line rewakes like a wake
ok - auto-arm: a wake the host hands back under the away record says it is automatic supervision, not a return
ok - auto-arm: a wake the host hands back beside a quiet record carries no away note
ok - auto-arm: without the host the rewake banner is unchanged, eight wake lines at most
ok - auto-arm: a host handback delivers every host line, while its wake lines keep their cap
ok - auto-arm: a host that stood down closes silently without a retry
ok - auto-arm: a host rewake refused on an acknowledged marker opens no failure episode
ok - auto-arm: a lost host hand-back notifies once per failure episode
ok - auto-arm: a lost host hand-back on an announced marker notifies once per failure episode
ok - auto-arm: a host that died without a close is retried, then reported as a failure
ok - auto-arm: --help, -h, and an unknown argument arm nothing; the Stop path still arms
ok - fm-lock: shared session-lock lib preserves the status path
ok - auto-arm: stands down only on a pi-code-delivered transcript_path (/.pi/)
rc=0
Evidence: Cursor primary consumer suite

Source: Cursor primary consumer suite

ok - fm-turnend-guard: Cursor payload is inert without --cursor and blocks with it
ok - fm-turnend-guard: a non-Cursor payload keeps blocking
ok - fm-claude-stop-autoarm: inert on a Cursor-delivered payload
ok - fm-sessionstart-run: inert on a Cursor payload, unchanged otherwise
ok - fm-arm-pretool-check: Cursor duplicate allows, --cursor denies in Cursor's own shape
ok - fm-cd-pretool-check: Cursor duplicate allows, --cursor denies in Cursor's own shape
ok - cursor park: silent no-op when no supervision is needed
ok - cursor park: an actionable close is delivered as one watcher-kind follow-up
ok - cursor park: always exits 0, even when supervision is genuinely down
ok - cursor park: the repair nag is bounded and then goes quiet
ok - cursor park: a repair nag is emitted only after its budget persists
ok - cursor park: a delivered wake resets the bounded repair budget
ok - cursor park: the loop_count ceiling warns exactly once, then stops the loop
ok - cursor park: an older park stands down after a newer stop claim
ok - cursor park: the newest stop exclusively owns a concurrent commit
ok - cursor park: a superseded park cannot consume repair budget
ok - cursor park: inert while away mode is active
ok - cursor park: an opted-in home parks on the supervision host and relays every host line
ok - cursor park: the host's boundary wakes, its stand-down is silent, and a host that died is retried
ok - cursor park: inert when PI_CODING_AGENT marks a Pi host session
ok - cursor park: parks when PI_CODING_AGENT leaks alongside Cursor identity
ok - cursor park: an away-mode transition wins before follow-up commit
ok - cursor park: inert when this session does not hold the home lock
ok - cursor park: session takeover stops polling without output or state mutation
warning: re-init: ignored --initial-branch=main
ok - cursor park: inert inside a child crewmate worktree
ok - cursor park: malformed payloads fail open without arming
ok - fm-sessionstart-cursor: sessionStart injects context
warning: re-init: ignored --initial-branch=main
ok - fm-sessionstart-cursor: silent inside a child crewmate worktree
ok - cursor registration: covers every primary event with a bounded stop loop
ok - cursor bounds nest: firstmate's default ceiling stops the loop before Cursor's loop_limit does
rc=0
- Outcome: 🔧 1 issue found → auto-fixed → no changes applied ✅ across 4 runs (1h8m43s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ No issues found.

🔧 **Test** - 1 issue found → auto-fixed → no changes applied ✅
  • ⚠️ The Test agent did not finish within its invocation budget. Reported: agent run tests timed out after 30m0s: agent last produced output 2s ago (111 observed); agent reported: claude parse events: context deadline exceeded. This is a budget or provider-slowness cut, not a code failure. Re-running the same request costs another full budget, so no further attempt is made automatically. If this repository's targeted tests or evidence gathering routinely approach the default 30m0s, raise test_agent_timeout in global config. Respond with fix to spend another budget: a repair turn runs only for selected findings other than this budget cut, then validation re-runs. Or abort and retry after raising the budget.

🔧 No changes applied.
1 warning still open:

  • ⚠️ tests/fm-supervision-host.test.sh:1313 - Both new idle-return controls (test_returned_driver_is_caught_attended/away) assert a 25 s wall-clock bound against a 4 s stale threshold. In this run both failed with 'missed the bounded lab stale threshold' while another supervision-host test run competed for CPU, then passed when rerun alone. Slow CI runners are likely to hit the same flake. Consider loosening the bound or checking the stale event's ordering instead of elapsed wall-clock time.
  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Main-only close after an earlier handled engine turn: the Stop hook exits 2, rewakes main, keeps the main-owned rows, and leaves a live successor ✅ pass live after-fix-new-tests.log (ok); before-fix-new-tests.log shows 'expected exit 2, got 0' on base
Recovery-marker publish refused: main gets a failure notification and a failed outcome is recorded, not a silent hook success ✅ pass live after-fix-new-tests.log (ok); before-fix-new-tests.log 'expected exit 2, got 0'
Attended: worker reports paused, then resolved, then sits idle; the stale event is handled within the threshold ✅ pass live after-fix-new-tests.log; before-fix-controls-rerun.log
Away: worker reports paused, then resolved, then sits idle; the stale event is handled within the threshold ✅ pass live after-fix-new-tests.log; before-fix-controls-rerun.log
Real Claude lab primary running the hand-back through a fm-lab tmux socket ⏸️ untested no The round-1 lab attempt had its arm refused and used up the 30-minute budget. This round I covered the same host+hook path with the real scripts and a fake worker instead. A real Claude primary would…
  • bash tests/fm-supervision-host.test.sh subset in a disposable copy of HEAD 4f2b6f1e, run one at a time: test_main_only_close_after_handled_turn_restores_inherited_handling, test_main_only_close_after_handled_turn_delivers_restore_failure, test_returned_driver_is_caught_attended, test_returned_driver_is_caught_away
  • Same four tests in a disposable copy with bin/fm-supervision-host.sh reverted to base 9ea0c41a (before fix)
  • Base controls (attended/away) rerun with no competing load
  • Full bash tests/fm-supervision-host.test.sh on HEAD started, stopped after 49 tests with no failures because it was too slow for the budget

🔧 Fix applied.
1 warning still open:

  • ⚠️ live validation verdict: inconclusive (0 of 5 scenarios were driven live against the product); untested: Main-only close during a handled engine turn: after the turn ends, the Stop hook rewakes main, the marker becomes downtime and the successor watcher stays alive, Adversarial: marker publish fails during the main-only hand-back, and main gets a committed failure notice instead of a silent hook success, Attended: a worker whose driver returns ('resolved') and sits idle is stale-handled after its resolved signal, within the bounded stale threshold, Away: the same returned-driver idle worker is stale-handled while in away posture, Host consumers (Claude Stop hook, Cursor primary) still handle host output and failures correctly
  • Live validation: ⚠️ inconclusive - 0 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Main-only close during a handled engine turn: after the turn ends, the Stop hook rewakes main, the marker becomes downtime and the successor watcher stays alive ⏸️ untested no The prior payload did not establish a live result: it ran only in a hermetic fixture home with a stub engine (after-fix-new-scenarios.txt passed; base host failed). A live Claude-primary lab was not d…
Adversarial: marker publish fails during the main-only hand-back, and main gets a committed failure notice instead of a silent hook success ⏸️ untested no The prior payload did not establish a live result: the publish failure was injected through a fixture mktemp shim in the hermetic home, and no live product run was performed.
Attended: a worker whose driver returns ('resolved') and sits idle is stale-handled after its resolved signal, within the bounded stale threshold ⏸️ untested no The prior payload did not establish a live result: it used a fake Pi/tmux worker endpoint and a stub engine, and running a real overnight Pi worker in the gate was not practical.
Away: the same returned-driver idle worker is stale-handled while in away posture ⏸️ untested no The prior payload did not establish a live result: it used the same fake worker endpoint and stub engine as the attended control, with no live product run.
Host consumers (Claude Stop hook, Cursor primary) still handle host output and failures correctly ⏸️ untested no The prior payload did not establish a live result: only the existing hermetic consumer suites were run (claude-stop-autoarm 59 ok, cursor-primary 30 ok), and no live Claude or Cursor primary was drive…
  • Selective runner (the test file's functions plus only the 4 new tests) against the fixed tree: test_main_only_close_after_handled_turn_restores_inherited_handling, test_main_only_close_after_handled_turn_delivers_restore_failure, test_returned_driver_is_caught_attended, test_returned_driver_is_caught_away
  • The same tests run one at a time against a git archive copy with bin/fm-supervision-host.sh reverted to base 9ea0c41a, to show the fail-before/pass-after behaviour
  • bash tests/fm-claude-stop-autoarm.test.sh (Stop hook consumer of the host's exit/failure path)
  • bash tests/fm-cursor-primary.test.sh (Cursor host consumer that recognises watcher FAILED output)

✅ No issues found.

  • Live validation: ✅ go - 4 of 6 scenarios driven live against the product
Scenario Result Live Evidence
Main-only close during a handled engine turn: the Stop hook rewakes main (exit 2), the marker becomes downtime, main-owned rows stay queued, and the successor watcher stays alive ✅ pass live after-fix-new-scenarios.log (restore case); before-fix-handback-regression.log shows the same scenario failing pre-fix with exit 0 and pending:handling
Adversarial: the marker publish fails during the main-only hand-back, and main gets a committed failure notice (exit 2, outcome=failed) instead of a silent success ✅ pass live after-fix-new-scenarios.log (refuse case); pre-fix run got exit 0
Attended: a worker whose driver returns ('resolved') and then sits idle is stale-handled after its resolved signal ✅ pass live after-fix-new-scenarios.log (attended control)
Away: the same returned-driver idle worker is stale-handled while in away posture ✅ pass live after-fix-new-scenarios.log (away control)
Host consumers (Claude Stop hook, Cursor primary) still handle host output and failures correctly ⏸️ untested no The prior payload did not establish a live result: it recorded only the existing hermetic consumer suites (claude-stop-autoarm.log, cursor-primary.log, both rc=0), not a live primary session.
A real Claude lab primary hits the overlapping-turn hand-back ⏸️ untested no Reproducing this needs one real Claude engine turn held open before its drain while a second task closes the successor. A real Claude turn can't be paused deterministically from a lab tmux socket, so…
  • bash tests/.nm-scratch-new.sh: a temporary runner holding the unchanged test file body plus only the 4 new tests (restore, refuse, returned-driver attended, returned-driver away), run against HEAD
  • git show 3c58ec8e:bin/fm-supervision-host.sh > bin/fm-supervision-host.sh then the two hand-back tests, to check they fail before the fix; the file was restored with git checkout HEAD -- bin/fm-supervision-host.sh
  • bash tests/fm-claude-stop-autoarm.test.sh (Stop-hook consumer compatibility)
  • bash tests/fm-cursor-primary.test.sh (Cursor host consumer compatibility)
✅ **Document** - passed

✅ No issues found.

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

✅ No issues found.

@greptile-apps

greptile-apps Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[High risk] Changes process supervision and recovery marker handling in the watcher.

The PR appears safe to merge based on the reviewed hand-back and failure paths.

Reviews (1) · Last reviewed commit: "no-mistakes(document): Document main-onl..."

@jasonm4130

Copy link
Copy Markdown

Live incident this PR would have prevented, with a reproduction of the ordering seen in production.

Claude Code 2.1.289 primary, attended supervision host on by default, firstmate main f470a01c (host, Stop auto-arm, drain and wake-lib byte-identical), macOS 26.6.2, bash 5.3.20.

In one park, watcher A closed on a routine signal. The host started handling successor B and confirmed its handoff, so the marker read pending:handling:G. One second later B closed on a main-only check: process-event result captured: …, and B's exit republished pending:downtime:G. The engine turn's first tool call came 2 s after that: fm-wake-drain.sh, which as the branch actor flipped the shared marker back to pending:handling:G (its output names --recovery-generation G). The engine acknowledged only its own row, so the main-only row kept the marker from retiring. The host then made the main-only pass-through. The Stop hook printed the banner, autoarm_commit rewake refused on the handling marker, and the lost-handback fallback was skipped because the successor just left for main was healthy, so the hook exited 0. That successor closed on the next status 33 s later. With main idle there was no further Stop: 39 minutes without a watcher, including a worker's needs-decision, until the user typed.

The same refusal happened three more times in two days when main's drain began handling just before a first-cycle rearm-resurface pass-through (that close uses release-lock-existing, so it publishes nothing). Those three were masked because main was mid-turn and its next Stop took over the left successor.

Repro on f470a01c with tests/fm-supervision-host.test.sh's harness. Add a stub mode that blocks before its first drain (the real model ordering; stock held drains first). Then: routine status → engine holds → needs-decision status closes the successor → release. Base: hook rc=0, marker pending:handling, and no watcher after the next event, 3/3 runs. With this PR's host diff: rc=2, outcome=rewake, 2/2. The same main-only status landing after the drain is delivered on base (2/2). Happy to share the test.

Separately from this PR: the fallback's ! fm_watcher_healthy gate counts the successor recorded in .supervision-host-left, which nothing owns. Excluding it would turn any future refusal on this path into a notice instead of silence.

* Restored downtime so an earlier engine turn could not suppress a later
  main-owned close while leaving a healthy successor behind
* Routed restoration failures through the existing Stop-hook alarm
  instead of silently discarding the hand-back
* Added host-and-hook regressions plus attended and away idle-return
  controls to separate missing monitoring from status classification
@zachlandes
zachlandes force-pushed the fm/idle-after-run-stale-miss branch from 76fb0d5 to 04f3d05 Compare October 8, 2026 03:15
@zachlandes zachlandes changed the title fix(bin): restore watcher downtime before a main-only hand-back fix(bin): restore watcher downtime before main-only hand-back Oct 8, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @zachlandes, and @jasonm4130 for the production trace. I read head 04f3d059 against main.

What it does: after starting the successor, the main-only attended pass-through in bin/fm-supervision-host.sh republishes the recovery marker as downtime, even when an earlier engine turn left it at handling. If that publish fails, the host prints watcher: FAILED and exits nonzero instead of printing a close that can never be delivered.

Contract-class: restore. The host header and docs/supervision-host.md already promise that on this pass-through "the recovery marker still reads downtime and the re-arm owner delivers the close to main". The incident trace shows that promise breaking when an engine turn has already flipped the marker to handling. No new surface or wake class is added.

VISION, rule by rule: One captain, one interface (aligns: no silent 39-minute supervision gap). Authority explicit (aligns). Scripts own the mechanics (aligns). Restart a non-event (aligns: a close is retired by its delivery, not dropped). Delegation with a spine (aligns: a failure becomes a visible notice). Outlives any vendor (neutral). Scope (aligns).

Blocking (on you): Behavior portable serial 2 hit the 30-minute job limit twice on this head (run 37721861914, original attempt and my rerun). Every other check is green, the attestation matches, and Require no-mistakes passes. On main 3c58ec8e the same shard passes in about 19 minutes, and tests/fm-supervision-host.test.sh takes about 16 minutes there. On this head that file was still running at the limit. The 69 cases it shares with main took about 1,720 s against main's 900 s, a fairly uniform 2x slowdown, including cases this PR doesn't touch. Two other PRs' serial 2 reruns that started at the same moment finished in about 18 minutes, so this doesn't look like runner load. Please check whether the host change, or the new cases' setup, slows every host cycle. Once serial 2 finishes under the limit, this can be auto-merged as restore.

@zachlandes

Copy link
Copy Markdown
Contributor Author

Thanks for the careful read. I don't think this PR is what slows serial 2: main itself hit the same 30-minute cancellation that morning. Run 37737126056 on main 0ec1c5a was cancelled at 30m, and tests/fm-supervision-host.test.sh took 1705s there. That file and bin/fm-supervision-host.sh are identical between 3c58ec8 and 0ec1c5a, and the same code took 966s on the earlier run, so the 2x spread follows the runner rather than the commit.

On the slow runners the cases this PR shares with main took 1588s on this head against 1694s on unmodified main, and the four new cases add about 43s. I also checked for leftover watcher or host processes after the new cases and found none beyond what the base already leaves.

Could you rerun serial 2? On a normal runner it should finish around 19 minutes like main b062eb9 did. Separately, the host test file running close to the limit on slow runners looks like a main shard balance issue that's worth its own fix.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate (OSS triage, not the captain).

Thanks @zachlandes. Your timing evidence holds up. Main itself hit the same 30-minute Behavior portable serial 2 cancellation on 0ec1c5a4 (run 37737126056). bin/fm-supervision-host.sh and its test file are identical there to the earlier fast run, so the 2x spread follows the runner, not this diff. I'm withdrawing the "please check whether the host change slows every cycle" ask from my last stamp. This is no longer waiting on you.

Head 04f3d059 (attestation MATCH) is unchanged against main 19fcbbde. The body edit at 03:55Z re-passed Require no-mistakes. I re-read the host diff. leave_successor_for_main republishes downtime after it starts the successor. A failed publish returns 2, and the host prints watcher: FAILED … and exits nonzero instead of printing a close that can't be delivered. Nothing else in the marker protocol changes.

Contract-class: restore (unchanged). The host header and docs/supervision-host.md already promise that on the main-only pass-through "the recovery marker still reads downtime and the re-arm owner delivers the close to main." #6704 / @jasonm4130's trace shows that promise breaking. No new wake class or surface.

VISION.md, rule by rule: One captain, one interface (aligns: no silent supervision gap). Authority explicit (aligns). Scripts own the mechanics (aligns). Restart a non-event (aligns: a close is retired by delivery, not dropped). Delegation with a spine (aligns: a failure becomes a visible notice). Outlives any vendor (neutral). Scope (aligns).

CI: I re-ran the cancelled serial 2 job on run 37721861914 (attempt 3). Outcome: waiting-ci. If it finishes green, and no-mistakes and mergeability still hold, this auto-merges as restore on a later pass.

@LiamSarsfield

Copy link
Copy Markdown
Contributor

Another production occurrence of the path this PR fixes, on main at e0d95ac7 (Claude primary, attended, supervision host on by default). It cost about 10.5 hours of silent supervision overnight.

Host log for one generation (task names redacted). An engine turn handled one close, and then a main-only close was passed through:

1791762275  start         gen=host-242591-1791762275 primary=claude
1791762275  take-over     arm=231446
1791762285  handled       turn=host-242591-1791762275.1 posture=attended rc=0 ... stale: <task A>
1791762285  pass-through  attended main-only stale: <task B>

What followed:

  • The session never received a Stop hook feedback for that Stop. The previous Stop's feedback had arrived 37 s after it.
  • state/.claude-autoarm-epoch stayed at epoch=1412 owner_pid=242275 outcome=arming, with the owner gone and no .claude-autoarm-failure-* record.
  • The pass-through successor ran until 23:52Z, queued one more wake and closed, and nothing re-armed.
  • Both wake rows stayed queued until a manual turn the next morning.
  • There was no suspend, no OOM, and the session process stayed alive throughout.

This matches the handled-then-main-only ordering in the description. Our bin/fm-supervision-host.sh at e0d95ac7 has no downtime republish in leave_successor_for_main.

As @jasonm4130 noted, this path fails without leaving any trace. The PR's failure branch would at least turn it into a visible watcher: FAILED. An out-of-session detector (#5754) would still be needed for other shapes.

@LiamSarsfield

Copy link
Copy Markdown
Contributor

This hit us again last night on main at 9b1ada04 (Claude primary, attended, host on by default). Same shape: the host log shows an engine turn handling one close, then a pass-through attended main-only in the same second. .claude-autoarm-epoch stayed at outcome=arming with the owner gone and no failure record, the successor closed on the next status 2.5 minutes later, and nothing re-armed. That was 8.7 hours of silent supervision, and a second home on the same machine hit the identical handled-then-main-only sequence at 00:11Z and lost about 7 hours. We've switched the host off locally until this lands.

On the merge: the serial 2 rerun from the last triage (run 37721861914, attempt 3) was also cancelled at 30 minutes on Oct 9, so this has been in waiting-ci with nothing left to wait for. Main hits the same limit too, cancelled on 1a6714f2 and fc8972cd in the last day (#6790). Could it get another rerun, or go in as a restore with that shard waived @kunchenguid?

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate (OSS triage, not the captain).

Thanks @LiamSarsfield for the fresh production remiss on main 9b1ada04 (and the earlier ones), and @zachlandes / @jasonm4130 for the original path. Head 04f3d059 is unchanged; attestation still MATCHES.

Contract-class: restore (unchanged). The host header and docs/supervision-host.md already promise that on the main-only pass-through the recovery marker reads downtime so the re-arm owner delivers the close to main. This tip republishes downtime after starting the successor (and fails visibly if that publish cannot land). No new wake class or surface.

VISION.md, rule by rule: One captain (aligns — no silent multi-hour supervision gap). Authority explicit (aligns). Scripts own the mechanics (aligns). Restart a non-event (aligns — a close is retired by delivery). Delegation with a spine (aligns — failure becomes a visible notice). Outlives any vendor (neutral). Scope (aligns).

CI: Behavior portable serial 2 is still CANCELLED at the 30-minute ceiling on run 37721861914 (including the Oct 9 attempt-3 re-run). That is the known #7255 shard-budget class — main itself hits the same cancel. I am not re-running it again this wake (one re-run already spent; endless re-runs will not clear a ceiling). Every other required check on this head is green, including Require no-mistakes.

Outcome: waiting-ci from a strict green-gate view. Flagging for Firstmate: restore is otherwise-ready; the only CI blocker is the #7255 serial2 ceiling; production remisses keep landing on main. Land-despite that ceiling (or raise the shard limit) is a Firstmate/captain call — I will not squash-merge while the required check is cancelled.

@LiamSarsfield

Copy link
Copy Markdown
Contributor

@kunchenguid Thanks for the re-check. The only red is Behavior portable serial 2 at the same 30-minute ceiling that main hits, every other required check is green and the attestation still matches, so could this land as a restore with that shard waived? My firstmate homes keep the supervision host off until it does.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @LiamSarsfield for the repeated production traces, and @zachlandes for the fix.

Re-checked on head 04f3d05 (unchanged; mergeable). Main still has no downtime republish in leave_successor_for_main, so this fix is still needed. Contract-class: restore (unchanged): the host header and docs/supervision-host.md already promise that the recovery marker reads downtime on the main-only pass-through, and this tip makes that hold. VISION: aligns (removes a silent multi-hour supervision gap and turns an undeliverable hand-back into a visible watcher: FAILED).

CI: the only red is still Behavior portable serial 2 cancelled at the 30-minute ceiling (#7255), which main hits too. I've started one more re-run of that shard for this pass (run 37721861914, attempt 4). If it comes back green, this can merge as a restore. If it is cancelled again, merging with that shard waived is Kun's decision. That request is already with him. This is a captain-decision hold, not waiting on either of you.

@WTF-Am-ID

Copy link
Copy Markdown
Contributor

The serial 2 re-run you started (run 37721861914, attempt 4) finished green on 2026-10-18, so per your last note this can merge as a restore with no waiver needed. We're still carrying this fix as a local patch on every update, and #7428 is parked behind it. Thanks.

@kunchenguid
kunchenguid merged commit 05a68cb into kunchenguid:main Oct 22, 2026
72 of 75 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @zachlandes — really appreciate you taking the time on this.

Thanks also @jasonm4130 and @LiamSarsfield for the production traces, and @WTF-Am-ID for the nudge. You're right: the serial 2 re-run came back green, so no waiver was needed. Before merging I re-read head 04f3d059 against current main. Main still had no downtime republish in leave_successor_for_main, and the only main-side change to these files since the branch point was #7467's fixture stabilization in tests/fm-supervision-host.test.sh, which merges cleanly. I also ran tests/fm-supervision-host.test.sh on the merged tree: 79/79 passed, including the new hand-back cases.

Contract-class: restore (my own read, unchanged). The host header and docs/supervision-host.md already promised that the marker reads downtime on the main-only pass-through, and this makes that hold. When it can't, it now fails loudly instead of succeeding silently. VISION aligns: this closes a silent multi-hour supervision gap. The attestation matched this head, and all checks were green with a CLEAN merge state. It landed as 05a68cb2.

WTF-Am-ID added a commit to WTF-KRP/firstmate that referenced this pull request Oct 22, 2026
Keep only the hand-back exits kunchenguid#6588 does not cover: its main-only arm stays as merged, and exit_to_main, the non-main-only attended pass-through, the turn-start pass-through and the park boundary go through hand_back.
roderik added a commit to roderik/firstmate-rex that referenced this pull request Oct 23, 2026
…10's downtime restoration

Main gained PR 10 (idle-session wake backstop and downtime restoration on
host pass-through) after the upstream merge started. Upstream's kunchenguid#6588
fixed the same lost hand-back with a narrower main-only restore that
prints a FAILED line instead of the close; PR 10's restore_downtime_for_main
covers every attended pass-through, including a successor that failed to
start, and prints the close before exiting 1 so the Stop hook's
lost-hand-back path reports it. The resolution keeps PR 10's
implementation and its docs, alongside upstream's handling-settle and
announced hand-back changes, and adds the wake backstop section to
docs/watcher-continuity.md after upstream's handoff-settle text.
roderik added a commit to roderik/firstmate-rex that referenced this pull request Oct 23, 2026