Skip to content

fix: retire a leased task record when its copy and lease are both gone - #67

Merged
peterOC26 merged 1 commit into
mainfrom
fm/fm-leased-record-auto-retire-r1
Nov 15, 2026
Merged

peterOC26 merged 1 commit into
mainfrom
fm/fm-leased-record-auto-retire-r1

Conversation

@peterOC26

Copy link
Copy Markdown
Owner

Intent

Teardown: rule for retiring a leased task record whose copy directory is gone

Resolution recorded by fm-captain-hold.
Decision digest: 5bdc02baef9afb174011b9518ace85ceccc9553f92fc3327f30be8528c439697
Resolution mode: released

Captain decision:
Captain 2026-11-15 (Jobs page note 1794703235-3uxISq): "The 11 firstmate fixes - do all of these". Start now instead of the staggered dates; Grok builds, DeepSeek checks, firstmate repo reviews one at a time (fleet 133), captain merges each.

Follow-up from fm-worktree-record-clash-fix-c2 review r3 (leased-copy-missing-strands-record): that PR only prints manual recovery steps; deciding what evidence may retire such a record automatically (e.g. no pool entry names the path and none carries the lease_id) extends the ownership contract and needs its own decision.

"The 11 firstmate fixes - do all of these" (2026-11-15)

What Changed

  • When a leased task's copy directory is missing, teardown (bin/fm-teardown.sh) now retires the task record without touching the pool, but only if the copy is provably absent and the readable treehouse-state.json has no entry naming that path and no entry carrying the recorded lease id. It also removes this task's own .fm-slot-owner claim if one is still there, and the completion message says the pool was left untouched. If that proof is missing, for example because pool state is missing, unreadable, a symlink, or malformed, or a matching entry exists, teardown still refuses, keeps the lease and records, and prints the manual recovery steps.
  • New helpers in bin/fm-treehouse-slot-lib.sh (fm_treehouse_lexical_absolute, fm_treehouse_anchor_path, fm_treehouse_copy_provably_absent, fm_treehouse_missing_copy_lease_unheld) build the proof without running any Treehouse command. bin/fm-wake-lib.sh records the retirement rule in the ownership contract and lets the slot-claim helpers read and remove a claim next to a copy that no longer exists (missing mode, fm_treehouse_missing_copy_release_own_claim). It never removes another task's claim.
  • docs/configuration.md now describes the automatic retirement and keeps the manual recovery steps as the fallback. tests/fm-spawn-slot-ownership.test.sh adds a test where the copy is deleted and its pool entry dropped, and teardown then retires the record.

🤖 Generated with Claude Code

Risk Assessment

✅ Low: The change adds the captain-authorized rule for automatically retiring a leased task record whose copy is gone. It is conservative: retirement requires provable absence of the copy and pool state that is a real, readable, well-formed file with no entry naming the path or carrying the lease id. It never runs Treehouse, never touches another task's claim, and refuses with recovery steps in every other case. Direct and descendant teardown are both covered by behavioral tests.

Testing

