Skip to content

fix(bin): reclaim a task whose herdr endpoint was destroyed - #5007

Merged
kunchenguid merged 12 commits into
kunchenguid:mainfrom
RooseveltAdvisors:fm/fm-endpoint-missing-reclaim-20260913
Sep 20, 2026
Merged

kunchenguid merged 12 commits into
kunchenguid:mainfrom
RooseveltAdvisors:fm/fm-endpoint-missing-reclaim-20260913

Conversation

@RooseveltAdvisors

@RooseveltAdvisors RooseveltAdvisors commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor

Intent

The main firstmate routed this as a structural order: an endpoint re-binding deadlock is blocking real work across the fleet. I confirmed the deadlock from source before dispatching, so these are verified facts, not a relayed report.

The deadlock, exactly:

  • bin/fm-spawn.sh:1301 requires RELAUNCH_STATE to equal dead exactly. Anything else is refused, with advice to "stop the agent first with bin/fm-control.sh <id> exit".
  • bin/fm-control.sh:459 handles missing by dying: "recorded endpoint is gone, so there is no agent to stop; reconcile the task before any further control action".
  • There is no reconcile verb. bin/fm-control.sh's verb list is closed at interrupt|exit|relaunch.

Each command names the other as its prerequisite, so missing is a terminal state with no way out.

Trigger / mask / symptom, kept separate:

  • Trigger: the endpoint itself is destroyed - a pane or workspace removed in Herdr churn or a session restart - so the state classifies missing rather than dead.
  • Mask: dead works perfectly (exit returns already-stopped, relaunch proceeds), so this only bites when the endpoint vanished rather than just its agent. That is why it looks intermittent.
  • Symptom: a parked task cannot be reclaimed by any command, and its no-mistakes approval gate is stranded with no seat able to answer it.

Blast radius: 5+ stranded tasks, the fork-converge home's parked gates on fm-zeel and fm-sesh-sync-20260912, and PR 4031's orphaned ask-user gate. This home's own firstmate-endpoint-binding-backfill is the same deadlock, already escalated separately.

What Changed

  • Adds fm_control_endpoint_absence_verdict to bin/fm-control-lib.sh as the single owner of the per-backend proof that an endpoint reading missing is actually gone rather than merely unreachable: herdr proves it by starting the recorded session's server and re-reading the recorded pane (new fm_backend_herdr_endpoint_absence_recheck in bin/backends/herdr.sh), while tmux always answers unproven because a task record carries no socket identity for its endpoint.
  • bin/fm-spawn.sh --relaunch now treats a proven-gone endpoint as relaunchable — it mints one fresh tab in the recorded worktree and the recorded herdr session (fm_backend_herdr_container_ensure gained an explicit session parameter) and the republished record rebinds the task to it; secondmate rebinds and every tmux missing still refuse. bin/fm-control.sh exit routes missing through the same proof and reports endpoint-gone or already-stopped instead of dying, re-resolves the endpoint after a rebinding launch, and now restores the prior instructions when rollback cannot prove the old agent stopped.
  • Documents the reclaim path, its Herdr-only scope, and the known stray-husk-pane limitation in docs/agent-control.md, with pointers from docs/herdr-backend.md, docs/scripts.md, and the stuck-crewmate-recovery skill; adds 11 cases to tests/fm-control-relaunch.test.sh (tmux refusals, herdr adopt-vs-rebind, recorded-session pinning, task-wholeness, secondmate refusal) and rewrites the tmux missing case in tests/fm-control.test.sh to assert refusal with nothing sent.

Risk Assessment

✅ Low: The reclaim is tightly gated - absence is re-proven per backend before any rebind, herdr reads are pinned to the recorded session, tmux and secondmates refuse, and the relaunch transaction re-resolves its endpoint through the same shared validation - with new behavior-level tests covering adopt, rebind, returning-agent refusal, and task-integrity, leaving only two non-behavioral wording defects in explanatory text.

Testing

Ran both targeted suites green (tests/fm-control-relaunch.test.sh, tests/fm-control.test.sh, no skips), then proved the intent at the CLI level by replaying the same stranded herdr task through the real fm-control.sh/fm-spawn.sh on the base tree and the fix: base reproduces the exact circular deadlock (exit says reconcile first, relaunch says stop the agent first), while the fix reports endpoint-gone, rebinds the task to a fresh pane in its recorded session, and leaves the worktree, uncommitted work, status log and armed check whole. Also captured the duplicate-agent guardrails (surviving pane adopted, returning agent refused, tmux missing refused with its note rolled back) and a per-test fail-before/pass-after matrix in which 10 of the 11 new reclaim tests fail on base and pass on target. No product failures; the one fix I made was to a stale evidence script whose herdr stub predated the base's staged-launch-file delivery. This change has no UI surface, so the reviewer-visible evidence is CLI transcripts rather than screenshots.

Evidence: Operator transcript - the deadlock on base 90cd351

Source: Operator transcript - the deadlock on base 90cd351a

$ bin/fm-control.sh fmzeela exit error: task fmzeela's recorded endpoint is gone, so there is no agent to stop; reconcile the task before any further control action -> exit 1 $ bin/fm-spawn.sh fmzeelb --relaunch --harness claude error: task fmzeelb's endpoint reads 'missing'; a relaunch requires a positively agent-free endpoint (stop the agent first with bin/fm-control.sh fmzeelb exit) -> exit 1 $ bin/fm-control.sh fmzeelc relaunch --note "the pane was destroyed; pick the work back up" error: task fmzeelc's recorded endpoint is gone, so there is no agent to stop; reconcile the task before any further control action error: relaunch of fmzeelc failed while stopping the old agent and its state is 'missing'; the durable record and progress note were retained for recovery -> exit 1

==============================================================================
 BEFORE THE FIX - base commit 90cd351a
 firstmate code root: /tmp/fm-base-tree.Wzl2V0
 commit:              (tree extracted with git archive)
==============================================================================

A ship task parked on a no-mistakes approval. Its recorded herdr endpoint
fmlab:%7 was destroyed in churn; the fmlab server is still running and
answers pane_not_found for %7. Its worktree holds 1 commit + 1 uncommitted
file. Each attempt below starts from a fresh copy of exactly that state.

------------------------------------------------------------------------------
 1. Stop the agent, as the relaunch refusal tells the operator to
------------------------------------------------------------------------------

$ bin/fm-control.sh fmzeela exit
error: task fmzeela's recorded endpoint is gone, so there is no agent to stop; reconcile the task before any further control action
  -> exit 1

  the task afterwards:
    record: window=fmlab:%7
    record: herdr_session=fmlab
    record: herdr_tab_id=tab1
    record: herdr_pane_id=%7
    worktree HEAD unchanged:  yes
    branch:                   task-fmzeela
    uncommitted change:       uncommitted change the agent never got to save
    status log:               working: parked on a no-mistakes approval nobody can answer
    progress note in brief:   not present

------------------------------------------------------------------------------
 2. Relaunch directly, as the exit refusal leaves the operator to
------------------------------------------------------------------------------

$ bin/fm-spawn.sh fmzeelb --relaunch --harness claude
error: task fmzeelb's endpoint reads 'missing'; a relaunch requires a positively agent-free endpoint (stop the agent first with bin/fm-control.sh fmzeelb exit)
  -> exit 1

  the task afterwards:
    record: window=fmlab:%7
    record: herdr_session=fmlab
    record: herdr_tab_id=tab1
    record: herdr_pane_id=%7
    worktree HEAD unchanged:  yes
    branch:                   task-fmzeelb
    uncommitted change:       uncommitted change the agent never got to save
    status log:               working: parked on a no-mistakes approval nobody can answer
    progress note in brief:   not present

------------------------------------------------------------------------------
 3. The supported reclaim verb: control-plane relaunch with a progress note
------------------------------------------------------------------------------

$ bin/fm-control.sh fmzeelc relaunch --note "the pane was destroyed; pick the work back up"
error: task fmzeelc's recorded endpoint is gone, so there is no agent to stop; reconcile the task before any further control action
error: relaunch of fmzeelc failed while stopping the old agent and its state is 'missing'; the durable record and progress note were retained for recovery
  -> exit 1

  the task afterwards:
    record: window=fmlab:%7
    record: herdr_session=fmlab
    record: herdr_tab_id=tab1
    record: herdr_pane_id=%7
    worktree HEAD unchanged:  yes
    branch:                   task-fmzeelc
    uncommitted change:       uncommitted change the agent never got to save
    status log:               working: parked on a no-mistakes approval nobody can answer
    progress note in brief:   delivered to the replacement

  herdr calls the reclaim made (all scoped to the RECORDED session fmlab):
    pane get %7 --session fmlab
Evidence: Operator transcript - the reclaim on target 8b2d669

Source: Operator transcript - the reclaim on target 8b2d6692

$ bin/fm-control.sh fmzeela exit endpoint-gone fmzeela harness=claude backend=herdr endpoint=fmlab:%7 worktree=.../wt -> exit 0 $ bin/fm-spawn.sh fmzeelb --relaunch --harness claude spawned fmzeelb harness=claude kind=ship mode=no-mistakes yolo=off window=fmlab:%9 worktree=.../wt -> exit 0 $ bin/fm-control.sh fmzeelc relaunch --note "the pane was destroyed; pick the work back up" relaunched fmzeelc harness=claude from=claude model=default effort=default backend=herdr endpoint=fmlab:%9 worktree=.../wt -> exit 0 the task afterwards: record: window=fmlab:%9 record: herdr_session=fmlab record: herdr_pane_id=%9 worktree HEAD unchanged: yes branch: task-fmzeelc uncommitted change: uncommitted change the agent never got to save status log: working: parked on a no-mistakes approval nobody can answer progress note in brief: delivered to the replacement herdr calls the reclaim made (all scoped to the RECORDED session fmlab): pane get %7 --session fmlab tab create --workspace wsnew --cwd .../wt --label fm-fmzeelc --no-focus --session fmlab pane send-text %9 . '/tmp/fm-fmzeelc+.../launch.sh' --session fmlab

==============================================================================
 AFTER THE FIX - target commit 8b2d6692
 firstmate code root: ~/.no-mistakes/worktrees/46339c0817e0/01M2EGP13EBQJT4SQM7NFB7W74
 commit:              8b2d6692
==============================================================================

A ship task parked on a no-mistakes approval. Its recorded herdr endpoint
fmlab:%7 was destroyed in churn; the fmlab server is still running and
answers pane_not_found for %7. Its worktree holds 1 commit + 1 uncommitted
file. Each attempt below starts from a fresh copy of exactly that state.

------------------------------------------------------------------------------
 1. Stop the agent, as the relaunch refusal tells the operator to
------------------------------------------------------------------------------

$ bin/fm-control.sh fmzeela exit
endpoint-gone fmzeela harness=claude backend=herdr endpoint=fmlab:%7 worktree=/tmp/fm-reclaim-demo.f1c2mp/fmzeela/wt
  -> exit 0

  the task afterwards:
    record: window=fmlab:%7
    record: herdr_session=fmlab
    record: herdr_tab_id=tab1
    record: herdr_pane_id=%7
    worktree HEAD unchanged:  yes
    branch:                   task-fmzeela
    uncommitted change:       uncommitted change the agent never got to save
    status log:               working: parked on a no-mistakes approval nobody can answer
    progress note in brief:   not present

------------------------------------------------------------------------------
 2. Relaunch directly, as the exit refusal leaves the operator to
------------------------------------------------------------------------------

$ bin/fm-spawn.sh fmzeelb --relaunch --harness claude
spawned fmzeelb harness=claude kind=ship mode=no-mistakes yolo=off window=fmlab:%9 worktree=/tmp/fm-reclaim-demo.f1c2mp/fmzeelb/wt
  -> exit 0

  the task afterwards:
    record: window=fmlab:%9
    record: herdr_session=fmlab
    record: herdr_tab_id=tabnew
    record: herdr_pane_id=%9
    worktree HEAD unchanged:  yes
    branch:                   task-fmzeelb
    uncommitted change:       uncommitted change the agent never got to save
    status log:               working: parked on a no-mistakes approval nobody can answer
    progress note in brief:   not present

------------------------------------------------------------------------------
 3. The supported reclaim verb: control-plane relaunch with a progress note
------------------------------------------------------------------------------

$ bin/fm-control.sh fmzeelc relaunch --note "the pane was destroyed; pick the work back up"
relaunched fmzeelc harness=claude from=claude model=default effort=default backend=herdr endpoint=fmlab:%9 worktree=/tmp/fm-reclaim-demo.f1c2mp/fmzeelc/wt
  -> exit 0

  the task afterwards:
    record: window=fmlab:%9
    record: herdr_session=fmlab
    record: herdr_tab_id=tabnew
    record: herdr_pane_id=%9
    worktree HEAD unchanged:  yes
    branch:                   task-fmzeelc
    uncommitted change:       uncommitted change the agent never got to save
    status log:               working: parked on a no-mistakes approval nobody can answer
    progress note in brief:   delivered to the replacement

  herdr calls the reclaim made (all scoped to the RECORDED session fmlab):
    agent get %9 --session fmlab
    pane get %7 --session fmlab
    pane get %9 --session fmlab
    pane send-text %9 . '/tmp/fm-fmzeelc+ee7b7257b965dd4f0d8f4c5f7ac119d7f659ff0067caa5e6c960dde9e41125fd/launch.s1789880106.1770814.15214.sh' --session fmlab
    tab create --workspace wsnew --cwd /tmp/fm-reclaim-demo.f1c2mp/fmzeelc/wt --label fm-fmzeelc --no-focus --session fmlab
    tab list --workspace wsnew --session fmlab
    workspace create --cwd /tmp/fm-reclaim-demo.f1c2mp/fmzeelc/proj --label firstmate --no-focus --session fmlab
    workspace list --session fmlab
Evidence: Reclaim guardrails - adopt, refuse-alive, tmux refuses

Source: Reclaim guardrails - adopt, refuse-alive, tmux refuses

CASE 1 - server was STOPPED; the recorded pane survives a restart $ bin/fm-control.sh idle1 exit already-stopped idle1 ... endpoint=fmlab:%7 [exit 0] $ bin/fm-control.sh idle1 relaunch --note "server bounced; carry on" relaunched idle1 ... endpoint=fmlab:%7 [exit 0] endpoint after : fmlab:%7 (unchanged - the pane was ADOPTED) tabs created : none - no second tab beside the surviving pane CASE 2 - the server comes back and so does the AGENT $ bin/fm-spawn.sh back1 --relaunch --harness claude error: task back1's endpoint reads 'alive'; a relaunch requires a positively agent-free endpoint [exit 1] endpoint after : fmlab:%7 (record untouched) tabs created: none CASE 3 - a TMUX window absent from a readable inventory $ bin/fm-control.sh tmux1 exit error: task tmux1's endpoint fmses:fm-tmux1 reads 'missing', but tmux absence cannot be proven from a task record ...; exit will not claim an agent stopped at an address it cannot trust [exit 1] $ bin/fm-control.sh tmux1 relaunch --note "this note must never reach a live agent" error: ... its original instructions were restored and the durable record was retained for recovery [exit 1] windows created: none bytes sent into any pane: none instructions : byte-identical - the progress note was rolled back

================================================================
  reclaim guardrails - three operator transcripts
  (tree under test: ~/.no-mistakes/worktrees/46339c0817e0/01M2EGP13EBQJT4SQM7NFB7W74)
================================================================
CASE 1 - herdr session server was STOPPED; the recorded pane survives a restart.
         The state read says 'missing'; the pane was never destroyed.
------------------------------------------------------------
$ bin/fm-control.sh idle1 exit
already-stopped idle1 harness=claude backend=herdr endpoint=fmlab:%7 worktree=/tmp/fm-guardrails.vqir5u/stopped/wt
[exit status 0]
$ bin/fm-control.sh idle1 relaunch --note "server bounced; carry on"
warning: /tmp/fm-guardrails.vqir5u/stopped/home/data/idle1/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
relaunched idle1 harness=claude from=claude model=default effort=default backend=herdr endpoint=fmlab:%7 worktree=/tmp/fm-guardrails.vqir5u/stopped/wt
[exit status 0]
  endpoint after : fmlab:%7  (unchanged - the pane was ADOPTED)
  tabs created   : none - no second tab beside the surviving pane
  side effect    : exit ran `herdr server --session fmlab` to ask - it is not a read-only inspection (documented)
------------------------------------------------------------
CASE 2 - the herdr server comes back and so does the AGENT.
         Re-creating an endpoint here would put two agents on one worktree.
------------------------------------------------------------
$ bin/fm-spawn.sh back1 --relaunch --harness claude
error: task back1's endpoint reads 'alive'; a relaunch requires a positively agent-free endpoint (stop the agent first with bin/fm-control.sh back1 exit)
[exit status 1]
  endpoint after : fmlab:%7  (record untouched)
  tabs created   : none
------------------------------------------------------------
CASE 3 - a TMUX task whose window is absent from a readable inventory.
         A task record carries no socket identity, so 'gone' and 'on a
         server this seat cannot address' are indistinguishable.
------------------------------------------------------------
$ bin/fm-control.sh tmux1 exit
error: task tmux1's endpoint fmses:fm-tmux1 reads 'missing', but tmux absence cannot be proven from a task record: the record does not carry the endpoint's socket identity, and a server-wide window inventory only describes the tmux server this process addresses, so a window absent from it may still be alive on another; exit will not claim an agent stopped at an address it cannot trust, nor send lifecycle input to one
[exit status 1]
$ bin/fm-control.sh tmux1 relaunch --note "this note must never reach a live agent"
error: task tmux1's endpoint fmses:fm-tmux1 reads 'missing', but tmux absence cannot be proven from a task record: the record does not carry the endpoint's socket identity, and a server-wide window inventory only describes the tmux server this process addresses, so a window absent from it may still be alive on another; exit will not claim an agent stopped at an address it cannot trust, nor send lifecycle input to one
error: relaunch of tmux1 failed while stopping the old agent and its state is 'missing', so it was not proven stopped; its original instructions were restored and the durable record was retained for recovery
[exit status 1]
  windows created: none
  bytes sent into any pane: none
  instructions   : byte-identical - the progress note was rolled back
------------------------------------------------------------
Evidence: Fail-before / pass-after matrix for the 11 new reclaim tests

Source: Fail-before / pass-after matrix for the 11 new reclaim tests

test BASE TARGET test_tmux_refuses_a_window_missing_from_its_session FAIL pass test_tmux_refuses_a_session_that_cannot_be_found FAIL pass test_tmux_refuses_when_the_server_is_gone FAIL pass test_reclaim_refuses_an_unreadable_endpoint pass pass test_herdr_reclaim_adopts_a_pane_that_outlived_its_server FAIL pass test_herdr_exit_reports_already_stopped_when_the_pane_outlived_its_server FAIL pass test_herdr_rebind_stays_in_the_recorded_session FAIL pass test_herdr_reclaim_refuses_an_agent_that_came_back FAIL pass test_herdr_reclaim_keeps_the_task_whole FAIL pass test_herdr_reclaim_of_a_secondmate_names_its_own_owner FAIL pass test_herdr_rebind_failure_from_a_plain_shell_names_the_real_cause FAIL pass

Each reclaim test added by this change, run individually from the SAME test file
(tests/fm-control-relaunch.test.sh at the target commit) against both trees.

  base   90cd351a  (tree extracted with git archive; target's test file dropped in)
  target 8b2d6692  (this worktree)

test                                                                     BASE     TARGET
-----------------------------------------------------------------------------------------------
test_tmux_refuses_a_window_missing_from_its_session                      FAIL     pass
    base refuses: not ok - a refused relaunch edited instructions an agent that may still be running is reading (window absent from a readable session inventory)
test_tmux_refuses_a_session_that_cannot_be_found                         FAIL     pass
    base refuses: not ok - a refused relaunch edited instructions an agent that may still be running is reading (recorded session not found)
test_tmux_refuses_when_the_server_is_gone                                FAIL     pass
    base refuses: not ok - a refused relaunch edited instructions an agent that may still be running is reading (no tmux server on this socket)
test_reclaim_refuses_an_unreadable_endpoint                              pass     pass
test_herdr_reclaim_adopts_a_pane_that_outlived_its_server                FAIL     pass
    base refuses: not ok - a pane that outlived its stopped server is adoptable
test_herdr_exit_reports_already_stopped_when_the_pane_outlived_its_server FAIL     pass
    base refuses: not ok - a pane that outlived its stopped server holds no agent, which is success
test_herdr_rebind_stays_in_the_recorded_session                          FAIL     pass
    base refuses: not ok - a herdr pane that did not survive its server should be rebound
test_herdr_reclaim_refuses_an_agent_that_came_back                       FAIL     pass
    base refuses: not ok - the refusal should name the state it actually read (missing: 'alive')
test_herdr_reclaim_keeps_the_task_whole                                  FAIL     pass
    base refuses: not ok - the owning seat should be able to reclaim a task whose pane is gone
test_herdr_reclaim_of_a_secondmate_names_its_own_owner                   FAIL     pass
    base refuses: not ok - the refusal should name the path that owns this recovery (missing: '--secondmate')
test_herdr_rebind_failure_from_a_plain_shell_names_the_real_cause        FAIL     pass
    base refuses: not ok - the refusal should name the session the reclaim was targeting (missing: 'fmlab')
Evidence: Replayable driver behind the before/after transcripts

Source: Replayable driver behind the before/after transcripts

#!/usr/bin/env bash
# reclaim-deadlock-demo.sh <code-root> <label>
#
# Operator-level reproduction of the endpoint re-binding deadlock named in this
# change's intent, run against an arbitrary firstmate code root so the SAME
# scenario can be replayed on the base commit and on the fix.
#
# Scenario (the intent's trigger, exactly): a ship task recorded on the herdr
# backend at session `fmlab`, pane `%7`. The pane was destroyed in herdr churn.
# That session's server is still RUNNING, so this is not a merely unreachable
# endpoint - the pane genuinely does not exist and herdr answers
# `pane_not_found`. The task is parked on a no-mistakes approval, has one
# commit on its branch and one uncommitted file.
#
# Each of the three commands an operator would reach for is run against its own
# FRESH copy of that stranded task, so no attempt is coloured by a previous one:
#   bin/fm-control.sh <id> exit
#   bin/fm-spawn.sh   <id> --relaunch --harness claude
#   bin/fm-control.sh <id> relaunch --note "..."
#
# Everything runs against a throwaway FM_HOME, a throwaway user HOME and a
# canned `herdr` CLI. No real herdr session, no real agent, no network.
# FM_GATE_REFUSE_BYPASS=1 is the sanctioned test-harness escape hatch documented
# in bin/fm-gate-refuse-lib.sh, needed because this runs from a gate worktree.
set -u

ROOT=${1:?usage: reclaim-deadlock-demo.sh <code-root> <label>}
LABEL=${2:?usage: reclaim-deadlock-demo.sh <code-root> <label>}
SES=fmlab

TOP=$(mktemp -d /tmp/fm-reclaim-demo.XXXXXX)
CASE_IDS=()
cleanup() {
  local id
  rm -rf "$TOP"
  for id in "${CASE_IDS[@]:-}"; do [ -n "$id" ] && rm -rf "/tmp/fm-$id"; done
}
trap cleanup EXIT

# --- canned herdr CLI: server up, recorded pane destroyed -------------------
herdr_stub() {  # <fakebin>
  cat > "$1/herdr" <<'SH'
#!/usr/bin/env bash
set -u
D=$FM_FAKE_DIR
printf '%s\n' "$*" >> "$D/herdr-log"
if [ "${1:-}" = status ] && [ "${2:-}" = --json ]; then
  printf '{"client":{"version":"0.9.0","protocol":22},"server":{"running":true}}\n'; exit 0
fi
[ "${1:-}" = server ] && exit 0
case "${1:-} ${2:-}" in
  'pane get')
    if [ "${3:-}" = "$(cat "$D/herdr-pane")" ]; then
      printf '{"result":{"pane":{"pane_id":"%s","foreground_cwd":"%s"}}}\n' "${3:-}" "$(cat "$D/cwd")"
    else
      printf '{"error":{"code":"pane_not_found"}}\n'
    fi
    exit 0 ;;
  'agent get')
    if [ -f "$D/herdr-agent-live" ]; then
      printf '{"result":{"agent":{"agent_status":"idle"}}}\n'
    else
      printf '{"error":{"code":"agent_not_found"}}\n'
    fi
    exit 0 ;;
  'pane process-info')
    printf '{"result":{"type":"pane_process_info","process_info":{"pane_id":"%s","shell_pid":4242,"foreground_processes":[{"pid":4243,"name":"claude","argv":["claude"],"cmdline":"claude"}]}}}\n' "$(cat "$D/herdr-pane")"
    exit 0 ;;
  'pane send-text')
    payload=${4:-}
    case "$payload" in ". '"*"'") staged=${payload#". '"}; staged=${staged%"'"}; [ ! -f "$staged" ] || payload=$(cat "$staged") ;; esac
    case "$payload" in *'encode launch-brief'*) : > "$D/herdr-agent-live" ;; esac
    exit 0 ;;
  'workspace list') printf '{"result":{"workspaces":[]}}\n'; exit 0 ;;
  'workspace create') printf '{"result":{"workspace":{"workspace_id":"wsnew"},"tab":{"tab_id":"seedtab"}}}\n'; exit 0 ;;
  'tab list') printf '{"result":{"tabs":[]}}\n'; exit 0 ;;
  'tab create')
    printf '{"result":{"tab":{"tab_id":"tabnew"},"root_pane":{"pane_id":"%%9"}}}\n'
    printf '%s' '%9' > "$D/herdr-pane"
    exit 0 ;;
esac
exit 0
SH
  chmod +x "$1/herdr"
}

# new_stranded_case <id> -> builds $TOP/<id> and echoes nothing; sets DIR.
DIR=
HEAD_BEFORE=
new_stranded_case() {  # <id>
  local id=$1
  DIR="$TOP/$id"
  CASE_IDS+=("$id")
  mkdir -p "$DIR/home/state" "$DIR/home/data/$id" "$DIR/fake" "$DIR/fakebin" "$DIR/user-home"
  git -C "$DIR" init -q -b main proj
  git -C "$DIR/proj" -c user.name=demo -c [email protected] commit -q --allow-empty -m initial
  git clone --quiet --bare "$DIR/proj" "$DIR/proj.origin.git"
  git -C "$DIR/proj" remote add origin "file://$DIR/proj.origin.git"
  git -C "$DIR/proj" worktree add --quiet -b "task-$id" "$DIR/wt"
  printf 'the work this task already landed on its branch\n' > "$DIR/wt/landed.txt"
  git -C "$DIR/wt" add landed.txt
  git -C "$DIR/wt" -c user.name=demo -c [email protected] commit -qm "work in progress"
  HEAD_BEFORE=$(git -C "$DIR/wt" rev-parse HEAD)
  printf 'uncommitted change the agent never got to save\n' > "$DIR/wt/dirty.txt"
  cat > "$DIR/home/data/$id/brief.md" <<EOF
# Task
## Captain's intent
Reclaim a task whose terminal was destroyed.

## Firstmate spec
Keep the task whole while its endpoint is re-created.
EOF
  {
    echo "window=$SES:%7"
    echo "endpoint_task_id=$id"
    echo "worktree=$DIR/wt"
    echo "project=$DIR/proj"
    echo "harness=claude"
    echo "kind=ship"
    echo "mode=no-mistakes"
    echo "yolo=off"
    echo "tasktmp=/tmp/fm-$id"
    echo "model=default"
    echo "effort=default"
    echo "backend=herdr"
    echo "herdr_session=$SES"
    echo "herdr_workspace_id=ws1"
    echo "herdr_tab_id=tab1"
    echo "herdr_pane_id=%7"
  } > "$DIR/home/state/$id.meta"
  printf 'working: parked on a no-mistakes approval nobody can answer\n' > "$DIR/home/state/$id.status"
  printf '%s' "$DIR/wt" > "$DIR/fake/cwd"
  printf '%s' '%none' > "$DIR/fake/herdr-pane"   # nothing answers to %7 any more
  : > "$DIR/fake/herdr-log"
  herdr_stub "$DIR/fakebin"
}

fm() {  # <script> <args...>
  local script=$1; shift
  env -u HERDR_ENV -u HERDR_PANE_ID -u HERDR_SESSION -u HERDR_SOCKET_PATH \
      -u HERDR_TAB_ID -u HERDR_WORKSPACE_ID \
      PATH="$DIR/fakebin:$PATH" FM_HOME="$DIR/home" FM_FAKE_DIR="$DIR/fake" \
      HOME="$DIR/user-home" CLAUDE_CONFIG_DIR='' FM_SPAWN_NO_GUARD=1 \
      FM_GATE_REFUSE_BYPASS=1 \
      FM_CONTROL_POLL=0.01 FM_CONTROL_EXIT_WAIT=0.05 FM_CONTROL_LAUNCH_WAIT=0.05 \
      "$ROOT/bin/$script" "$@" 2>&1 | grep -v '^warning: .*records no delivery contract line'
  return "${PIPESTATUS[0]}"
}

aftermath() {  # <id>
  local id=$1
  echo
  echo "  the task afterwards:"
  grep -E '^(window|herdr_session|herdr_pane_id|herdr_tab_id)=' "$DIR/home/state/$id.meta" | sed 's/^/    record: /'
  printf '    worktree HEAD unchanged:  %s\n' \
    "$([ "$(git -C "$DIR/wt" rev-parse HEAD)" = "$HEAD_BEFORE" ] && echo yes || echo 'NO')"
  printf '    branch:                   %s\n' "$(git -C "$DIR/wt" rev-parse --abbrev-ref HEAD)"
  printf '    uncommitted change:       %s\n' \
    "$([ -f "$DIR/wt/dirty.txt" ] && cat "$DIR/wt/dirty.txt" || echo 'LOST')"
  printf '    status log:               %s\n' "$(tail -1 "$DIR/home/state/$id.status")"
  printf '    progress note in brief:   %s\n' \
    "$(grep -q 'pick the work back up' "$DIR/home/data/$id/brief.md" && echo 'delivered to the replacement' || echo 'not present')"
}

echo "=============================================================================="
echo " $LABEL"
echo " firstmate code root: $ROOT"
echo " commit:              $(git -C "$ROOT" rev-parse --short HEAD 2>/dev/null || echo "(tree extracted with git archive)")"
echo "=============================================================================="
echo
echo "A ship task parked on a no-mistakes approval. Its recorded herdr endpoint"
echo "fmlab:%7 was destroyed in churn; the fmlab server is still running and"
echo "answers pane_not_found for %7. Its worktree holds 1 commit + 1 uncommitted"
echo "file. Each attempt below starts from a fresh copy of exactly that state."

echo
echo "------------------------------------------------------------------------------"
echo " 1. Stop the agent, as the relaunch refusal tells the operator to"
echo "------------------------------------------------------------------------------"
new_stranded_case fmzeela
printf '\n$ bin/fm-control.sh fmzeela exit\n'
fm fm-control.sh fmzeela exit; printf '  -> exit %s\n' "$?"
aftermath fmzeela

echo
echo "------------------------------------------------------------------------------"
echo " 2. Relaunch directly, as the exit refusal leaves the operator to"
echo "------------------------------------------------------------------------------"
new_stranded_case fmzeelb
printf '\n$ bin/fm-spawn.sh fmzeelb --relaunch --harness claude\n'
fm fm-spawn.sh fmzeelb --relaunch --harness claude; printf '  -> exit %s\n' "$?"
aftermath fmzeelb

echo
echo "------------------------------------------------------------------------------"
echo " 3. The supported reclaim verb: control-plane relaunch with a progress note"
echo "------------------------------------------------------------------------------"
new_stranded_case fmzeelc
printf '\n$ bin/fm-control.sh fmzeelc relaunch --note "the pane was destroyed; pick the work back up"\n'
fm fm-control.sh fmzeelc relaunch --note 'the pane was destroyed; pick the work back up'
printf '  -> exit %s\n' "$?"
aftermath fmzeelc
echo
echo "  herdr calls the reclaim made (all scoped to the RECORDED session fmlab):"
sort -u "$DIR/fake/herdr-log" | grep -E '^(workspace|tab|pane send-text|agent get|pane get)' | sed 's/^/    /'
Evidence: Evidence index (names which transcripts are current for 8b2d669)

Source: Evidence index (names which transcripts are current for 8b2d6692)

# Evidence index

Current for **base `90cd351a` -> target `8b2d6692`**:

| file | what it shows |
|---|---|
| `before-base-90cd351a-deadlock.txt` | The deadlock reproduced on the base commit: `exit` and `relaunch` each name the other as its prerequisite. |
| `after-target-8b2d6692-reclaim.txt` | The same three operator commands on the fix: `exit` reports `endpoint-gone`, `relaunch` re-creates the endpoint in the recorded session, the task survives whole. |
| `reclaim-deadlock-demo.sh` | The driver behind both transcripts. Takes a firstmate code root, so the same scenario replays on either tree. |
| `reclaim-guardrails.txt` | The other half of the contract: a pane that outlived a stopped server is adopted (not duplicated), a returning agent refuses, and a tmux `missing` refuses both verbs with its reason. |
| `guardrails-demo.sh` | The driver behind `reclaim-guardrails.txt`. |
| `regression-fail-before-pass-after.txt` | Each reclaim test added by this change, run individually against both trees. |

Superseded (produced in an earlier round, against pre-rebase commits `b182d0f` / `57757fd`
that are no longer in this branch's history) - kept for the record, do not read the
commit ids as current:

- `reclaim-before-after.txt`
- `reclaim-demo.sh`

Pipeline

Updates from git push no-mistakes

... (7 earlier update rounds omitted to keep the PR body within GitHub's 65536-char limit; full history is in the run log.)

⚠️ **Review** - 2 infos

🔧 Fix: narrow endpoint reclaim to herdr; tmux refuses honestly
3 issues (2 warnings, 1 info) still open:

  • ⚠️ bin/fm-spawn.sh:2894 - The rebind refusal asserts a cross-session cause that its condition does not establish, misdirecting the operator on the exact recovery path this change exists to enable. HERDR_AMBIENT_SES=$(fm_backend_herdr_session) returns the literal string default when the process is in no herdr pane at all (bin/backends/herdr.sh:546, ${HERDR_SESSION:-default}), so the inequality is true for EVERY task recorded on a named session whenever the reclaim runs from a plain shell. Concrete case: a task recorded herdr_session=fmlab, reclaimed from an ssh/cron seat with no HERDR_* env, where fm_backend_herdr_container_ensure fails because workspace create returned an error (bin/backends/herdr.sh:1989). fm_backend_herdr_launcher_identity returned 2 there, not 1 (bin/backends/herdr.sh:1752) - cross-session launcher identity was never consulted - yet the operator is told "this seat is running in herdr session 'default', and a reclaim never moves a task to another session", implying they should re-run from a seat in fmlab, which neither describes what failed nor would fix it. The condition should additionally require that this process actually claims a launcher pane, i.e. [ -n &#34;$RELAUNCH_LAUNCHER_PANE_ID&#34; ] &amp;&amp; [ &#34;$HERDR_AMBIENT_SES&#34; != &#34;$HERDR_REBIND_SES&#34; ], falling through to the accurate "see the refusal above" branch otherwise. docs/agent-control.md:112 carries the same overstatement ("A seat that cannot prove it belongs to the recorded session is refused rather than allowed to place the endpoint somewhere else"): a seat with no herdr pane cannot prove membership and is NOT refused - it proceeds through the label search and places the tab in the recorded session - so that sentence should be corrected alongside the message.
  • ⚠️ docs/agent-control.md:119 - The documented known limitation states a failure mode the code contradicts, so it gives operators manual-cleanup guidance for a leak that self-heals. Line 119 claims "Retrying the reclaim proves the old pane absent again and mints another pane, leaving the previous one too, so the leak compounds one pane per attempt", and line 120 instructs "Close the stray panes by hand". On retry, fm_backend_herdr_create_task lists the workspace's tabs and finds the leaked tab, which carries the same fm-&lt;id&gt; label it was minted with (bin/fm-spawn.sh:2905 passes $W), then calls fm_backend_herdr_tab_is_husk (bin/backends/herdr.sh:2296). The stray pane holds a bare shell with no agent registration, so fm_backend_herdr_pane_agent_state returns no-agent (bin/backends/herdr.sh:2274), which IS a husk, and create_task closes and replaces it (bin/backends/herdr.sh:2475-2497). The retry therefore leaves exactly zero extra panes, not one more. The paragraph's stated trigger is also the least reachable one: the worktree-position check it names (bin/fm-spawn.sh:3423) runs against a tab that tab create --cwd &#34;$WT&#34; already opened in the recorded worktree. The honest limitation is narrower - a refusal AFTER the harness has started leaves a live pane that is not a husk, which makes the next create_task refuse outright with "herdr tab ... already exists" rather than compound. Correct the paragraph (and the fm-herdr-rebind-leak-20260913 bead's premise) to describe that, and drop the by-hand cleanup instruction for the shell-only case.
  • ℹ️ tests/fm-control-relaunch.test.sh:1815 - Three of the six new herdr cases inline the four-line setup that herdr_case_or_skip (line 1905) was added in the same change to encapsulate: test_herdr_reclaim_adopts_a_pane_that_outlived_its_server (1815-1823), test_herdr_exit_reports_already_stopped_when_the_pane_outlived_its_server (1854-1862), and test_herdr_rebind_stays_in_the_recorded_session (1875-1886) each repeat the jq guard, new_case, add_herdr_ship_task, and make_herdr_stub calls, while the other three use the helper. Routing all six through herdr_case_or_skip removes the duplication without changing any assertion, and keeps the skip message in one place.

🔧 Fix: stop refusals and docs asserting unestablished causes
1 warning still open:

  • ⚠️ tests/fm-control-relaunch.test.sh:1819 - herdr_case_or_skip communicates the case directory on stdout, so every one of its seven call sites invokes it as dir=$(herdr_case_or_skip ...) (lines 1830, 1866, 1888, 1911, 1933, 1987, 2005). That runs add_herdr_ship_task (line 1823) inside a command-substitution subshell, where its TASK_TMPS+=(&#34;/tmp/fm-$id&#34;) at line 1816 mutates a copy of the array and is discarded on subshell exit. The suite's EXIT trap (relaunch_cleanup, line 40) iterates TASK_TMPS precisely to remove the out-of-tmproot /tmp/fm-&lt;id&gt; roots that bin/fm-spawn.sh:3576 creates (mkdir -p &#34;$TASK_TMP/gotmp&#34;), so the three herdr cases that reach a real spawn - rl68 (adopt), rl73 (rebind), rl75 (full relaunch) - now leave /tmp/fm-rl68, /tmp/fm-rl73, and /tmp/fm-rl75 behind after the suite passes. The tmux cases are unaffected because add_ship_task (line 216) is still called as a plain statement. Fix by having the helper communicate through a global (e.g. set HERDR_CASE_DIR and return 0, called as a plain statement) or by registering the tmp root in the caller, so the array mutation happens in the test shell. Note the earlier round's finding asked for exactly this consolidation; the helper itself is right, only its subshell invocation shape defeats the cleanup trap.

🔧 Fix: stop herdr fixture helper losing tmp-root registration
2 infos still open:

  • ℹ️ bin/fm-spawn.sh:2886 - The rebind pins the herdr SESSION but not the WORKSPACE, so a reclaim run from a seat inside the recorded session silently relocates the task's container. HERDR_REBIND_SES is threaded into fm_backend_herdr_container_ensure specifically so the tab cannot land on another server, but the relationship stays launcher-home, so fm_backend_herdr_workspace_ensure (bin/backends/herdr.sh:1963-1972) short-circuits on fm_backend_herdr_launcher_identity returning 0 and uses FM_BACKEND_HERDR_LAUNCHER_WORKSPACE_ID — the reclaiming seat's own workspace — never the recorded herdr_workspace_id, even when that workspace still exists and only the pane was destroyed. Concretely: task recorded at fmlab:%7 with herdr_workspace_id=ws1; pane %7 destroyed, ws1 intact; firstmate reclaims from its own herdr pane in ws9 (same session fmlab); launcher_identity returns 0 with ws9, create_task opens fm-&lt;id&gt; there, and the record republishes herdr_workspace_id=ws9. The record stays self-consistent and no work is lost, so this is not a wrong result — but it is the path docs/agent-control.md:113 actively recommends ("reclaim such a task from a seat in the recorded session"), and that doc only promises the session is preserved, saying nothing about the workspace moving. Either pin the recorded workspace when it is still present, or state in that paragraph that the workspace follows the reclaiming seat. Flagging rather than fixing because the choice of launcher-home looks deliberate (it matches the ordinary spawn placement rule) and pinning the workspace would add new validation logic beyond this change's stated intent.
  • ℹ️ bin/backends/herdr.sh:2386 - The absence proof makes fm-control.sh &lt;id&gt; exit start a herdr daemon as a side effect, and for a session that no longer exists that daemon is left behind empty. fm_backend_herdr_endpoint_absence_recheck calls fm_backend_herdr_server_ensure &#34;$FM_BACKEND_HERDR_SESSION&#34;, which launches herdr server --session &lt;name&gt; when status --json reports running:false (bin/backends/herdr.sh:1656-1672). Trace: the recorded session fmlab and its server were destroyed outright (the "session restart" trigger named in the intent); an operator runs exit to see whether the agent stopped; server_ensure stands up a brand-new empty fmlab server, pane get %7 answers pane_not_found, the verdict is gone, and exit prints endpoint-gone. The verdict is correct — a destroyed session does mean a destroyed pane — but a fresh idle herdr server for every destroyed session name is now created by a command that reads as read-only, and unlike the relaunch path nothing ever uses it. docs/agent-control.md:99 does disclose that the recheck "starts that server", though its parenthetical "(only the server: nothing is created)" is about workspaces and tabs and does not cover the residue. Worth either a sentence in that paragraph or accepting it explicitly. Not auto-fixable: stopping a server the probe started would require tracking whether this process started it, which is new state beyond the change's intent.

🔧 Fix: document workspace drift and absence-probe server residue
1 warning still open:

  • ⚠️ docs/agent-control.md:121 - The "Known limitation" paragraph (lines 121-126) documents a failure state the code cannot reach, and gives operator advice that is harmful in the state it names. The replacement record is republished at bin/fm-spawn.sh:4153 (fm_backlog_atomic_transition publish inside the RELAUNCH -eq 1 block), and the harness launch is not delivered until bin/fm-spawn.sh:4336 (spawn_send_literal &#34;$T&#34; &#34;$LAUNCH&#34;); the only sends in between are shell export lines. So the combination the paragraph describes - a stray pane that reads live while "the record still names the old, gone one" - is unreachable: by the time any harness is running, the record already names the new pane. Concrete trace: task rl75 recorded at fmlab:%7, pane destroyed; reclaim mints fmlab:%9 at fm-spawn.sh:2912, publishes window=fmlab:%9 at 4153, launches claude at 4336, then agy/kimi/rovo readiness (or fm-control's wait_agent_state alive) refuses. Next attempt: fm_backend_validate_task_endpoint resolves fmlab:%9, fm_backend_agent_state reads alive, fm-spawn.sh:1418's case takes the * branch ("endpoint reads 'alive'"), and bin/fm-control.sh &lt;id&gt; relaunch succeeds normally by stopping that agent and adopting the pane - nothing is blocked and herdr's tab already exists is never reached, because the rebind gate is only entered on missing. Following line 126 ("Close that one pane before retrying") in that state kills a running replacement agent that the record correctly points at. Only line 124 is accurate: a refusal in the window between tab create (2912) and publication (4153) leaves a bare-shell pane, which fm_backend_herdr_create_task classifies as a husk and replaces on the next attempt - and even that self-heals only when the retry resolves the same workspace, which docs line 116 already says is not guaranteed (the container follows the reclaiming seat). Remedy is a correction, not new machinery: restate the limitation as "a refusal before the record is republished leaves a stray husk pane, which the next reclaim from the same workspace closes and replaces", and drop the unreachable live-pane case and its close-the-pane instruction.

🔧 Fix: correct rebind limitation to its one reachable case
3 issues (2 warnings, 1 info) still open:

  • ⚠️ docs/agent-control.md:109 - The "What a reclaim is not" bullet states that on a reclaim "The task id, its instructions, its armed poll and registration, and its status log are untouched", but the instructions ARE rewritten on every ship/scout reclaim. record_note (bin/fm-control.sh:827-847) copies data/&lt;id&gt;/brief.md to $BRIEF_PRIOR and appends a ## Progress note (&lt;ts&gt;) block plus the --note text to it before do_exit is ever called, and that happens on the reclaim path exactly as on an ordinary relaunch. This change's own test proves it: tests/fm-control-relaunch.test.sh asserts assert_contains &#34;$(cat &#34;$dir/home/data/rl75/brief.md&#34;)&#34; &#34;the pane was destroyed&#34; ("the replacement must inherit the progress note") in test_herdr_reclaim_keeps_the_task_whole. Concrete consequence: an operator reading line 109 before reclaiming a task with a stranded approval gate concludes the brief is byte-identical afterwards and does not re-read it, yet the brief now carries an appended note and, after a failed-then-retried reclaim, more than one. The bullet two lines above already acknowledges "the ordinary --note requirement still applies", so the fix is to drop its instructions from the untouched list (the note append is the ordinary relaunch contract, not something the reclaim adds).
  • ⚠️ bin/fm-control-lib.sh:265 - The deadlock the intent names remains fully in place for tmux, which is the DEFAULT backend for any task record without a backend= line (bin/fm-backend.sh: case &#34;$backend_count&#34; in 0) backend=tmux). For those tasks fm_control_endpoint_absence_verdict returns unproven unconditionally, so exit still dies (bin/fm-control.sh:513) and relaunch still dies (bin/fm-spawn.sh:1413) - the exact "each command names the other as its prerequisite" state the intent asks to break, with no reconcile verb added. The stated justification is also narrower than the rest of the control plane: the refusal argues "a window absent from it may still be alive on another" tmux server, but bin/backends/tmux.sh addresses every endpoint through the AMBIENT socket with no -S/TMUX_TMPDIR from the record (tmux send-keys -t &#34;$1&#34; at lines 50/113/121, tmux list-windows -t &#34;$session&#34; at line 266). The adjacent, unchanged tmux dead path already launches a brand-new agent into $RELAUNCH_TARGET over that same ambient socket on exactly the same assumption, so missing is being held to a stricter standard than the duplicate-agent risk it is defending against. Trace: task fm-zeel recorded window=fmses:fm-zeel with no backend= row; its window is destroyed; bin/fm-control.sh fm-zeel exit -> agent_state=missing -> tmux verdict unproven -> die; bin/fm-control.sh fm-zeel relaunch --note ... -> same -> die. Still stranded. Flagging rather than fixing because the remedy is a scope decision, not a correction: either accept the same ambient-socket assumption the dead path already makes, or add socket identity to the task record - the latter is new durable record state beyond this change's stated intent. Please confirm the tasks named in the intent's blast radius (fm-zeel, fm-sesh-sync-20260912, PR 4031's gate, firstmate-endpoint-binding-backfill) are all herdr-backed; if any are tmux, this change does not unblock them.
  • ℹ️ bin/fm-spawn.sh:2909 - The rebind branch (lines 2909-2921) re-implements the flat herdr container/task sequence that already exists at lines 3086-3098: the same ${RAW%%$&#39;\t&#39;*} / ${RAW#*$&#39;\t&#39;} split of fm_backend_herdr_container_ensure's output, the same HERDR_SES/HERDR_WORKSPACE_ID derivation, the same create_task call threading the seeded default tab id, the same read -r HERDR_TAB_ID HERDR_PANE_ID heredoc, and the same empty-id refusal with a byte-identical message. Only two things differ (the create_task cwd is $WT rather than $PROJ_ABS, and no FM_HOME shadow is needed because secondmate rebinds are refused upstream). The seeded-tab split is a contract that fm_backend_herdr_create_task is the sole permitted pruner of, so having two copies of it is the kind of thing that drifts silently. No defect today - both copies are currently correct. Noting only; a shared helper taking (cwd-for-workspace, create-task-cwd, session) would collapse them, but that is refactoring beyond this change's scope.

🔧 Fix: stop claiming reclaim leaves instructions untouched
2 infos still open:

  • ℹ️ bin/fm-spawn.sh:2874 - The KNOWN LIMITATION comment on the rebind branch says a refusal "leaves that pane behind and a retry mints another", implying the stray-pane leak accumulates per attempt. docs/agent-control.md:127-129 - the file this comment explicitly defers to - says the opposite: the next reclaim's tab create finds the same fm-&lt;id&gt; label, classifies it a husk, and closes and replaces it, so it self-heals whenever the retry resolves the same workspace. The doc is the accurate one: fm_backend_herdr_create_task (bin/backends/herdr.sh:2449-2459) collects same-labelled tabs, checks each via fm_backend_herdr_tab_is_husk, and a stray rebind pane holds a bare shell (the harness is not delivered until bin/fm-spawn.sh:4336, long after the tab is minted at 2913), so fm_backend_herdr_pane_agent_state returns no-agent and the tab is closed after the replacement exists. Consequence: whoever picks up bead fm-herdr-rebind-leak-20260913 from this comment sizes the leak as unbounded growth per failed attempt, when the only real residue is one pane per workspace a retry fails to re-resolve. Remedy is a comment correction only - restate it to match the doc (residue persists only across a workspace change), no code change.

  • ℹ️ bin/fm-control-lib.sh:249 - The tmux unproven rationale - in the header comment here and in the refusal string at line 266 ("a server-wide window inventory only describes the tmux server this process addresses"), mirrored at docs/agent-control.md:97 as "list-windows -a" - names a read the absence classifier does not perform. fm_backend_tmux_agent_state runs tmux list-windows -t &#34;$session&#34; (bin/backends/tmux.sh:266), a per-session inventory. The only -a reads in the tree are fm_backend_tmux_find_window (bin/backends/tmux.sh:35) and bin/fm-supervise-daemon.sh:1217, neither of which feeds this proof. The socket-scoping conclusion is unaffected, but the per-session form has an additional failure mode the "server-wide" framing obscures: a renamed session fails the read even on a server this process can reach. docs/agent-control.md:99 already lists "a renamed session" among the refused cases, so only the named command is wrong. This matters because this text is the stated justification for leaving tmux deadlocked and is the starting point for follow-up bead fm-es2ri. Remedy is a wording correction in the comment, the refusal string, and the doc sentence - name the per-session inventory the classifier actually reads; no behavior change.

  • ℹ️ bin/fm-control-lib.sh:270 - The tmux unproven rationale names a read the absence classifier never performs. The operator-facing refusal string here says "a server-wide window inventory only describes the tmux server this process addresses", the header comment at bin/fm-control-lib.sh:254 says "list-windows -a describes only the server the CURRENT process addresses", and docs/agent-control.md:101 repeats "list-windows -a". What actually produces the missing verdict is fm_backend_tmux_agent_state (bin/backends/tmux.sh:322) calling fm_backend_tmux_window_inventory (bin/backends/tmux.sh:146), which runs tmux list-windows -t &#34;$session&#34; at bin/backends/tmux.sh:148 - a PER-SESSION inventory. The only -a reads in the tree are fm_backend_tmux_find_window (bin/backends/tmux.sh:35) and bin/fm-supervise-daemon.sh:1217, neither of which feeds this proof. The socket-scoping conclusion still stands, but the "server-wide" framing hides a second failure mode the per-session read has: it also returns status 2 (can&#39;t find session:) for a renamed session on a server this process CAN reach - which this branch's own test test_tmux_refuses_a_session_that_cannot_be_found stages deliberately, and which docs/agent-control.md:104 already lists among the refused cases. Concrete consequence: this text is the stated justification for leaving tmux deadlocked and the starting point for follow-up bead fm-es2ri, so whoever picks that bead up goes looking for a socket-scoping fix to a server-wide read that is not the read being made. Remedy is wording in three places - the comment, the refusal string, and the doc sentence - naming the per-session inventory the classifier actually reads; no behavior change.

  • ℹ️ bin/fm-spawn.sh:3156 - The KNOWN LIMITATION comment on the rebind branch contradicts the document it explicitly defers to. It says the minted tab "is registered with no abort cleanup, so a later refusal leaves that pane behind and a retry mints another", which reads as residue accumulating once per failed attempt. docs/agent-control.md:127-129 says the opposite and is the accurate one: the next reclaim's tab create finds the same fm-&lt;id&gt; label, classifies it a husk, and closes and replaces it, so it self-heals whenever the retry resolves the same workspace. Verified against source: fm_backend_herdr_create_task (bin/backends/herdr.sh:2444) collects every same-labelled tab in the target workspace and tests each with fm_backend_herdr_tab_is_husk (bin/backends/herdr.sh:2296), which accepts dead and no-agent; a stray rebind pane holds a bare shell because the harness is not delivered until long after the tab is minted at bin/fm-spawn.sh:3197, so fm_backend_herdr_pane_agent_state returns no-agent and the husk is closed after the replacement tab exists. Concrete consequence: whoever picks up bead fm-herdr-rebind-leak-20260913 from this comment sizes the leak as unbounded per-attempt growth, when the only real residue is one pane per workspace a retry fails to re-resolve. Remedy is a comment correction restating it to match the doc (residue persists only across a workspace change); no code change.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-control-relaunch.test.sh - 64 assertions, exit 0 (includes the 11 new reclaim/refusal tests)
  • bash tests/fm-control.test.sh - 35 assertions, exit 0
  • bash tests/fm-backend-herdr.test.sh - 206 assertions, exit 0 (covers the changed fm_backend_herdr_container_ensure signature on the ordinary spawn path)
  • Manual CLI evidence: reclaim-demo.sh drives the real bin/fm-control.sh &lt;id&gt; exit and bin/fm-control.sh &lt;id&gt; relaunch --note ... against a hermetic herdr fixture (destroyed pane fmlab:%7, session server up), run once against a git archive export of base b182d0f and once against the worktree
  • Manual CLI evidence: guardrails-demo.sh runs three refusal/adoption transcripts on the fixed tree - stopped-server pane adoption, bin/fm-spawn.sh &lt;id&gt; --relaunch against a returned agent, and tmux missing on both verbs with a brief byte-identity check
  • Fail-before/pass-after matrix: each new test run individually from the same test file against both trees (head -2066 tests/fm-control-relaunch.test.sh + one test name)

✅ No issues found.

  • bash tests/fm-control-relaunch.test.sh - full file, 67 assertions pass, exit 0 (includes all 11 new reclaim tests)
  • bash tests/fm-control.test.sh - full file, 35 assertions pass, exit 0 (includes the rewritten test_missing_tmux_endpoint_refuses_rather_than_claiming_a_stop)
  • Operator transcript on the BASE tree (git archive 90cd351a into a temp root): bin/fm-control.sh &lt;id&gt; exit, bin/fm-spawn.sh &lt;id&gt; --relaunch --harness claude, bin/fm-control.sh &lt;id&gt; relaunch --note ... against a herdr task whose recorded pane fmlab:%7 answers pane_not_found on a running server - all three refuse, each naming the other as prerequisite
  • Same three commands on the TARGET tree, each against its own fresh copy of the stranded task - endpoint-gone (exit 0), rebind to fmlab:%9 (exit 0), and relaunched ... endpoint=fmlab:%9 (exit 0)
  • Post-reclaim record and worktree inspection: window=/herdr_session=/herdr_pane_id= rows, git rev-parse HEAD unchanged, branch still task-&lt;id&gt;, uncommitted file intact, status log intact, progress note present in brief.md
  • Herdr call log assertion that every call the reclaim made carries --session fmlab (the recorded session), never the ambient default
  • Guardrail transcripts on the target tree: stopped-server pane ADOPTED at fmlab:%7 with no second tab; returning agent refused with endpoint reads &#39;alive&#39;; tmux missing refused on both verbs with instructions restored byte-exact and nothing sent into any pane
  • Per-test fail-before/pass-after matrix: each of the 11 reclaim tests invoked individually from the target's test file against both trees - 10 FAIL on base / pass on target, 1 passes on both
🔧 **Document** - 1 issue found ✅
  • ℹ️ docs/tmux-backend.md:53 - Terminology overlap worth a follow-up, not fixed here. docs/tmux-backend.md:53 states "Only dead and missing authorize recovery because a false dead result could launch a duplicate agent." That sentence is about which liveness verdicts recovery paths may act on at all, and it remains true of the session-start secondmate liveness sweep (bin/fm-bootstrap.sh relaunches from dead or missing). But this change added the opposite-sounding statement for the control plane in the new owner text - docs/agent-control.md:82 and :155, "On tmux, both verbs refuse a missing endpoint" - so a reader who lands on tmux-backend.md first can conclude that bin/fm-control.sh &lt;id&gt; exit|relaunch will act on a tmux missing endpoint, which it never does. tmux behavior itself is unchanged by this branch, so I left the sentence alone rather than rewriting another doc's ownership claim; the minimal follow-up is one clause there distinguishing the sweep from the control plane, or a pointer to docs/agent-control.md "Reclaiming a task whose endpoint is gone".

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

✅ No issues found.

RooseveltAdvisors and others added 12 commits September 20, 2026 00:37
A destroyed pane or workspace made `missing` a terminal state. Relaunch
accepted only `dead` and said to stop the agent first; exit refused
`missing` and said to reconcile the task first; there is no reconcile
verb. Each command named the other as its prerequisite, so a task whose
terminal went away could not be reclaimed by anything, and a no-mistakes
approval it was parked on had no seat left to answer it.

`missing` is agent-free a fortiori: there is no endpoint, so there is no
agent in it. Widen the existing guards rather than add a verb.

- fm-spawn --relaunch accepts a positively proven `missing` and creates
  one fresh endpoint in the recorded worktree; the record it already
  republishes rebinds the task to it. A `dead` endpoint is still adopted
  in place.
- fm-control exit reports `endpoint-gone` instead of dying, so the
  relaunch transaction's stop step no longer dead-ends, and re-resolves
  the endpoint from the record before verifying the replacement.

The duplicate-agent refusal is untouched: both verdicts come from the
same recovery-grade classifier, which claims `missing` only from positive
absence, so `alive`, `ambiguous`, and `unreadable` all still refuse. The
backends' own create paths refuse a live same-labeled endpoint as a
second independent guard. The worktree, its branch, commits, uncommitted
changes, armed poll and registration, record rows, and status log are all
untouched - a reclaim is a recovery, never a teardown.

A secondmate is excluded: its gone-endpoint recovery already has one
owner in the session-start liveness sweep, so relaunch refuses and names
it rather than becoming a second path to the same outcome.

Tests reproduce both halves of the deadlock, the reclaim succeeding,
unlanded work surviving it, and the refusals that still hold.
Rebasing onto main picked up kunchenguid#4994, which stages a long worker launch
command into a script and delivers the short `. '<path>'` line instead of
the literal command. The tmux fake and tests/fixtures.sh were updated for
that; the herdr fake this branch adds was written before it and still
keyed "an agent now exists on this pane" off the literal
`encode launch-brief` text, so after the rebase it never marked the
rebound pane live and the reclaim's alive-wait read `dead`.

Dereference the staged file first, exactly as the tmux fake above does.
Test-fixture only; no production path changes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@RooseveltAdvisors
RooseveltAdvisors force-pushed the fm/fm-endpoint-missing-reclaim-20260913 branch from 0eb3aed to 8894ab4 Compare September 20, 2026 04:58
@RooseveltAdvisors RooseveltAdvisors changed the title fix(bin): let relaunch reclaim a task whose herdr endpoint was destroyed fix(bin): reclaim a task whose herdr endpoint was destroyed Sep 20, 2026
@kunchenguid
kunchenguid merged commit 1b1b3cd into kunchenguid:main Sep 20, 2026
19 of 20 checks passed
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: this is merged. Thank you @RooseveltAdvisors — really appreciate you taking the time on this.

First look on HEAD 8894ab403e9380f82e2acd34234743a5cc757c09 vs prior main 90cd351… (merge landed after #4974). Attestation MATCH. CI/NM all SUCCESS; MERGEABLE/CLEAN. No Closes/Fixes in author body (structural reclaim fix).

Contract-class: restore. Main tip's fm-control.sh exit on missing died saying reconcile, while fm-spawn.sh --relaunch required dead exactly — a circular deadlock for a classifier state the product already emits. Tip restores relaunchability when Herdr proves the endpoint gone (fm_control_endpoint_absence_verdict); tmux/secondmate still refuse. Not a new always-on surface.

VISION.md (each rule)

  • One captain, one interface: aligns — stranded parked gates become reclaimable without captain tab-juggling.
  • Authority is explicit and never inferred: aligns — absence proven per backend; no inferred destroy.
  • Scripts own the mechanics, agents own the judgment: aligns.
  • A restart is a non-event: aligns — worktree/task identity survive; only endpoint rebinds.
  • Delegation with a spine: aligns — unlanded work never torn down.
  • The fleet outlives any vendor: aligns — Herdr-only proof; tmux stays refused with reason.
  • Scope: aligns — control/spawn command layer.

Auto-merged (restore + MATCH + green CI/NM + safe). Squash 1b1b3cd4c3130303803cf1c93a5f7127e0245bb7.

Ivory2024 pushed a commit to Ivory2024/firstmate that referenced this pull request Sep 20, 2026
…uid#5007)

* fix(control): let the owning seat reclaim a task whose endpoint is gone

A destroyed pane or workspace made `missing` a terminal state. Relaunch
accepted only `dead` and said to stop the agent first; exit refused
`missing` and said to reconcile the task first; there is no reconcile
verb. Each command named the other as its prerequisite, so a task whose
terminal went away could not be reclaimed by anything, and a no-mistakes
approval it was parked on had no seat left to answer it.

`missing` is agent-free a fortiori: there is no endpoint, so there is no
agent in it. Widen the existing guards rather than add a verb.

- fm-spawn --relaunch accepts a positively proven `missing` and creates
  one fresh endpoint in the recorded worktree; the record it already
  republishes rebinds the task to it. A `dead` endpoint is still adopted
  in place.
- fm-control exit reports `endpoint-gone` instead of dying, so the
  relaunch transaction's stop step no longer dead-ends, and re-resolves
  the endpoint from the record before verifying the replacement.

The duplicate-agent refusal is untouched: both verdicts come from the
same recovery-grade classifier, which claims `missing` only from positive
absence, so `alive`, `ambiguous`, and `unreadable` all still refuse. The
backends' own create paths refuse a live same-labeled endpoint as a
second independent guard. The worktree, its branch, commits, uncommitted
changes, armed poll and registration, record rows, and status log are all
untouched - a reclaim is a recovery, never a teardown.

A secondmate is excluded: its gone-endpoint recovery already has one
owner in the session-start liveness sweep, so relaunch refuses and names
it rather than becoming a second path to the same outcome.

Tests reproduce both halves of the deadlock, the reclaim succeeding,
unlanded work surviving it, and the refusals that still hold.

* no-mistakes(review): prove endpoint absence per backend before reclaim rebinds

* no-mistakes(review): give exit and relaunch one absence proof; pin herdr rebind session

* no-mistakes(review): narrow endpoint reclaim to herdr; tmux refuses honestly

* no-mistakes(review): stop refusals and docs asserting unestablished causes

* no-mistakes(review): stop herdr fixture helper losing tmp-root registration

* no-mistakes(review): document workspace drift and absence-probe server residue

* no-mistakes(review): correct rebind limitation to its one reachable case

* no-mistakes(review): stop claiming reclaim leaves instructions untouched

* no-mistakes(document): scope fm-control-lib purity claim, note reclaim coverage

* no-mistakes(rebase): read the staged launch file in the herdr fixture

Rebasing onto main picked up kunchenguid#4994, which stages a long worker launch
command into a script and delivers the short `. '<path>'` line instead of
the literal command. The tmux fake and tests/fixtures.sh were updated for
that; the herdr fake this branch adds was written before it and still
keyed "an agent now exists on this pane" off the literal
`encode launch-brief` text, so after the rebase it never marked the
rebound pane live and the reclaim's alive-wait read `dead`.

Dereference the staged file first, exactly as the tmux fake above does.
Test-fixture only; no production path changes.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>

* no-mistakes(document): note reclaim placement in herdr and scripts inventories

---------

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
Ivory2024 added a commit to Ivory2024/firstmate that referenced this pull request Sep 20, 2026
* fix(bin): preserve Claude lock ownership after helper recycling (kunchenguid#4894)

* fix(bin): let a background Claude session keep owning its session lock

Session-lock ownership was decided by process ancestry alone. Under an
unattended Claude session the model loop runs in a transient bg-spare
bridged to the front-end by a shared daemon; when that bridge is
recycled the contiguous claude-named ancestry from a hook to the
recorded owner breaks while the owner pid stays alive, so the Stop
auto-arm stood down as a foreign live owner, the turn-end guard ended
every turn with its read-only diagnostic, and fm-lock.sh refused - a
self-sustaining outage until res