Skip to content

fix(bin): reserve pool slots that kept task records still name - #313

Merged
sKeLe100 merged 4 commits into
mainfrom
fm/worktree-slot-double-record
Nov 22, 2026
Merged

sKeLe100 merged 4 commits into
mainfrom
fm/worktree-slot-double-record

Conversation

@sKeLe100

@sKeLe100 sKeLe100 commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Intent

Captain's standing order for this session's gaps: "We should be filing any tasks in relation to the gaps mentioned this session as priority 0 on pc01 and within resources."

The gap: a shelved scout (its pane closed, its isolated copy deliberately kept) still recorded worktree pool slot 22 in its task metadata, yet the pool handed slot 22 to a newly spawned ship. When that ship's PR merged, its cleanup refused because two task records claimed the same slot. The fix: a pool slot that any task record still names must never be reissued to a new task (or, if the shelve/park path is the intended release point, that path must release the record) so two live records can never share one slot.

What Changed

  • Added fm_treehouse_reserve_recorded_slots to bin/fm-wake-lib.sh. It finds every pool slot that another task's worktree= record still names, such as a parked, shelved, or exited worker's kept copy. It then reserves each one with a durable treehouse lease, so the pool can no longer hand that slot to a new task. The spawning task's own record is skipped. If jq is missing or the pool listing is unreadable, it refuses.
  • bin/fm-spawn.sh now calls the reservation just before treehouse get, under the project allocation lock. It refuses to acquire a slot if that lock isn't held or if a reservation fails. Only the ship/scout treehouse get path is changed.
  • Added tests/fm-spawn-slot-record-reservation.test.sh. The shared spawn fakebin in tests/fixtures.sh now answers treehouse status --json with an empty pool. docs/architecture.md and the spawn header comment describe the new reservation.

Risk Assessment

✅ Low: Reservation runs under the allocation lock and fails closed with concrete diagnostics, and lease_id is a confirmed real field. Teardown's treehouse return --force already releases durable leases, so the reserved slots are freed when their owner is torn down.

Testing

The baseline changed-tests run passed. The focused spawn reservation test passed all 6 cases: kept record reserved, control, own stale record, and the three refusal exits (status fails, garbage listing, lease fails). I also ran the real treehouse CLI in a disposable repo and home. Its listing is a top-level array with name, path, status, lease_id and lease_holder, and lease_id and status change after treehouse lease. That matches the jq filter, which closes the earlier review concern about an unverified schema.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Spawn with a kept task record naming a pool slot reserves that slot and does not reissue it ✅ pass live tests/fm-spawn-slot-record-reservation.test.sh ok lines 1-3 (real fm-spawn.sh, fake treehouse binary)
Real treehouse CLI listing shape and lease behavior match what the reservation reads ✅ pass live real treehouse in a temp repo: status --json array with lease_id/lease_holder; lease 1 sets status leased and lease_id
Refusal exits (status failure, unparsable listing, lease failure) refuse the spawn ✅ pass live test ok lines 4-6

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-wake-lib.sh:1862 - The reservation still depends on an unverified lease_id field in treehouse status --json. The sweep in bin/fm-orphan-pane-sweep.sh only confirms a top-level array with .name, .path and .status. The real CLI's pool here is empty ([]), and the test fake invents lease_id and lease_holder, so it passes whatever the real field is called. If the real field has another name, lease is always empty. Every spawn then re-runs treehouse lease on slots that are already leased, which can fail and refuse the spawn beside any kept record. Smallest fix: use a captured real listing that includes a leased slot, or key off .status as the sweep does, or treat an already-leased failure from treehouse lease as non-fatal. The same assumption appears in tests/fm-spawn-slot-record-reservation.test.sh (fake status) branch, about line 100). This was recorded as a fix decision in rounds 1 and 2, and is only partly closed.
  • ℹ️ tests/fm-spawn-slot-record-reservation.test.sh:259 - The new test file covers three cases only: kept record reserved, control, and own stale record. It covers none of the new refusal exits: treehouse status failing, an unparsable listing, treehouse lease failing, jq missing, or the missing allocation lock guard in bin/fm-spawn.sh. Each of those refuses the spawn, but none is exercised. Round 1 recorded a decision to fix this, and it is still open.

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 3 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Spawn with a kept task record naming a pool slot reserves that slot and does not reissue it ✅ pass live tests/fm-spawn-slot-record-reservation.test.sh ok lines 1-3 (real fm-spawn.sh, fake treehouse binary)
Real treehouse CLI listing shape and lease behavior match what the reservation reads ✅ pass live real treehouse in a temp repo: status --json array with lease_id/lease_holder; lease 1 sets status leased and lease_id
Refusal exits (status failure, unparsable listing, lease failure) refuse the spawn ✅ pass live test ok lines 4-6
  • bin/fm-test-run.sh --changed --exclude-family real-herdr-gated --exclude-quarantined --pc02-if-idle
  • bash tests/fm-spawn-slot-record-reservation.test.sh
  • real treehouse status --json / treehouse lease 1 --lease-holder x in a throwaway repo with isolated HOME
✅ **Document** - passed

✅ No issues found.

🔧 **Lint** - 1 issue found → auto-fixed ✅
  • ⚠️ linter found issues (exit code 1)

🔧 Fix applied.
✅ Re-checked - no issues remain.

✅ **Push** - passed

✅ No issues found.

sKeLe100 and others added 4 commits November 21, 2026 21:48
A kept task record names a pool slot the task still owns, but Treehouse's
interactive acquire carries only a process lease that lapses with the pane,
so the pool can hand that slot to a new task and leave two live records
claiming it, which makes the newcomer's teardown refuse.

Before a fresh Treehouse-backed spawn acquires, lease every pool slot
another task record still names, under the existing project allocation
lock, so the acquire skips it. A stale record for the spawning task itself
is skipped because the fresh spawn republishes it.
… in bin/fm-wake-lib.sh: it probes `treehouse lease --help` before `status --json`. If the subcommand is missing (CI-pinned Treehouse v2.0.1), it warns once on stderr and returns 0 instead of refusing the spawn. On v3.1.8 the probe succeeds and the existing fail-closed reservation runs unchanged. Updated the fake treehouse in tests/fm-spawn-slot-record-reservation.test.sh so `lease --help` exits 0, with a `.no-lease-command` marker that simulates v2.0.1. Added a regression case: with no lease subcommand, a spawn beside a kept record succeeds and warns. The reservation test passes locally; the two real-Herdr E2E tests were not run here, since they need real Herdr. An uncommitted edit to tests/fm-backend-herdr-presentation-e2e.test.sh was already in the worktree and I left it alone. The PR body should note the v2.0.1 vs v3.1.8 gap as a follow-up; the Treehouse pin is unchanged
@sKeLe100
sKeLe100 merged commit 02b4049 into main Nov 22, 2026
25 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