Skip to content

fix: restore tmux worker relaunch after endpoint loss - #120

Merged
EvanAgee merged 22 commits into
mainfrom
fm/fm-relaunch-after-restart-review-fixes
Sep 15, 2026
Merged

EvanAgee merged 22 commits into
mainfrom
fm/fm-relaunch-after-restart-review-fixes

Conversation

@EvanAgee

@EvanAgee EvanAgee commented Sep 14, 2026 •

Copy link
Copy Markdown
Owner

Intent

Fix tmux worker relaunch after the named endpoint disappears while preserving the full accepted tmux contract. Every named-window read in bin/backends/tmux.sh and bin/fm-tmux-lib.sh must prove exact session and canonical window membership through the shared resolver, treat a missing window or tmux server as an absent endpoint with an empty current path, and use stable window or pane IDs so dotted canonical names cannot alias a similarly named sibling or pane. Preserve supported explicit numeric pane selectors and relative window selectors. Captures, status reads, explicit key sends, composer reads, typing, Enter, verification, fresh spawn launch input, and relaunch launch input must stay on the same resolved pane. A missing endpoint must route through the existing recreate path at the recorded worktree and fm-control relaunch must report relaunched; a present endpoint in the wrong directory must still refuse. Preserve teardown behavior that does not signal a sibling when the canonical window is gone, and retain the real isolated-tmux tests and walkthrough for missing windows, missing servers, sibling survival, recorded worktree recovery, and wrong-directory refusal. Retain c26dcb6's bounded cleanup for test-owned child processes and its TERM-responsive and stuck-child regressions. Apply only the remaining accepted review corrections in commit 07e083a8: document supported session:1.0 rather than unsupported session:editor.0; make the shared fake tmux kill-window remove only the matching exact window inventory row while preserving a similarly named sibling, with a production-path create-kill-relaunch regression using the exact =session:=window target; remove the unused stale strip_send_preflight test helper. Keep all existing exact-name and same-pane command-plus-Enter assertions. Do not make unrelated production changes, broaden the refactor, change another backend, or weaken assertions. Validate touched scripts with ShellCheck, run the focused tmux relaunch, backend, submit, and secondmate lifecycle regressions plus the repository test runner, and keep the PR evidence accurate that 21e4777 was not proved transient by an unchanged rerun. Reference backlog task fm-relaunch-after-restart because issue 112 is related OMP behavior and out of scope.

What Changed

  • Recreate missing tmux windows and sessions at the recorded worktree so relaunch succeeds, while preserving wrong-directory refusal. Addresses backlog task fm-relaunch-after-restart.
  • Resolve exact session and window membership before reads, and pin captures, submissions, and launch input to stable pane IDs. Prevent dotted task names from targeting siblings and teardown from signaling an unrelated pane.
  • Document supported selectors and recovery behavior, expand tmux recovery and sibling-survival regressions, correct fake window inventory handling, and bound test-child cleanup with TERM-responsive and stuck-child coverage.

Seen, not fixed

R1 identified a pre-existing multi-pane liveness limitation and is banked rather than fixed in this PR.
Both the current and pre-PR readers return dead when pane A is an idle shell, pane B runs sleep, and the active pane switches from A to B between liveness reads.
Both readers also return dead with pane A held active while pane B remains alive, so pinning pane A alone does not prove the whole task window safe to relaunch.
This PR does not claim whole-window safety for multi-pane task windows.

Risk Assessment

⚠️ Medium: Exact canonical resolution prevents missing or dotted task windows from aliasing siblings, while the banked pre-existing multi-pane liveness limitation remains outside this bounded follow-up.

Testing

The focused backend, relaunch, same-pane submit, secondmate lifecycle, teardown, and watcher regressions passed.
Repository ShellCheck passed.
CI passed all 20 reported checks on df0520567d454fcb33b9c49e213ca56621784547.
The fake create-kill-relaunch regression calls fm_backend_kill tmux firstmate:fm-design, verifies kill-window -t =firstmate:=fm-design, preserves fm-design.0, and recreates fm-design through fm_backend_tmux_create_task.

Evidence: Real-tmux relaunch walkthrough: recovery, sibling survival, and wrong-directory refusal

Source: Real-tmux relaunch walkthrough: recovery, sibling survival, and wrong-directory refusal

Task: fm-relaunch-after-restart
Real tmux; local stand-in for the agent, no model/network calls.

