Repository navigation
fix(bin): acknowledge opt-in supervision-host hand-backs to main - #7731
Conversation
When the attended supervision host hands responsibility back to the main conversation, at the park boundary or on a main-only pass-through, it left no watcher that outlived a lost continuation, so a home could stay unsupervised with no alarm. With config/supervision-handoff-ack present, a Claude host hand-back now queues a token-bound check and starts a verified, home-scoped successor (bin/fm-supervision-handoff.sh). The successor keeps replacing closed watcher cycles and raises the hand-back again until the main conversation acknowledges it through the sequence-bound wake drain. Automatic retry delivery needs a verified tmux pane; other terminals keep watching and wait for a normal turn. The behavior is off unless the flag exists, so the default hand-back paths are unchanged.
|
Speaking as Kun's firstmate: thank you @tiago-peixoto for turning #7725 into a PR this quickly, and for being clear about which scenarios were driven live and which weren't. I read head
Contract-class (my own read): opt-in. #7725 itself was new-default as an always-on change. This PR keeps it behind a home-local flag, so that doesn't apply here. VISION.md, rule by rule: One captain, one interface: aligns (a lost hand-back gets raised again instead of going silent). Authority: aligns (off unless the home turns it on, and it grants no new authority). Scripts own the mechanics: aligns (the token, ack and retry are all exact script work). Restart is a non-event: aligns strongly (the obligation is closed by a durable ack record). Delegation with a spine: partly there. The suite covers the three checks from the issue, but see CI below. Vendor: aligns (scoped to Claude, other owners unchanged). Scope: aligns. What's blocking: CI is red, and the failure is in one of the PR's own new tests. In run One more, if you can: the two lost-continuation scenarios, which are the heart of #7725, are only covered by the suite so far. If you can drive either one against a real Claude primary and post the evidence, that would really help. If you can't, just say so in the PR body. Status: waiting on you for the serial 1 fix. Once CI is green and the attestation is bound to the new head, this is on track to merge as opt-in. |
…t.sh (test_acknowledged_handoff_at_the_turn_keeps_the_pass_through_row), the only failure in "Behavior portable serial 1". Invariant: after an acknowledged hand-back at the turn, a live watcher must exist, but the owner replaces the stopped successor arm only within its one-second poll, so a one-shot watcher_live read at the hand-back instant can observe the gap. The sibling lost-continuation cases already wait for the owner's replacement, so this was the one remaining one-shot site on the hand-back path. Change, per the user's instruction: the assertion is now `wait_until 150 watcher_live "$home" || fail "ack turns-main-only: the hand-back left no watcher: $(cat "$home/state/.watch-cycle-exits.log")"`, and the timed-out agent's comment is cut to two lines saying the owner replaces the stopped arm within its poll, with no date. Nothing else changed (diff: 4 insertions, 2 deletions in that one file). Verification: ran the four hand-back tests (lost boundary, lost pass-through, acknowledged at the turn, retry respects receiving pane) via a temporary reduced copy three times, all passed with exit 0 each time; shellcheck -x on the test file passes. A full-file run and an 8-iteration reproduction loop with the original one-shot assertion were started but stopped before completing when the structured result was demanded; the three repro iterations that finished passed locally, so the race was not reproduced on this host (it depends on the owner poll timing CI hit). Temporary copies were removed; the worktree contains only the one modified test file, uncommitted
|
Speaking as Kun's firstmate: thanks @tiago-peixoto, that fix is exactly what was needed. New head Thanks also for saying plainly in the body that the two lost-continuation scenarios weren't driven against a live Claude primary. The four live Claude scenarios plus the suite are enough for an opt-in path, so I'm not asking for more. Contract-class (mine): opt-in, unchanged. The gate, state files and unconfigured path are the same as at Status: waiting on CI. Nothing is needed from you. If the serial 1 rerun comes back green and it's still CLEAN, I'll squash-merge it on a later pass. |
|
Speaking as Kun's firstmate: this is merged. Thank you @tiago-peixoto — really appreciate you taking the time on this. The serial 1 rerun came back green, so all 19 checks pass on |
Port #7731's acknowledged hand-back tests into the split host suites, keep the combined host test file deleted, and add estimated CI cost of the four new tests to the serial duration hints. Co-authored-by: Kun Chen <[email protected]>
Replace the host-a/b share-of-sample hints with timing-artifact duration_ms, cap watch-triage at the packing budget so it occupies its own shard, refresh previously unhinted and understated companions from the same CI artifacts, and restore the four #7731 registrations to main's relative order. Co-authored-by: Kun Chen <[email protected]>
…chenguid#7731) * fix(supervision): acknowledge opt-in host hand-backs When the attended supervision host hands responsibility back to the main conversation, at the park boundary or on a main-only pass-through, it left no watcher that outlived a lost continuation, so a home could stay unsupervised with no alarm. With config/supervision-handoff-ack present, a Claude host hand-back now queues a token-bound check and starts a verified, home-scoped successor (bin/fm-supervision-handoff.sh). The successor keeps replacing closed watcher cycles and raises the hand-back again until the main conversation acknowledges it through the sequence-bound wake drain. Automatic retry delivery needs a verified tmux pane; other terminals keep watching and wait for a normal turn. The behavior is off unless the flag exists, so the default hand-back paths are unchanged. * no-mistakes(test): log host rows before the acknowledged hand-back * no-mistakes(document): document acknowledged hand-back flag, state files, retry knob * no-mistakes(ci): Fixed the test race in tests/fm-supervision-host.test.sh (test_acknowledged_handoff_at_the_turn_keeps_the_pass_through_row), the only failure in "Behavior portable serial 1". Invariant: after an acknowledged hand-back at the turn, a live watcher must exist, but the owner replaces the stopped successor arm only within its one-second poll, so a one-shot watcher_live read at the hand-back instant can observe the gap. The sibling lost-continuation cases already wait for the owner's replacement, so this was the one remaining one-shot site on the hand-back path. Change, per the user's instruction: the assertion is now `wait_until 150 watcher_live "$home" || fail "ack turns-main-only: the hand-back left no watcher: $(cat "$home/state/.watch-cycle-exits.log")"`, and the timed-out agent's comment is cut to two lines saying the owner replaces the stopped arm within its poll, with no date. Nothing else changed (diff: 4 insertions, 2 deletions in that one file). Verification: ran the four hand-back tests (lost boundary, lost pass-through, acknowledged at the turn, retry respects receiving pane) via a temporary reduced copy three times, all passed with exit 0 each time; shellcheck -x on the test file passes. A full-file run and an 8-iteration reproduction loop with the original one-shot assertion were started but stopped before completing when the structured result was demanded; the three repro iterations that finished passed locally, so the race was not reproduced on this host (it depends on the owner poll timing CI hit). Temporary copies were removed; the worktree contains only the one modified test file, uncommitted (cherry picked from commit 3c1e468)
…chenguid#7731) * fix(supervision): acknowledge opt-in host hand-backs When the attended supervision host hands responsibility back to the main conversation, at the park boundary or on a main-only pass-through, it left no watcher that outlived a lost continuation, so a home could stay unsupervised with no alarm. With config/supervision-handoff-ack present, a Claude host hand-back now queues a token-bound check and starts a verified, home-scoped successor (bin/fm-supervision-handoff.sh). The successor keeps replacing closed watcher cycles and raises the hand-back again until the main conversation acknowledges it through the sequence-bound wake drain. Automatic retry delivery needs a verified tmux pane; other terminals keep watching and wait for a normal turn. The behavior is off unless the flag exists, so the default hand-back paths are unchanged. * no-mistakes(test): log host rows before the acknowledged hand-back * no-mistakes(document): document acknowledged hand-back flag, state files, retry knob * no-mistakes(ci): Fixed the test race in tests/fm-supervision-host.test.sh (test_acknowledged_handoff_at_the_turn_keeps_the_pass_through_row), the only failure in "Behavior portable serial 1". Invariant: after an acknowledged hand-back at the turn, a live watcher must exist, but the owner replaces the stopped successor arm only within its one-second poll, so a one-shot watcher_live read at the hand-back instant can observe the gap. The sibling lost-continuation cases already wait for the owner's replacement, so this was the one remaining one-shot site on the hand-back path. Change, per the user's instruction: the assertion is now `wait_until 150 watcher_live "$home" || fail "ack turns-main-only: the hand-back left no watcher: $(cat "$home/state/.watch-cycle-exits.log")"`, and the timed-out agent's comment is cut to two lines saying the owner replaces the stopped arm within its poll, with no date. Nothing else changed (diff: 4 insertions, 2 deletions in that one file). Verification: ran the four hand-back tests (lost boundary, lost pass-through, acknowledged at the turn, retry respects receiving pane) via a temporary reduced copy three times, all passed with exit 0 each time; shellcheck -x on the test file passes. A full-file run and an 8-iteration reproduction loop with the original one-shot assertion were started but stopped before completing when the structured result was demanded; the three repro iterations that finished passed locally, so the race was not reproduced on this host (it depends on the owner poll timing CI hit). Temporary copies were removed; the worktree contains only the one modified test file, uncommitted (cherry picked from commit 3c1e468)
Fixes #7725
This change is opt-in: it does nothing unless a home creates
config/supervision-handoff-ack.Automatic retry delivery needs a verified tmux pane, while other terminals keep watching but wait for a normal turn.
The two lost-continuation scenarios, the park boundary and the attended main-only pass-through, are covered by the suite and were not driven against a live Claude primary.
The assertion in
test_acknowledged_handoff_at_the_turn_keeps_the_pass_through_rowwaits for the watcher because the owner replaces the stopped arm within its one-second poll.Behavior portable serial 1 was cancelled at the 30-minute job cap while every test that ran passed, and upstream main hits the same cap in https://github.com/kunchenguid/firstmate/actions/runs/40101665463 (tracked as #7706).
Intent
Fix the supervision-host handoff defect reported in #7725, as an upstream pull request after the maintainer approved the issue.
When the attended supervision host hands responsibility back to the main conversation, at the park boundary or on an attended main-only pass-through, it leaves no watcher that outlives a lost continuation, so a home can sit unsupervised for hours with no alarm.
A host hand-back must be acknowledged, not fire-and-forget: a verified home-scoped successor keeps watching until the main conversation confirms it owns supervision, and raises the lost hand-back again when that confirmation never comes.
The change is opt-in, off unless a home enables it.
The maintainer triage asks the pull request to carry the three checks from the issue "How to verify" section as behavior tests: the park boundary with no continuation, the attended main-only pass-through with no continuation, and exactly one owning watcher after an acknowledgement.
What Changed
bin/fm-supervision-host.shgains anacknowledged_handbackpath, active only on a Claude primary with the new home-localconfig/supervision-handoff-ackflag, that runs at the park boundary, inexit_to_main, and on both attended main-only pass-throughs: it writes a generation token tostate/.supervision-handoff-pending, queues acheck: supervision-handoff:<token>wake, republishes watcher downtime, and only emits the close after a detached successor reports a healthy watcher (otherwise it prints asupervision-host:failure line and exits nonzero). The next host activation stops the recorded retry owner before taking over its arm, so one watcher remains. Without the flag every hand-back path is unchanged.bin/fm-supervision-handoff.shis that detached owner: it records itself instate/.supervision-handoff-owner, replaces each closed one-shot arm viafm-watch-arm.shand records it in.supervision-host-left, and everyFM_SUPERVISION_HANDOFF_RETRY_SECONDS(default 300) retries a record-backed watcher doorbell, submitting through the tmux primitive only when the inherited pane owns the pinned session, is in the foreground, is idle, and has an empty composer. It stops when the token is acknowledged, the opt-in is removed, the session is lost, or away mode starts.bin/fm-wake-drain.shremoves the pending token only when main's sequence-bound ack covers that specific check row.tests/fm-supervision-host.test.shadds four cases: a lost continuation at the boundary and at the main-only pass-through (watcher survives, retry is logged, stale ack is rejected, real ack clears the token, next park owns exactly one watcher), an acknowledged hand-back at the turn keeping its pass-through log row, and retry transport guards against human drafts, foreign panes, and background sessions. Default-path tests now assert the flag's absence changes nothing. Docs (docs/configuration.md,docs/supervision-host.md,docs/watcher-continuity.md, the operational-home-layout skill) describe the flag, state files, retry knob, and limits, andbin/fm-test-run.shmaps the new script to the host test family.Risk Assessment
Testing
Ran the seven targeted supervision-host suite cases on the target tree (four new hand-back tests plus three default-path tests), all passing; ran the restored-log-row assertions against a plain copy of the pre-fix parent commit 9509bfd, where both the pass-through-row and boundary-row checks fail as expected; then drove real Claude twice in disposable lab checkouts: one run covering the park boundary, the attended main-only pass-through, and the one-watcher take-over after each acknowledgement, and a second run landing the bound on a busy primary to exercise the retry owner's deferral and the eventual acknowledgement. Every live check passed except two rows in the first run's busy segment, which failed only because this machine's global Claude hook blocked the bare sleep command (fixture problem, annotated in the evidence and superseded by the second run). The lost-continuation contract, the opt-in-absent default paths, and the human-draft/foreign-pane/background-terminal transport guards were exercised only by the suite under a fake harness, not against the live product, and are reported as untested. Both labs were torn down and the worktree is clean.
boundary after 60sthenhandoff, a pending receipt, a live detached owner and a live watcher exist before main…start | boundary after 60s | handoff host-4007999-… | start | take-over arm=4061122pass-through attended main-onlythenhandoff, pending receipt, live owner and w…retry … deferredx3 during a 52s busy window, pane shows the running wait loop with no retry text, thenStop hook feedback-> drain -> ack -> `take-over ar…boundaryandpass-through attended main-onlyrows before thehandoffrow; the assertions fail on the pre-fix parent commi…not ok … dropped the pass-through row/dropped the boundary rowon 9509bfd with host logs containing only `start |…Evidence: Live Claude: boundary and pass-through hand-backs, acknowledgement, and one-watcher take-over (round 2, with fixed log rows)
Source: Live Claude: boundary and pass-through hand-backs, acknowledgement, and one-watcher take-over (round 2, with fixed log rows)
Evidence: Live busy-pane run: host log and handoff retry log
Evidence: Selected supervision-host suite tests on the target tree
Source: Selected supervision-host suite tests on the target tree
Evidence: Pre-fix parent 9509bfd: pass-through row assertion fails
Source: Pre-fix parent 9509bfd0: pass-through row assertion fails
Evidence: Pre-fix parent 9509bfd: boundary row assertion fails
Source: Pre-fix parent 9509bfd0: boundary row assertion fails
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-supervision-host.sh:1216- In the HANDLE_RC=2 pass-through branch the opt-inacknowledged_handbackcall sits before thelog_line "pass-through attended ..."write, and it never returns when the flag is on, so the host log records onlyhandoff <gen>and no pass-through row for that hand-back. The sibling attended pass-through at line 1168 logs first and then callsacknowledged_handback, so the two sites disagree. The host log is the forensic record the issue was diagnosed from. Remedy: move theacknowledged_handbackcall below thelog_lineat line 1217 so both pass-through sites log the hand-back reason before transferring.bin/fm-supervision-host.sh:373- The newactivate()block that stops a live.supervision-handoff-ownerbefore the arm take-over is the only thing that keeps the next park from running beside a still-retrying owner, and no test reaches it: both lost-hand-back tests acknowledge first, so the owner has already exited on.supervision-handoff-pendingremoval beforeturn_endstarts the next park, and the doorbell test never parks again. The realistic retry flow (doorbell wakes main, main's turn ends without acknowledging, Stop hook parks) goes through this block alone. I traced it: the owner's TERM trap runscleanup, which disowns the recorded arm and removes the owner file, and the host then takes over.supervision-host-left; identities match because_fm_engine_identitynormalizesfm_pid_identityoutput without changing it on Linux. No defect found, but the one-watcher invariant in the unacknowledged next-park case rests on an untested branch.🔧 **Test** - 1 issue found → auto-fixed ✅
bin/fm-supervision-host.sh:529- With config/supervision-handoff-ack present, acknowledged_handback exits the host before the ordinary host-log row is written on two paths: boundary_exit() calls it beforelog_line "boundary after ${PARK_ELAPSED}s"(line 529 vs 538), and the handle_wake rc 2 branch calls it beforelog_line "pass-through attended ..."(line 1216 vs 1217), unlike the attended_acceptor branch at line 1167-1168 which logs first. Result: state/.supervision-host.log shows onlyhandoff <gen>with no boundary or pass-through row, which is exactly the diagnostic row issue 7725 used to find the outage. Reproduced live (evidence live-claude-boundary-only.log: the real Claude run reached the bound at +62s and recordedhandoffbut noboundaryrow) and deterministically with the suite fixture (late-main-only-host-log-rows.md: identical close with the flag absent logs the pass-through row, with the flag present it does not). Fix: move theacknowledged_handbackcall after the respectivelog_lineon both paths, matching line 1167-1168. The hand-back itself, the queued check, the rewake, and the acknowledgement all work; this is a logging regression on the opt-in path only.test_lost_boundary_handoff(target-new-tests.log) and boundary-lost-continuation-transcript.md phases 2-3 (owner pid alive, watcher replaced, retry row, check row still queued)test_lost_pass_through_handoffand pass-through-lost-continuation-transcript.mdtake-over arm=and one arm whose parent is the host); live-claude-handoff-ack.md steps 3-4 and 6-7 with a real Claude primary--ack-through 0leaves the pending token in placetest_handoff_retry_respects_the_receiving_pane(target-new-tests.log)lost continuation left no verified watcherpass-through attended main-only,handoff,take-over)handoffat +62s of a 60s bound, pane shows Stop hook feedback, the check row,--ack-through 1, ACKED, thentake-over arm=; the script's own assertion on a…tests/fm-supervision-host.test.shfiltered totest_lost_boundary_handoff,test_lost_pass_through_handoff,test_handoff_retry_respects_the_receiving_paneon the target commit (all ok, 49s)tests/fm-supervision-host.test.shfiltered totest_park_boundary_ends_the_park_before_the_hook_timeout,test_successor_close_during_main_turn_is_delivered_at_the_next_turn_end,test_claude_stop_hook_delivers_a_main_only_pass_throughon the target commit (default paths without the opt-in, all ok)The newtest_lost_boundary_handoffandtest_lost_pass_through_handoffrun against the base commit d96bff00 scripts (git archive): both fail withlost continuation left no verified watcher, reproducing the issueCustom evidence drive of the issue's three verify steps with per-phase state snapshots (boundary and pass-through transcripts): watcher survives the torn-down hook group, successor close is replaced and the hand-back re-raised, main drain re-presents the check, a stale--ack-through 0does not clear the pending token, the exact printed ack clears it, next parktake-overleaves one host-owned armAdversarial: removing config/supervision-handoff-ack while a hand-back is pending stops the retry owner within seconds, keeps the current watcher, fires no retry, and the next park takes over exactly one watcher (opt-in-removal-transcript.md)Real Claude Code 2.1.310 (haiku, low effort) in an isolated lab copy of the target checkout with both opt-ins, private tmux server, real Stop hook: pass-through hand-back queued a token-bound check, left a live owner and watcher, the idle primary was rewoken, ranbin/fm-wake-drain.shand the exact--ack-throughcommand, pending cleared, next park took over one host-owned watcher (live-claude-handoff-ack.md)Real Claude lab, boundary-only variant with one registered project and no status appends: the park reached its 60s bound, queued the check, rewoke the primary which drained and acknowledged it, and the next park took over one arm (live-claude-boundary-only.log; script assertion on theboundarylog row failed, which is the reported finding)Fixture comparison of a close that turns main-only at its turn with and without the opt-in: host log has the pass-through row without the flag and lacks it with the flag (late-main-only-host-log-rows.md)🔧 Fix applied.
✅ Re-checked - no issues remain.
boundary after 60sthenhandoff, a pending receipt, a live detached owner and a live watcher exist before main…start | boundary after 60s | handoff host-4007999-… | start | take-over arm=4061122pass-through attended main-onlythenhandoff, pending receipt, live owner and w…retry … deferredx3 during a 52s busy window, pane shows the running wait loop with no retry text, thenStop hook feedback-> drain -> ack -> `take-over ar…boundaryandpass-through attended main-onlyrows before thehandoffrow; the assertions fail on the pre-fix parent commi…not ok … dropped the pass-through row/dropped the boundary rowon 9509bfd with host logs containing only `start |…bash <copy of tests/fm-supervision-host.test.sh running only test_lost_boundary_handoff test_lost_pass_through_handoff test_acknowledged_handoff_at_the_turn_keeps_the_pass_through_row test_handoff_retry_respects_the_receiving_pane test_park_boundary_ends_the_park_before_the_hook_timeout test_successor_close_during_main_turn_is_delivered_at_the_next_turn_end test_claude_stop_hook_delivers_a_main_only_pass_through>on the target tree - 7 ok (evidence r2-target-selected-tests.log)Same selected teststest_acknowledged_handoff_at_the_turn_keeps_the_pass_through_rowandtest_lost_boundary_handoffrun against agit archive 9509bfd0copy of the pre-fix parent - both fail on the dropped host-log row (evidence r2-prefix-regression-check.log, r2-prefix-boundary-regression-check.log)Live Claude lab (realclaude --model haiku --dangerously-skip-permissionsintmux -L fm-labon a private socket, FM_HOME = disposable checkout of 35155da3 with config/supervision-host + config/supervision-handoff-ack, FM_SUPERVISION_HOST_PARK_SECONDS=60, FM_SUPERVISION_HANDOFF_RETRY_SECONDS=20): park boundary hand-back, attended main-only pass-through hand-back, acknowledgement by the primary, next-park take-over with exactly one arm owning the watcher (evidence r2-live-claude-handoff-ack.md)Live Claude lab, busy primary: the bound landed while Claude blocked in a Bash wait loop; three retries loggeddeferred, no retry text in the pane, watcher alive throughout, acknowledgement after release, one host-owned watcher after (evidence r2-live-claude-busy-pane.md)Teardown:tmux -L fm-lab kill-serveron each lab socket, TERM of every process running from the lab checkout,rm -rfof each lab dir and of the temp test copies;git status --shortin the worktree is emptydocs/supervision-protocols/supervision-host.md:17- docs/supervision-protocols/supervision-host.md (the agent-runtime block rendered into every Claude session on a host home) says a handed-back wake reaches main only as Stop hook feedback. With config/supervision-handoff-ack, bin/fm-supervision-handoff.sh can also type a 'check: supervision-handoff' retry message into the idle owning pane. Nothing in the protocol is wrong, and the retry message carries its own drain-and-acknowledge instruction, so I left this always-loaded surface untouched rather than add opt-in detail to it. A maintainer may prefer one tagged {claude} line pointing at supervision-host.md#acknowledged-hand-back.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.