Repository navigation
fix: reserve Treehouse pool copies until explicit task cleanup - #32
Merged
Merged
Conversation
A record from before durable leases may relaunch into its own claimed, unleased copy; fresh-spawn preflight already keeps that copy out of allocation. A cleanup re-run after an earlier run returned the copy and then failed retires records only instead of refusing forever.
…al recovery assertions
…es for durable leases, distinct copies, and ownership claims. Targeted regressions and fast lint pass. Live Herdr verification remains blocked by its reference-session prerequisite; the full secondmate safety suite hit temporary-disk limits
…rktree-record-clash-fix-c2 # Conflicts: # tests/fm-backend-herdr-presentation-e2e.test.sh
Brings the branch to the validated pipeline tree: Herdr and child-cleanup fixture repairs, missing-copy and unrecognized-slot recovery handling, empty record fields treated as absent, and refreshed lease documentation.
Durable leases now keep a copy reserved while its record exists, and a Treehouse return terminates processes in the copy. The orphan fixture returned its copy mid-suite, killing the restored husk shell the reclaim under test must find. Retire only the acquisition journal, keep the record for the reclaim, and clear stale slot claims when the suite returns copies whose records are already torn down.
added 2 commits
October 22, 2026 18:17
…Check diagnostics, and moved Herdr pane closure before process reaping and pool return. Targeted regressions and lint pass. Full cleanup verification remains limited by missing lsof
… remote worker tree before deleting fixtures. Added a regression that failed before the fix and now passes. The full public-followup suite passes with an isolated TMPDIR; lint and diff checks pass
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
Keep each pool copy reserved while a task record names it (worktree record clash fix).
The diagnosis (2026-10-22) found that ordinary ship and scout spawns use interactive
treehouse get, whose reservation lasts only as long as its processes, while Firstmate keeps task records until explicit cleanup. An idle or exited task can leave a valid-lookingworktree=record after its slot becomes reusable; the next spawn overwrites.fm-slot-ownerand publishes the same path under a different task. Today pv-voice-reliability-program-p1 is the stale record and pv-typed-caller-repair-t1 owns slot 9. The report designs the fix: keep each pool copy reserved for as long as a task record names it, plus the safe teardown path for an existing clash.The report's fix design, in substance: use Treehouse's existing durable lease contract for ordinary Treehouse-backed ships and scouts (no new pool service, no Treehouse change). Before acquisition, under the project lock, inspect retained task records in this home and registered local homes; a referenced pool copy without a verified matching durable lease refuses before
getis invoked (a post-get scan is too late because get resets the copy), and "free" is never inferred from done status, an empty endpoint, or clean Git state. Acquire withtreehouse get --lease --lease-holder <home/task/acquisition identity> --json, persist the path, lease id and holder, keep isolation and freshness checks, recheck record exclusivity before claiming/publishing, and never overwrite a conflicting claim. Keep the lease through worker exit, finished status and relaunch until explicit teardown; the holder binds home plus task plus acquisition, not spawn_gen; relaunch takes the project lock and validates lease/claim and exclusive record ownership before any endpoint or wiring mutation, refusing a stale record. Release through identity-conditionaltreehouse return --if-lease-id --if-lease-holderafter the normal completion and landed-work gates, validating ownership before any process reaping, hook/branch/scratch edits or return; keep records and lease on unknown failures; a spawn abort keeps a durable recovery record of a newly acquired lease. For existing duplicate records keep the records-only route for a stale record whose slot claim names another task, refuse owner-first cleanup while another record still names the copy and say which stale task to reconcile first, and never touch the successor's copy, processes, claim or lease. Do not weaken the shared-copy teardown refusal or the slot-owner marker protection. The CI Treehouse pin must support the required flags. Prove the behaviour with offline tests using a mock treehouse (never realtreehouse statusor teardown): reserved slot skipped on spawn, reservation released at cleanup, existing clash resolved by the safe teardown path without touching the successor's copy.Q1178 C 2026-10-22 ("q1178 C but instead of gpt-6.1-sol xhigh use astra medium"): diagnosis on gpt-6-astra medium, code on gpt-6.1-sol high, Claude Opus checks.
Q1180 A 2026-10-22 ("q1180 A"): firstmate-repo PRs go to the fork peterOC26/firstmate.
What Changed
Risk Assessment
✅ Low: The latest fix round only adds REFUSED diagnostics before existing
return 1exits infm_treehouse_record_exclusiveandfm_treehouse_records_reserved, plus a behavioural test; the control flow is unchanged, and the earlier fixes (shared lease-CLI gate in bootstrap, the state-directory refusal, the never-acquired and orphan-claim recovery steps) check out against the current code.Testing
Five focused scripts passed after correcting temporary-fixture placement; ten real CLI scenarios passed after correcting one driver assertion. Transcripts demonstrate refusal, reconciliation and preservation behavior. Full live lease mutations and descendant teardown remain unverified under the accepted boundaries; no source changes remain.
Evidence: Live CLI guards and stale-record cleanup
Source: Live CLI guards and stale-record cleanup
Evidence: Validation report with results and limitations
Source: Validation report with results and limitations
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 4 issues found → auto-fixed (2) ✅
bin/fm-spawn.sh:5033- Iftreehouse get --lease --jsonfails, every later spawn for that project is refused, and the printed recovery steps have no path for the most likely outcome. How it happens: Treehouse v2.3.0 fetches origin before it acquires a copy (its ownget --helpsays so). An offline host or a remote outage therefore makesgetexit non-zero after the journal'sidentitywas written (fm-spawn.sh:5032), leavingallocation.jsonempty. spawn_abort_cleanup keeps the journal. From then on,fm_treehouse_records_reservedrefuses every spawn for that project with "unresolved Treehouse acquisition journal" (fm-wake-lib.sh:1874-1876), and a retry of the same task id is refused at fm-spawn.sh:3586-3590. The recovery steps (fm-spawn.sh:1486-1491) only describe recovering a lease that exists in pool state. When no pool entry carries the recorded holder (the normal result of a fetch failure), no step lets the operator retire the journal, so they have to improvise anrm -rfof it. At base, a failedgetjust failed that one spawn. The fix needs a policy decision: what evidence proves the acquisition never happened (for example, notreehouse-state.jsonentry carries the recorded holder) and so allows the journal to be removed. That is a new evidence rule for retiring a journal, so the remedy needs authorization.bin/fm-spawn.sh:5052- A slot claim left behind by the old code makes the new spawn take a durable lease and then strand it, with no documented way out. The base code knowingly left claims behind: an abort after the project lock was released "leaves the claim for the next spawn's atomic replacement" (removed base comment in spawn_abort_cleanup), so after an upgrade some free pool slots still carry a.fm-slot-ownernaming a task that no record describes. Preflight passes, because no record names that copy.get --leasecan then hand out such a slot. The spawn finds a non-absent claim and refuses (fm-spawn.sh:5050-5053; the same check again at :5125-5129) while keeping both the durable lease and the journal. That copy stays out of the pool, retries of the same task id are blocked, and the recovery text says "Stop if another task owns the claim or lease" (fm-spawn.sh:1487). The text never says how to confirm a claim is orphaned or how to clear it, so each leftover claim costs one slot and one task id until someone improvises a manual cleanup. The intent forbids overwriting a conflicting claim, so the refusal itself is correct. A remedy needs authorization: a documented rule for treating a claim as orphaned (no local record anywhere names that task and home) and returning this acquisition's own lease.bin/fm-wake-lib.sh:1697- Spawn and teardown now require the full Treehouse lease CLI (get --lease --lease-holder --jsonplusreturn --if-lease-id --if-lease-holder, checked by fm_treehouse_lease_cli and enforced at fm-spawn.sh:3817 and fm-teardown.sh require_owned_worktree_slot_record). The bootstrap check that tells the operator to upgrade still looks only for--lease(bin/fm-bootstrap.sh:906-908, used at :1472-1475). An install of Treehouse 2.0.1 (the previous CI pin, which already supported--leasefor home seeding) passes bootstrap with no MISSING line. Every ship and scout dispatch then fails at spawn, and teardown of a leased task refuses. Fix: havetreehouse_supports_leasecheck the same flag set as fm_treehouse_lease_cli (or call it), so bootstrap reportsMISSING: treehousebefore anything is dispatched.bin/fm-wake-lib.sh:1816-fm_treehouse_records_reservedandfm_treehouse_record_exclusive(fm-wake-lib.sh:1895) return 1 without printing anything when a local state dir is missing or unreadable. That dir can be the root home's or a registered secondmate home'sstate/. The fresh spawn (fm-spawn.sh:3592) and the relaunch (fm-spawn.sh:3584) then exit 1 with no explanation. The sibling capacity scan (fm-project-capacity-lib.sh:190-193) treats a missing state dir as empty and names an unreadable one. Fix: print a REFUSED line naming the directory before returning, matching the other refusals in these functions.🔧 Fix applied.
3 issues (1 warning, 2 infos) still open:
bin/fm-wake-lib.sh:1697- Spawn and teardown now require the full Treehouse lease CLI (get --lease --lease-holder --jsonplusreturn --if-lease-id --if-lease-holder, checked by fm_treehouse_lease_cli and enforced at fm-spawn.sh:3817 and fm-teardown.sh require_owned_worktree_slot_record). The bootstrap check that tells the operator to upgrade still looks only for--lease(bin/fm-bootstrap.sh:906-908, used at :1472-1475). An install of Treehouse 2.0.1 (the previous CI pin, which already supported--leasefor home seeding) passes bootstrap with no MISSING line. Every ship and scout dispatch then fails at spawn, and teardown of a leased task refuses. Fix: havetreehouse_supports_leasecheck the same flag set as fm_treehouse_lease_cli (or call it), so bootstrap reportsMISSING: treehousebefore anything is dispatched.bin/fm-wake-lib.sh:1816-fm_treehouse_records_reservedandfm_treehouse_record_exclusive(fm-wake-lib.sh:1895) return 1 without printing anything when a local state dir is missing or unreadable. That dir can be the root home's or a registered secondmate home'sstate/. The fresh spawn (fm-spawn.sh:3592) and the relaunch (fm-spawn.sh:3584) then exit 1 with no explanation. The sibling capacity scan (fm-project-capacity-lib.sh:190-193) treats a missing state dir as empty and names an unreadable one. Fix: print a REFUSED line naming the directory before returning, matching the other refusals in these functions.bin/fm-wake-lib.sh:1897- The round-1 fix for silent-refusal-missing-state-dir added a REFUSED line only for a missing or unreadable state directory. It missed sibling silentreturn 1exits in the same function,fm_treehouse_record_exclusive: the local-home registry walk failing at fm-wake-lib.sh:1897 (fm_local_firstmate_state_dirs "$state" || return 1), an ambiguous record at :1905 (fm_treehouse_record_paths_safe "$meta" || return 1), and the slot path failing to resolve at :1896. Its relaunch caller (fm-spawn.sh:3588,|| exit 1) runs no other scan, so these refusals print nothing. Example: a registered secondmate home that was deleted but is still listed in data/secondmates.md sets FM_LOCAL_FIRSTMATE_ERROR="registered local Firstmate home is unavailable". Every Treehouse relaunch in the root home then exits 1 with no explanation. The siblingfm_treehouse_records_reserved(:1811-1813, :1822-1825) already prints REFUSED lines for the same two conditions, and so does teardown'scollect_local_firstmate_states(fm-teardown.sh:2445-2447). Fix: printREFUSED: $FM_LOCAL_FIRSTMATE_ERRORand the 'unreadable or ambiguous task record $meta' line infm_treehouse_record_exclusive, matchingfm_treehouse_records_reserved. The post-get callers (fm-spawn.sh:5052, :5129) benefit from the same change.🔧 Fix applied.
✅ Re-checked - no issues remain.
TMPDIR="$PWD/.test-validation-tmp" FM_TEST_MOCK_LIFECYCLE_ONLY=1 bash bin/fm-test-run.sh --jobs 1 tests/fm-spawn-slot-ownership.test.sh tests/fm-spawn-worktree-settle.test.sh tests/fm-spawn-pool-base-freshen.test.sh tests/fm-teardown-endpoint-safety.test.sh tests/fm-bootstrap.test.shenv -u TMPDIR FM_TEST_MOCK_LIFECYCLE_ONLY=1 bash bin/fm-test-run.sh --jobs 1 tests/fm-spawn-slot-ownership.test.shenv -u TMPDIR FM_TEST_MOCK_LIFECYCLE_ONLY=1 bash bin/fm-test-run.sh --jobs 1 tests/fm-teardown-endpoint-safety.test.shpython3 ~/.no-mistakes/evidence/01M5J1J041ZAMEAPEMVEM4AYB9/live-cli-checks.pypython3 ~/.no-mistakes/evidence/01M5J1J041ZAMEAPEMVEM4AYB9/live-relaunch-checks.pypython3 ~/.no-mistakes/evidence/01M5J1J041ZAMEAPEMVEM4AYB9/live-relaunch-rerun.pytreehouse --version,treehouse get --help, andtreehouse return --helpRemoved disposable homes, stopped private tmux servers, removed test temporary directories, and verified a clean working tree.✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.