I ran the targeted slot-ownership suite, which passed. It drives the real fm-teardown.sh against throwaway pools, with a fake Treehouse and fake tmux, through the direct, descendant, slot-removed and other-task-claim retire cases and the path-still-listed, lease-moved, symlinked-pool and malformed-pool refuse cases. Then I ran two live end-to-end checks in throwaway /tmp homes. The real fm-spawn.sh took a lease from the real Treehouse, I deleted the copy, and the real fm-teardown.sh ran. The tmux window and agent launch were stubbed with the repo's test fixtures, so no real agent started. With no pool entry naming the path or the lease, teardown printed the new warning and completion message, exited 0, and removed the task records and its own slot claim. The pool state stayed byte-identical and the moved-aside copy was untouched. With the real Treehouse still holding the lease, teardown refused with the manual recovery steps, exited 1, and kept the record, the acquisition journal, the slot claim and the pool state. The first live attempt failed during my setup, because the throwaway origin had no default branch set. I fixed that and re-ran both checks. All temp dirs were removed, and the worktree is clean.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Operator tears down a task whose leased copy was deleted and whose pool state no longer names the path or the lease: the record is retired and the pool is left alone (local throwaway home, real Treeho… ✅ pass live live-teardown-unheld.log: warning line, completion message, rc=0, no live1 records left, pool state byte-identical, own .fm-slot-owner removed, moved-aside copy intact
Adversarial: the copy was deleted but the real Treehouse pool still holds the path and lease, so teardown must refuse and keep the lease, records and claim ✅ pass live live-teardown-held.log: 'REFUSED: leased task copy is unavailable; retaining its lease and records', manual recovery steps printed, rc=1, live1.meta and treehouse-acquire kept, slot claim kept, pool u…
Adversarial: the lease moved to another entry, the pool file is a symlink or malformed, the path is still listed without a lease, another task claims the slot, or teardown runs from a parent home: tea… ✅ pass live bash tests/fm-spawn-slot-ownership.test.sh: 'ok - a missing leased copy retires only when no pool entry names its path or carries its lease' and 'ok - missing leased copies retain records and print…
Evidence: Live teardown: copy gone, pool names neither path nor lease → record retired, pool untouched

Source: Live teardown: copy gone, pool names neither path nor lease → record retired, pool untouched

== spawn (real treehouse) ==
🌳 Setting up worktree...
🌳 Leased worktree at /tmp/fm-live.If4hhX/pool/.treehouse/proj-8175e5/1/proj. Run 'treehouse return /tmp/fm-live.If4hhX/pool/.treehouse/proj-8175e5/1/proj' to release it.
spawned live1 harness=codex kind=scout window=firstmate:fm-live1 worktree=/tmp/fm-live.If4hhX/pool/.treehouse/proj-8175e5/1/proj
spawn rc=0
== task record ==
worktree=/tmp/fm-live.If4hhX/pool/.treehouse/proj-8175e5/1/proj
treehouse_lease_id=8544937b4ba5bb5c5b89a9a697b15842
treehouse_lease_holder=/tmp/fm-live.If4hhX/home/live1/a1794727045.1132392.23649
== pool state after spawn ==
{"path":"/tmp/fm-live.If4hhX/pool/.treehouse/proj-8175e5/1/proj","leased":true,"lease_id":"8544937b4ba5bb5c5b89a9a697b15842"}
== slot claim ==
task=live1
home=/tmp/fm-live.If4hhX/home
== pool state before teardown ==
== teardown (real) ==
warning: task live1's leased copy /tmp/fm-live.If4hhX/pool/.treehouse/proj-8175e5/1/proj is gone and no pool entry names that path or carries its lease; leaving the pool untouched and running records-only cleanup.
teardown live1 complete (window firstmate:fm-live1; leased copy /tmp/fm-live.If4hhX/pool/.treehouse/proj-8175e5/1/proj is gone and no pool entry names it or carries its lease, so the pool was left untouched)
Backlog: live1 just finished (this home keeps no markdown backlog at /tmp/fm-live.If4hhX/home/data/backlog.md). Update /tmp/fm-live.If4hhX/home/data/backlog.md - move live1 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.
teardown rc=0
== after ==
(no live1 records left)
pool state unchanged
slot claim removed
moved-aside copy intact
lease=8544937b4ba5bb5c5b89a9a697b15842
Evidence: Live teardown: copy gone, real Treehouse still holds the lease → refused, records and lease kept

Source: Live teardown: copy gone, real Treehouse still holds the lease → refused, records and lease kept

