Repository navigation
Conversation
…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.
…ease-identity floor
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
force-pushed
the
fm/treehouse-slot-neuvergabe-trotz-meta
branch
from
September 20, 2026 19:36
ef58458 to
d653e4a
Compare
Closed
2 of 3 tasks
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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'sstate/<id>.meta- including one in a secondmate home - still records that same slot as itsworktree=. This typically happens for a task whose work already landed but which was never torn down.Consequence:
bin/fm-teardown.shstops 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:
What Changed
bin/fm-spawn.sh) and secondmate home seeding (bin/fm-home-seed.sh) now take a durabletreehouse get --lease --lease-holder firstmate:<home>:<id>. The old process-onlytreehouse getlost its lease once the worker exited. Before theget, still under the shared Treehouse project lock, the newfm_treehouse_require_reserved_recordsinbin/fm-wake-lib.shwalks every reachable local home: the root, the parent chain, registered secondmates, and secondmate.metafiles not yet in a registry. The spawn is refused if anystate/*.metarecords aworktree=/home=in that pool without a durable lease. The slot-owner claim (.fm-slot-owner) now also stores the lease'slease_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.bin/fm-teardown.shno 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--forcedoesn't override this. The ownership check runs again before the process reap, the branch reset, and every return, which is nowtreehouse 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 sharedfm_treehouse_collect_states.treehouse return --helplists--if-lease-id. The CI installer is pinned to v2.3.0, andjqis now required for thetmuxbackend too.docs/architecture.md,docs/configuration.mdand 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 beforeget, locally and in secondmate homes, and teardown of a reassigned slot refuses and leaves both tasks intact.Risk Assessment
status --jsonshape, 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-safetyandfm-secondmate-safetytest 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 isolatedTREEHOUSE_ROOTpool 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.bash bin/fm-install-treehouse.sh <tmp>: installed treehouse v2.3.0; return --help lists --if-lease-holder and --if-lease-idEvidence: 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)
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
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
Evidence: Real-herdr e2e suite run (10/10)
Source: Real-herdr e2e suite run (10/10)
Evidence: Before/after reissue excerpt
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 hitscontinueand 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 runsfm-teardown.sh <secondmate> --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 readsabsentand 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 withtreehouse 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 manualtreehouse return --if-lease-holder firstmate:<home>:<id>. 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 "$id"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 makesjqa hard requirement on the tmux spawn path, butfm_backend_required_toolsstill lists onlytmux treehousefor tmux (bin/fm-backend.sh:313). The docs say tmux needsjqonly for crew-dispatch, and at base the onlyjqcall in fm-spawn sat behind the optionalconfig/launch-env-allowlist. On a supported tmux host withoutjq, three things happen. (1)fm_treehouse_require_reserved_recordsgets a non-zero exit fromfm_treehouse_slot_registered(a missingjqlooks the same as "not a slot") andcontinues, 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 atfm_treehouse_slot_owner_claim, becausefm_treehouse_slot_leasefails. (3)spawn_return_aborted_leasealso callsfm_treehouse_slot_leaseand 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: declarejqfor the Treehouse-backed tmux backend infm_backend_required_tools, so bootstrap reports MISSING: jq. Also makefm_treehouse_slot_registered,fm_treehouse_slot_leaseandspawn_return_aborted_leasefail closed and loudly whenjqis 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 toSPAWN_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'streehouse get --lease(which fetches origin first by default) has not finished at 60s.last_seenis still the project directory, sospawn_return_aborted_leasebails atfm_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_seenis that stale path; if two stale reads agree, it becomesWT, the claim refuses because the holder does not match, and the holder check inspawn_return_aborted_leaseskips 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 manualtreehouse 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'streehouse-state.jsonentry whoselease_holderequalsSPAWN_LEASE_HOLDER, or have the pane command write$fm_slotto 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: thelease_idfield thatfm_treehouse_slot_leaserequires (wake-lib:1361),treehouse status --jsoninspawn_return_aborted_lease(fm-spawn.sh:971), andreturn --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'sstatushas no--jsonflag and itsreturnhas only--force. Bootstrap's gatetreehouse_supports_lease(bin/fm-bootstrap.sh:920) only checks thatget --helpmentions--lease, which has been true since 1.8.0. CI's real-Herdr lane still installs the pinnedFM_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'streehouse get --lease --lease-holder Hrecordsleased=truewith nolease_id.fm_treehouse_slot_owner_claimthen fails, so every pool-slot crewmate spawn aborts with "could not claim Treehouse pool slot". The abort handler'streehouse status --jsonexits 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 exampletreehouse return --helplisting--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_recordsusesfm_treehouse_slot_leaseto decide whether a recorded slot is "durably reserved". That helper only accepts entries withleased == trueAND a non-emptylease_id. Treehouse's own v2.1.0 notes say leases taken before lease identities existed load with an emptylease_iduntil they are released and re-acquired, but they are still durable:getskips them andpruneleaves them. Concrete sequence: a secondmate home was seeded by fm-home-seed (get --lease --lease-holder <id>) under treehouse 1.8–2.0, and treehouse was later upgraded. That secondmate's meta recordshome=/worktree=as a registered slot in FM_ROOT's pool withleased=true, lease_id="". From then on, every crewmate spawn into the Firstmate project, and every newfm-home-seed.sh <id> -, 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 == trueon the exact registered path entry), keeping the identity-requiringfm_treehouse_slot_leasefor claim binding and teardown, wherelease_idis 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.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 passedTREEHOUSE_ROOT=<tmp> bash tests/fm-backend-herdr-workspace-per-home-e2e.test.shbefore the fix: failed at cm1 teardown (home-mismatch refusal)TREEHOUSE_ROOT=<tmp> bash tests/fm-backend-herdr-workspace-per-home-e2e.test.shafter passing FM_HOME to its teardown calls: 10/10 okbash 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 realtreehouse get --lease --lease-holder,status --json,return --if-lease-holderin a scratch repo to confirm the state-file layout and JSON fields the lease helpers read🔧 Fix applied.
✅ Re-checked - no issues remain.
bash bin/fm-install-treehouse.sh <tmp>: installed treehouse v2.3.0; return --help lists --if-lease-holder and --if-lease-idbash 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 <worktree> 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 <git archive of ecfe0719> base: before-fix reproduction; B reissued A's still-recorded slotbash bin/fm-install-treehouse.sh <tmpdir>: downloads the pinned v2.3.0, verifies its sha256 and version, and checks thatreturn --helplists --if-lease-id✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.