Skip to content

fix(bin): restore downtime on host pass-through and add an idle-session wake backstop - #10

Merged
roderik merged 2 commits into
mainfrom
fm/fm-wake-backstop
Oct 23, 2026
Merged

roderik merged 2 commits into
mainfrom
fm/fm-wake-backstop

Conversation

@roderik

@roderik roderik commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Intent

Figure out what died in firstmate so that the primary firstmate lost several hours, and make sure it cannot happen silently again.

Context: on 2026-10-23 at 02:38:04 local (00:38:04Z) the primary firstmate session (Claude, pid 85903, home ~/code/firstmate-rex) ended a turn. Its three Stop hooks started (fm-turnend-guard.sh, fm-claude-stop-autoarm.sh asyncRewake, fm-host-mirror.sh). The supervision host handled one wake and at 02:39:10 passed a further wake (check: inactive-outcome for a finished worker) through to main. That wake should have reached the primary through the autoarm hook's exit-2 rewake. It never did: the session stayed idle for 197 minutes (transcript gap 00:38:04Z to 03:55:21Z) until the captain typed 'What's up? Are you stuck?'. During that time the workers kept running and merged PRs, but nothing was supervised. Hundreds of earlier rewakes the same day worked. Evidence in the firstmate workspace, state/: .supervision-host.log (last line 1792715950 'pass-through attended main-only check: inactive-outcome'), .claude-autoarm-epoch (epoch=216 owner_pid=9021 outcome=arming updated_at=1792715884, never finalised; pid 9021, host pid 9713 and the left arm pid 91245 are all dead), .supervision-host-left (02:39:10 bash fm-watch-arm.sh), .last-watcher-beat (stale since about 02:40), .guard-watcher-stale-banner, plus the Claude session transcript ~/.claude/projects/-Users-roderik-code-firstmate-rex/1302ae45-9d44-4c67-ae51-b33d4eb0b61b.jsonl (stop_hook_summary at 00:38:04.119Z, then nothing). The session's own commands afterwards printed 'WATCHER DOWN' banners, but only when it ran a command; an idle session never sees them.

What Changed

  • Added bin/fm-wake-backstop.sh (ensure/check/stop/run), a per-home loop independent of Stop hooks. When the oldest durable wake has waited past FM_WAKE_BACKSTOP_SECS with no open Stop-hook claim, it rings the primary's pane with a record-backed doorbell. It does this only after two consecutive passes see the same stranded wake, and only if the pane is idle with an empty composer. It records state/.wake-backstop-alarm when no pane was found. bin/fm-session-start.sh and bin/fm-claude-stop-autoarm.sh now start it. bin/fm-host-mirror.sh drops these doorbells from the dialog mirror.
  • bin/fm-supervision-host.sh now republishes the downtime recovery marker before it prints a pass-through close. Previously an engine turn's drain could move the marker to handling, so the re-arm owner skipped delivering the close to main. A failed republication stops the successor and exits 1 so the owner takes its lost-hand-back path.
  • Added tests/fm-wake-backstop.test.sh and extended the supervision-host, autoarm and host-mirror tests and tests/lib.sh. Updated docs/watcher-continuity.md, docs/supervision-host.md, docs/turnend-guard.md and docs/scripts.md.

Risk Assessment

⚠️ Medium: I found no defects, and the downtime republish and the new independent backstop loop both address the incident's failure path. The change adds a new detached background process that types into the primary's pane, and I did not run it, so it carries some residual operational risk.

Testing

I ran the four test files this change touches. The wake-backstop tests replay the incident state, ring the idle primary once, change no supervision state, and stay inert in away mode and secondmate homes. The supervision-host tests cover the pass-through that restores downtime and the failed-republish case that sends a failure notice. The autoarm and host-mirror tests passed. The wake-backstop run's output was cut at its last visible line, so I did not see whether its remaining tests passed. The supervision-host suite is slow: the first run was killed by my 550-second timeout and the rerun by its time limit, so its last tests did not run. I did not stand up a real Claude primary in a disposable lab, so nothing was driven against the live product.

  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Replay the 2026-10-23 stranded state: the backstop reads it as stranded once the oldest wake passes the threshold, rings the idle primary once, and changes no supervision state ✅ pass live tests/fm-wake-backstop.test.sh: the replay, ring-once, and loop tests report ok
