Repository navigation
fix: restore main-only watcher handoff before successor start - #39
Conversation
Reviewer's GuideFixes a race where a supervisor drain left the recovery marker in handling and suppressed a queued main-only task-budget wake by publishing downtime before successor handoff, propagating restoration failures, and adding focused real-host regression tests. Validation covers red/green behavior, ShellCheck, syntax, and diff hygiene; the full suite and live runtime validation remain CI-owned. Sequence diagram for main-only watcher handoff restorationsequenceDiagram
participant Host as SupervisionHost
participant Marker as RecoveryMarker
participant Successor as Successor
participant Main as Main
Host->>Marker: fm_recovery_marker_publish downtime
alt publication succeeds
Host->>Successor: start_successor or detach_successor
Host-->>Main: exit 0, queued wake can be handled
else publication fails
Host-->>Host: log_line downtime-unrestored
Host-->>Main: emit, exit 1
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="bin/fm-supervision-host.sh" line_range="708" />
<code_context>
# downtime (autoarm_commit in bin/fm-claude-stop-autoarm.sh). A failed start
# returns 1; the caller still prints the close unchanged.
leave_successor_for_main() {
+ if ! fm_recovery_marker_publish "$STATE/.watcher-down" downtime >/dev/null 2>&1; then
+ log_line "pass-through downtime-unrestored $(printf '%s\n' "$REASON" | head -n 1)"
+ return 1
</code_context>
<issue_to_address>
**Main-only close is withheld**
When a live process stalls while holding the recovery-marker lock, `fm_recovery_marker_publish` waits indefinitely for the lock, so `leave_successor_for_main` never starts a successor or returns an error; the caller does not deliver the main-only wake, leaving main idle.
Bound the marker-lock wait so `leave_successor_for_main` can return and the caller can deliver the close.
</issue_to_address>| # downtime (autoarm_commit in bin/fm-claude-stop-autoarm.sh). A failed start | ||
| # returns 1; the caller still prints the close unchanged. | ||
| leave_successor_for_main() { | ||
| if ! fm_recovery_marker_publish "$STATE/.watcher-down" downtime >/dev/null 2>&1; then |
There was a problem hiding this comment.
🟡 Medium · Main-only close is withheld
When a live process stalls while holding the recovery-marker lock, fm_recovery_marker_publish waits indefinitely for the lock, so leave_successor_for_main never starts a successor or returns an error; the caller does not deliver the main-only wake, leaving main idle.
Bound the marker-lock wait so leave_successor_for_main can return and the caller can deliver the close.
Prompt for AI agents
In `bin/fm-supervision-host.sh` at line 708:
**Main-only close is withheld**
When a live process stalls while holding the recovery-marker lock, `fm_recovery_marker_publish` waits indefinitely for the lock, so `leave_successor_for_main` never starts a successor or returns an error; the caller does not deliver the main-only wake, leaving main idle.
Bound the marker-lock wait so `leave_successor_for_main` can return and the caller can deliver the close.…lish and failure exit
|
Review disposition for head 787420b:
Final disposition: all review items addressed or rejected with evidence above; CI is green on all 22 checks including the no-mistakes attestation. |
Intent
Apply the reviewed supervisor continuity fix so that an attended main-only wake is actually delivered to the primary session. The standing direction for this period: the top priority is velocity on merging bbchat PRs, and pipeline or supervision changes are in scope when they keep that moving; everything else is second priority. Twice on 2026-10-21 the primary session stopped receiving wakes: a supervisor drain left the recovery marker in handling while a main-only task-budget wake waited; the host left a healthy successor; Stop could not commit rewake and silently returned 0. Deliver the reviewed fix through the normal PR path, tests green, nothing else changed. Keep bin/fm-supervision-host.sh byte-identical to SHA256 1dfd99f2f98666a18120f437e7449cf144d8efe301c8e39b7d7d30780b0e1e70. Existing PR #39 must receive attestation; do not open another PR or force-push. Approved deviation: two new test tab regexes use ANSI-C quoting for GNU grep portability. Out of scope: away policy, admission, ownership, watcher cycle, other hooks, live runtime edits or live restarts.
What Changed
bin/fm-supervision-host.sh: on an attended main-only pass-through,leave_successor_for_mainnow republishesdowntimeon the watcher's recovery marker (.watcher-down) before it starts the successor. This replaces a marker that an earlier engine drain left inhandling. If that publication fails, the host logspass-through downtime-unrestoredand starts no successor. If either the publication or the successor start fails, the host still prints the close but exits 1 instead of always exiting 0. Before this change, the failure was swallowed with|| true. The script also gains twoABOUTMEheader lines.tests/fm-supervision-host.test.sh: addsassert_budget_close_after_supervisor_drainand two host+hook tests. The first checks that a queued main-only task-budget wake still rewakes main after an early or a delayed supervisor drain, with a deliverabledowntimemarker, the wake still queued and the successor running. The second forces the marker publication to fail. It checks that thedowntime-unrestoredlog line appears, the Stop hook exits 2,outcome=failedis recorded and no successor watcher is left running. The tab regexes use ANSI-C quoting ($'\t...') so they work with GNU grep.docs/supervision-host.md: describes the downtime republish on main-only pass-through, thedowntime-unrestoredandsuccessor-unverifiedfailure logs, and the nonzero exit.🤖 Generated with Claude Code
Risk Assessment
✅ Low: This is a small, bounded host change. Before a main-only hand-back starts a successor, it moves the recovery marker from handling to downtime, the same transition exit_to_main and the HANDLE_RC=2 path already make. The host's SHA256 matches the pinned 1dfd99f2…0e70. Both outcomes were traced through the Stop hook's actionable path: a successful write commits the rewake, and a refused write leaves no live watcher, so the lost-handback branch commits failed and exits 2.
Testing
I ran the focused supervision-host suite on the change (58 passed, 0 failed) and confirmed both new regression tests fail on the pre-fix host, as expected. I then stood up a disposable live Claude lab on this commit with a real primary, supervision host, headless engine, watcher and gated worker. In it I drove the incident's exact race: the real engine was paused right after the drain, so the main-only task-budget wake closed the successor while the marker was still in handling. With the fix, the host restored a deliverable downtime marker and the primary was rewoken. The same race against the pre-fix host left main silent, with the budget wake stranded in the queue. Four more live runs (early drain) also delivered to main. The refused-marker-write path was checked only through its automated test (fault injected through a fake mktemp), not live. The host SHA256 check is a source-level check, not a live scenario. The lab, its leftover treehouse pool, and the temp trees were torn down; the worktree is clean.
sha256sum bin/fm-supervision-host.sh=…Evidence: Focused suite on fixed source (58 ok, rc=0)
Source: Focused suite on fixed source (58 ok, rc=0)
Evidence: New delayed-drain test fails on pre-fix host (Stop exit 0 instead of 2)
Source: New delayed-drain test fails on pre-fix host (Stop exit 0 instead of 2)
Evidence: New refusal test fails on pre-fix host (no downtime-unrestored)
Source: New refusal test fails on pre-fix host (no downtime-unrestored)
Evidence: Live lab up readiness transcript
Source: Live lab up readiness transcript
Evidence: Live run 5 (fixed host, delayed drain) marker/host trace
Source: Live run 5 (fixed host, delayed drain) marker/host trace
Evidence: Live run 5 primary pane showing Stop hook rewake after delayed-drain handoff
Source: Live run 5 primary pane showing Stop hook rewake after delayed-drain handoff
Evidence: Live run 1 primary pane
Source: Live run 1 primary pane
Evidence: Live lab teardown
Source: Live lab teardown
Evidence: Live A/B summary
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ **Review** - passed
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
sha256sum bin/fm-supervision-host.sh=…bash tests/fm-supervision-host.test.shon 2c66c2e: 58 ok, 0 not ok, rc=0, including the two new budget-handoff tests (focused-fixed.log)The two new tests (delayed/early drain and refused marker write) run against the pre-fix host 79423d8 in a disposablegit archivetree: delayed drain fails with Stopexpected exit 2, got 0while the marker ispending:handling; refusal fails because nothing logsdowntime-unrestoredsha256sum bin/fm-supervision-host.sh= 1dfd99f2f98666a18120f437e7449cf144d8efe301c8e39b7d7d30780b0e1e70bin/fm-live-lab.sh up --harness claude --worker(lab at /tmp/fmlab.0fiLqZ, tree 2c66c2e): every readiness check ok (primary, probe, trust, mirror, host, watcher, worker)Live runs 1–4: a routine worker status wake handled by the real engine, then a task-budget wake made due through the worker meta; each time the host passed it throughattended main-onlyand the primary was rewoken (outcome=rewake, Stop hook feedback in the pane). These covered the early-drain orderingLive run 5 (fixed host): SIGSTOP the realclaude -pengine after the host announced handling, until the successor watcher closed on the budget wake, then SIGCONT. The marker went topending:handlingwith the budget wake queued; the host passed it through main-only and republishedpending:downtime; the ledger recordedoutcome=rewake; the primary pane shows Stop hook feedback and a handled turnLive run 6 (A/B): swapped the lab home's ownbin/fm-supervision-host.sh(a copy inside the lab) to pre-fix 79423d8 and repeated run 5 exactly. Pass-through main-only was logged, but the marker stayedpending:handling, the ledger stayedarming, the budget wake stayed queued, no Stop hook was alive, and the primary pane showed no new turnbin/fm-live-lab.sh down /tmp/fmlab.0fiLqZplus removal of the lab worker's leftover ~/.treehouse-fm/f951c1f44250 pool and the temp pre-fix treebin/fm-supervision-host.sh:706- The doc comment on leave_successor_for_main only mentions a failed successor start returning 1. It doesn't mention that a failed downtime publication also returns 1, or that the caller now exits nonzero. The comment is incomplete, not wrong. I left it alone because the intent requires this file to stay byte-identical (SHA256 1dfd99f2…). docs/supervision-host.md#attended now owns this behavior.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.