Repository navigation
fix(bin): recover aborted Treehouse spawn leases through teardown - #72
Merged
Merged
Conversation
A spawn that aborted after leasing its copy left the lease, slot claim, and acquisition journal behind with no task record. A same-id retry refused the journal, and teardown refused for want of the record, so only manual steps could clean it up. Teardown now accepts a task id that has only that journal. Under the project, control, and spawn locks it returns exactly the journal's lease when the copy is a recognized pool slot no record names, its claim is this task's or absent, no process works inside it, it has no uncommitted change outside generated wiring, and HEAD is on a remote or local main or master. A lease the pool already shows released, or a missing copy that meets the missing-copy rule, retires only this task's claim and the journal. Anything else keeps all three and prints the manual recovery steps; --force relaxes none of it. The spawn refusal and abort warning now name the guarded command.
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
Q2244 ALL (2026-11-18, main chat): "q2244 all. feel free to do whatever you think is the good idea amd is safe" - use the Claude allowance before its reset on three Claude-only jobs.
This job is part of option C: build this held Firstmate fix now, with Claude writing the code.
After a spawn aborts after acquiring its copy lease, the lease, claim and journal stay behind, a retry of the same id is refused, and bin/fm-teardown.sh needs state/.meta, so only manual steps clean it up (follow-up from fm-worktree-record-clash-fix-c2 review finding no-journal-reconciliation-route, 2026-10-22). Wanted: a guarded release path, for example teardown accepting a journal-only id.
What Changed
fm-teardown.sh <id>path that conditionally returns a validated Treehouse lease when the copy is safe, and cleans up the task’s claim and journal when the lease is already released or the copy qualifies for missing-copy retirement. Unsafe cases keep recovery state intact, including with--force.Risk Assessment
✅ Low: The new journal-only release runs under the project, control and spawn locks, re-checks every safety condition, and refuses while keeping the lease, claim and journal whenever any proof is missing; the round-1 fixes (landed check matching record-based teardown, claim drop verified before the journal is removed) are correctly implemented and covered by tests that check behavior.
Testing
After inspecting the target diff and lab runbook, I exercised the real spawn and teardown scripts against Treehouse 2.3.0 with a disposable local origin and private lab tmux session. Journal recovery enabled the same-ID retry, both --force safety guards preserved state as expected, and the disposable fixture was removed.
Evidence: Live Treehouse journal reconciliation
Source: Live Treehouse journal reconciliation
Pipeline
Updates from git push no-mistakes
✅ **Intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
🔧 **Review** - 2 issues found → auto-fixed ✅
bin/fm-teardown.sh:680- The journal-only release counts HEAD as landed whenever it is reachable from the slot's localmainormaster, for every project. The existing record-based teardown is stricter: it accepts only remote-tracking refs (excluding no-mistakes) (bin/fm-teardown.sh:2420), and it falls back to the local default branch only when MODE=local-only (bin/fm-teardown.sh:2445-2457). A journal has no record, so it has no mode, and this path widens that fallback to remote-backed projects as well. Concrete case: a spawn delivers its launch (the polytoken and Herdr abort paths explicitly allow this), and the worker commits on the copy's localmainbefore the spawn later aborts with no record. Once the worker exits, the copy is clean and HEAD is in localmain, sotreehouse return --forceruns and the unpushed commits are returned to the pool. Origin-less pools do need the local-branch fallback, because--remotesis empty there. A narrower form would accept localmain/masteronly when the copy has no remote-tracking refs (mirroring local-only), or use the project's default branch rather than both hardcoded names. Whether remote-backed projects should get this relaxation is a product decision on the safety rule.bin/fm-teardown.sh:699- In the 'already released' branch,fm_treehouse_slot_owner_releasealways returns 0, even whenrmof the claim fails, and the result is never checked. The journal is then removed unconditionally at line 711. If the claim drop fails (e.g. permissions), the task's own.fm-slot-ownerstays behind with no journal, so journal-only teardown can no longer reach it. Any later spawn handed that slot, including a same-id retry, then refuses at spawn_lease_treehouse_slot ('carries an existing slot claim'). The leased branch already re-reads the claim state after release and refuses unless it isabsent(lines 689-694), and the missing-copy branch checks its helper's status. Apply the same re-read-and-refuse check here before removing the journal.🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Test** - passed
✅ No issues found.
git diff 011b8ddfd14981a2d758b69f6470876ecb70c732 72dd612ad36e1963104ed1a6444332e14d4d433etreehouse get --root "$POOL" --lease --lease-holder live-warmup --jsonand conditionaltreehouse returnagainst the disposable local poolbin/fm-lab-home.sh create "$LAB"; privatetmux -L fm-labsession start, capture, task-pane close, and stopbash bin/fm-spawn.sh aborted "$PROJECT" --scout --backend tmux --base-branch absent --harness codexbefore and after recoverybash bin/fm-teardown.sh abortedandbash bin/fm-teardown.sh aborted --forcewith a live task shell and an unpushed commitChecked persisted Treehouse lease state, claim and journal removal or retention, and preservation of the unpushed commitCaptured the live command transcript injournal-reconciliation-live.log; confirmed the disposable lab, pool, and worktree fixture were removed✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.