== spawn (real treehouse) ==
🌳 Setting up worktree...
🌳 Leased worktree at /tmp/fm-live.StMftt/pool/.treehouse/proj-c763ce/1/proj. Run 'treehouse return /tmp/fm-live.StMftt/pool/.treehouse/proj-c763ce/1/proj' to release it.
spawned live1 harness=codex kind=scout window=firstmate:fm-live1 worktree=/tmp/fm-live.StMftt/pool/.treehouse/proj-c763ce/1/proj
spawn rc=0
== task record ==
worktree=/tmp/fm-live.StMftt/pool/.treehouse/proj-c763ce/1/proj
treehouse_lease_id=fc82d6c956082f95a705f2fe463b2575
treehouse_lease_holder=/tmp/fm-live.StMftt/home/live1/a1794727050.1135310.31742
== pool state after spawn ==
{"path":"/tmp/fm-live.StMftt/pool/.treehouse/proj-c763ce/1/proj","leased":true,"lease_id":"fc82d6c956082f95a705f2fe463b2575"}
== slot claim ==
task=live1
home=/tmp/fm-live.StMftt/home
== pool state before teardown ==
{"path":"/tmp/fm-live.StMftt/pool/.treehouse/proj-c763ce/1/proj","leased":true,"lease_id":"fc82d6c956082f95a705f2fe463b2575"}
== teardown (real) ==
REFUSED: leased task copy is unavailable; retaining its lease and records
Manual recovery: pause allocations and cleanup for this project; retain the task metadata, acquisition journal, pool state, and slot claim.
meta=/tmp/fm-live.StMftt/home/state/live1.meta
worktree=/tmp/fm-live.StMftt/pool/.treehouse/proj-c763ce/1/proj
Read project=, treehouse_lease_id=, and treehouse_lease_holder= from "$meta"; compare them with the acquisition journal and the pool treehouse-state.json. Do not use treehouse status.
Restore the original copy at "$worktree" from backup, including its Git metadata and unlanded work; do not create an empty replacement or overwrite another task's copy.
Verify that pool state still holds the exact recorded lease ID and holder and that .fm-slot-owner names this task and home. Do not fabricate ownership evidence.
If the original copy or matching ownership cannot be restored, keep the records and lease and obtain operator reconciliation; do not delete the metadata, journal, or claim or return another lease.
After restoring and verifying the original copy, retry guarded teardown:
  FM_HOME=/tmp/fm-live.StMftt/home bash {run-worktree}/bin/fm-teardown.sh live1
teardown rc=1
== after ==
live1.git-hooks
live1.meta
live1.treehouse-acquire
pool state unchanged
slot claim still present
moved-aside copy intact
lease=fc82d6c956082f95a705f2fe463b2575
Evidence: Targeted slot-ownership suite transcript

Source: Targeted slot-ownership suite transcript

ok - retained records reserve their copies through exit; explicit cleanup releases exactly their lease
ok - legacy, aliased, and cross-home pre-lease records keep their copies untouched while a fresh spawn leases another
ok - when every free copy is named by a legacy record, get hands out nothing and both copies stay untouched
ok - unverified, empty, and unreadable Treehouse versions refuse legacy admission before allocation
ok - hold preparation and confirmation failures leave no journal and allow a successful retry
ok - fresh spawns with no records or only durable leases succeed when mkfifo fails
ok - unreadable, contradictory, partial-lease, and leased-elsewhere records refuse before allocation or endpoint mutation
ok - relaunch preserves the acquisition across spawn_gen, keeps legacy owners relaunchable, and rejects stale or cross-home claims before mutation
ok - a cleanup re-run after its lease was released retires records only; an unclaimed held lease still refuses
ok - unsupported CLIs refuse before mutation; interrupted acquisitions retain exact lease evidence and block unsafe reuse
ok - retained copies of another repository do not block this project's allocation
ok - separate clones sharing an origin honor legacy references and keep lease claims and cleanup scoped to one copy
ok - partial journals block their own project; unknown and unsafe journals diagnose refusal across local homes
ok - unclaimed legacy ships retain dirty and unpushed work; clean copies retire records without return
ok - a missing leased copy retires only when no pool entry names its path or carries its lease
ok - missing leased copies retain records and print recovery steps for direct and descendant teardown
ok - unrecognized leased copies refuse before claim and publication while retaining recovery evidence
ok - empty path fields permit allocation relaunch and cleanup; duplicate empty fields still refuse
ok - never-acquired and orphan-claim refusals explain manual recovery without clearing evidence
ok - both record scans diagnose missing local and registered state directories
ok - record scans diagnose registry, record, and path resolution refusals

real	3m46.239s
user	2m17.183s
sys	1m44.453s
Evidence: Retire transcript excerpt
warning: task live1's leased copy .../1/proj is gone and no pool entry names that path or carries its lease; leaving the pool untouched and running records-only cleanup.
teardown live1 complete (window firstmate:fm-live1; leased copy .../1/proj is gone and no pool entry names it or carries its lease, so the pool was left untouched)
teardown rc=0
(no live1 records left)
pool state unchanged
slot claim removed

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • ℹ️ bin/fm-teardown.sh:3058 - The missing-copy retirement branch inside require_owned_worktree_slot_record deletes this task's own .fm-slot-owner claim (fm_treehouse_missing_copy_release_own_claim) during what is otherwise a validation pass. Teardown can still abort after that and keep the records. Direct path: require_owned_task_worktree_slot at fm-teardown.sh:4100 runs before validate_pr_poll_cleanup and the later endpoint/backlog steps. Descendant path: the preflight scan at fm-teardown.sh:3716 runs before the remaining descendants are validated. A re-run still converges: the claim is now absent, release_own_claim treats that as nothing to remove, and the pool proof still holds, so the record retires. If the pool later lists the path again, the re-run refuses safely. So the only effect is that the claim is removed before the records it belongs to. Optional tidy-up: record that a claim release is pending and do it after the records are removed. No change is required.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Operator tears down a task whose leased copy was deleted and whose pool state no longer names the path or the lease: the record is retired and the pool is left alone (local throwaway home, real Treeho… ✅ pass live live-teardown-unheld.log: warning line, completion message, rc=0, no live1 records left, pool state byte-identical, own .fm-slot-owner removed, moved-aside copy intact
Adversarial: the copy was deleted but the real Treehouse pool still holds the path and lease, so teardown must refuse and keep the lease, records and claim ✅ pass live live-teardown-held.log: 'REFUSED: leased task copy is unavailable; retaining its lease and records', manual recovery steps printed, rc=1, live1.meta and treehouse-acquire kept, slot claim kept, pool u…
Adversarial: the lease moved to another entry, the pool file is a symlink or malformed, the path is still listed without a lease, another task claims the slot, or teardown runs from a parent home: tea… ✅ pass live bash tests/fm-spawn-slot-ownership.test.sh: 'ok - a missing leased copy retires only when no pool entry names its path or carries its lease' and 'ok - missing leased copies retain records and print…
  • bash tests/fm-spawn-slot-ownership.test.sh (the new test_missing_leased_copy_retires_when_pool_names_neither_path_nor_lease plus the existing missing-copy, recovery and ownership cases; all ok, rc=0)
  • Live, pool entry dropped: real bin/fm-spawn.sh live1 <proj> --scout leased a copy through the real treehouse get --lease; then I moved the copy aside, removed its entry from the pool's treehouse-state.json, and ran the real bin/fm-teardown.sh live1 --force
  • Live, pool still holds the lease: same setup, but the real Treehouse pool entry still named the path and lease before bin/fm-teardown.sh live1 --force
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Direct and descendant teardown kept a leased record and printed manual
recovery steps whenever the copy directory was missing. When readable
pool state shows no entry naming that path and none carrying the lease
id, teardown now retires the record, drops only this task's own slot
claim, and leaves the pool untouched. Any weaker proof still keeps the
record and prints the recovery steps.
@peterOC26
peterOC26 merged commit 6d7e171 into main Nov 15, 2026
57 of 59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant