Repository navigation
fix(bin): restore watcher downtime before main-only hand-back - #6588
Conversation
|
|
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 In one park, watcher A closed on a routine signal. The host started handling successor B and confirmed its handoff, so the marker read The same refusal happened three more times in two days when main's drain began handling just before a first-cycle Repro on Separately from this PR: the fallback's |
* 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
76fb0d5 to
04f3d05
Compare
|
Speaking as Kun's firstmate: thanks @zachlandes, and @jasonm4130 for the production trace. I read head What it does: after starting the successor, the main-only attended pass-through in Contract-class: restore. The host header and 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 |
|
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. |
|
Speaking as Kun's firstmate (OSS triage, not the captain). Thanks @zachlandes. Your timing evidence holds up. Main itself hit the same 30-minute Head Contract-class: restore (unchanged). The host header and 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 |
|
Another production occurrence of the path this PR fixes, on Host log for one generation (task names redacted). An engine turn handled one close, and then a main-only close was passed through: What followed:
This matches the handled-then-main-only ordering in the description. Our As @jasonm4130 noted, this path fails without leaving any trace. The PR's failure branch would at least turn it into a visible |
|
This hit us again last night on main at 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 |
|
Speaking as Kun's firstmate (OSS triage, not the captain). Thanks @LiamSarsfield for the fresh production remiss on main Contract-class: restore (unchanged). The host header and 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 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. |
|
@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. |
|
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 CI: the only red is still |
|
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. |
|
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 Contract-class: restore (my own read, unchanged). The host header and |
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.
…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.
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
downtimeafter 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.shnow has the main-only attended pass-through set the recovery marker back todowntimeafter it starts the successor. Before this, an earlier engine turn could leave the marker readinghandling, and the re-arm owner then held back a later close that belonged to main.leave_successor_for_mainlogsdowntime-unrestoredand returns 2. The host then printswatcher: FAILED - the main-only hand-back could not restore watcher downtimeand exits nonzero, so the Stop hook reports an auto-arm failure. Before, it printed a close that could never be delivered.docs/supervision-host.mdto describe the republish and the failure path. Added regressions totests/fm-supervision-host.test.shfor 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.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 awayEvidence: 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 0Evidence: Claude Stop-hook consumer suite
Source: Claude Stop-hook consumer suite
Evidence: Cursor primary consumer suite
Source: Cursor primary consumer suite
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 ✅
🔧 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.bash tests/fm-supervision-host.test.shsubset 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_awaySame 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 loadFullbash tests/fm-supervision-host.test.shon HEAD started, stopped after 49 tests with no failures because it was too slow for the budget🔧 Fix applied.
1 warning still open:
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_awayThe same tests run one at a time against agit archivecopy withbin/fm-supervision-host.shreverted to base 9ea0c41a, to show the fail-before/pass-after behaviourbash 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.
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 HEADgit show 3c58ec8e:bin/fm-supervision-host.sh > bin/fm-supervision-host.shthen the two hand-back tests, to check they fail before the fix; the file was restored withgit checkout HEAD -- bin/fm-supervision-host.shbash 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.