Repository navigation
fix(bin): refuse launching into a working copy another task record names - #17
Merged
Merged
Conversation
Treehouse hands out a pool slot by what is RUNNING under it, so a slot whose worker exited reads free while a task record still names it. Cleanup already refuses to return a slot a second record names; the launch path applied no such check. A machine restart that killed a worker therefore let the next spawn take the same copy. Two workers then share one copy and silently overwrite each other, and because the cleanup refusal is symmetric, afterwards NEITHER record can be cleaned up - a deadlock with no supported way out. The cross-record scan moves to bin/fm-slot-record-lib.sh, and bin/fm-spawn.sh asks it the moment `treehouse get` hands it a copy, refusing with the record that already holds it named. Refusing there costs the launch and nothing else, because no work exists in the copy yet. A relaunch is deliberately untouched: it acquires no copy, it reuses the one its own record names, so it can still recover work sitting behind a collision. bin/fm-slot-release.sh is the way out of a collision that already exists. It adds worktree_claim=released to one task record, and only when another record really does name that copy, the copy's own slot-owner claim does not name this one, and the copy holds no uncommitted changes and no unlanded commits - the same landed-work test cleanup uses, now shared in bin/fm-unlanded-work-lib.sh. It never forces and has no way to discard work. The released record keeps its copy PATH, because bin/fm-backend.sh refuses to validate an endpoint without one and removing it would only trade one wedge for another. What it loses is the claim: its own cleanup then takes the existing not-my-slot path, killing nothing under that copy, inspecting nothing in it and returning nothing to the pool, while the other record's cleanup proceeds normally. A relaunch of a released record refuses rather than putting a fresh worker into another task's copy. Covered in both cleanup orders end to end, plus the launch refusal across homes, the relaunch exemption, and each release refusal.
…released its claim
…elease in architecture
…ling A home reached through a symlink put ONE state directory into the cross-record scan under two spellings: the caller's, and the canonical one fm_firstmate_root_home returns. The own-record exclusion compared raw path strings, so the canonical pass found the caller's own record and reported it as a second record naming the same copy. A lone task was refused because of itself - cleanup of a task in a symlinked home told the operator its worktree was also its own worktree, and the release command saw a collision that did not exist. The scan now keys state directories by resolved path, so one directory cannot enter the set twice, and compares the caller's own record by resolved identity rather than spelling. An unresolvable directory is kept as given: it holds no readable records, so nothing changes for it. The structure predates this branch - teardown's own walk had the same shape - but this branch lifted it into the shared helper that launch and release also use, which is what makes it worth fixing here rather than leaving it. Four test fixtures launched task after task into a single fake copy, which the new refusal correctly rejects because the pool never hands one copy to two live records. Each now models the cleanup that really happens between reuses: the pool-base-refresh and account-pin cases retire the previous record, the submodule-pin seed retires its own once it has left the residue under test, and the path-spelling case retires the first task before comparing spellings. The fm-gotmp fake roots gained the two libraries teardown now sources. A batch is different: every pair launches for real and each task gets its own copy, so no record can be retired between them. The shared spawn fake grew an opt-in per-window pane path (FM_FAKE_PANE_PATH_BY_WINDOW) so a batch case can give each task its own worktree; unset, every window reports the single FM_FAKE_PANE_PATH exactly as before, so no other suite changes. Also quote the HERDR_LAUNCHER_RELATIONSHIP literals: unquoted `other-home` reads as arithmetic to ShellCheck (SC2100) once names like `other` and `home` are in scope through a sourced library.
max-metaplanet
added a commit
that referenced
this pull request
Oct 6, 2026
Carried from fork commit 0a554f8 (#17). This commit and upstream both hardened the same destructive path, in different directions, so the conflicts are merged and neither protection is dropped. bin/fm-teardown.sh keeps this commit's extraction: bin/fm-slot-record-lib.sh owns the cross-record exclusivity scan, shared with the launch path that refuses to hand a spawn a copy another record already names, and bin/fm-slot-release.sh is the supported way out of a pair that already exists. Upstream's slot-owner-claim exception is kept at the teardown call site, where its justification lives: a slot whose claim names another task was reassigned, so that teardown is records-only and refusing would strand the stale record and block the claimant's own cleanup. The launch-side caller of the same scan deliberately has no such exception, which the code now states. The inline landed-work cluster upstream still carried is removed, because bin/fm-unlanded-work-lib.sh owns that contract now and nothing outside the cluster called it; keeping both would have left two implementations of a proof that decides whether work is destroyed. Removing it would have dropped a real upstream fix, so that fix is carried into the library instead: upstream had taught `content_in_default` to compare against a task's recorded base branch rather than the project default. The library had no such parameter, so a task started from a named base would have had its landed work read as unlanded. `fm_unlanded_content_in_default` and `fm_unlanded_work_is_landed` now take an optional base branch, and both callers pass the task's recorded value. docs/architecture.md keeps this commit's spawn-scan and slot-release sentences and upstream's claim sentence, which is the one that states the contradictory-record case the retained exception covers. tests/fm-control-relaunch.test.sh keeps both test groups; the conflict boundary fell inside an upstream test, so its closing brace is restored.
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
A fresh launch can be handed a working copy that another task record in the same home still names. Cleanup (bin/fm-teardown.sh) already checks other task records for the copy it is about to remove and refuses; the launch path (bin/fm-spawn.sh worktree acquisition) does not check at all. Observed in another home after a session restart: two task records named the same working copy, and the pool showed that slot in use with no branch checked out. The consequence there was a finished investigation that could not be cleaned up and a board task whose worker could not be relaunched into its own copy; the dangerous version is two live workers in one copy, one silently overwriting the other. Because the cleanup guard is symmetric, a collision is also a deadlock: neither task can be cleaned up while the other record exists, and no supported command breaks it short of force. The fix has two parts: (1) at the point where the launch acquires its working copy, refuse a copy another live record names, the same way cleanup already does, treating the cross-record check as the guard rather than the pool's in-use flag; (2) a supported, non-forced way to resolve a collision that has already happened, allowed only when the copy is proven to hold no unlanded work.
What Changed
bin/fm-spawn.shnow runs the same cross-record check teardown uses on a freshly acquired working copy. It refuses the launch if another local task record already names that copy, and it also refuses when that can't be determined. It no longer relies on Treehouse's in-use flag for this.--relaunchis refused for a record that has released its claim on its copy.bin/fm-slot-release.sh, a supported way to break a collision that already exists without--force. It writesworktree_claim=releasedto one task record, and only when all of these hold: another record really does name the same copy, the copy's slot-owner claim does not name this record, the copy has no uncommitted changes or unlanded commits, and the record isn't a secondmate's.bin/fm-teardown.shthen leaves a released copy untouched on any backend, Orca included, and removes only that record's own state.bin/fm-slot-record-lib.shand the landed-work test into the newbin/fm-unlanded-work-lib.sh. Teardown, spawn and slot-release all use them. Slot records are now compared by resolved path identity, not by how the path is spelled. Updated docs (docs/architecture.md,docs/scripts.md) and tests, including the newtests/fm-spawn-worktree-claimed.test.shandtests/fm-slot-release.test.sh.🤖 Generated with Claude Code
Risk Assessment
Testing
I ran the targeted suites for the spawn guard, the release command, Orca teardown and the full teardown test file, and all passed. I then drove the real
fm-spawn.sh,fm-teardown.shandfm-slot-release.shagainst a scratch home, a real Treehouse pool, real git remotes and an isolated tmux server. The gate-refusal hatchFM_GATE_REFUSE_BYPASS=1was set because this was a sandbox fleet. The only stubs were acodexagent that just sleeps, andghreturning failure so nothing touched the network. All eight live scenarios passed: the claimed-copy refusal (and the base commit reproducing the bug), the deadlock, both adversarial release refusals, a clean release, blocking a relaunch of a released record, non-forced cleanup of both records, and a normal launch into an unclaimed slot. Two scenarios are marked untested because they weren't driven live: the secondmate-home records check (no live secondmate home was set up) and Orca-backed teardown (no Orca runtime was available). Unit tests cover both. This is a command-line change, so the evidence is terminal transcripts, not screenshots. The scratch environment was removed afterwards.tests/fm-spawn-worktree-claimed.test.shcase 2 covers it. To drive it live, set…tests/fm-backend-orca.test.shcovers it. An installed, running Orca backend i…Evidence: Live spawn refused: copy named by another record
Source: Live spawn refused: copy named by another record
Evidence: Live restart-incident repro refused at the final commit
Source: Live restart-incident repro refused at the final commit
Evidence: Baseline: base commit launches into the claimed slot
Source: Baseline: base commit launches into the claimed slot
Evidence: Live deadlock, release refusals, release, relaunch block, both teardowns
Source: Live deadlock, release refusals, release, relaunch block, both teardowns
Evidence: Live spawn into unclaimed slot succeeds
Source: Live spawn into unclaimed slot succeeds
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
✅ No issues found.
✅ **Test** - passed
✅ No issues found.
tests/fm-spawn-worktree-claimed.test.shcase 2 covers it. To drive it live, set…tests/fm-backend-orca.test.shcovers it. An installed, running Orca backend i…bash tests/fm-spawn-worktree-claimed.test.sh(3/3 ok)bash tests/fm-slot-release.test.sh(8/8 ok)bash tests/fm-backend-orca.test.sh(includes 'fm-teardown.sh backend=orca: a released record cleans up without touching the shared worktree' ok)bash tests/fm-teardown.test.sh(94 ok, rc=0, including the released-claim collision cases)Live: realtreehousepool under a scratch TREEHOUSE_ROOT, isolated tmux server (TMUX_TMPDIR), scratch FM_HOME. Ranbin/fm-spawn.sh fresh-c1 <project> --mode no-mistakes --yolo offwith a stale record naming the only free slot → refusedLive: killed a spawned worker's pane (restart) so Treehouse reported the slot free while its record remained, then ranfm-spawn.sh second-c2 ...→ refused at the change's final commit 15a859e; the same run with base 65fc15d (extracted via git archive) spawned into the same copyLive:bin/fm-teardown.shon both colliding records → both REFUSED (deadlock)Live:bin/fm-slot-release.sh stale-scoutwith a staged uncommitted file → REFUSED; with a local unlanded commit → REFUSED; after pushing to origin/main → released; ran it again → REFUSEDLive:bin/fm-spawn.sh stale-scout --relaunchon the released record → refusedLive:bin/fm-teardown.sh board-task→ completed and returned the slot to the real Treehouse pool;bin/fm-teardown.sh stale-scout(released) → completed without touching the copyLive:fm-spawn.sh fresh-c1 ...into the now-unclaimed slot → spawned✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.