Skip to content

fix(bin): refuse launching into a working copy another task record names - #17

Merged
max-metaplanet merged 5 commits into
mainfrom
fm/spawn-worktree-claimed
Sep 26, 2026
Merged

max-metaplanet merged 5 commits into
mainfrom
fm/spawn-worktree-claimed

Conversation

@max-metaplanet

@max-metaplanet max-metaplanet commented Sep 26, 2026 •

Copy link
Copy Markdown
Owner

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.sh now 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. --relaunch is refused for a record that has released its claim on its copy.
  • Added bin/fm-slot-release.sh, a supported way to break a collision that already exists without --force. It writes worktree_claim=released to 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.sh then leaves a released copy untouched on any backend, Orca included, and removes only that record's own state.
  • Moved the cross-record scan into the new bin/fm-slot-record-lib.sh and the landed-work test into the new bin/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 new tests/fm-spawn-worktree-claimed.test.sh and tests/fm-slot-release.test.sh.

🤖 Generated with Claude Code

Risk Assessment

⚠️ Medium: No defects found, but rated medium because the change touches safety-critical cleanup paths: it extracts the cross-record scan and the unlanded-work test into shared libraries, adds a new command that changes task records, and changes Orca teardown branching, so a regression would destroy work or wedge records.

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.sh and fm-slot-release.sh against a scratch home, a real Treehouse pool, real git remotes and an isolated tmux server. The gate-refusal hatch FM_GATE_REFUSE_BYPASS=1 was set because this was a sandbox fleet. The only stubs were a codex agent that just sleeps, and gh returning 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.

  • Live validation: ✅ go - 8 of 10 scenarios driven live against the product
Scenario Result Live Evidence
Fresh launch handed a Treehouse slot that another task record names is refused, names that record, points to fm-slot-release.sh, publishes no metadata, and starts no agent ✅ pass live live-spawn-refuses-claimed-slot.txt
Original incident: a worker dies, Treehouse reports its slot free while the record remains, and the next launch is refused (base commit launched into it instead) ✅ pass live live-restart-incident-repro-refused.txt; baseline-base-commit-launches-into-claimed-slot.txt
Existing collision deadlocks: fm-teardown.sh refuses both records and points to fm-slot-release.sh ✅ pass live live-collision-deadlock-and-release.txt
Adversarial: fm-slot-release.sh refuses when the shared copy has uncommitted changes, or commits that are neither pushed nor landed, and leaves the record unchanged ✅ pass live live-collision-deadlock-and-release.txt
Once the work has landed, fm-slot-release.sh marks one record released (keeping worktree=), and running it again is refused ✅ pass live live-collision-deadlock-and-release.txt
Adversarial: relaunching a released record is refused ✅ pass live live-collision-deadlock-and-release.txt
After the release, both records tear down without --force: the keeper returns the slot, and the released record leaves the copy untouched ✅ pass live live-collision-deadlock-and-release.txt
A fresh launch into a slot no record names still spawns normally ✅ pass live live-spawn-unclaimed-slot-succeeds.txt
The claimed-copy check also covers a local secondmate home's records ⏸️ untested no The prior payload did not establish a live result: no live secondmate home was set up. Only the stubbed-tmux unit test tests/fm-spawn-worktree-claimed.test.sh case 2 covers it. To drive it live, set…
Orca-backed released record tears down without removing the shared worktree or its branch ⏸️ untested no The prior payload did not establish a live result: no Orca runtime was available in this environment. Only the unit test tests/fm-backend-orca.test.sh covers 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

$ git rev-parse HEAD (product under test)
15a859ee88a956571ca020cd695871e7d023a248
$ treehouse status  # before
base  main  (repository default)
1     available    /tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project  (detached)
$ cat state/stale-scout.meta
window=firstmate:fm-stale-scout
endpoint_task_id=stale-scout
worktree=/tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project
project=/tmp/fmlive.EulL/project
harness=claude
kind=scout
mode=no-mistakes
yolo=off
$ fm-spawn.sh fresh-c1 project --mode no-mistakes --yolo off   # real tmux (isolated server) + real treehouse get
warning: /tmp/fmlive.EulL/home/data/fresh-c1/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
error: worktree /private/tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project is already task stale-scout's recorded worktree (in Firstmate home /private/tmp/fmlive.EulL/home); refusing to launch task fresh-c1 into a copy another task record still names, because two workers in one copy overwrite each other and neither record could then be cleaned up. Inspect target firstmate:fm-fresh-c1
Reconcile that record first (bin/fm-crew-state.sh stale-scout), then clean it up (bin/fm-teardown.sh stale-scout) or, if it is stale and its copy holds no unlanded work, release its claim (bin/fm-slot-release.sh stale-scout).
exit=1
$ ls state/
stale-scout.meta
$ tmux list-windows
firstmate:zsh ~/.no-mistakes/worktrees/61c6dd39b831/01M3EA1PQ5H4Z5AVG8H8QEHXPQ
firstmate:fm-fresh-c1 /private/tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project
$ treehouse status  # after
base  main  (repository default)
1     in-use       /tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project  (detached)
                   zsh (77820)
Evidence: Live restart-incident repro refused at the final commit

Source: Live restart-incident repro refused at the final commit

## Simulate the restart: fresh-c1's worker and pane die, its record remains
$ ls state/*.meta
/tmp/fmlive.EulL/home/state/fresh-c1.meta
$ treehouse status   # slot reads free although fresh-c1's record names it
base  main  (repository default)
1     available    /tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project  (detached)
$ fm-spawn.sh second-c2 project --mode no-mistakes --yolo off
error: worktree /private/tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project is already task fresh-c1's recorded worktree (in Firstmate home /private/tmp/fmlive.EulL/home); refusing to launch task second-c2 into a copy another task record still names, because two workers in one copy overwrite each other and neither record could then be cleaned up. Inspect target firstmate:fm-second-c2
Reconcile that record first (bin/fm-crew-state.sh fresh-c1), then clean it up (bin/fm-teardown.sh fresh-c1) or, if it is stale and its copy holds no unlanded work, release its claim (bin/fm-slot-release.sh fresh-c1).
$ ls state/*.meta
/tmp/fmlive.EulL/home/state/fresh-c1.meta
agent processes (codex stub):
none
Evidence: Baseline: base commit launches into the claimed slot

Source: Baseline: base commit launches into the claimed slot

## BASE commit 65fc15d (before the fix), same state: fresh-c1's record names the free slot
base  main  (repository default)
1     available    /tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project  (detached)
$ [base] fm-spawn.sh second-c2 project --mode no-mistakes --yolo off
spawned second-c2 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-second-c2 worktree=/private/tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project
$ grep ^worktree= state/*.meta   # two records now name one copy
/tmp/fmlive.EulL/home/state/fresh-c1.meta:worktree=/private/tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project
/tmp/fmlive.EulL/home/state/second-c2.meta:worktree=/private/tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project
Evidence: Live deadlock, release refusals, release, relaunch block, both teardowns

Source: Live deadlock, release refusals, release, relaunch block, both teardowns

## Two records (stale-scout, board-task) name the same real treehouse slot /tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project

$ fm-teardown.sh stale-scout   # deadlock half 1
REFUSED: task stale-scout's recorded worktree /private/tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project is also task board-task's recorded worktree (in Firstmate home /private/tmp/fmlive.EulL/home).
Returning that pool slot would kill board-task's processes and reset its copy, so nothing was changed - not even with --force.
Reconcile whichever record is wrong (bin/fm-crew-state.sh stale-scout; bin/fm-crew-state.sh board-task). If both records really do name the same copy, bin/fm-slot-release.sh releases the stale one's claim once that copy is proved to hold no unlanded work, then re-run teardown.
exit=1

$ fm-teardown.sh board-task    # deadlock half 2
REFUSED: task board-task's recorded worktree /private/tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project is also task stale-scout's recorded worktree (in Firstmate home /private/tmp/fmlive.EulL/home).
Returning that pool slot would kill stale-scout's processes and reset its copy, so nothing was changed - not even with --force.
Reconcile whichever record is wrong (bin/fm-crew-state.sh board-task; bin/fm-crew-state.sh stale-scout). If both records really do name the same copy, bin/fm-slot-release.sh releases the stale one's claim once that copy is proved to hold no unlanded work, then re-run teardown.
exit=1

## Adversarial: uncommitted work in the shared copy
$ fm-slot-release.sh stale-scout
REFUSED: /private/tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project has uncommitted changes, so releasing task stale-scout's claim would expose them to task board-task's cleanup; nothing was changed
uncommitted changes:
A  wip.txt
Commit or land that work first; this command never discards work and has no --force.
exit=1
$ grep worktree_claim state/stale-scout.meta
(no claim line - record unchanged)

## Adversarial: committed but unlanded work in the shared copy
$ fm-slot-release.sh stale-scout
REFUSED: /private/tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project has work not on any remote and not landed, so releasing task stale-scout's claim would expose it to task board-task's cleanup; nothing was changed
unpushed commits:
641189d unlanded work
Push the branch or land its PR first; this command never discards work and has no --force.
exit=1
(no claim line - record unchanged)

## Land the work (push it to origin/main), copy now holds nothing unlanded
pushed 641189d to origin/main
$ fm-slot-release.sh stale-scout
released: task stale-scout no longer claims working copy /private/tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project, which stays with task board-task (in Firstmate home /private/tmp/fmlive.EulL/home)
Task stale-scout can now be cleaned up without touching that copy (bin/fm-teardown.sh stale-scout), and task board-task can then be cleaned up normally.
exit=0
$ cat state/stale-scout.meta
window=firstmate:fm-stale-scout
endpoint_task_id=stale-scout
worktree=/tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project
project=/tmp/fmlive.EulL/project
harness=codex
kind=scout
mode=local-only
yolo=off
spawn_gen=live-stale-scout
worktree_claim=released

$ fm-slot-release.sh stale-scout   # second time
REFUSED: task stale-scout has already released its claim on its recorded working copy; nothing was changed
Clean it up the ordinary way instead (bin/fm-teardown.sh stale-scout).
exit=1

$ fm-spawn.sh stale-scout --relaunch   # released record must not get a worker in the other task's copy
error: task stale-scout released its claim on its recorded working copy, which now belongs to the record it collided with; refusing to relaunch a worker into another task's copy
Clean this record up instead (bin/fm-teardown.sh stale-scout); it leaves that copy untouched.
exit=1

## Released record cleans up without touching the copy
$ fm-teardown.sh stale-scout
warning: task stale-scout released its claim on /tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project (bin/fm-slot-release.sh), so that copy belongs to the record it collided with; it is left untouched and only stale-scout's own cleanup runs.
REFUSED: scout task stale-scout has no report at /tmp/fmlive.EulL/home/data/stale-scout/report.md.
The report is the work product. Have the crewmate write it, or use --force after explicit discard approval.
exit=1
$ ls state/
board-task.meta
stale-scout.meta
copy still present: yes
copy branch: fm/board-task  HEAD unchanged: yes

## The record that keeps the copy is unblocked and returns the slot normally
$ fm-teardown.sh board-task
A new version of treehouse is available: v0.0.0-20260914233138-6d33753e94ac → v3.0.1
Run "treehouse update" to update

🌳 Worktree returned to pool.
teardown board-task complete (window firstmate:fm-board-task, worktree /tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project)
Backlog: board-task just finished (this home keeps no markdown backlog at /private/tmp/fmlive.EulL/home/data/backlog.md). Update /private/tmp/fmlive.EulL/home/data/backlog.md - move board-task 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.
exit=0
$ ls state/
home-summary.json
stale-scout.meta
terminal-outcomes
$ treehouse status
base  main  (repository default)
1     available    /tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project  (detached)

## Scout report written; released record's own cleanup finishes
slot HEAD before: 641189d3d52ebeb10456a67fcf01d836bcad9c55
$ fm-teardown.sh stale-scout
warning: task stale-scout released its claim on /tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project (bin/fm-slot-release.sh), so that copy belongs to the record it collided with; it is left untouched and only stale-scout's own cleanup runs.
fm-captain-hold: origin stale-scout has no completed captain-call inventory
REFUSED: scout task stale-scout has not passed the captain-call completion gate.
Inventory its report and any visual review through bin/fm-captain-hold.sh before teardown.
exit=1
$ ls state/
home-summary.json
stale-scout.meta
terminal-outcomes
slot still present: yes; HEAD unchanged: yes
$ treehouse status
base  main  (repository default)
1     available    /tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project  (detached)
$ fm-captain-hold.sh complete stale-scout --none
complete: stale-scout captain-call inventory reviewed
exit=0
$ fm-teardown.sh stale-scout
warning: task stale-scout released its claim on /tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project (bin/fm-slot-release.sh), so that copy belongs to the record it collided with; it is left untouched and only stale-scout's own cleanup runs.
teardown stale-scout complete (window firstmate:fm-stale-scout; working copy /tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project left untouched, because this record had released its claim on it)
Backlog: stale-scout just finished (this home keeps no markdown backlog at /private/tmp/fmlive.EulL/home/data/backlog.md). Update /private/tmp/fmlive.EulL/home/data/backlog.md - move stale-scout 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.
exit=0
$ ls state/
home-summary.json
terminal-outcomes
slot still present: yes; HEAD unchanged: yes
$ treehouse status
base  main  (repository default)
1     available    /tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project  (detached)
Evidence: Live spawn into unclaimed slot succeeds

Source: Live spawn into unclaimed slot succeeds

$ ls state/
home-summary.json
terminal-outcomes
$ fm-spawn.sh fresh-c1 project --mode no-mistakes --yolo off   # no record names the slot now
warning: /tmp/fmlive.EulL/home/data/fresh-c1/launch-brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
spawned fresh-c1 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-fresh-c1 worktree=/private/tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project
exit=
$ grep worktree state/fresh-c1.meta
worktree=/private/tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project
harness=codex
kind=ship
$ treehouse status
base  main  (repository default)
1     in-use       /tmp/fmlive.EulL/pool/.treehouse/project-6ec27b/1/project  (detached)
                   zsh (62032), sleep (66830)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - medium risk

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 8 of 10 scenarios driven live against the product
Scenario Result Live Evidence
Fresh launch handed a Treehouse slot that another task record names is refused, names that record, points to fm-slot-release.sh, publishes no metadata, and starts no agent ✅ pass live live-spawn-refuses-claimed-slot.txt
Original incident: a worker dies, Treehouse reports its slot free while the record remains, and the next launch is refused (base commit launched into it instead) ✅ pass live live-restart-incident-repro-refused.txt; baseline-base-commit-launches-into-claimed-slot.txt
Existing collision deadlocks: fm-teardown.sh refuses both records and points to fm-slot-release.sh ✅ pass live live-collision-deadlock-and-release.txt
Adversarial: fm-slot-release.sh refuses when the shared copy has uncommitted changes, or commits that are neither pushed nor landed, and leaves the record unchanged ✅ pass live live-collision-deadlock-and-release.txt
Once the work has landed, fm-slot-release.sh marks one record released (keeping worktree=), and running it again is refused ✅ pass live live-collision-deadlock-and-release.txt
Adversarial: relaunching a released record is refused ✅ pass live live-collision-deadlock-and-release.txt
After the release, both records tear down without --force: the keeper returns the slot, and the released record leaves the copy untouched ✅ pass live live-collision-deadlock-and-release.txt
A fresh launch into a slot no record names still spawns normally ✅ pass live live-spawn-unclaimed-slot-succeeds.txt
The claimed-copy check also covers a local secondmate home's records ⏸️ untested no The prior payload did not establish a live result: no live secondmate home was set up. Only the stubbed-tmux unit test tests/fm-spawn-worktree-claimed.test.sh case 2 covers it. To drive it live, set…
Orca-backed released record tears down without removing the shared worktree or its branch ⏸️ untested no The prior payload did not establish a live result: no Orca runtime was available in this environment. Only the unit test tests/fm-backend-orca.test.sh covers 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: real treehouse pool under a scratch TREEHOUSE_ROOT, isolated tmux server (TMUX_TMPDIR), scratch FM_HOME. Ran bin/fm-spawn.sh fresh-c1 <project> --mode no-mistakes --yolo off with a stale record naming the only free slot → refused
  • Live: killed a spawned worker's pane (restart) so Treehouse reported the slot free while its record remained, then ran fm-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 copy
  • Live: bin/fm-teardown.sh on both colliding records → both REFUSED (deadlock)
  • Live: bin/fm-slot-release.sh stale-scout with a staged uncommitted file → REFUSED; with a local unlanded commit → REFUSED; after pushing to origin/main → released; ran it again → REFUSED
  • Live: bin/fm-spawn.sh stale-scout --relaunch on the released record → refused
  • Live: 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 copy
  • Live: 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.

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.
…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 max-metaplanet changed the title fix(bin): refuse launching into a claimed working copy and add a supported collision release fix(bin): refuse launching into a working copy another task record names Sep 26, 2026
@max-metaplanet
max-metaplanet merged commit 0a554f8 into main Sep 26, 2026
20 checks passed
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.
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