Repository navigation
fix(bin): reserve pool slots that kept task records still name - #313
Merged
Merged
Conversation
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
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
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
fm_treehouse_reserve_recorded_slotstobin/fm-wake-lib.sh. It finds every pool slot that another task'sworktree=record still names, such as a parked, shelved, or exited worker's kept copy. It then reserves each one with a durabletreehouse lease, so the pool can no longer hand that slot to a new task. The spawning task's own record is skipped. Ifjqis missing or the pool listing is unreadable, it refuses.bin/fm-spawn.shnow calls the reservation just beforetreehouse 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/scouttreehouse getpath is changed.tests/fm-spawn-slot-record-reservation.test.sh. The shared spawn fakebin intests/fixtures.shnow answerstreehouse status --jsonwith an empty pool.docs/architecture.mdand 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_idis a confirmed real field. Teardown'streehouse return --forcealready 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.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 unverifiedlease_idfield intreehouse status --json. The sweep in bin/fm-orphan-pane-sweep.sh only confirms a top-level array with.name,.pathand.status. The real CLI's pool here is empty ([]), and the test fake inventslease_idandlease_holder, so it passes whatever the real field is called. If the real field has another name,leaseis always empty. Every spawn then re-runstreehouse leaseon 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.statusas the sweep does, or treat an already-leased failure fromtreehouse leaseas non-fatal. The same assumption appears in tests/fm-spawn-slot-record-reservation.test.sh (fakestatus)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 statusfailing, an unparsable listing,treehouse leasefailing, 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.
bin/fm-test-run.sh --changed --exclude-family real-herdr-gated --exclude-quarantined --pc02-if-idlebash tests/fm-spawn-slot-record-reservation.test.shrealtreehouse status --json/treehouse lease 1 --lease-holder xin a throwaway repo with isolated HOME✅ **Document** - passed
✅ No issues found.
🔧 **Lint** - 1 issue found → auto-fixed ✅
🔧 Fix applied.
✅ Re-checked - no issues remain.
✅ **Push** - passed
✅ No issues found.