Adversarial: the backstop stays inert in away mode, in a secondmate home, and while a live Stop-hook claim is open ✅ pass live tests/fm-wake-backstop.test.sh: the inert and open-claim tests report ok
An attended main-only pass-through republishes downtime. If republishing fails, it exits 1 and the hook delivers a failure notice instead of staying silent ✅ pass live tests/fm-supervision-host.test.sh: 'a pass-through that cannot restore downtime becomes a delivered failure notice' and 'an attended main-only pass-through rewakes main and keeps its successor watcher…
A live record-backed doorbell is machinery, not captain dialog, so the host mirror does not record it ✅ pass live tests/fm-host-mirror.test.sh: all ok, exit 0
A real Claude primary in a disposable lab goes idle with a stranded wake and the backstop rings its pane ⏸️ untested no I did not stand up a lab primary. The wake-backstop tests drive the real scripts against disposable fixtures, but not a real Claude CLI session, so this end-to-end case is untested.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - medium risk

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 4 of 5 scenarios driven live against the product
Scenario Result Live Evidence
Replay the 2026-10-23 stranded state: the backstop reads it as stranded once the oldest wake passes the threshold, rings the idle primary once, and changes no supervision state ✅ pass live tests/fm-wake-backstop.test.sh: the replay, ring-once, and loop tests report ok
Adversarial: the backstop stays inert in away mode, in a secondmate home, and while a live Stop-hook claim is open ✅ pass live tests/fm-wake-backstop.test.sh: the inert and open-claim tests report ok
An attended main-only pass-through republishes downtime. If republishing fails, it exits 1 and the hook delivers a failure notice instead of staying silent ✅ pass live tests/fm-supervision-host.test.sh: 'a pass-through that cannot restore downtime becomes a delivered failure notice' and 'an attended main-only pass-through rewakes main and keeps its successor watcher…
A live record-backed doorbell is machinery, not captain dialog, so the host mirror does not record it ✅ pass live tests/fm-host-mirror.test.sh: all ok, exit 0
A real Claude primary in a disposable lab goes idle with a stranded wake and the backstop rings its pane ⏸️ untested no I did not stand up a lab primary. The wake-backstop tests drive the real scripts against disposable fixtures, but not a real Claude CLI session, so this end-to-end case is untested.
  • bash tests/fm-wake-backstop.test.sh (the first nine tests, up to pane delivery)
  • bash tests/fm-supervision-host.test.sh (45 ok, 0 not ok before the run hit the time limit)
  • bash tests/fm-claude-stop-autoarm.test.sh (all ok)
  • bash tests/fm-host-mirror.test.sh (all ok, exit 0)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Pre-existing environment-only test failure

tests/fm-daemon.test.sh case "bare fallback (no override, no TMUX_PANE, no HERDR_ENV) should return non-zero" fails when the suite runs inside a Rex pane, because the inherited REX_BLOCK/REX_SESSION/REX_SERVER let supervisor-pane discovery prove a Rex pane.
It fails identically on clean main (409f886) in the same environment and passes with those variables unset; this PR does not touch that discovery code, and the test is left unchanged.

…on wake backstop

On 2026-10-23 a main-only close queued during a host engine turn reached the
Claude Stop hook with the recovery marker in handling (the engine's own drain
had begun handling on the shared generation), so the hook refused the rewake
and exited 0 beside the healthy successor the pass-through left. Nothing else
could wake the idle primary, and it stayed unsupervised for 197 minutes.

- fm-supervision-host.sh: every attended pass-through republishes downtime
  before printing the close; a failed republication leaves no successor and
  exits 1, so the hook's lost-hand-back path delivers a failure notice.
- fm-wake-backstop.sh: a detached, home-scoped loop per Claude primary
  session, ensured at session start and every owned Stop. When the oldest
  durable wake has waited past FM_WAKE_BACKSTOP_SECS with no open Stop-hook
  claim, it rings the idle primary's pane once with a record-backed watcher
  doorbell through the away daemon's guards. It never starts or stops a
  watcher and is inert in secondmate homes and under away or quiet mode.
- fm-host-mirror.sh: a live record-backed doorbell is machinery, not
  captain dialog.
- Tests replay the incident state and the drain race; docs describe the
  backstop and the cause.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-23T07:45:44.772517Z 7390996 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@roderik
roderik merged commit ad9ef9d into main Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant