Skip to content

fix(bin): stop reissuing or tearing down Treehouse slots another task still owns - #4366

Open
MLA82 wants to merge 10 commits into
kunchenguid:mainfrom
MLA82:fm/treehouse-slot-neuvergabe-trotz-meta
Open

MLA82 wants to merge 10 commits into
kunchenguid:mainfrom
MLA82:fm/treehouse-slot-neuvergabe-trotz-meta

Conversation

@MLA82

@MLA82 MLA82 commented Sep 13, 2026 •

Copy link
Copy Markdown

Intent

Close a Treehouse pool-slot ownership gap.

fm-spawn/Treehouse re-issues a pool worktree slot as soon as no process is running there anymore, even while a DIFFERENT task's state/<id>.meta - including one in a secondmate home - still records that same slot as its worktree=. This typically happens for a task whose work already landed but which was never torn down.

Consequence: bin/fm-teardown.sh stops every process in the recorded worktree and resets it; its only check is that the path is a Treehouse-managed pool slot, a check a re-issued slot still passes. Tearing down the old, forgotten task's record would therefore kill the unrelated worker that now legitimately holds that slot and reset its unlanded work.

What is needed:

  1. Refuse to re-issue a pool slot while any state/*.meta - including in secondmate homes - still records it as worktree=, or otherwise bind the lease to the owning task until that task is torn down.
  2. Before bin/fm-teardown.sh stops or resets a slot, it must verify the slot still belongs to the recorded task, and refuse otherwise.
  3. A regression test for both behaviors.

What Changed

  • Durable leases: crewmate spawns (bin/fm-spawn.sh) and secondmate home seeding (bin/fm-home-seed.sh) now take a durable treehouse get --lease --lease-holder firstmate:<home>:<id>. The old process-only treehouse get lost its lease once the worker exited. Before the get, still under the shared Treehouse project lock, the new fm_treehouse_require_reserved_records in bin/fm-wake-lib.sh walks every reachable local home: the root, the parent chain, registered secondmates, and secondmate .meta files not yet in a registry. The spawn is refused if any state/*.meta records a worktree=/home= in that pool without a durable lease. The slot-owner claim (.fm-slot-owner) now also stores the lease's lease_id, and it only counts as this task's own when both the task id and the canonical home match. A spawn that aborts while it still holds the lock returns any leases Treehouse records under its holder.
  • Teardown refuses when the slot isn't this task's: bin/fm-teardown.sh no longer warns and carries on when a slot has been handed to another task. If the claim names a different task or home, is unreadable, or its bound lease no longer matches Treehouse's current lease, it refuses before stopping processes or resetting the slot, and --force doesn't override this. The ownership check runs again before the process reap, the branch reset, and every return, which is now treehouse return --force --if-lease-id <id>. This covers child worktrees in secondmate homes too. The home walk that used to live in teardown is now the shared fm_treehouse_collect_states.
  • Toolchain: the Treehouse floor is now v2.1.0, the first release with lease identities; bootstrap detects it by checking whether treehouse return --help lists --if-lease-id. The CI installer is pinned to v2.3.0, and jq is now required for the tmux backend too. docs/architecture.md, docs/configuration.md and the bootstrap-diagnostics skill are updated to match. There are new regression tests for both behaviours: a slot still named by a record is refused before get, locally and in secondmate homes, and teardown of a reassigned slot refuses and leaves both tasks intact.

Risk Assessment

⚠️ Medium: After checking against the real Treehouse v2.3.0 (help flags, status --json shape, state-file fields, release checksums and archive layout), I found no material defects in the current code, but the change reworks every crewmate spawn onto durable Treehouse leases, adds a Treehouse ≥2.1.0 floor, and makes allocation and teardown fail closed in ways that can deliberately block spawns until legacy stale records are reconciled, so it deserves a careful merge rather than a rubber stamp.

Testing

Test runs: the real-herdr e2e suite (spawn and teardown in a primary and a secondmate home, with real Treehouse) passed 10/10. The targeted fm-spawn-pool-base-freshen, fm-teardown-endpoint-safety and fm-secondmate-safety test files passed; the one tmux-only case skipped because tmux is not installed. That coverage includes the new regression tests, the home-seed preflight and the missing-jq refusal. Live scenarios: a purpose-built driver ran the real spawn and teardown scripts through 7 scenarios against Treehouse 2.3.0 in an isolated TREEHOUSE_ROOT pool and herdr lab session, with all 33 checks passing. The same driver run on an extract of the base commit reproduced the reported reissue bug: the next spawn got the stale task's slot. The install script's new Treehouse 2.3.0 pin was installed and checksum-verified. The home-seed refusal scenario was exercised only through the repo's fake-backend test suite, not live, so it is marked untested. The first driver run had one failure caused by the driver itself: it planted an uncommitted file in D's slot, so D's final teardown refused on the dirty-work guard, which is correct behavior. I fixed the driver and the re-run was fully green. The worktree is clean and all temp dirs, lab sessions and the base extract were removed. There is no UI surface, so the evidence is CLI transcripts.

  • Live validation: ✅ go - 9 of 10 scenarios driven live against the product
Scenario Result Live Evidence
Stale but unreissued slot: task A's worker exits without teardown, and the next spawn B is given a different slot while A's slot stays leased to A ✅ pass live live-slot-ownership-head.log S2 (B got slot 2; A's slot 1 stayed leased by firstmate:<home>:A with 0 processes). live-slot-ownership-base.log shows base ecfe071 reissuing slot 1 to B, the reported bu…
Reported legacy case: a pre-fix record in a registered secondmate home names a free, unleased slot, so a new spawn refuses before any slot is requested and leaves the slot's work and the pool state un… ✅ pass live live-slot-ownership-head.log S3: REFUSED naming secondmate-home/state/legacy.meta; 'no slot was requested'; treehouse-state.json unchanged byte for byte; the unlanded file and HEAD are intact; no C me…
Guard is not a blanket refusal: once the stale record is reconciled, the same spawn succeeds and durably leases the slot to the new task ✅ pass live live-slot-ownership-head.log S3-control (C leased slot 3 under holder firstmate:<home>:C)
New spawn binds the durable Treehouse lease to the task: the holder is firstmate:<home>:<id>, and the claim file records task, home and Treehouse's lease_id ✅ pass live live-slot-ownership-head.log S1 (claim file contents and status --json output shown)
Teardown of a stale record whose slot now belongs to a live task from another home refuses even with --force, and the other task's worker, uncommitted file and lease survive ✅ pass live live-slot-ownership-head.log S4: 'REFUSED: task A's recorded worktree .../4/proj was reassigned to task D ... not even --force'; D's slot still has 2 processes and D-WORK.txt, lease still firstmate:<o…
Adversarial lease swap: the task's claim still names it, but its Treehouse lease was returned by hand and re-leased to 'drydock'; teardown --force refuses and drydock's work and lease survive ✅ pass live live-slot-ownership-head.log S5: 'REFUSED: ... no longer holds its Treehouse lease <old id> (current lease: <new id> drydock)'
Normal teardown of a task that still owns its slot returns the lease, removes the claim and removes the record (primary home and an unregistered other home) ✅ pass live live-slot-ownership-head.log S6 and S6b (A, B, C and D torn down with rc 0; slots back to 'available'). herdr-e2e.log also covers primary and secondmate-home teardown
Spawn aborted while holding the allocation lock (slot claimed by another task) returns the lease it took, found through Treehouse's own holder record, and leaves the foreign claim intact ✅ pass live live-slot-ownership-head.log S7: F aborts with 'could not claim Treehouse pool slot'; no lease remains under F's holder; task=ghost claim intact
Home seeding refuses to lease a Firstmate slot that a stale unleased record names, and refuses loudly when jq is missing ⏸️ untested no The prior payload did not establish a live result: this scenario was only exercised through the repo's fake-tmux/fake-treehouse test (tests/fm-secondmate-safety.test.sh). A live run needs a disposable…
The CI Treehouse pin bump installs v2.3.0 with a matching checksum, and that binary exposes the --if-lease-id capability bootstrap now probes ✅ pass live bash bin/fm-install-treehouse.sh &lt;tmp&gt;: installed treehouse v2.3.0; return --help lists --if-lease-holder and --if-lease-id
Evidence: Live driver script (real fm-spawn/fm-teardown on herdr + treehouse 2.3.0)

Source: Live driver script (real fm-spawn/fm-teardown on herdr + treehouse 2.3.0)

#!/usr/bin/env bash
# Live driver: real bin/fm-spawn.sh + bin/fm-teardown.sh on the herdr backend,
# real Treehouse (pool isolated under a temp TREEHOUSE_ROOT), isolated herdr
# lab session. Exercises slot-reissue refusal and teardown ownership checks.
#
# Usage: live-slot-ownership-driver.sh <firstmate-root> [head|base]
set -u
ROOT=$(cd "$1" && pwd)
MODE=${2:-head}

command -v herdr >/dev/null && command -v jq >/dev/null && command -v treehouse >/dev/null \
  || { echo "missing herdr/jq/treehouse"; exit 2; }

# shellcheck source=/dev/null
. "$ROOT/tests/herdr-test-safety.sh"
herdr_forget_inherited_pane

TMP=$(mktemp -d "$(cd "${TMPDIR:-/tmp}" && pwd -P)/fm-live-slot.XXXXXX")
SESSION="fm-lab-slotlease-$$"
export HERDR_SESSION="$SESSION"
export TREEHOUSE_ROOT="$TMP/th"
FAILS=0
cleanup() { herdr_safe_stop_and_delete "$SESSION" >/dev/null 2>&1; rm -rf "$TMP"; }
trap cleanup EXIT
fm_herdr_lab_prepare "$SESSION" || { echo "lab prepare failed"; exit 2; }
# shellcheck source=/dev/null
. "$ROOT/bin/fm-backend.sh"
fm_backend_source herdr

say()   { printf '\n=== %s\n' "$*"; }
ok()    { printf 'PASS: %s\n' "$*"; }
bad()   { printf 'FAIL: %s\n' "$*"; FAILS=$((FAILS + 1)); }
check() { local msg=$1; shift; if "$@"; then ok "$msg"; else bad "$msg"; fi; }

mkhome() {  # <dir>
  mkdir -p "$1/state" "$1/data" "$1/config"
  printf 'off\n' > "$1/config/herdr-presentation-spaces"
}
brief() {  # <home> <id>
  mkdir -p "$1/data/$2"
  printf '# Task\n## Captain'"'"'s intent\nLive slot test %s.\n\n## Firstmate spec\nIdle.\n' "$2" > "$1/data/$2/brief.md"
}
spawn() {  # <home> <id>  -> rc; stdout+stderr to $TMP/<id>.spawn
  brief "$1" "$2"
  (cd "$TMP" && FM_SPAWN_NO_GUARD=1 FM_HOME="$1" FM_ROOT_OVERRIDE="$ROOT" \
    "$ROOT/bin/fm-spawn.sh" "$2" "$PROJ" "sh -c 'echo worker-$2-up; exec sleep 3600'" \
    --mode no-mistakes --yolo off --backend herdr) >"$TMP/$2.spawn" 2>&1
}
teardown() {  # <home> <id> [--force] -> rc; output to $TMP/<id>.td
  (cd "$TMP" && FM_HOME="$1" FM_ROOT_OVERRIDE="$ROOT" FM_STATE_OVERRIDE="$1/state" \
    FM_DATA_OVERRIDE="$1/data" FM_CONFIG_OVERRIDE="$1/config" \
    "$ROOT/bin/fm-teardown.sh" "$2" ${3:+"$3"}) >"$TMP/$2.td" 2>&1
}
wt_of()   { sed -n 's/^worktree=//p' "$1/state/$2.meta"; }
pane_of() { sed -n 's/^herdr_pane_id=//p' "$1/state/$2.meta"; }
pool()    { (cd "$PROJ" && treehouse status --json); }
slot_json() { pool | jq -c --arg p "$1" '.[] | select(.path == $p) | {name,status,lease_holder,lease_id,processes:(.processes|length)}'; }
holder_of() { pool | jq -r --arg p "$1" '.[] | select(.path == $p) | .lease_holder // ""'; }
leaseid_of() { pool | jq -r --arg p "$1" '.[] | select(.path == $p) | .lease_id // ""'; }
nproc_of() { pool | jq -r --arg p "$1" '.[] | select(.path == $p) | (.processes|length)'; }
canon()   { (cd "$1" && pwd -P); }
kill_pane() { fm_backend_herdr_kill "$SESSION:$1" >/dev/null 2>&1; sleep 1; }
show()    { printf -- '--- %s ---\n' "$1"; sed 's/^/  | /' "$2"; }

PH="$TMP/primary-home"; mkhome "$PH"; PH=$(canon "$PH")
SM="$TMP/secondmate-home"; mkhome "$SM"; SM=$(canon "$SM")
printf 'mate\n' > "$SM/.fm-secondmate-home"
printf -- '- mate - Test (home: %s; scope: test; projects: proj; added 2026-09-13)\n' "$SM" > "$PH/data/secondmates.md"
OH="$TMP/other-home"; mkhome "$OH"; OH=$(canon "$OH")
PROJ="$TMP/proj"
mkdir -p "$PROJ"; git -C "$PROJ" init -q -b main
printf '# scratch\n' > "$PROJ/README.md"; git -C "$PROJ" add README.md
git -C "$PROJ" -c user.name=t -c [email protected] commit -qm initial
git clone -q --bare "$PROJ" "$PROJ.origin.git"; git -C "$PROJ" remote add origin "file://$PROJ.origin.git"
echo "ROOT=$ROOT MODE=$MODE TREEHOUSE_ROOT=$TREEHOUSE_ROOT treehouse=$(treehouse --version)"

# ---------------------------------------------------------------- S1
say "S1 spawn task A from the primary home: durable lease bound to A"
spawn "$PH" A; rc=$?
[ "$rc" -eq 0 ] || { show "A spawn" "$TMP/A.spawn"; bad "A spawn rc=$rc"; exit 1; }
WTA=$(canon "$(wt_of "$PH" A)"); PANEA=$(pane_of "$PH" A)
echo "A worktree=$WTA"; echo "A slot: $(slot_json "$WTA")"
case "$WTA" in "$TREEHOUSE_ROOT"/*) ok "pane shell used the isolated TREEHOUSE_ROOT pool" ;; *) bad "slot outside isolated pool: $WTA" ;; esac
if [ "$MODE" = head ]; then
  echo "A claim ($(dirname "$WTA")/.fm-slot-owner):"; sed 's/^/  | /' "$(dirname "$WTA")/.fm-slot-owner"
  check "A's slot is durably leased by holder firstmate:$PH:A" [ "$(holder_of "$WTA")" = "firstmate:$PH:A" ]
  check "A's claim stores Treehouse's lease_id" grep -Fxq "lease_id=$(leaseid_of "$WTA")" "$(dirname "$WTA")/.fm-slot-owner"
fi

# ---------------------------------------------------------------- S2
say "S2 A's worker exits (pane closed) but A is never torn down; spawn B"
kill_pane "$PANEA"
echo "A slot after worker exit: $(slot_json "$WTA")"
spawn "$PH" B; rc=$?
[ "$rc" -eq 0 ] || { show "B spawn" "$TMP/B.spawn"; bad "B spawn rc=$rc"; exit 1; }
WTB=$(canon "$(wt_of "$PH" B)"); PANEB=$(pane_of "$PH" B)
echo "B worktree=$WTB"; echo "A meta still records worktree=$(wt_of "$PH" A)"
if [ "$WTB" = "$WTA" ]; then
  bad "REISSUE: B was handed slot $WTB while A's record still names it"
else
  ok "B got a different slot ($WTB); A's still-recorded slot was not reissued"
fi
[ "$MODE" = head ] || { echo "RESULT mode=$MODE fails=$FAILS"; exit "$FAILS"; }
check "A's slot is still leased by A with no process in it" \
  [ "$(holder_of "$WTA"):$(nproc_of "$WTA")" = "firstmate:$PH:A:0" ]

# ---------------------------------------------------------------- S3
say "S3 legacy (process-only, pre-fix) record in the SECONDMATE home names a free, unleased slot"
L=$(cd "$PROJ" && treehouse get --lease --no-fetch --lease-holder setup 2>/dev/null)
(cd "$PROJ" && treehouse return --force --if-lease-holder setup "$L") >/dev/null 2>&1
WTL=$(canon "$L")
echo "legacy-unlanded-work" > "$WTL/UNLANDED.txt"
printf 'window=firstmate:fm-legacy\nworktree=%s\nproject=%s\nharness=echo\nkind=ship\nmode=no-mistakes\nyolo=off\n' \
  "$WTL" "$PROJ" > "$SM/state/legacy.meta"
echo "legacy slot before: $(slot_json "$WTL")"
state_file="$(dirname "$(dirname "$WTL")")/treehouse-state.json"
before=$(sha256sum < "$state_file"); head_before=$(git -C "$WTL" rev-parse HEAD)
spawn "$PH" C; rc=$?
show "C spawn (expected refusal)" "$TMP/C.spawn"
check "spawn C refuses (rc=$rc)" [ "$rc" -ne 0 ]
check "refusal names the secondmate-home record" grep -Fq "$SM/state/legacy.meta" "$TMP/C.spawn"
check "refusal happens before any slot is requested" grep -Fq "no slot was requested" "$TMP/C.spawn"
check "no record published for C" [ ! -e "$PH/state/C.meta" ]
check "Treehouse pool state is byte-identical (no lease taken)" [ "$(sha256sum < "$state_file")" = "$before" ]
check "legacy slot's unlanded file and HEAD untouched" \
  [ "$(cat "$WTL/UNLANDED.txt" 2>/dev/null):$(git -C "$WTL" rev-parse HEAD)" = "legacy-unlanded-work:$head_before" ]

say "S3-control: once the legacy record is reconciled, spawn C proceeds"
rm -f "$SM/state/legacy.meta" "$WTL/UNLANDED.txt"
spawn "$PH" C; rc=$?
[ "$rc" -eq 0 ] || show "C spawn" "$TMP/C.spawn"
check "spawn C succeeds after reconciliation" [ "$rc" -eq 0 ]
WTC=$(canon "$(wt_of "$PH" C)"); echo "C worktree=$WTC slot: $(slot_json "$WTC")"

# ---------------------------------------------------------------- S4
say "S4 reported case: A's stale record names a slot now held by live task D of an unregistered home"
spawn "$OH" D; rc=$?
[ "$rc" -eq 0 ] || { show "D spawn" "$TMP/D.spawn"; bad "D spawn rc=$rc"; exit 1; }
WTD=$(canon "$(wt_of "$OH" D)"); sleep 1
echo "D-unlanded-work" > "$WTD/D-WORK.txt"
echo "D slot before: $(slot_json "$WTD")"
cp "$PH/state/A.meta" "$TMP/A.meta.orig"
sed -i "s|^worktree=.*|worktree=$WTD|" "$PH/state/A.meta"
teardown "$PH" A --force; rc=$?
show "teardown A --force (expected refusal)" "$TMP/A.td"
echo "D slot after: $(slot_json "$WTD")"
check "teardown of the stale record refuses even with --force (rc=$rc)" [ "$rc" -ne 0 ]
check "refusal names the reassignment to D" grep -Fq "reassigned to task D (home $OH)" "$TMP/A.td"
check "D's worker is still running in its slot" [ "$(nproc_of "$WTD")" -ge 1 ]
check "D's unlanded file survives" [ "$(cat "$WTD/D-WORK.txt" 2>/dev/null)" = "D-unlanded-work" ]
check "D's lease is untouched" [ "$(holder_of "$WTD")" = "firstmate:$OH:D" ]
check "A's stale record is preserved for reconciliation" [ -e "$PH/state/A.meta" ]
cp "$TMP/A.meta.orig" "$PH/state/A.meta"

# ---------------------------------------------------------------- S5
say "S5 adversarial: E's slot lease is returned by hand and re-leased to another holder; E's claim still says E"
spawn "$PH" E; rc=$?
[ "$rc" -eq 0 ] || { show "E spawn" "$TMP/E.spawn"; bad "E spawn rc=$rc"; exit 1; }
WTE=$(canon "$(wt_of "$PH" E)"); kill_pane "$(pane_of "$PH" E)"
old_id=$(leaseid_of "$WTE")
(cd "$PROJ" && treehouse return --force --if-lease-holder "firstmate:$PH:E" "$WTE") >/dev/null 2>&1
G=$(cd "$PROJ" && treehouse get --lease --no-fetch --lease-holder drydock 2>/dev/null); G=$(canon "$G")
echo "E slot=$WTE old lease=$old_id; drydock got $G; now: $(slot_json "$WTE")"
if [ "$G" = "$WTE" ]; then
  echo "drydock-work" > "$WTE/DRYDOCK.txt"
  teardown "$PH" E --force; rc=$?
  show "teardown E --force (expected refusal)" "$TMP/E.td"
  check "teardown refuses when the slot's lease identity changed (rc=$rc)" [ "$rc" -ne 0 ]
  check "refusal cites the lost lease" grep -Fq "no longer holds its Treehouse lease $old_id" "$TMP/E.td"
  check "drydock's file survives and lease is still drydock's" \
    [ "$(cat "$WTE/DRYDOCK.txt" 2>/dev/null):$(holder_of "$WTE")" = "drydock-work:drydock" ]
else
  bad "drydock did not receive E's returned slot ($G); lease-swap case not constructed"
fi

# ---------------------------------------------------------------- S6
say "S6 normal teardown of A (its own slot, lease and claim) still works"
teardown "$PH" A; rc=$?
show "teardown A" "$TMP/A.td"
check "teardown A succeeds" [ "$rc" -eq 0 ]
check "A's record removed" [ ! -e "$PH/state/A.meta" ]
check "A's slot returned to the pool (no lease)" [ -z "$(holder_of "$WTA")" ]
check "A's claim removed" [ ! -e "$(dirname "$WTA")/.fm-slot-owner" ]
echo "A slot after teardown: $(slot_json "$WTA")"

# ---------------------------------------------------------------- S7
say "S7 locked abort: the only free slot carries a foreign claim, so spawn F aborts and must return its lease"
printf 'task=ghost\nhome=%s\n' "$TMP/ghost-home" > "$(dirname "$WTA")/.fm-slot-owner"
echo "free slots: $(pool | jq -c '[.[] | select(.status != "leased") | .path]')"
spawn "$PH" F; rc=$?
show "F spawn (expected abort)" "$TMP/F.spawn"
check "spawn F aborts (rc=$rc)" [ "$rc" -ne 0 ]
check "abort reason is the unclaimable slot" grep -Fq "could not claim Treehouse pool slot" "$TMP/F.spawn"
check "no record published for F" [ ! -e "$PH/state/F.meta" ]
check "no Treehouse lease remains under F's holder" \
  [ -z "$(pool | jq -r --arg h "firstmate:$PH:F" '.[] | select(.lease_holder == $h) | .path')" ]
check "the foreign claim is left intact" grep -Fxq "task=ghost" "$(dirname "$WTA")/.fm-slot-owner"
echo "pool after F abort: $(pool | jq -c '[.[] | {name,status,lease_holder}]')"

# ---------------------------------------------------------------- S6b
say "S6b normal teardown of live tasks B, C (primary) and D (other home) still works"
rm -f "$WTD/D-WORK.txt"  # driver-planted S4 sentinel; the dirty-work guard would rightly refuse it
for spec in "$PH:B" "$PH:C" "$OH:D"; do
  h=${spec%:*}; id=${spec##*:}; w=$(canon "$(wt_of "$h" "$id")")
  teardown "$h" "$id"; rc=$?
  [ "$rc" -eq 0 ] || show "teardown $id" "$TMP/$id.td"
  check "teardown $id succeeds and returns its lease" [ "$rc:$(holder_of "$w")" = "0:" ]
done
echo "final pool: $(pool | jq -c '[.[] | {name,status,lease_holder}]')"
echo "RESULT mode=$MODE fails=$FAILS"
exit "$FAILS"
Evidence: Live transcript on the change: S1-S7, 33/33 PASS, with pool JSON, claim files and refusal messages

Source: Live transcript on the change: S1-S7, 33/33 PASS, with pool JSON, claim files and refusal messages

ROOT=~/.no-mistakes/worktrees/04f432826927/01M2DC3SR16QBK16VWJ577KM1Y MODE=head TREEHOUSE_ROOT=/tmp/fm-live-slot.PNzoKi/th treehouse=v2.3.0

=== S1 spawn task A from the primary home: durable lease bound to A
A worktree=/tmp/fm-live-slot.PNzoKi/th/.treehouse/proj-32ab91/1/proj
A slot: {"name":"1","status":"leased","lease_holder":"firstmate:/tmp/fm-live-slot.PNzoKi/primary-home:A","lease_id":"af0911e611b5700124f5d7f1cedc9f8c","processes":2}
PASS: pane shell used the isolated TREEHOUSE_ROOT pool
A claim (/tmp/fm-live-slot.PNzoKi/th/.treehouse/proj-32ab91/1/.fm-slot-owner):
  | task=A
  | home=/tmp/fm-live-slot.PNzoKi/primary-home
  | lease_id=af0911e611b5700124f5d7f1cedc9f8c
PASS: A's slot is durably leased by holder firstmate:/tmp/fm-live-slot.PNzoKi/primary-home:A
PASS: A's claim stores Treehouse's lease_id

=== S2 A's worker exits (pane closed) but A is never torn down; spawn B
A slot after worker exit: {"name":"1","status":"leased","lease_holder":"firstmate:/tmp/fm-live-slot.PNzoKi/primary-home:A","lease_id":"af0911e611b5700124f5d7f1cedc9f8c","processes":0}
B worktree=/tmp/fm-live-slot.PNzoKi/th/.treehouse/proj-32ab91/2/proj
A meta still records worktree=/tmp/fm-live-slot.PNzoKi/th/.treehouse/proj-32ab91/1/proj
PASS: B got a different slot (/tmp/fm-live-slot.PNzoKi/th/.treehouse/proj-32ab91/2/proj); A's still-recorded slot was not reissued
PASS: A's slot is still leased by A with no process in it

=== S3 legacy (process-only, pre-fix) record in the SECONDMATE home names a free, unleased slot
legacy slot before: {"name":"3","status":"dirty","lease_holder":"","lease_id":"","processes":0}
--- C spawn (expected refusal) ---
  | warning: /tmp/fm-live-slot.PNzoKi/primary-home/data/C/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
  | REFUSED: /tmp/fm-live-slot.PNzoKi/secondmate-home/state/legacy.meta still records worktree=/tmp/fm-live-slot.PNzoKi/th/.treehouse/proj-32ab91/3/proj without a durable Treehouse lease; allocation could re-issue that task's slot. Tear down or reconcile that record before spawning; no slot was requested.
PASS: spawn C refuses (rc=1)
PASS: refusal names the secondmate-home record
PASS: refusal happens before any slot is requested
PASS: no record published for C
PASS: Treehouse pool state is byte-identical (no lease taken)
PASS: legacy slot's unlanded file and HEAD untouched

=== S3-control: once the legacy record is reconciled, spawn C proceeds
PASS: spawn C succeeds after reconciliation
C worktree=/tmp/fm-live-slot.PNzoKi/th/.treehouse/proj-32ab91/3/proj slot: {"name":"3","status":"leased","lease_holder":"firstmate:/tmp/fm-live-slot.PNzoKi/primary-home:C","lease_id":"8a8ad0ebbf6ccf7c88cdde98a278900d","processes":2}

=== S4 reported case: A's stale record names a slot now held by live task D of an unregistered home
D slot before: {"name":"4","status":"leased","lease_holder":"firstmate:/tmp/fm-live-slot.PNzoKi/other-home:D","lease_id":"3d0cf8c9f761b5aedd0c268169aa86f5","processes":2}
--- teardown A --force (expected refusal) ---
  | ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  | ●  WATCHER DOWN - SUPERVISION IS OFF
  | ●  3 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
  | ●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
  | ●  This is a supervision warning only; the guarded operation WILL still run.
  | ●  watcher supervision needs Stop-owned automatic recovery; inspect the hook registration and startup status before ending the turn.
  | ●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
  | REFUSED: task A's recorded worktree /tmp/fm-live-slot.PNzoKi/th/.treehouse/proj-32ab91/4/proj was reassigned to task D (home /tmp/fm-live-slot.PNzoKi/other-home); preserving the slot and task records - not even --force authorizes touching another task's work.
D slot after: {"name":"4","status":"leased","lease_holder":"firstmate:/tmp/fm-live-slot.PNzoKi/other-home:D","lease_id":"3d0cf8c9f761b5aedd0c268169aa86f5","processes":2}
PASS: teardown of the stale record refuses even with --force (rc=1)
PASS: refusal names the reassignment to D
PASS: D's worker is still running in its slot
PASS: D's unlanded file survives
PASS: D's lease is untouched
PASS: A's stale record is preserved for reconciliation

=== S5 adversarial: E's slot lease is returned by hand and re-leased to another holder; E's claim still says E
E slot=/tmp/fm-live-slot.PNzoKi/th/.treehouse/proj-32ab91/5/proj old lease=5852ea859b48064c0d09ad80a253f389; drydock got /tmp/fm-live-slot.PNzoKi/th/.treehouse/proj-32ab91/5/proj; now: {"name":"5","status":"leased","lease_holder":"drydock","lease_id":"c9de5926a2f48281a1301b0fa92750a7","processes":0}
--- teardown E --force (expected refusal) ---
  | WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
  | REFUSED: task E's recorded worktree /tmp/fm-live-slot.PNzoKi/th/.treehouse/proj-32ab91/5/proj no longer holds its Treehouse lease 5852ea859b48064c0d09ad80a253f389 (current lease: c9de5926a2f48281a1301b0fa92750a7	drydock); nothing was changed - not even with --force.
PASS: teardown refuses when the slot's lease identity changed (rc=1)
PASS: refusal cites the lost lease
PASS: drydock's file survives and lease is still drydock's

=== S6 normal teardown of A (its own slot, lease and claim) still works
--- teardown A ---
  | WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
  | 🌳 Worktree returned to pool.
  | WARNING: watcher still down (same stale episode; last beat: never, grace 300s) - full banner already printed this episode.
  | /tmp/fm-live-slot.PNzoKi/proj: already current
  | teardown A complete (window fm-lab-slotlease-1850836:w1:p2, worktree /tmp/fm-live-slot.PNzoKi/th/.treehouse/proj-32ab91/1/proj)
  | Backlog: A just finished (this home keeps no markdown backlog at /tmp/fm-live-slot.PNzoKi/primary-home/data/backlog.md). Update /tmp/fm-live-slot.PNzoKi/primary-home/data/backlog.md - move A to Done, keep Done to the 10 most recent, then re-scan Queued and dispatch only work whose blockers are gone and date is due.
PASS: teardown A succeeds
PASS: A's record removed
PASS: A's slot returned to the pool (no lease)
PASS: A's claim removed
A slot after teardown: {"name":"1","status":"available","lease_holder":"","lease_id":"","processes":0}

=== S7 locked abort: the only free slot carries a foreign claim, so spawn F aborts and must return its lease
free slots: ["/tmp/fm-live-slot.PNzoKi/th/.treehouse/proj-32ab91/1/proj"]
--- F spawn (expected abort) ---
  | warning: /tmp/fm-live-slot.PNzoKi/primary-home/data/F/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
  | error: could not claim Treehouse pool slot /tmp/fm-live-slot.PNzoKi/th/.treehouse/proj-32ab91/1/proj for task F; refusing to launch a worker whose slot cannot later be proved to be its own; inspect window fm-lab-slotlease-1850836:w2:p7
PASS: spawn F aborts (rc=1)
PASS: abort reason is the unclaimable slot
PASS: no record published for F
PASS: no Treehouse lease remains under F's holder
PASS: the foreign claim is left intact
pool after F abort: [{"name":"1","status":"available","lease_holder":""},{"name":"2","status":"leased","lease_holder":"firstmate:/tmp/fm-live-slot.PNzoKi/primary-home:B"},{"name":"3","status":"leased","lease_holder":"firstmate:/tmp/fm-live-slot.PNzoKi/primary-home:C"},{"name":"4","status":"leased","lease_holder":"firstmate:/tmp/fm-live-slot.PNzoKi/other-home:D"},{"name":"5","status":"leased","lease_holder":"drydock"}]

=== S6b normal teardown of live tasks B, C (primary) and D (other home) still works
PASS: teardown B succeeds and returns its lease
PASS: teardown C succeeds and returns its lease
PASS: teardown D succeeds and returns its lease
final pool: [{"name":"1","status":"available","lease_holder":""},{"name":"2","status":"available","lease_holder":""},{"name":"3","status":"available","lease_holder":""},{"name":"4","status":"available","lease_holder":""},{"name":"5","status":"leased","lease_holder":"drydock"}]
RESULT mode=head fails=0
rc=0
Evidence: Live transcript on base ecfe071: slot reissued to B while A's record still names it

Source: Live transcript on base ecfe0719: slot reissued to B while A's record still names it

ROOT=/tmp/fm-base-ecfe0719 MODE=base TREEHOUSE_ROOT=/tmp/fm-live-slot.gIasFh/th treehouse=v2.3.0

=== S1 spawn task A from the primary home: durable lease bound to A
A worktree=/tmp/fm-live-slot.gIasFh/th/.treehouse/proj-69542b/1/proj
A slot: {"name":"1","status":"in-use","lease_holder":"","lease_id":"","processes":2}
PASS: pane shell used the isolated TREEHOUSE_ROOT pool

=== S2 A's worker exits (pane closed) but A is never torn down; spawn B
A slot after worker exit: {"name":"1","status":"available","lease_holder":"","lease_id":"","processes":0}
B worktree=/tmp/fm-live-slot.gIasFh/th/.treehouse/proj-69542b/1/proj
A meta still records worktree=/tmp/fm-live-slot.gIasFh/th/.treehouse/proj-69542b/1/proj
FAIL: REISSUE: B was handed slot /tmp/fm-live-slot.gIasFh/th/.treehouse/proj-69542b/1/proj while A's record still names it
RESULT mode=base fails=1
rc=1
Evidence: Real-herdr e2e suite run (10/10)

Source: Real-herdr e2e suite run (10/10)

ok - real herdr E2E: a primary-shaped home spawns a crewmate on the herdr backend
ok - real herdr E2E: the primary-shaped home's crewmate landed in the 'firstmate' workspace
ok - real herdr E2E: the primary spawns a --secondmate task on the herdr backend
ok - real herdr E2E: a --secondmate spawn by the PRIMARY lands in the SECONDMATE's own labeled workspace, distinct from the primary's
ok - real herdr E2E: a crewmate spawns successfully FROM a secondmate-shaped home's own fm-spawn.sh process
ok - real herdr E2E: a crewmate spawned FROM the secondmate-shaped home lands in the secondmate's OWN workspace - falls out of per-home resolution, no glue needed
ok - real herdr E2E: list_live from the primary's own context sees only the primary's own task
ok - real herdr E2E: list_live from the secondmate's own context sees only tasks in the secondmate's own workspace (both its own tab and its crewmate's)
ok - real herdr E2E: tearing down cm1 closes only its own tab - the secondmate's and cm2's tabs survive untouched
ok - real herdr E2E: tearing down cm2 closes only its own tab - the secondmate's own tab (same workspace) survives untouched
rc=0
Evidence: Before/after reissue excerpt
BASE: A slot after worker exit: {"status":"available","lease_holder":""}
BASE: B worktree=.../proj-69542b/1/proj ; A meta still records .../1/proj
FAIL: REISSUE: B was handed slot .../1/proj while A's record still names it

HEAD: A slot after worker exit: {"status":"leased","lease_holder":"firstmate:<home>:A","processes":0}
HEAD: PASS: B got a different slot (.../2/proj); A's still-recorded slot was not reissued
HEAD: REFUSED: <secondmate-home>/state/legacy.meta still records worktree=.../3/proj without a durable Treehouse lease; allocation could re-issue that task's slot. Tear down or reconcile that record before spawning; no slot was requested.
HEAD: REFUSED: task A's recorded worktree .../4/proj was reassigned to task D (home <other-home>); preserving the slot and task records - not even --force authorizes touching another task's work.
- Outcome: 🔧 1 issue found → auto-fixed ✅ across 2 runs (22m7s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 5 issues found → auto-fixed (3) ✅
  • 🚨 bin/fm-wake-lib.sh:1275 - fm_treehouse_collect_states puts record_state in place of the invoking home's own state dir. The fm-teardown.sh helper it replaced (collect_local_firstmate_states) scanned record_state in addition to every home's state/. The two differ in forced secondmate teardown: preflight_descendant_treehouse_slots (bin/fm-teardown.sh:2684) calls require_exclusive_worktree_slot_record with record_state=<secondmate-home>/state while FM_HOME is still the parent P. The P iteration then scans the secondmate's state instead of P/state. When the loop later reaches the secondmate home, its state is already known, so it hits continue and skips that home's own secondmates.md registry too. P's own task records are never checked for a slot collision. Concrete path: secondmate child task Y (pre-upgrade, process lease) lands but is never torn down. Its slot is reissued to P's crewmate X. The captain runs fm-teardown.sh &lt;secondmate&gt; --force. Slot-owner claims only exist since 2026-09-12 (fix(teardown): leave a Treehouse pool slot reassigned to another task untouched #4243), so a pre-claim slot reads absent and the record scan is its only protection. The old code found X's record in P/state and refused. The new code passes, and cleanup_firstmate_home_children then kills X's worker and resets and returns X's slot, which is exactly the harm this change is meant to prevent. The existing test (tests/fm-secondmate-safety.test.sh test_secondmate_force_teardown_refuses_duplicated_child_slot) puts both colliding records in the secondmate home, so it doesn't catch this. Fix: always scan each home's own state/ and add record_state as one more state, as the old helper did (seed TREEHOUSE_OWNER_STATES with record_state rather than substituting it). Add a forced-secondmate case whose colliding record sits in the parent's own state.
  • ⚠️ bin/fm-spawn.sh:3283 - The crewmate slot is now taken with treehouse get --lease, which survives the shell and the window. Any spawn failure after that line leaves the lease held forever with nothing to return it. Examples: the 60s wait-loop timeout, validate_spawn_worktree, a claim refusal, freshen_spawn_worktree_base, or later pre-publication exits. The EXIT handler (bin/fm-spawn.sh:1068-1077) even drops the task's claim while the lock is held, leaving a leased slot with no claim and no meta. No reconciliation command exists (the new error messages say 'reconcile' but name no tool), teardown can't target it with no record, and treehouse never reissues or prunes a leased slot. So every failed spawn permanently removes a pool copy until someone runs a manual treehouse return --if-lease-holder firstmate:&lt;home&gt;:&lt;id&gt;. Before this change the plain process lease ended when the aborted window died. Remedy options, both needing authorization because they add lifecycle behavior: return the lease with --if-lease-holder in the abort handler while the project lock is held and no worker was launched, or ship an explicit reconcile command and print the holder label in the abort message.
  • ⚠️ bin/fm-home-seed.sh:396 - Intent chore: initialize no-mistakes gate #1 says: "Refuse to re-issue a pool slot while any state/*.meta ... still records it as worktree=". acquire_treehouse_home is a second allocation path on FM_ROOT's pool: treehouse get --lease --lease-holder &#34;$id&#34; for secondmate homes. It takes neither the Treehouse project lock nor fm_treehouse_require_reserved_records. A crewmate task spawned before this upgrade on the Firstmate root project records a process-only slot. Once its worker exits, seeding a new secondmate can lease and reset that slot even though the stale record still names it. That is the reported reissuance class, reachable on this sibling path during migration. Teardown's record scan would then refuse the stale task, but the reissue and reset of its copy already happened. Remedy: run the same preflight under the project lock before this get. Needs confirmation because it can block secondmate creation.
  • ℹ️ bin/fm-spawn.sh:1075 - The abort-path warning and its comment (lines 1061-1067, 1075) still say an orphaned claim is left 'for the next spawn's atomic replacement' / 'the next spawn's claim replaces it'. Neither is true now. fm_treehouse_slot_owner_claim refuses a surviving claim that names another task, and the durable lease means the next spawn never receives this slot. Reword the warning so operators aren't told the state will fix itself.
  • ℹ️ bin/fm-wake-lib.sh:1360 - Rollout note, consistent with the stated intent: after this lands, any in-flight task spawned before the upgrade holds only a process lease. Each such record now makes fm_treehouse_require_reserved_records refuse every new non-orca crewmate spawn in that project (and projects sharing its origin), including while that task's worker is still live and legitimate. Spawns resume only after each such task is torn down. Also, the new scan runs from the spawn path, so a missing registered local secondmate home, or a symlinked or unreadable *.meta anywhere in the local tree, now fails every crewmate spawn closed instead of only teardown.

🔧 Fix applied.
2 warnings still open:

  • ⚠️ bin/fm-wake-lib.sh:1325 - The lease model added in this change makes jq a hard requirement on the tmux spawn path, but fm_backend_required_tools still lists only tmux treehouse for tmux (bin/fm-backend.sh:313). The docs say tmux needs jq only for crew-dispatch, and at base the only jq call in fm-spawn sat behind the optional config/launch-env-allowlist. On a supported tmux host without jq, three things happen. (1) fm_treehouse_require_reserved_records gets a non-zero exit from fm_treehouse_slot_registered (a missing jq looks the same as "not a slot") and continues, so the legacy-record preflight passes vacuously. This includes fm-home-seed's new preflight, so seeding a secondmate there can still reissue a Firstmate slot that a stale process-only record names, which is the exact class intent chore: initialize no-mistakes gate #1 forbids. (2) Each crewmate spawn into a pool slot then fails at fm_treehouse_slot_owner_claim, because fm_treehouse_slot_lease fails. (3) spawn_return_aborted_lease also calls fm_treehouse_slot_lease and treats its failure as || return 0, so it silently skips the return, with no warning. Every retry therefore leaves another durable lease stranded until the pool is exhausted. Remedy: declare jq for the Treehouse-backed tmux backend in fm_backend_required_tools, so bootstrap reports MISSING: jq. Also make fm_treehouse_slot_registered, fm_treehouse_slot_lease and spawn_return_aborted_lease fail closed and loudly when jq is unavailable, instead of reading that as "not a slot" or "not our lease".
  • ⚠️ bin/fm-spawn.sh:1086 - The intent asks for the abort handler to return the lease on every locked, pre-publication abort, explicitly including the 60s wait-loop timeout. The fix finds the slot to return through ${WT:-${last_seen:-}}, the path the tmux pane reports, not the slot Treehouse actually leased to SPAWN_LEASE_HOLDER. The tmux abort path never kills the task window (only orca's terminal is killed), and the header comment itself documents that pane_current_path can stay stale on some tmux/WSL hosts. Concrete sequences: (a) the pane shell's treehouse get --lease (which fetches origin first by default) has not finished at 60s. last_seen is still the project directory, so spawn_return_aborted_lease bails at fm_treehouse_pool_slot, the lock is released, and the get then completes and takes a durable lease that no code returns. (b) The get completed and cd'd into the slot, but the pane keeps reporting a stale path. On timeout, last_seen is that stale path; if two stale reads agree, it becomes WT, the claim refuses because the holder does not match, and the holder check in spawn_return_aborted_lease skips the return. Either way the task's real lease on the other slot stays leased forever, the pre-fix property that an aborted spawn's slot dies with it is lost, and pool capacity shrinks until someone runs a manual treehouse return. Remedy, within the round's authorized scope: resolve the slot from Treehouse's own lease record, not from the pane's path. For example, look up the pool's treehouse-state.json entry whose lease_holder equals SPAWN_LEASE_HOLDER, or have the pane command write $fm_slot to the task temp dir and read it on abort. Then return that slot with --if-lease-holder. Sub-case (a) additionally needs the in-flight get stopped or awaited before the lock is released; if that is not done, name it in the PR body alongside the post-lock gap.

🔧 Fix applied.
2 issues (1 error, 1 warning) still open:

  • 🚨 bin/fm-wake-lib.sh:1361 - The new lease model depends on Treehouse ≥ v2.1.0, but nothing declares that. Four new call paths need 2.1.0 features: the lease_id field that fm_treehouse_slot_lease requires (wake-lib:1361), treehouse status --json in spawn_return_aborted_lease (fm-spawn.sh:971), and return --if-lease-holder / --if-lease-id (fm-spawn.sh:979, fm-teardown.sh:1574). All four arrived in treehouse v2.1.0 (upstream commit e914cca, "add stable lease identities"). v2.0.1's status has no --json flag and its return has only --force. Bootstrap's gate treehouse_supports_lease (bin/fm-bootstrap.sh:920) only checks that get --help mentions --lease, which has been true since 1.8.0. CI's real-Herdr lane still installs the pinned FM_TREEHOUSE_CI_VERSION=2.0.1 (bin/fm-install-treehouse.sh:15), and tests/fm-backend-herdr-workspace-per-home-e2e.test.sh drives the real bin/fm-spawn.sh with that treehouse. Concrete sequence on any treehouse 1.8.0–2.0.x host that bootstrap accepts: the pane's treehouse get --lease --lease-holder H records leased=true with no lease_id. fm_treehouse_slot_owner_claim then fails, so every pool-slot crewmate spawn aborts with "could not claim Treehouse pool slot". The abort handler's treehouse status --json exits with an unknown-flag error, so it only warns, and the durable lease just taken is never returned. Every retry leaks another permanently leased slot. Remedy: make bootstrap probe the capability actually used, for example treehouse return --help listing --if-lease-id (or a version floor of 2.1.0), and report MISSING/incompatible treehouse otherwise. Bump the CI pin to a release ≥ 2.1.0 with its checksums, and document the floor.
  • ⚠️ bin/fm-wake-lib.sh:1404 - fm_treehouse_require_reserved_records uses fm_treehouse_slot_lease to decide whether a recorded slot is "durably reserved". That helper only accepts entries with leased == true AND a non-empty lease_id. Treehouse's own v2.1.0 notes say leases taken before lease identities existed load with an empty lease_id until they are released and re-acquired, but they are still durable: get skips them and prune leaves them. Concrete sequence: a secondmate home was seeded by fm-home-seed (get --lease --lease-holder &lt;id&gt;) under treehouse 1.8–2.0, and treehouse was later upgraded. That secondmate's meta records home=/worktree= as a registered slot in FM_ROOT's pool with leased=true, lease_id=&#34;&#34;. From then on, every crewmate spawn into the Firstmate project, and every new fm-home-seed.sh &lt;id&gt; -, refuses with "still records home=... without a durable Treehouse lease ... Tear down or reconcile that record". That tells the operator to tear down a live, correctly reserved secondmate home. I found no such lease in this host's current pools, so this is an upgrade-path sequence, not observed state. Remedy: in the preflight, test only reservation (leased == true on the exact registered path entry), keeping the identity-requiring fm_treehouse_slot_lease for claim binding and teardown, where lease_id is actually needed.

🔧 Fix applied.
✅ Re-checked - no issues remain.

🔧 **Test** - 1 issue found → auto-fixed ✅
  • ⚠️ tests/fm-backend-herdr-workspace-per-home-e2e.test.sh:277 - The real-herdr e2e suite failed at teardown with 'REFUSED: task cm1's recorded worktree ... was reassigned to task cm1 (home …/primary-home)'. The suite spawns with FM_HOME=<home> but called fm-teardown.sh with only FM_STATE_OVERRIDE, so FM_HOME defaulted to the repo root. The change now matches the claim's home against $FM_HOME; the base commit only reported the home. Every production caller sets FM_HOME (bin/backends/herdr.sh:63), so this is a test-invocation bug, not a product regression. I fixed it by passing the spawning FM_HOME to both teardown calls, and the suite now passes 10/10 live. Side note: when only the home differs, the refusal still says 'reassigned to task cm1', the same task id, which misleads.
  • Live validation: ✅ go - 7 of 10 scenarios driven live against the product
Scenario Result Live Evidence
A crewmate spawned into a Treehouse pool gets a durable lease under holder firstmate:<home>:<id>, and its slot claim records that exact lease_id ✅ pass live live-slot-ownership-transcript.txt, scenario A: status=leased, holder firstmate:$T/primary-home:t-alpha, claim lease_id equals Treehouse lease_id
After a task's worker exits without teardown, its slot stays leased and the next spawn gets a different slot ✅ pass live live-slot-ownership-transcript.txt, scenario B: slot 1 still leased to t-alpha with 0 processes; t-beta got slot 2
Reported incident: a secondmate's landed, never-torn-down record names a process-free slot; the new spawn refuses before any slot is requested, and the pool is unchanged (the base code reissues that s… ✅ pass live live-slot-ownership-transcript.txt, scenario C: new-code REFUSED naming the stale record in the secondmate home, treehouse state byte-identical; base-code spawn handed the same slot to th…
Tearing down the stale record whose slot now belongs to another task refuses, with and without --force; the successor's worker, unlanded file, HEAD/branch, claim and both records survive ✅ pass live live-slot-ownership-transcript.txt, scenario D: both runs exit 1 reporting the slot as reassigned to the successor task; worker pids unchanged; successor-work.txt present
Tearing down the slot's real owner still succeeds, returns exactly its lease via --if-lease-id, closes its pane and leaves the other task's lease alone ✅ pass live live-slot-ownership-transcript.txt, scenario E: t-beta slot back to available, t-alpha still leased; then t-alpha's forgotten record also tears down cleanly
A spawn that aborts after Treehouse leased it a slot (claim fails) returns that lease, found by holder, and publishes no record ✅ pass live live-slot-ownership-transcript.txt, scenario F: 'could not claim Treehouse pool slot', slot available again, no lease under firstmate:...:t-zeta
The repo's real-herdr e2e lane (spawn in primary and secondmate homes, then teardown) still passes on the lease model ✅ pass live herdr-e2e-after-fix.log (10/10 ok); it failed before I added FM_HOME to its teardown calls, see finding herdr-e2e-teardown-missing-fm-home
fm-home-seed.sh refuses to lease a Firstmate slot while a stale record names it unleased, and refuses without jq ⏸️ untested no fm-home-seed leases from FM_ROOT's pool, which here is the operator's real Firstmate pool under ~/.treehouse, outside the worktree. Driving it live would modify real lease state. To drive it: point FM…
Bootstrap reports treehouse MISSING when the installed Treehouse is older than v2.1.0 ⏸️ untested no Only Treehouse v2.3.0 is installed, and installing an older release is outside this step's allowed scope. Needs a host or container with Treehouse 2.0.x on PATH.
A pre-identity lease (leased=true, no lease_id) still counts as reserved in the spawn preflight ⏸️ untested no Treehouse 2.3.0 always mints a lease_id. Creating a real pre-identity lease needs a lease taken with Treehouse <2.1.0 and then an upgrade.
  • bash ~/.no-mistakes/evidence/01M2DC3SR16QBK16VWJ577KM1Y/live-slot-ownership-driver.sh: real fm-spawn.sh and fm-teardown.sh on the herdr backend (isolated fm-lab-* session), real Treehouse v2.3.0 with a scratch pool root, base commit ecfe0719 exported read-only for contrast; 42/42 checks passed
  • TREEHOUSE_ROOT=&lt;tmp&gt; bash tests/fm-backend-herdr-workspace-per-home-e2e.test.sh before the fix: failed at cm1 teardown (home-mismatch refusal)
  • TREEHOUSE_ROOT=&lt;tmp&gt; bash tests/fm-backend-herdr-workspace-per-home-e2e.test.sh after passing FM_HOME to its teardown calls: 10/10 ok
  • bash tests/fm-spawn-pool-base-freshen.test.sh (26 ok)
  • bash tests/fm-teardown-endpoint-safety.test.sh (18 ok)
  • bash tests/fm-secondmate-safety.test.sh (79 ok)
  • bash tests/fm-bootstrap.test.sh (28 ok)
  • Probed real treehouse get --lease --lease-holder, status --json, return --if-lease-holder in a scratch repo to confirm the state-file layout and JSON fields the lease helpers read

🔧 Fix applied.
✅ Re-checked - no issues remain.

  • Live validation: ✅ go - 9 of 10 scenarios driven live against the product
Scenario Result Live Evidence
Stale but unreissued slot: task A's worker exits without teardown, and the next spawn B is given a different slot while A's slot stays leased to A ✅ pass live live-slot-ownership-head.log S2 (B got slot 2; A's slot 1 stayed leased by firstmate:<home>:A with 0 processes). live-slot-ownership-base.log shows base ecfe071 reissuing slot 1 to B, the reported bu…
Reported legacy case: a pre-fix record in a registered secondmate home names a free, unleased slot, so a new spawn refuses before any slot is requested and leaves the slot's work and the pool state un… ✅ pass live live-slot-ownership-head.log S3: REFUSED naming secondmate-home/state/legacy.meta; 'no slot was requested'; treehouse-state.json unchanged byte for byte; the unlanded file and HEAD are intact; no C me…
Guard is not a blanket refusal: once the stale record is reconciled, the same spawn succeeds and durably leases the slot to the new task ✅ pass live live-slot-ownership-head.log S3-control (C leased slot 3 under holder firstmate:<home>:C)
New spawn binds the durable Treehouse lease to the task: the holder is firstmate:<home>:<id>, and the claim file records task, home and Treehouse's lease_id ✅ pass live live-slot-ownership-head.log S1 (claim file contents and status --json output shown)
Teardown of a stale record whose slot now belongs to a live task from another home refuses even with --force, and the other task's worker, uncommitted file and lease survive ✅ pass live live-slot-ownership-head.log S4: 'REFUSED: task A's recorded worktree .../4/proj was reassigned to task D ... not even --force'; D's slot still has 2 processes and D-WORK.txt, lease still firstmate:<o…
Adversarial lease swap: the task's claim still names it, but its Treehouse lease was returned by hand and re-leased to 'drydock'; teardown --force refuses and drydock's work and lease survive ✅ pass live live-slot-ownership-head.log S5: 'REFUSED: ... no longer holds its Treehouse lease <old id> (current lease: <new id> drydock)'
Normal teardown of a task that still owns its slot returns the lease, removes the claim and removes the record (primary home and an unregistered other home) ✅ pass live live-slot-ownership-head.log S6 and S6b (A, B, C and D torn down with rc 0; slots back to 'available'). herdr-e2e.log also covers primary and secondmate-home teardown
Spawn aborted while holding the allocation lock (slot claimed by another task) returns the lease it took, found through Treehouse's own holder record, and leaves the foreign claim intact ✅ pass live live-slot-ownership-head.log S7: F aborts with 'could not claim Treehouse pool slot'; no lease remains under F's holder; task=ghost claim intact
Home seeding refuses to lease a Firstmate slot that a stale unleased record names, and refuses loudly when jq is missing ⏸️ untested no The prior payload did not establish a live result: this scenario was only exercised through the repo's fake-tmux/fake-treehouse test (tests/fm-secondmate-safety.test.sh). A live run needs a disposable…
The CI Treehouse pin bump installs v2.3.0 with a matching checksum, and that binary exposes the --if-lease-id capability bootstrap now probes ✅ pass live bash bin/fm-install-treehouse.sh &lt;tmp&gt;: installed treehouse v2.3.0; return --help lists --if-lease-holder and --if-lease-id
  • bash tests/fm-backend-herdr-workspace-per-home-e2e.test.sh (real herdr + real treehouse v2.3.0 spawn/teardown, 10/10)
  • bash tests/fm-spawn-pool-base-freshen.test.sh (includes test_recorded_slot_blocks_reissue_before_get, test_pre_identity_lease_counts_as_reserved, test_aborted_spawn_returns_the_lease_treehouse_recorded)
  • bash tests/fm-teardown-endpoint-safety.test.sh (includes test_reassigned_pool_slot_refuses_without_touching_either_task)
  • bash tests/fm-secondmate-safety.test.sh (includes test_home_seed_refuses_recorded_unleased_firstmate_slot incl. no-jq mode, test_secondmate_force_teardown_refuses_child_slot_recorded_by_parent)
  • bash live-slot-ownership-driver.sh &lt;worktree&gt; head: live S1-S7 against real fm-spawn/fm-teardown, herdr lab session, treehouse v2.3.0 in isolated TREEHOUSE_ROOT (33/33 PASS)
  • bash live-slot-ownership-driver.sh &lt;git archive of ecfe0719&gt; base: before-fix reproduction; B reissued A's still-recorded slot
  • bash bin/fm-install-treehouse.sh &lt;tmpdir&gt;: downloads the pinned v2.3.0, verifies its sha256 and version, and checks that return --help lists --if-lease-id
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…l claims it

fm-spawn's crewmate path now acquires the pool slot through Treehouse's own
durable get --lease --lease-holder rather than the interactive pane's plain
get, and binds the spawn-side owner claim to that lease. Before any get,
fm-spawn refuses when a still-recorded state/*.meta anywhere reachable
(including secondmate homes) names that slot without a durable lease, closing
the reissuance window a landed-but-not-torn-down task record used to leave
open. fm-teardown re-verifies the recorded lease at every destructive
boundary and now refuses outright (never with --force) on a claim naming
another task or a lease that no longer matches, rather than warning and
finishing only its own cleanup, per the requirement to refuse otherwise.

fm_treehouse_require_reserved_records only enforces the lease requirement for
paths structurally registered in a treehouse-state.json, so an ordinary
worktree recorded incidentally against the same project is never mistaken
for a pool slot.
Slot ownership now binds a task id to its canonical home, so teardown must run
with the FM_HOME the task was spawned from. The launcher-workspace e2e spawns
dupC from the primary home but tore it down with only FM_ROOT_OVERRIDE set, so
teardown resolved the repository root as its home and refused the slot's own
claim as another task's.
The task pane of an aborted spawn is now a lone idle shell, so cleanup removes it
through Herdr's pane-death path, which logs no pane.close. The order check only
looked for pane.close on the task pane and saw no close at all. Count any
pane.close inside the task's own projected workspace, the seeded pane's prune
included, so the create-then-close serialization is still asserted for both
aborts.
The pane's own shell used to cd into the leased slot, so teardown's reap of
processes under the slot ended the endpoint shell itself. Herdr then removed
the pane and its workspace on its own, ahead of the focus-preserving close, and
the active workspace jumped. Run the worker in a child shell inside the slot,
as the interactive treehouse get subshell did, so the endpoint shell stays in
the project.
A claim naming another task is never overwritten by a later spawn, so the
restart fixtures, which return their leased slots with treehouse directly
instead of through teardown, left a stale claim behind. The next fixture then
received that slot and its spawn refused to claim it. Return the lease and drop
the claim together, as reconciling such a slot by hand does.
@MLA82
MLA82 force-pushed the fm/treehouse-slot-neuvergabe-trotz-meta branch from ef58458 to d653e4a Compare September 20, 2026 19:36
MLA82 added a commit to MLA82/firstmate that referenced this pull request Sep 28, 2026
…guid#4366 and PR kunchenguid#4683

- tests/fm-control-relaunch.test.sh: read the whole recorded launch command
  instead of the retired inline 'encode launch-brief' grep shape (needed by
  PR kunchenguid#5288's own new test).
- tests/fm-backend-herdr-launcher-workspace-e2e.test.sh: pass FM_HOME to the
  teardown call explicitly, kept as a precaution.

Dropped: the 10s->20s Herdr server poll-budget widening in
bin/backends/herdr.sh. It was PR kunchenguid#4683's own fix for its own setsid-wrapped
server launch; without kunchenguid#4683, bin/backends/herdr.sh reverts to the original,
unmodified 10s poll and needs no widening.
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