Scenario: missing exact window with live sibling
before: state=missing current_path=<>
$ fm-control.sh evidence-5463.0 relaunch --note "recover missing window"
warning: /Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/.test-tmp/walk.PmVI5u/home/data/evidence-5463.0/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode local-only - confirm its definition of done matches
notice: evidence-5463.0 ships mode=local-only while the standing posture for project is no-mistakes - less rigor than the captain's standing posture; proceed only on a current explicit captain instruction or an intake judgment you can state
relaunched evidence-5463.0 harness=claude from=claude model=default effort=default backend=tmux endpoint=evidence:fm-evidence-5463.0 worktree=/Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/.test-tmp/walk.PmVI5u/worktree
pane=%1
cwd=/Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/.test-tmp/walk.PmVI5u/worktree
agent_state=alive

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
bash-3.2$ export GOTMPDIR=/tmp/fm-evidence-5463.0/gotmp
bash-3.2$ export CHROME_DEVTOOLS_AXI_MCP_PATH='/Users/evanagee/.no-mistakes/work
trees/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/bin/fm-chrome-devtools-mcp.js'
bash-3.2$ export CHROME_DEVTOOLS_AXI_SESSION='evidence-5463.0'
bash-3.2$ unset TRACEPARENT; env -u CURSOR_AGENT -u CURSOR_INVOKED_AS CLAUDE_COD
E_ENABLE_PROMPT_SUGGESTION=false claude --dangerously-skip-permissions --append-
system-prompt-file '/tmp/fm-evidence-5463.0/worker-skills.eigKNr59' "$('/Users/e
vanagee/.no-mistakes/worktrees/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/bin/fm-op
erational-input.sh' encode launch-brief < '/Users/evanagee/.no-mistakes/worktree
s/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/.test-tmp/walk.PmVI5u/home/data/eviden
ce-5463.0/brief.md')"
replacement running in /Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M2G
X2XPZVRC2M9PGWACBTVH1/.test-tmp/walk.PmVI5u/worktree on %1







sibling_pid=5737 survived=true

Scenario: missing server
before: state=missing current_path=<>
$ fm-control.sh evidence-5463.0 relaunch --note "recover missing server"
warning: /Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/.test-tmp/walk.PmVI5u/home/data/evidence-5463.0/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode local-only - confirm its definition of done matches
notice: evidence-5463.0 ships mode=local-only while the standing posture for project is no-mistakes - less rigor than the captain's standing posture; proceed only on a current explicit captain instruction or an intake judgment you can state
relaunched evidence-5463.0 harness=claude from=claude model=default effort=default backend=tmux endpoint=evidence:fm-evidence-5463.0 worktree=/Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/.test-tmp/walk.PmVI5u/worktree
pane=%0
cwd=/Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/.test-tmp/walk.PmVI5u/worktree
agent_state=alive

The default interactive shell is now zsh.
To update your account to use zsh, please run `chsh -s /bin/zsh`.
For more details, please visit https://support.apple.com/kb/HT208050.
bash-3.2$ export GOTMPDIR=/tmp/fm-evidence-5463.0/gotmp
bash-3.2$ export CHROME_DEVTOOLS_AXI_MCP_PATH='/Users/evanagee/.no-mistakes/work
trees/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/bin/fm-chrome-devtools-mcp.js'
bash-3.2$ export CHROME_DEVTOOLS_AXI_SESSION='evidence-5463.0'
bash-3.2$ unset TRACEPARENT; env -u CURSOR_AGENT -u CURSOR_INVOKED_AS CLAUDE_COD
E_ENABLE_PROMPT_SUGGESTION=false claude --dangerously-skip-permissions --append-
system-prompt-file '/tmp/fm-evidence-5463.0/worker-skills.e7fqKfqx' "$('/Users/e
vanagee/.no-mistakes/worktrees/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/bin/fm-op
erational-input.sh' encode launch-brief < '/Users/evanagee/.no-mistakes/worktree
s/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/.test-tmp/walk.PmVI5u/home/data/eviden
ce-5463.0/brief.md')"
replacement running in /Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M2G
X2XPZVRC2M9PGWACBTVH1/.test-tmp/walk.PmVI5u/worktree on %0








Scenario: existing window in wrong directory
warning: /Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/.test-tmp/walk.PmVI5u/home/data/evidence-5463.0/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode local-only - confirm its definition of done matches
notice: evidence-5463.0 ships mode=local-only while the standing posture for project is no-mistakes - less rigor than the captain's standing posture; proceed only on a current explicit captain instruction or an intake judgment you can state
error: task evidence-5463.0's endpoint is in '/Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/.test-tmp/walk.PmVI5u/project', not its recorded worktree '/Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/.test-tmp/walk.PmVI5u/worktree'; refusing to relaunch an agent outside the copy holding its work
error: the replacement agent for evidence-5463.0 could not be launched on claude
error: evidence-5463.0's agent was stopped but the replacement did not launch; no agent is running, and its work plus the recorded progress note are preserved at /Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/.test-tmp/walk.PmVI5u/worktree
exit=1
metadata_unchanged=true replacement_launched=false

Scenario: relative selectors
evidence:+1 resolved=%1 native=%1

What I walked

The isolated real-tmux walkthrough recreated a missing canonical task window and a missing server at the recorded worktree, preserved the similarly named sibling, and retained the wrong-directory refusal.
The exact-name and same-pane regressions confirmed that launch text and Enter reach the same verified pane while the sibling receives no input.
The fake lifecycle regression drove the production tmux create and kill adapters through create, exact-name kill, sibling preservation, and recreation.
The isolated R1 diagnostic produced these controls:

current_switched before=%0 bash after=%1 sleep state=dead
pre_pr_switched before=%0 bash after=%1 sleep state=dead
current_steady_a before=%0 bash after=%0 bash state=dead
pre_pr_steady_a before=%0 bash after=%0 bash state=dead
current_steady_b before=%1 sleep after=%1 sleep state=ambiguous
pre_pr_steady_b before=%1 sleep after=%1 sleep state=ambiguous

These results bank R1 as pre-existing and do not establish multi-pane whole-window relaunch safety.

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 error
  • 🚨 /Users/evanagee/.no-mistakes/worktrees/b99440365b40/01M2GX2XPZVRC2M9PGWACBTVH1/bin/backends/tmux.sh:316 - The required status reads "must stay on the same resolved pane", but the changed hunk stores only window_state=$(fm_tmux_named_window_state &#34;$target&#34;) and independently resolves the original name for subsequent reads. With idle bash in pane A and foreground sleep in pane B, reading foreground names from A and switching to B before the remaining reads returns dead instead of ambiguous. Relaunch accepts that verdict and later pins B for launch input. Resolve one pane before status evaluation and retain its identity through relaunch authorization and launch.
✅ **Test** - passed

✅ No issues found.

  • TMPDIR="$PWD/.test-tmp" bash bin/fm-test-run.sh tests/fm-backend.test.sh tests/fm-control-relaunch.test.sh tests/fm-backend-tmux-smoke.test.sh tests/fm-tmux-submit-busy.test.sh tests/fm-secondmate-lifecycle-e2e.test.sh tests/fm-teardown-gone-window-reap.test.sh tests/fm-watch-triage.test.sh
  • TMPDIR=/tmp bash bin/fm-test-run.sh tests/fm-control-relaunch.test.sh tests/fm-secondmate-lifecycle-e2e.test.sh
  • bash /Users/evanagee/.no-mistakes/evidence/01M2GX2XPZVRC2M9PGWACBTVH1/relaunch-walkthrough.sh: isolated real tmux with a local agent stand-in; verified missing-window/server recovery, pane and directory receipts, sibling survival, wrong-directory refusal, and relative selection.
  • Diagnosed the copied-executable fixture failure by comparing copied and original sleep executables; replaced the stand-in with the working original executable.
  • git status --short confirmed a clean worktree after cleanup.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

EvanAgee and others added 22 commits September 14, 2026 16:27
The tmux backend now proves a named window exists before it reads a pane
field, so a gone endpoint reads as gone rather than as the current window's
path. Every fake `tmux` in the suite answered `list-windows` with nothing,
which under the new membership proof made every window look missing.

Give the stubs the shape the production code now expects: `new-window` and
`new-session` record the window name they were asked to create, and
`list-windows` reports it back. The exact-selector assertions in the tangle
guard move to the `=session:` form the backend now sends.

tests/fm-trace-context-spawn.test.sh's relaunch case called a plain spawn
despite its name; it now runs the task through `--relaunch`, which is what
it claimed to cover.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FBybnvdYjr3mqCMwQKa3ZT
Both files still read a tmux pane with a raw `display-message -p -t`, the
fallback class the rest of this branch closed. When the target window is gone,
tmux answers for the client's current window instead of failing, so the read
returns a value for a live, unrelated window.

In fm-teardown.sh this was a kill path. reap_task_backend_process_group
resolved the pane leader that way, so a gone window handed back the pid of a
live neighbour, and the function then sent SIGTERM to that process group. The
identity guards below it could not catch this: leader_start is sampled from the
same wrong pid, so it matches itself, and the pgid comparison is self-consistent
for the same reason. Route the read through fm_tmux_display_message, which
proves the named window exists first, so an absent window yields an empty
leader and takes the existing non-numeric early return without killing anything.

In fm-crew-state.sh pane_readable had the same read with a smaller blast
radius, since it is consulted only in the no-run fallback. Route it the same way
so a gone window reads as not readable.

tests/fm-teardown-gone-window-reap.test.sh covers this against a real tmux
server on a private socket: a gone window resolves no leader, the live
neighbour's process group survives, a live window still resolves its own pane
leader, and a dead server resolves nothing. It fails against the raw read,
where the gone window resolves the neighbour's exact pid.

The tmux stubs in fm-crew-state.test.sh and fm-teardown.test.sh did not answer
list-windows, so the membership gate saw an empty inventory and reported every
window missing. Teach both to report the window they represent, matching the
stubs this branch already updated.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01TyKd8b9n6NyYNg6CbXwGcE
@coderabbitai

coderabbitai Bot commented Sep 14, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 47 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 59119760-455d-48ab-80f2-1b5108dc7f3e

📥 Commits

Reviewing files that changed from the base of the PR and between 9e1b276 and df05205.

📒 Files selected for processing (45)
  • bin/backends/tmux.sh
  • bin/fm-backend.sh
  • bin/fm-crew-state.sh
  • bin/fm-spawn.sh
  • bin/fm-teardown.sh
  • bin/fm-tmux-lib.sh
  • docs/tmux-backend.md
  • tests/fm-backend-tmux-smoke.test.sh
  • tests/fm-backend.test.sh
  • tests/fm-bearings-snapshot.test.sh
  • tests/fm-busy-adapter-wiring.test.sh
  • tests/fm-composer-ghost.test.sh
  • tests/fm-control-relaunch.test.sh
  • tests/fm-crew-state.test.sh
  • tests/fm-decision-hold-lifecycle.test.sh
  • tests/fm-gate-refuse.test.sh
  • tests/fm-grok-harness.test.sh
  • tests/fm-kimi-harness.test.sh
  • tests/fm-muse-harness.test.sh
  • tests/fm-pending-reply.test.sh
  • tests/fm-secondmate-harness.test.sh
  • tests/fm-secondmate-lifecycle-e2e.test.sh
  • tests/fm-secondmate-liveness.test.sh
  • tests/fm-secondmate-sync.test.sh
  • tests/fm-send-popup-settle.test.sh
  • tests/fm-send-resolve-key.test.sh
  • tests/fm-send-secondmate-marker.test.sh
  • tests/fm-send-settle.test.sh
  • tests/fm-send-strict.test.sh
  • tests/fm-session-start.test.sh
  • tests/fm-spawn-dispatch-profile.test.sh
  • tests/fm-spawn-issue-guard.test.sh
  • tests/fm-spawn-pi-launch-robustness.test.sh
  • tests/fm-spawn-pool-base-freshen.test.sh
  • tests/fm-spawn-worktree-settle.test.sh
  • tests/fm-startup-memory-budget.test.sh
  • tests/fm-tangle-guard.test.sh
  • tests/fm-teardown-gone-window-reap.test.sh
  • tests/fm-teardown.test.sh
  • tests/fm-tmux-submit-busy.test.sh
  • tests/fm-trace-context-spawn.test.sh
  • tests/fm-watch-triage.test.sh
  • tests/fm-watcher-lock.test.sh
  • tests/secondmate-helpers.sh
  • tests/wake-helpers.sh

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@EvanAgee EvanAgee added the agent-pr-watched An agent merge watch is armed on this PR label Sep 15, 2026
@EvanAgee
EvanAgee merged commit 406f7ee into main Sep 15, 2026
21 checks passed
EvanAgee added a commit that referenced this pull request Sep 22, 2026
Re-architects Claude's Stop-owned supervision onto successor-first ordering, the
same shape Pi and OpenCode already use.

The former between-turns auto-arm made the watcher one-shot: it delivered one
wake and exited, and the successor armed only at the NEXT Stop. Any handling
turn longer than the beacon grace therefore ran with no live watcher, so the
beacon went stale and supervision was genuinely absent even though nothing had
crashed. Two cooperating Stop hooks replace it:

- bin/fm-claude-watch-coordinator.sh (async) admits one owner per session
  generation (state/.claude-coordinator.lock, role coordinator) and keeps
  exactly one arm/watcher cycle alive by driving the real bin/fm-watch-arm.sh as
  a tracked background child. After an actionable close it reads the queue
  high-water mark, arms and verifies a fresh successor, and only then publishes
  an atomic state/.claude-ready-to-notify record binding that mark, the recovery
  generation, the predecessor arm pid, the verified successor pid and identity,
  the coordinator generation, and the session owner. After a bounded
  successor-timeout streak with no healthy watcher it stands down.
- bin/fm-claude-watch-notifier.sh (asyncRewake) keeps the former auto-arm's
  scope, identity, AFK, need, stale-session-lock recovery, and single-flight
  gates, and parks until it can exit 2 on a ready record whose ready_seq is past
  its own high-water mark, still belongs to this session and coordinator
  generation, and covers at least one durable unacked queue row. It surfaces a
  typed degraded-supervision failure rather than exiting 0 into a
  still-needed-but-unsurfaced state, and drives the same failure-episode
  progression the turn-end guard reads.

bin/fm-claude-stop-autoarm.sh and its two suites are gone; the notifier is its
successor, and .claude/settings.json registers the coordinator and the notifier
alongside the turn-end guard.

Root-specific decisions recorded in the port:

- The notifier adopts the root's generation-claim contract in
  bin/fm-wake-lib.sh (fm_autoarm_claim_open/fm_autoarm_claim_next plus the epoch
  ledger) instead of the fork's plain owner lock, because the root explicitly
  forbids holding a mutex across a blocking step and a parked hook can block for
  hours. Claims are open while their outcome is arming or parked, which keeps
  the turn-end guard's recovery proof unchanged, and fm_lock_set_role gains the
  coordinator role.
- A coordinator lock alone never satisfies the turn-end guard: a coordinator
  cannot exit 2, so its state stays diagnostic evidence.
- The notifier commits its rewake epoch with the session-lock pid only; the
  fork's recovery-generation binding existed for the between-turns model, and
  the coordinator now keeps the beacon fresh instead.

Tests carried over and adapted: tests/fm-claude-watch-coordinator.test.sh drives
the real arm and watcher and proves a verified successor owns the lock before
the ready record is published, one stable watcher holds a fresh beacon across a
turn longer than grace, an actionable close re-arms and re-publishes, and a
coordinator lock never satisfies the guard. tests/fm-claude-watch-notifier.test.sh
covers the parked/rewake/failed progression, the unacked-queue rewake gate,
single-flight, and host-timeout translation. The ancestry, cursor, guard, and
instructions suites were re-pointed at the two hooks, and the fork's
prime-seen helper is replaced by the root's own production owner
(tests/wake-helpers.sh).

Refs #19
Refs #18

## What I walked

Everything below ran in a throwaway home under this worktree (`$PWD/.walk-home`, a
plain git checkout carrying a copy of `bin/`, so the scope predicate accepts it),
with `FM_HOME`/`FM_ROOT_OVERRIDE`/`FM_STATE_OVERRIDE`/`FM_CONFIG_OVERRIDE`
pointing at it; the live home and the trial home were never touched. The scratch
home held one in-flight task (`state/task.meta` + `state/task.status`), a fake
Claude session (a `bash` symlink named `claude`) that owns `state/.lock` and
fires both hooks from inside its own process tree the way `.claude/settings.json`
does, and fast knobs (`FM_POLL=1`, `FM_GUARD_GRACE=6`).

1. `bash session.sh` (the fake session) then
   `cat .walk-home/state/.lock` -> `session lock: 78208`.
2. Waiting on `state/.watch.lock/pid`:
   ```
   watcher pid: 79305 alive: yes
   coordinator lock role: coordinator
   t=1s watcher pid=79305 alive=yes beacon_age=1s (grace 6s)
   t=2s watcher pid=79305 alive=yes beacon_age=2s (grace 6s)
   t=3s watcher pid=none alive=no beacon_age=3s (grace 6s)
   t=4s watcher pid=88427 alive=yes beacon_age=4s (grace 6s)
   t=5s watcher pid=88427 alive=yes beacon_age=1s (grace 6s)
   ready-to-notify record:
   ready_seq=2
   recovery_generation=85049.1790074216.uOltZZ
   predecessor_arm_pid=79156
   successor_watch_pid=88427
   ```
   and one cycle-ledger row per cycle:
   `arm_pid=79156 watcher_pid=79305 origin=started ... reason=actionable-signal ... lock_after=pid:none|identity:none successor=started:88427`.
   The t=3s line is the arm's own actionable close: that cycle delivered a wake and
   exited, and `successor=started:88427` in the same row shows the coordinator had
   already armed and verified the next watcher, which is the successor-first
   ordering this port exists for. No model arm command was issued at any point.
3. Writing a real actionable status (`printf 'blocked: needs a decision [key=walk]\n' > state/task.status`)
   made the parked notifier wake:
   ```
   notifier exit: 2
   notifier stderr: firstmate watcher wake - one supervision event needs a handling turn now. ... The watcher coordinator owns continuity: a verified successor is already supervising the fleet - do NOT run bin/fm-watch-arm.sh after an ordinary wake.
   epoch after the wake: rewake
   durable queue row: 1790074216|1|signal|task.status|signal: .../state/task.status
   ```
   and the drain presented that row with its `WAKE_ACK_REQUIRED --ack-through 2` line.
4. `printf '{"session_id":"walk","stop_hook_active":true}\n' | bin/fm-turnend-guard.sh --claude`
   -> `guard exit: 0` (the live successor allowed the stop).
5. A heartbeat row appended to the durable queue, then `bin/fm-wake-drain.sh`:
   ```
   ANCHOR (durable truth re-read on this heartbeat; survives context compaction):
   standing steers (data/captain.md ## Working style):
     stand up before you sit down
   open decisions: 1 | in-flight tasks: 1
   ```
   with `odometer: pid=78208 started_epoch=1790074223 wakes=2` and
   `last-anchor stamped: yes`.

Test evidence on this branch: `tests/fm-claude-watch-coordinator.test.sh` (10/10),
`tests/fm-claude-watch-notifier.test.sh` (18/18), `tests/fm-session-lock-ancestry.test.sh`,
`tests/fm-turnend-guard.test.sh`, `tests/fm-cursor-primary.test.sh` (Cursor
stand-down for both hooks), `tests/fm-guard-stale-banner.test.sh`,
`tests/fm-supervision-instructions.test.sh`, `tests/fm-daemon.test.sh` (after the
wedge-lib extraction), `tests/fm-watcher-beat-alarm.test.sh` (14/14), and
`tests/fm-wake-drain-anchor.test.sh` (8/8) all pass. `shellcheck -x` is clean on
every touched `bin/*.sh`.

## Port record

What the root already had, adopted rather than re-implemented:

- The generation-claim single-flight contract in `bin/fm-wake-lib.sh`
  (`fm_autoarm_claim_open`/`fm_autoarm_claim_next`/`fm_autoarm_write_owned` and the
  `state/.claude-autoarm-epoch` ledger). The fork's notifier held a plain
  `state/.claude-autoarm.lock` with role `notifier` for its whole park; the root
  explicitly forbids holding a mutex across a blocking step, and a parked hook can
  block for hours, so the ported notifier claims a generation instead and its
  parked claim is the open claim the turn-end guard already reads
  (`fm_autoarm_claim_open` now accepts outcome `parked`).
- The root's turn-end guard, its failure-episode machinery, and its
  `fm_session_lock_owned_by_self` identity verdict: unchanged in behavior. The
  port only reworded its user-facing lines and documented that a `coordinator`
  lock never satisfies it.
- The root's newer watcher, drain, classify, and session-lock code: kept as the
  base. The fork's versions of `fm-watch.sh`, `fm-wake-drain.sh`, and
  `fm-classify-lib.sh` were NOT wholesale-imported; only this feature's seams were
  added to the root's files (the anchor re-read branch, the drain's anchor call,
  the instructions' anti-drift duties, the knob loader).
- The root's stricter per-backend absence proof for a `missing` endpoint in
  `bin/fm-control.sh`: kept, and it is why ride #11 is dropped (see below).

What changed from the fork's version, and why:

- Rewake commit shape: the fork bound a rewake to the session-lock pid AND the
  recovery generation. The ported notifier commits the session-lock pid only,
  because that binding existed for the between-turns model where the beacon could
  legitimately go stale mid-turn; the coordinator now keeps the beacon fresh, so a
  stale mid-turn beacon with no live watcher is a genuinely loud coordinator miss.
- `fm_lock_set_role` accepts `coordinator|notifier`; only `coordinator` is used by
  the ported hooks (the notifier owns the ledger, not the lock).
- `tests/fm-claude-watch-notifier.test.sh` carries one adapted assertion: its
  parent-TERM case asserted that the dying hook releases the owner lock from an
  EXIT trap. That property belongs to the fork's lock-holding design; the ported
  design asserts the invariant that matters instead - the kill leaves no LIVE
  owner lock (a process killed inside a lock's critical section always leaves a
  reclaimable dead-owner record, which is what `fm-wake-lib.sh`'s steal path
  recovers), and the ledger still ends at `interrupted`.
- `tests/fm-claude-watch-coordinator.test.sh`'s `prime_seen` helper now calls the
  root's production priming owner (`prime_status_seen` from `tests/wake-helpers.sh`)
  instead of hand-writing the fork's seen-marker shape.
- `tests/fm-session-lock-ancestry.test.sh`'s end-to-end layer fires the notifier
  against a seeded ready-to-notify record (`$FM_HOME/seed-ready.sh`, installed by
  the fixture) rather than the deleted auto-arm's arm fixture, and its phase
  helpers dropped the arm-count assertions that belonged to the removed stub.
- Docs were reconciled inside this port's own scope: `docs/configuration.md`'s
  Claude supervision knob lines, the new odometer and supervision-env sections, and
  the new `docs/scripts.md` rows. The rest of that file belongs to C3's
  reconciliation per the spec's conflict map.

Deleted as superseded: `bin/fm-claude-stop-autoarm.sh`,
`tests/fm-claude-stop-autoarm.test.sh`, and
`tests/fm-claude-stop-autoarm-live-e2e.test.sh`, replaced by the coordinator,
the notifier, and their two suites.

Dropped, with reasons:

- Ride #11 (herdr husk relaunch): the root already implements a stricter
  per-backend absence proof for a missing endpoint than the fork's `dead|missing`
  shortcut in `bin/fm-control.sh` (its own header, lines 34-59, and the `missing`
  branch at 485-533), and its herdr backend already owns
  `fm_backend_herdr_tab_is_husk` and in-place husk replacement. Porting the fork's
  version would weaken that contract, so the ticket's "the root already has it"
  path applies.
- Rides #119 (stalled-validation wake) and #120 (tmux relaunch after endpoint
  loss): the root has no equivalent, so they cannot be dropped as already present.
  #119 is a feature-sized port across `fm-nm-run-lib.sh`, `fm-classify-lib.sh`,
  `fm-crew-state.sh`, `fm-watch.sh`, and `fm-supervise-daemon.sh` with roughly
  2000 lines of tests, larger than everything on this branch. #120's surface on the
  root is two raw `tmux display-message -p -t <target> '#{pane_id}'` endpoint reads
  (`bin/fm-crew-state.sh`, `bin/fm-backend.sh`) that bypass the backend's
  named-window check, but no live failure has been reproduced on the root and the
  endpoint-liveness path must not change without one. Firstmate decided
  `[key=rides-scope]` option 1 on 2026-09-22: this branch lands as-is, and #119
  (first), then #120 and #11, become their own port ticket after C1 lands.
EvanAgee added a commit that referenced this pull request Sep 22, 2026
The notifier accepted any ready record with a coordinator token prefix. A
record left by the previous coordinator could therefore wake Claude before the
current coordinator had verified a successor. Require the ready generation to
match the current coordinator generation before committing the rewake. A
published ready record still wakes the session if its coordinator later dies.

The notifier regression failed before the fix with "notifier surfaced a ready
record from a previous coordinator generation, got 2" and passes after it.
The ancestry fixture now publishes the coordinator identity it exercises.

The root live-test family uses the shared opt-in gate, and heartbeat drains
now print an ANCHOR block beside queue rows. The carried tests use that gate
and count only the five-field queue rows. Quoted Herdr launcher labels in
the touched spawn script to satisfy ShellCheck.

Refs #19

## What I walked

I used `.walk-c1` under this worktree as a throwaway FM_HOME. It was a plain
Git checkout with a copy of `bin/`, one fake in-flight task, and a `bash`
symlink named `claude` that held `state/.lock` and fired both Stop hooks.
The live home and trial home were not used.

1. I ran `.walk-c1/claude .walk-c1/session.sh .walk-c1`. The scratch home
   reported `lock=37516`, `coord_generation=coord-37516-38046`,
   `watch_pid=57778`, `ready=2`, and `notifier_rc=2`.
2. Eight seconds later, the same watcher reported
   `watch_pid=57778 alive=yes beacon_age=2s grace=6s`. The notifier wrote
   `firstmate watcher wake - one supervision event needs a handling turn now.`
3. I added a heartbeat queue row and ran the scratch home's
   `bin/fm-wake-drain.sh`. It printed `WAKE_ACK_REQUIRED --ack-through 3` and
   `ANCHOR (durable truth re-read on this heartbeat; survives context compaction)`.
   The ANCHOR included `stand up before you sit down` and
   `open decisions: 0 | in-flight tasks: 1`.
4. I passed `{"session_id":"walk","stop_hook_active":true}` to the scratch
   home's `bin/fm-turnend-guard.sh --claude`. It exited 0. The scratch
   odometer recorded `wakes=2`, and `state/.last-anchor` existed.

## Port record

The root already had the generation-claim ledger, the Claude turn-end guard
and its failure episodes, the newer watcher and drain, and a stricter proof
before relaunching a missing Herdr endpoint. This port adopted those owners.
The notifier uses the root's short generation claim instead of the fork's
long-held lock; the coordinator and anchor attach to the root's existing
watcher and drain without replacing their layouts.

The old `fm-claude-stop-autoarm.sh` and its tests were superseded by the
coordinator, notifier, and their carried and adapted suites. Ride #11 was
omitted because the root's Herdr absence proof is stronger. Rides #119 and
#120 have no root equivalent. Firstmate resolved `[key=rides-scope]` by
moving them to separate port tickets after C1, with #119 first.
EvanAgee added a commit that referenced this pull request Sep 22, 2026
Bind new tmux task records to their socket and server process identity. Prove a missing endpoint against that server before recreating its window or session in the recorded worktree. Keep the root's refusal for legacy records that lack the binding.

Refs #120

## What I walked

I made a fake ship task in data/fm-c1b-walk/home with a private tmux socket and a worktree in the same scratch directory. Before the port, I killed its window and ran the root control command:

$ FM_HOME="$PWD/data/fm-c1b-walk/home" bin/fm-control.sh t1 relaunch --note 'continue after window loss'
error: tmux absence cannot be proven from a task record: the record does not carry the endpoint's socket identity

After binding the record to that socket and server identity, I repeated the endpoint loss:

$ tmux -S "$PWD/data/fm-c1b-walk/tmux/c1b.sock" kill-window -t c1b:fm-t1
$ FM_HOME="$PWD/data/fm-c1b-walk/home" bin/fm-control.sh t1 exit
endpoint-gone t1 harness=claude backend=tmux endpoint=c1b:fm-t1 worktree=/Users/evanagee/.treehouse/firstmate-df5ff1/4/firstmate/data/fm-c1b-walk/wt
$ FM_HOME="$PWD/data/fm-c1b-walk/home" bin/fm-control.sh t1 relaunch --note 'continue after window loss'
relaunched t1 harness=claude from=claude model=default effort=default backend=tmux endpoint=c1b:fm-t1 worktree=/Users/evanagee/.treehouse/firstmate-df5ff1/4/firstmate/data/fm-c1b-walk/wt

The replacement window reported the fake claude process, the same scratch worktree, and the recorded private socket. I also killed the private server and confirmed relaunch created a replacement server and recorded its new PID. A legacy fake task without tmux_socket, tmux_server_pid, and tmux_server_identity still refused:

$ FM_HOME="$PWD/data/fm-c1b-walk/home" bin/fm-control.sh t2 relaunch --note 'legacy proof check'
error: tmux absence cannot be proven from a legacy task record without its socket and server identity

## Port record

Root already had the transactional control plane, worktree preservation, a recovery-grade endpoint classifier, and strict per-backend absence proof. I adopted those paths and bound only new tmux records to a verifiable socket and server identity. I adapted the spawn test fixtures to provide the same evidence. I dropped the fork's inventory-only relaunch for legacy records; those records still refuse endpoint loss because an ambient inventory cannot prove absence on their original server. The root's Herdr proof stays intact.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-pr-watched An agent merge watch is armed on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant