Skip to content

fix: adopt a verified Herdr pool lease before relaunch stops the agent - #64

Merged
peterOC26 merged 2 commits into
mainfrom
fm/fm-relaunch-herdr-lease-refusal-r1
Nov 14, 2026
Merged

peterOC26 merged 2 commits into
mainfrom
fm/fm-relaunch-herdr-lease-refusal-r1

Conversation

@peterOC26

Copy link
Copy Markdown
Owner

Intent

Found 2026-11-09 on pv-cash-toggle-payments-u1: fm-control relaunch refused with "recorded copy has no verifiable pool reservation; reconcile its ownership before relaunch" (bin/fm-treehouse-slot-lib.sh spawn_treehouse_reservation_preflight). The Herdr spawn path had taken the pool lease with treehouse get --lease --lease-holder (pool entry leased=true, lease_holder=task id, lease_id set) but wrote no treehouse_lease_id/treehouse_lease_holder into state/.meta. The relaunch preflight only accepts a meta with those fields or a fully unleased legacy entry, so it refuses the Herdr-native lease that fm_treehouse_task_holds_pool_lease already recognises. The first relaunch attempt stopped the Codex agent before refusing, leaving no agent running. Workaround used: append the verified pool lease_id and holder to the meta, then relaunch. Fix idea: in the relaunch preflight, accept fm_treehouse_task_holds_pool_lease and adopt its lease_id, or have the Herdr spawn record treehouse_lease_* in the meta; and run the preflight before stopping the old agent. PR 53 (fm-main-ci-red-fix-m1) restored durable leases for new spawns, so copies spawned before it still lack treehouse_lease_* and the preflight still stops the agent before refusing.
q2102 a

What Changed

  • fm-control relaunch now runs the Treehouse reservation check (spawn_treehouse_reservation_preflight) after the checkpoint and before it copies the task record, writes the journal or note, or stops the old agent. If the check refuses, the agent keeps running and the task record is unchanged.
  • The relaunch check now accepts a task record that has no treehouse_lease_* fields when the pool entry for the recorded copy is leased by this task and its lease id and holder can be read. This is the lease that Herdr-native spawns created. After the exclusivity check passes, the check writes that treehouse_lease_id/treehouse_lease_holder into the task record. It writes a temp copy and renames it into place, using the new fm_treehouse_record_adopt_pool_lease. Every other reservation it can't verify is still refused, and it also refuses if the lease can't be recorded.
  • Updated docs/agent-control.md (adds a new "Verify the pool reservation" relaunch step and the test coverage) and the ownership-contract comments in bin/fm-wake-lib.sh and bin/fm-control.sh. Added cases to tests/fm-control-relaunch.test.sh for a refusal that happens before the agent stops and for adopting a Herdr-native lease.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change is narrow and matches the intent. fm-control now runs the same reservation preflight that fm-spawn uses, and it runs it before anything durable is written or the agent stops. A Herdr-native lease is adopted only after verifying the holder, the slot claim and that no other record names the copy. The adopted fields go through preserve_relaunch_meta and are re-verified by fm-spawn under the project lock. Behavioral tests cover the refusal and adoption paths.

Testing

I drove three live scenarios on a disposable Herdr 0.9.0 lab session with a real Treehouse 2.3.0 pool and a real Claude worker started by fm-spawn. In each one I removed the lease fields from the task record to recreate a copy spawned before PR 53. First, with the pool lease held by the task id, fm-control relaunch exited 0: the record gained the lease id and holder from the pool, the pool entry was unchanged, and a new Claude came up idle in the same pane. Second, with the lease held by a different holder, relaunch refused and left Claude running idle, the record byte-identical, and no relaunch checkpoint. Third, the same adoption setup on the base commit reproduced the incident: Claude was stopped, the relaunch refused, and no agent was left running. My first adoption attempt failed only because I relaunched about 1s after Claude started, before its state could be read; after adding a wait for idle, the rerun passed. The targeted tests/fm-control-relaunch.test.sh suite passed, including the two new tests. All lab sessions, pools and temp homes were torn down, and the worktree is clean.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Relaunching a pre-PR53 Herdr task whose record has no lease fields, while the pool entry is leased to the task id, adopts the lease and starts a new Claude ✅ pass live live-adopt.log: fm-control exit=0, 'relaunched lease-adopt ... backend=herdr', meta now has treehouse_lease_id equal to the pool lease_id and treehouse_lease_holder=lease-adopt, pool entry unchanged,…
Adversarial: relaunch of a record with no lease fields, where the pool lease belongs to another holder, refuses while the agent keeps running and the record stays unchanged ✅ pass live live-foreign-holder-refuses.log: REFUSED ... no verifiable pool reservation; exit=1; claude still idle on the same pane; meta byte-identical; no control-relaunch checkpoint; pool entry unchanged
Regression contrast: the base commit stops the agent and then refuses in the incident shape (the reported bug) ✅ pass live live-base-commit-adopt-repro.log: REFUSED, then 'agent was stopped but the replacement did not launch; no agent is running'
Targeted fm-control relaunch suite, including the new refusal-shape and adoption/legacy tests ✅ pass live fm-control-relaunch.test.log: 'ok - ... an unverified pool reservation refuses before the agent stops' and 'ok - ... a verified Herdr-native pool lease is adopted and an unleased legacy copy stays unl…
Evidence: Live driver script (Herdr lab + real treehouse + fm-spawn + fm-control relaunch)

Source: Live driver script (Herdr lab + real treehouse + fm-spawn + fm-control relaunch)

#!/usr/bin/env bash
# Live driver: real Herdr lab session + real Treehouse pool + real fm-spawn and
# fm-control relaunch with the real claude CLI, all in disposable state.
# Usage: live-relaunch-herdr-lease.sh <repo-root> <case: adopt|foreign>
set -u
ROOT=$1 CASE=$2
ID="lease-$CASE"
. "$ROOT/tests/fixtures.sh"
HELPER="$ROOT/bin/fm-herdr-lab.sh"
SESSION=$("$HELPER" name "relaunch-$CASE")
export HERDR_LAB_HELPER=$HELPER HERDR_LAB_SESSION=$SESSION ORIGINAL_PATH=$PATH
TMP=$(mktemp -d /tmp/fm-relaunch-lease.XXXXXX)
LAB="$TMP/home"
log() { printf '[%s] %s\n' "$(date +%H:%M:%S)" "$*"; }
cleanup() {
  local st=$?
  log "teardown"
  "$HELPER" teardown "$SESSION" || st=1
  (cd "$TMP/project" 2>/dev/null && TREEHOUSE_ROOT="$TMP/pool" treehouse destroy --help >/dev/null 2>&1) || true
  find "$TMP" -type d -exec chmod u+rwx {} + 2>/dev/null
  rm -rf "$TMP"
  exit "$st"
}
trap cleanup EXIT
"$HELPER" provision "$SESSION" >/dev/null || { echo "provision failed"; exit 1; }
mkdir -p "$TMP/fakebin"
cat > "$TMP/fakebin/herdr" <<'EOF'
#!/usr/bin/env bash
set -eu
args=("$@")
if [ "${1:-}" = --version ]; then
  PATH="$ORIGINAL_PATH" "$HERDR_LAB_HELPER" run "$HERDR_LAB_SESSION" status --json | jq -r '"herdr " + .client.version'
  exit
fi
n=${#args[@]}
[ "$n" -lt 2 ] || {
  [ "${args[n-2]}" != --session ] || {
    [ "${args[n-1]}" = "$HERDR_LAB_SESSION" ] || exit 1
    unset 'args[n-1]' 'args[n-2]'
  }
}
exec env PATH="$ORIGINAL_PATH" "$HERDR_LAB_HELPER" run "$HERDR_LAB_SESSION" "${args[@]}"
EOF
chmod +x "$TMP/fakebin/herdr"
lab() { "$HELPER" run "$SESSION" "$@"; }
HERDR_SOCKET_PATH=$(lab session list --json | jq -er --arg s "$SESSION" '.sessions[] | select(.name == $s) | .socket_path')
export HERDR_SOCKET_PATH

# Disposable project with a bare origin; disposable Treehouse pool root.
git init -q --bare "$TMP/origin.git"
fm_git_init_commit "$TMP/project"
git -C "$TMP/project" remote add origin "$TMP/origin.git"
git -C "$TMP/project" push -q origin HEAD:main
git -C "$TMP/origin.git" symbolic-ref HEAD refs/heads/main
git -C "$TMP/project" fetch -q origin
git -C "$TMP/project" remote set-head origin main >/dev/null
export TREEHOUSE_ROOT="$TMP/pool"

"$ROOT/bin/fm-lab-home.sh" create "$LAB" >/dev/null
fm_test_spawn_home "$LAB" claude
fm_test_spawn_brief "$LAB" "$ID" 'Idle worker used to exercise relaunch lease adoption.'
PARENT=$(lab workspace create --cwd "$TMP/project" --label firstmate --focus)
export HERDR_PANE_ID=$(printf '%s' "$PARENT" | jq -er '.result.root_pane.pane_id')

FMENV=(env -u FM_ROOT_OVERRIDE -u FM_STATE_OVERRIDE -u FM_DATA_OVERRIDE -u FM_CONFIG_OVERRIDE -u FM_PROJECTS_OVERRIDE
  PATH="$TMP/fakebin:$ORIGINAL_PATH" FM_HOME="$LAB" FM_SPAWN_NO_GUARD=1 HERDR_SESSION="$SESSION" TREEHOUSE_ROOT="$TMP/pool")

log "== real fm-spawn (herdr backend, claude, real treehouse lease) =="
"${FMENV[@]}" bash "$ROOT/bin/fm-spawn.sh" "$ID" "$TMP/project" --harness claude --backend herdr --mode local-only --yolo off 2>&1 | tail -5
META="$LAB/state/$ID.meta"
[ -f "$META" ] || { echo "spawn produced no meta"; exit 1; }
WT=$(sed -n 's/^worktree=//p' "$META" | head -1)
PANE=$(sed -n 's/^herdr_pane_id=//p' "$META")
STATE_JSON="$(dirname "$(dirname "$WT")")/treehouse-state.json"
log "worktree=$WT pane=$PANE"
log "meta lease fields after spawn:"; grep '^treehouse_lease_' "$META"
log "pool entry after spawn:"; jq -c --arg p "$WT" '.worktrees[] | select(.path==$p) | {leased,lease_id,lease_holder}' "$STATE_JSON"

agent_status() { lab agent get "$PANE" 2>/dev/null | jq -r '.result.agent.agent // "none"'; }
for _ in $(seq 1 60); do [ "$(agent_status)" = claude ] && break; sleep 1; done
agent_state() { lab agent get "$PANE" 2>/dev/null | jq -r '.result.agent.agent_status // "none"'; }
for _ in $(seq 1 120); do [ "$(agent_state)" = idle ] && break; sleep 1; done
sleep 3
log "agent on pane before relaunch: $(agent_status) state=$(agent_state)"
log "fm-ps classification: $("${FMENV[@]}" bash -c '. "$1/bin/fm-control-lib.sh" 2>/dev/null; true' _ "$ROOT")"

log "== simulate a pre-PR53 Herdr record: strip treehouse_lease_* from the meta =="
grep -v '^treehouse_lease_' "$META" > "$META.x" && mv "$META.x" "$META"
if [ "$CASE" = adopt ]; then
  log "== pre-PR53 Herdr-native shape: pool lease (real lease_id) held by the task id =="
  jq --arg p "$WT" --arg id "$ID" '.worktrees |= map(if .path == $p then .lease_holder = $id else . end)' "$STATE_JSON" > "$STATE_JSON.x" && mv "$STATE_JSON.x" "$STATE_JSON"
fi
cp "$META" "$TMP/meta-before"
log "pool entry before relaunch:"; jq -c --arg p "$WT" '.worktrees[] | select(.path==$p) | {leased,lease_id,lease_holder}' "$STATE_JSON"

log "== real fm-control relaunch =="
"${FMENV[@]}" bash "$ROOT/bin/fm-control.sh" "$ID" relaunch --note "live lease check $CASE" 2>&1 | tail -8
rc=${PIPESTATUS[0]}
log "fm-control exit=$rc"
sleep 3
NEWPANE=$(sed -n 's/^herdr_pane_id=//p' "$META")
PANE=$NEWPANE
for _ in $(seq 1 30); do [ "$(agent_status)" = claude ] && break; sleep 1; done
for _ in $(seq 1 60); do [ "$(agent_state)" = idle ] && break; sleep 1; done
log "agent on pane after relaunch: $(agent_status) state=$(agent_state) (pane $PANE)"
log "meta lease fields after relaunch:"; grep '^treehouse_lease_' "$META" || echo "(none)"
log "meta unchanged vs before: $(cmp -s "$TMP/meta-before" "$META" && echo yes || echo no)"
log "relaunch checkpoint present: $( [ -e "$LAB/state/$ID.control-relaunch" ] && echo yes || echo no)"
log "pool entry after relaunch:"; jq -c --arg p "$WT" '.worktrees[] | select(.path==$p) | {leased,lease_id,lease_holder}' "$STATE_JSON"
log "pool entries total: $(jq '.worktrees|length' "$STATE_JSON")"
# stop the agent and release the pool copy so teardown leaves nothing
"${FMENV[@]}" bash "$ROOT/bin/fm-control.sh" "$ID" exit >/dev/null 2>&1 || true
Evidence: Live: Herdr-native pool lease adopted, relaunch succeeds

Source: Live: Herdr-native pool lease adopted, relaunch succeeds

pool entry before relaunch: {"leased":true,"lease_id":"569e2642...","lease_holder":"lease-adopt"} relaunched lease-adopt harness=claude ... backend=herdr fm-control exit=0 agent on pane after relaunch: claude state=idle meta: treehouse_lease_id=569e264219ebb594847822774a48ac0b treehouse_lease_holder=lease-adopt

[20:36:53] == real fm-spawn (herdr backend, claude, real treehouse lease) ==
Run "treehouse update" to update

🌳 Setting up worktree...
🌳 Leased worktree at /tmp/fm-relaunch-lease.Kw8XGv/pool/.treehouse/project-66a619/1/project. Run 'treehouse return /tmp/fm-relaunch-lease.Kw8XGv/pool/.treehouse/project-66a619/1/project' to release it.
spawned lease-adopt harness=claude kind=ship mode=local-only yolo=off window=fm-lab-relaunch-adopt-3696798-11797:w2:p2 worktree=/tmp/fm-relaunch-lease.Kw8XGv/pool/.treehouse/project-66a619/1/project
[20:36:57] worktree=/tmp/fm-relaunch-lease.Kw8XGv/pool/.treehouse/project-66a619/1/project pane=w2:p2
[20:36:57] meta lease fields after spawn:
treehouse_lease_id=569e264219ebb594847822774a48ac0b
treehouse_lease_holder=/tmp/fm-relaunch-lease.Kw8XGv/home/lease-adopt/a1794685014.3696949.15814
[20:36:57] pool entry after spawn:
{"leased":true,"lease_id":"569e264219ebb594847822774a48ac0b","lease_holder":"/tmp/fm-relaunch-lease.Kw8XGv/home/lease-adopt/a1794685014.3696949.15814"}
[20:37:08] agent on pane before relaunch: claude state=idle
[20:37:08] fm-ps classification: 
[20:37:08] == simulate a pre-PR53 Herdr record: strip treehouse_lease_* from the meta ==
[20:37:08] == pre-PR53 Herdr-native shape: pool lease (real lease_id) held by the task id ==
[20:37:08] pool entry before relaunch:
{"leased":true,"lease_id":"569e264219ebb594847822774a48ac0b","lease_holder":"lease-adopt"}
[20:37:08] == real fm-control relaunch ==
warning: /tmp/fm-relaunch-lease.Kw8XGv/home/data/lease-adopt/launch-brief.md records no ship branch; defaulting to legacy branch fm/lease-adopt
warning: /tmp/fm-relaunch-lease.Kw8XGv/home/data/lease-adopt/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode local-only - confirm its definition of done matches
notice: lease-adopt ships mode=local-only while the standing posture for project is no-mistakes - less rigor than the captain's standing posture; proceed only on a current explicit captain instruction or an intake judgment you can state
relaunched lease-adopt harness=claude from=claude model=default effort=default backend=herdr endpoint=fm-lab-relaunch-adopt-3696798-11797:w2:p2 worktree=/tmp/fm-relaunch-lease.Kw8XGv/pool/.treehouse/project-66a619/1/project
[20:37:20] fm-control exit=0
[20:37:26] agent on pane after relaunch: claude state=idle (pane w2:p2)
[20:37:26] meta lease fields after relaunch:
treehouse_lease_id=569e264219ebb594847822774a48ac0b
treehouse_lease_holder=lease-adopt
[20:37:26] meta unchanged vs before: no
[20:37:26] relaunch checkpoint present: yes
[20:37:26] pool entry after relaunch:
{"leased":true,"lease_id":"569e264219ebb594847822774a48ac0b","lease_holder":"lease-adopt"}
[20:37:26] pool entries total: 1
[20:37:30] teardown
Evidence: Live adversarial: lease held by another holder refuses before stopping the agent

Source: Live adversarial: lease held by another holder refuses before stopping the agent

REFUSED: task lease-foreign's recorded copy has no verifiable pool reservation; reconcile its ownership before relaunch fm-control exit=1 agent on pane after relaunch: claude state=idle meta unchanged vs before: yes relaunch checkpoint present: no

[20:37:40] == real fm-spawn (herdr backend, claude, real treehouse lease) ==
Run "treehouse update" to update

🌳 Setting up worktree...
🌳 Leased worktree at /tmp/fm-relaunch-lease.HtlmOB/pool/.treehouse/project-def1db/1/project. Run 'treehouse return /tmp/fm-relaunch-lease.HtlmOB/pool/.treehouse/project-def1db/1/project' to release it.
spawned lease-foreign harness=claude kind=ship mode=local-only yolo=off window=fm-lab-relaunch-foreign-3707091-1441:w2:p2 worktree=/tmp/fm-relaunch-lease.HtlmOB/pool/.treehouse/project-def1db/1/project
[20:37:45] worktree=/tmp/fm-relaunch-lease.HtlmOB/pool/.treehouse/project-def1db/1/project pane=w2:p2
[20:37:45] meta lease fields after spawn:
treehouse_lease_id=84741ccc487b95d40ac6ff19d5ff0fe0
treehouse_lease_holder=/tmp/fm-relaunch-lease.HtlmOB/home/lease-foreign/a1794685062.3707245.19448
[20:37:45] pool entry after spawn:
{"leased":true,"lease_id":"84741ccc487b95d40ac6ff19d5ff0fe0","lease_holder":"/tmp/fm-relaunch-lease.HtlmOB/home/lease-foreign/a1794685062.3707245.19448"}
[20:37:57] agent on pane before relaunch: claude state=idle
[20:37:57] fm-ps classification: 
[20:37:57] == simulate a pre-PR53 Herdr record: strip treehouse_lease_* from the meta ==
[20:37:57] pool entry before relaunch:
{"leased":true,"lease_id":"84741ccc487b95d40ac6ff19d5ff0fe0","lease_holder":"/tmp/fm-relaunch-lease.HtlmOB/home/lease-foreign/a1794685062.3707245.19448"}
[20:37:57] == real fm-control relaunch ==
REFUSED: task lease-foreign's recorded copy has no verifiable pool reservation; reconcile its ownership before relaunch
[20:37:57] fm-control exit=1
[20:38:01] agent on pane after relaunch: claude state=idle (pane w2:p2)
[20:38:01] meta lease fields after relaunch:
(none)
[20:38:01] meta unchanged vs before: yes
[20:38:01] relaunch checkpoint present: no
[20:38:01] pool entry after relaunch:
{"leased":true,"lease_id":"84741ccc487b95d40ac6ff19d5ff0fe0","lease_holder":"/tmp/fm-relaunch-lease.HtlmOB/home/lease-foreign/a1794685062.3707245.19448"}
[20:38:01] pool entries total: 1
[20:38:04] teardown
Evidence: Live base-commit reproduction of the incident (agent stopped, then refused)

Source: Live base-commit reproduction of the incident (agent stopped, then refused)

REFUSED: task lease-adopt's recorded copy has no verifiable pool reservation; reconcile its ownership before relaunch error: lease-adopt's agent was stopped but the replacement did not launch; no agent is running

[20:38:05] == real fm-spawn (herdr backend, claude, real treehouse lease) ==
Run "treehouse update" to update

🌳 Setting up worktree...
🌳 Leased worktree at /tmp/fm-relaunch-lease.N57lwL/pool/.treehouse/project-9ad5e2/1/project. Run 'treehouse return /tmp/fm-relaunch-lease.N57lwL/pool/.treehouse/project-9ad5e2/1/project' to release it.
spawned lease-adopt harness=claude kind=ship mode=local-only yolo=off window=fm-lab-relaunch-adopt-3716108-23637:w2:p2 worktree=/tmp/fm-relaunch-lease.N57lwL/pool/.treehouse/project-9ad5e2/1/project
[20:38:10] worktree=/tmp/fm-relaunch-lease.N57lwL/pool/.treehouse/project-9ad5e2/1/project pane=w2:p2
[20:38:10] meta lease fields after spawn:
treehouse_lease_id=5cbd757b24f10b55be59ac43edd0d285
treehouse_lease_holder=/tmp/fm-relaunch-lease.N57lwL/home/lease-adopt/a1794685087.3716247.19707
[20:38:10] pool entry after spawn:
{"leased":true,"lease_id":"5cbd757b24f10b55be59ac43edd0d285","lease_holder":"/tmp/fm-relaunch-lease.N57lwL/home/lease-adopt/a1794685087.3716247.19707"}
[20:38:23] agent on pane before relaunch: claude state=idle
[20:38:23] fm-ps classification: 
[20:38:23] == simulate a pre-PR53 Herdr record: strip treehouse_lease_* from the meta ==
[20:38:23] == pre-PR53 Herdr-native shape: pool lease (real lease_id) held by the task id ==
[20:38:23] pool entry before relaunch:
{"leased":true,"lease_id":"5cbd757b24f10b55be59ac43edd0d285","lease_holder":"lease-adopt"}
[20:38:23] == real fm-control relaunch ==
REFUSED: task lease-adopt's recorded copy has no verifiable pool reservation; reconcile its ownership before relaunch
error: the replacement agent for lease-adopt could not be launched on claude
error: lease-adopt's agent was stopped but the replacement did not launch; no agent is running, and its work plus the recorded progress note are preserved at /tmp/fm-relaunch-lease.N57lwL/pool/.treehouse/project-9ad5e2/1/project
[20:38:27] fm-control exit=1
[20:40:02] agent on pane after relaunch:  state= (pane w2:p2)
[20:40:02] meta lease fields after relaunch:
(none)
[20:40:02] meta unchanged vs before: no
[20:40:02] relaunch checkpoint present: yes
[20:40:02] pool entry after relaunch:
{"leased":true,"lease_id":"5cbd757b24f10b55be59ac43edd0d285","lease_holder":"lease-adopt"}
[20:40:02] pool entries total: 1
[20:40:03] teardown
Evidence: First adoption attempt: relaunched before Claude's state was readable (setup timing)

Source: First adoption attempt: relaunched before Claude's state was readable (setup timing)

[20:36:29] == real fm-spawn (herdr backend, claude, real treehouse lease) ==
Run "treehouse update" to update

🌳 Setting up worktree...
🌳 Leased worktree at /tmp/fm-relaunch-lease.ajHzDH/pool/.treehouse/project-0c8c0f/1/project. Run 'treehouse return /tmp/fm-relaunch-lease.ajHzDH/pool/.treehouse/project-0c8c0f/1/project' to release it.
spawned lease-adopt harness=claude kind=ship mode=local-only yolo=off window=fm-lab-relaunch-adopt-3690923-5404:w2:p2 worktree=/tmp/fm-relaunch-lease.ajHzDH/pool/.treehouse/project-0c8c0f/1/project
[20:36:33] worktree=/tmp/fm-relaunch-lease.ajHzDH/pool/.treehouse/project-0c8c0f/1/project pane=w2:p2
[20:36:33] meta lease fields after spawn:
treehouse_lease_id=bf4994d809c1556719f53cfe8fd6138a
treehouse_lease_holder=/tmp/fm-relaunch-lease.ajHzDH/home/lease-adopt/a1794684991.3691159.17196
[20:36:33] pool entry after spawn:
{"leased":true,"lease_id":"bf4994d809c1556719f53cfe8fd6138a","lease_holder":"/tmp/fm-relaunch-lease.ajHzDH/home/lease-adopt/a1794684991.3691159.17196"}
[20:36:34] agent on pane before relaunch: claude
[20:36:34] == simulate a pre-PR53 Herdr record: strip treehouse_lease_* from the meta ==
[20:36:34] == pre-PR53 Herdr-native shape: pool lease (real lease_id) held by the task id ==
[20:36:34] pool entry before relaunch:
{"leased":true,"lease_id":"bf4994d809c1556719f53cfe8fd6138a","lease_holder":"lease-adopt"}
[20:36:34] == real fm-control relaunch ==
error: task lease-adopt's endpoint reads 'unreadable' rather than a positively classified state; refusing to send a lifecycle command into an unattributed endpoint
error: relaunch of lease-adopt failed while stopping the old agent and its state is 'unreadable', so it was not proven stopped; its original instructions were restored and the durable record was retained for recovery
[20:36:35] fm-control exit=1
[20:36:38] agent on pane after relaunch: claude (pane w2:p2)
[20:36:38] meta lease fields after relaunch:
treehouse_lease_id=bf4994d809c1556719f53cfe8fd6138a
treehouse_lease_holder=lease-adopt
[20:36:38] meta unchanged vs before: no
[20:36:38] relaunch checkpoint present: yes
[20:36:38] pool entry after relaunch:
{"leased":true,"lease_id":"bf4994d809c1556719f53cfe8fd6138a","lease_holder":"lease-adopt"}
[20:36:38] pool entries total: 1
[20:36:42] teardown
Evidence: Targeted suite tests/fm-control-relaunch.test.sh output

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

ok - the away branch relaunches an existing In-flight task through fm-control at the spend cap
ok - a fresh away branch spawn still refuses an In-flight backlog item
ok - the away branch relaunch still refuses a held In-flight backlog item
ok - fm-spawn --relaunch: tracked opencode wiring is retired as on main
ok - fm-control removes the dialog file after exit and after relaunch
ok - fm-control exit removes the dialog file before it releases the control lock
ok - fm-control relaunch: a same-harness relaunch replaces the agent in the same endpoint and worktree
ok - fm-control relaunch: pending composer text refuses before the exit command is typed
ok - fm-control relaunch: an unreadable composer fails safe before the exit command is typed
ok - fm-control relaunch: a linked spawning home preserves committed and unfinished work in the recorded copy
ok - fm-control relaunch: an armed PR poll survives replacement launch publication
ok - fm-control relaunch: a traced replacement keeps an armed PR poll authenticated
ok - fm-control relaunch: delivery and concurrent task metadata publication serialize
ok - fm-control relaunch: disabling tracing clears metadata and pane context
ok - fm-control relaunch: progress and the Firstmate-worktree worker identity reach the replacement
ok - fm-control relaunch: Codex executes with a bounded pointer to an intact oversized brief
ok - fm-control relaunch: the progress note's inbox listing is silent on an empty inbox
ok - fm-control relaunch: a ship task refuses without the progress note its replacement needs
ok - fm-control relaunch: switching harness is one ordinary relaunch, and the old wiring goes with the old agent
ok - fm-control relaunch: a refused relaunch onto polytoken keeps the project's own hook layer and the running agent
ok - fm-control relaunch: a refused polytoken profile leaves the running agent untouched
ok - fm-spawn --relaunch: retiring a raw polytoken launch's wiring keeps the project's own layers
ok - fm-control relaunch: a harness switch resets model and effort unless they are named too
ok - fm-control relaunch: a prefixed recorded harness can switch adapters transactionally
ok - fm-control relaunch: a prefixed command requires an explicit replacement harness
ok - fm-control relaunch: a same-harness relaunch keeps the profile axes it was running with
ok - native Ultra relaunch preserves its profile and rejects an unsupported model before stopping
ok - fm-control relaunch: a signed-out worker account pin refuses before the old agent stops
ok - fm-control relaunch: the replacement follows the home's current worker account pin
ok - fm-control relaunch: a declared account list keeps the account the task records
ok - fm-control relaunch: only an explicit --account moves a task to another declared account
ok - fm-control relaunch: undeclared, newline-split, signed-out, unrecorded, retired, and wrong-runner accounts refuse before the old agent stops
ok - fm-control relaunch: mate pins are re-read for Claude and Pi, and unusable pins refuse before stopping the agent
ok - fm-control relaunch: a Pi replacement keeps the home's tool exclusions
ok - fm-control relaunch: exclusion-list refusals happen before the running agent stops
ok - fm-control relaunch: explicit model and effort win over the recorded ones
ok - fm-control relaunch: refuses to relaunch onto an adapter with no verified mechanics
ok - fm-control relaunch: the retired incarnation's global turn-end token is revoked
ok - fm-control relaunch: wiring cleanup failure refuses replacement arming
ok - fm-control-lib: one owner resolves each harness's turn-end registry entry, and refuses a malformed token
ok - fm-control relaunch: a secondmate relaunch re-resolves its durable configured harness pin
ok - fm-control relaunch: a claude secondmate keeps settings.local.json and retires the state settings file and the Stop pointer
ok - fm-control relaunch: a mate with a per-mate override line lands on that override, not the default pin
ok - fm-control relaunch: a mate with no override line still resolves the default pin
ok - fm-control relaunch: a legacy secondmate pin file still relaunches the mate onto its first line
ok - fm-control relaunch: an unparseable secondmate pin refuses before anything is stopped
ok - fm-control relaunch: invalid configured effort is ignored before stop
ok - fm-control relaunch: an adapter unverified for this task kind refuses before the agent is stopped
ok - fm-control relaunch: explicit secondmate harness resets unnamed profile axes
ok - fm-control relaunch: a ship task keeps its recorded harness instead of re-reading crew config
ok - fm-spawn --relaunch: with no explicit harness it reuses the task's recorded one, never the crew default
ok - fm-spawn --relaunch: a promoted scout with a recorded custom branch relaunches on it instead of being refused
ok - fm-promote/fm-spawn --relaunch: the current ship contract supersedes stale scout delivery text
ok - fm-spawn --relaunch: wiring armed under a prefixed harness name is still retired
ok - fm-spawn --relaunch: switching away from muse retires its session binding
ok - fm-spawn --relaunch: switching away from cursor retires its session binding
ok - fm-control relaunch: an unaccountable local copy refuses before the agent is touched
ok - fm-spawn --relaunch: a recorded worktree that is the primary home refuses
ok - fm-spawn --relaunch: a recorded worktree that is the project primary checkout refuses
ok - fm-spawn --relaunch: inherited Git overrides do not hide the project primary checkout
ok - fm-control relaunch: a worker with nothing to work from is never launched
ok - fm-control relaunch: a refusal before the agent is stopped leaves the durable record untouched
ok - fm-control relaunch: checkpoint inspection failures refuse before stopping
ok - fm-control relaunch: a launch failure after the stop keeps the prior record and reports the real state
ok - fm-control relaunch: unpublished rollback keeps concurrent durable metadata
ok - fm-control relaunch: post-publication failure keeps the new durable record
ok - fm-control relaunch: partial stop reconciles actual agent state
ok - fm-control relaunch: failed journal replacement preserves durable phase
ok - fm-spawn relaunch: prepublication abort removes replacement state
ok - fm-control relaunch: the checkpoint records the exact unlanded work it preserved
ok - fm-control relaunch: a secondmate's child work is accounted for and its charter is left alone
ok - fm-control relaunch: a secondmate home that is not this secondmate's is refused
ok - fm-control relaunch: unreadable child records fail checkpoint
ok - fm-control relaunch: unlistable state fails checkpoint
ok - fm-control relaunch: a vanished watcher scratch file does not fail the child-record checkpoint
ok - fm-control relaunch: two control actions on one task serialize instead of interleaving
ok - fm-spawn relaunch: direct entry participates in lifecycle serialization
ok - fm-promote: promotion participates in lifecycle serialization
ok - fm-spawn --relaunch: refuses to launch a second agent into a live endpoint
ok - fm-spawn --relaunch: symlinked records refuse before inspection
ok - fm-spawn --relaunch: keeps its early meta lock continuous
ok - fm-spawn --relaunch: pending closes refuse before replacement begins
ok - fm-spawn --relaunch: every identity axis comes from the record, and a contradicting flag refuses
ok - fm-spawn --relaunch: an unrecorded task is refused
ok - fm-spawn --relaunch: refuses to start a replacement outside the copy holding its work
ok - tmux: a window absent from its session refuses both verbs rather than being assumed gone
ok - tmux: an unfindable session refuses both verbs, so a live agent is never duplicated
ok - tmux: a dead server on this socket refuses both verbs rather than proving absence
ok - reclaim: an unclassifiable endpoint is still refused, so two agents cannot share one
ok - fm-spawn --relaunch: resumes the bound Pi session only for a Pi registration
ok - reclaim: a herdr pane that outlived its stopped server is adopted, never orphaned beside a new tab
ok - fm-control exit: a herdr pane that outlived its stopped server is already-stopped, not gone
ok - reclaim: a herdr rebind is created in the session the record names, never the ambient one
ok - reclaim: a herdr agent that came back with its server refuses, so one worktree keeps one agent
ok - reclaim: a herdr reclaim rebinds the endpoint and leaves the whole rest of the task alone
ok - reclaim: a herdr secondmate whose endpoint is gone is sent to its own respawn owner
ok - reclaim: a rebind refused from a plain shell reports the real cause, not a fabricated session mismatch
ok - relaunch re-reads the backlog item instead of blindly re-running the transition
ok - relaunch heals an item that drifted out of In flight while the task stayed live
ok - away supervision relaunches existing In-flight and queued items under the saturated fresh-spawn spend cap
ok - fm-control relaunch: an unverified pool reservation refuses before the agent stops
ok - fm-control relaunch: a verified Herdr-native pool lease is adopted and an unleased legacy copy stays unleased

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ bin/fm-treehouse-slot-lib.sh:470 - In the adoption branch, fm_treehouse_task_holds_pool_lease &#34;$RELAUNCH_WT&#34; &#34;$ID&#34; is redundant. The fm_treehouse_lease_read call right after it already requires leased==true, destroying!=true and a non-empty, tab/newline-free lease_id and lease_holder, and the following [ &#34;$FM_TREEHOUSE_LEASE_HOLDER&#34; = &#34;$ID&#34; ] checks the holder. The first call is a strict subset of those checks and costs one extra pool-state read and jq pass. Dropping it would not change behavior. It is optional to keep it as documentation that this is the contract fm-wake-lib.sh recognises.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 4 of 4 scenarios driven live against the product
Scenario Result Live Evidence
Relaunching a pre-PR53 Herdr task whose record has no lease fields, while the pool entry is leased to the task id, adopts the lease and starts a new Claude ✅ pass live live-adopt.log: fm-control exit=0, 'relaunched lease-adopt ... backend=herdr', meta now has treehouse_lease_id equal to the pool lease_id and treehouse_lease_holder=lease-adopt, pool entry unchanged,…
Adversarial: relaunch of a record with no lease fields, where the pool lease belongs to another holder, refuses while the agent keeps running and the record stays unchanged ✅ pass live live-foreign-holder-refuses.log: REFUSED ... no verifiable pool reservation; exit=1; claude still idle on the same pane; meta byte-identical; no control-relaunch checkpoint; pool entry unchanged
Regression contrast: the base commit stops the agent and then refuses in the incident shape (the reported bug) ✅ pass live live-base-commit-adopt-repro.log: REFUSED, then 'agent was stopped but the replacement did not launch; no agent is running'
Targeted fm-control relaunch suite, including the new refusal-shape and adoption/legacy tests ✅ pass live fm-control-relaunch.test.log: 'ok - ... an unverified pool reservation refuses before the agent stops' and 'ok - ... a verified Herdr-native pool lease is adopted and an unleased legacy copy stays unl…
  • bin/fm-herdr-lab.sh provision/teardown with a named fm-lab-relaunch-* session, a disposable FM_HOME made by bin/fm-lab-home.sh create, a disposable git project with a bare origin, and an isolated TREEHOUSE_ROOT pool
  • bin/fm-spawn.sh lease-adopt &lt;project&gt; --harness claude --backend herdr --mode local-only --yolo off (real treehouse lease, real claude in a Herdr pane), then lease fields stripped from the meta and the pool entry's lease_holder set to the task id, then bin/fm-control.sh lease-adopt relaunch --note ...
  • Adversarial: same setup, but the pool lease is held by a holder that is not the task id, then bin/fm-control.sh lease-foreign relaunch --note ...
  • Base-commit reproduction: the same adoption driver run against git archive 4cdc3a7 (pre-fix code)
  • bash tests/fm-control-relaunch.test.sh (the targeted suite containing the two new tests)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

A relaunch now checks the recorded pool reservation before it records a
checkpoint or stops the running agent, so a refusal leaves that agent and
its record in place. When the pool entry is leased by this task on the
recorded copy, relaunch records that lease id and holder and continues.
@peterOC26
peterOC26 merged commit 86c4f84 into main Nov 14, 2026
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant