Repository navigation
pool: stop warm provisioning bricking pool slots (fixes all 10 review findings on #44) - #45
Merged
Merged
Conversation
The warm runs the project's installer inside the leased slot, npm rewrites the tracked lockfile it installed from, and treehouse's reset on return is `git clean -fd` - no checkout - so the slot comes back dirty, is skipped by every later get, and is refused by prune. Every warm retired one slot. Half of optiroq's pool had already gone that way. Not macOS-specific: the clone degrades cleanly on Linux, but the install still runs in the slot, so WSL gets bricked slots too, minus the saving. The provision now snapshots which tracked paths were already modified and, on the way out including SIGINT/SIGTERM, restores from HEAD exactly the ones the installer added. The predicate is `git status`, not `git diff`: under optiroq's `text=auto eol=lf` a CRLF rewrite is invisible to diff and visible to status, which is the case that bricked slots in practice. Also in the provisioner and the warm: - The pool guard was dead code. `cd "$wt/../.."` succeeds for nearly any path, so the script would install into any directory handed to it. It now verifies containment under the treehouse root and the <pool>/<slot>/<repo> shape, and refuses with a reason. - A failed provision was logged WARMED and cleared the disk-budget block. The status is propagated and the slot is reported COLD. - `cp -c` exits 0 when it silently falls back to a full copy, so the probe proved nothing. Detection is now same-device, then apfs, then the probe. - The provision deadline was taken after the get, which is bounded by the same value, so the lease and pool lock could be held for twice the stated bound. One deadline is taken before the lease and passed down. - A failed cache refresh no longer destroys the usable previous entry. - INT/TERM now clean up and exit rather than continuing unlocked. Coverage for each, all confirmed to fail against the pre-fix code.
Fail-closed was right, but one unreadable subdir - or a file another process removed mid-walk - exempted a session dir forever and printed an unexplained alarm, so scratch would grow without bound. "The probe cannot run at all" and "traversal hit one bad entry" are now different states. The first is fatal to the sweep and says so. The second spares one directory, names it in the summary, and is bounded by a hard ceiling measured on the directory itself with -maxdepth 0, so no unreadable child can defeat it. Two smaller ones in the same file: - `--max-age-hours 0` produced `-mmin -0`, which matches nothing, so every session dir including the live caller's read as dead. Rejected now, with a textual check because $(( 08 )) is an octal error rather than eight. - The comment justifying the removal of -quit was factually wrong: BSD find on this box accepts it. Restored behind a capability probe, with a comment that says what is true.
bin/fm-brief.sh tells every crew to keep a running plan at .fm/progress.md and never commit it, and bin/fm-teardown.sh reads untracked files as unlanded work and refuses to release the worktree. A crew that follows its brief bricks its own teardown; one had to be force-released today. fm-spawn.sh already excludes its harness hook files this way, so .fm/ joins them, for every harness. `git rev-parse --git-path` answers relative to the repo it was asked about, and the spawn's cwd is not that repo, so exclude_path now resolves a relative answer against the worktree instead of creating a stray .git/info/ wherever the spawn happens to be standing.
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.
Follow-up to #44, which is merged. An independent review of it found 10 defects; this branch fixes all 10, plus one small adjacent thing that bit us today.
1. Warm provisioning bricks the slot it warms - on every platform
What happens
bin/fm-pool-warm.shleases a slot, runs the project's installer inside it, and returns it. npm rewrites the lockfile it installed from, and that lockfile is a tracked file. treehouse's reset on return isgit clean -fd- no-x, no checkout - so it removes untracked cruft but cannot revert a tracked edit. The slot comes backdirty;treehouse getskips a dirty slot forever andprunerefuses to reclaim it. Every warm retires one slot permanently.It is worse than a leak, because the state it leaves is misread:
bin/fm-pool-status.shreports the slot DIRTY, andbootstrap-diagnosticstells firstmate to read a dirty slot as a dead crew's uncommitted work and points attreehouse destroy --include-unlanded- a discard command aimed at a slot that never held anyone's work.On this box it had already taken half of optiroq's pool: slots 1 and 4, both
M src/admin-app/package-lock.json.Those two are still dirty after this PR, deliberately. This change prevents further bricking; it does not repair damage already done. Reclaiming a dirty slot means discarding whatever is in it, and no automated fix should decide that a modified tracked file is worthless - it looks identical to a dead crew's uncommitted work. Reclaiming slots 1 and 4 is a separate, explicitly user-authorised action. Do not read a green
treehouse statusafter this merges as "the pool is whole".Is Linux affected? Yes.
Confirmed, and worth stating plainly because it changes who is exposed. The clone is the macOS-specific half: on Linux
can_clonefails cleanly (GNUcphas no-c) and the provision degrades to a plain install. But the install still runs inside the leased slot, so it still rewrites the tracked lockfile and the slot still comes back dirty. Nothing on the dirtying path is macOS-specific. A WSL user gets bricked slots the same way, minus the disk saving.tests/fm-worktree-provision.test.shcase (s) pins that down: it forces the no-clone path and asserts the slot still comes back clean.The fix
Before the installer runs, the provision records which tracked paths were already modified; on the way out - including the SIGINT/SIGTERM path - it restores from HEAD exactly the ones the installer added, and nothing else. Never a blanket
git checkout -- ., which would discard a crew's own edits.One thing that only showed up when it was run for real, and that a reasoned argument would have got wrong: the first version detected the modification with
git diff --name-only HEAD, and that predicate cannot see the case that actually bricks slots. optiroq's.gitattributessetstext=auto eol=lf, npm rewrotepackage-lock.jsonwith CRLF, and:So the restore found nothing to restore and left the slot bricked anyway. It now asks
git status --porcelain, the same predicate that decides the slot is dirty.git checkout HEAD -- <path>still repairs the file regardless of what diff thinks.The evidence
Real
npmon this box, against real optiroq, driving the warm's own three steps (treehouse get --lease-> provision ->treehouse return):The slot npm rewrote a tracked file in comes back
available, notdirty, and the two pre-existing dirty slots are untouched. It went straight back into service: a crew picked slot 3 up minutes later.The run against the pre-fix code, on the same pool, is the counterfactual: it left the slot with
M src/admin-app/package-lock.json, andtreehouse returnthen refused it (Worktree has uncommitted changes. Clean and return? [Y/n]->Aborted), stranding itleased. That slot was restored by hand and returned; the pool is whole apart from the two pre-existing dirty slots.src/portal-ui: install FAILEDis a pre-existing dependency conflict in optiroq itself, not something this branch causes:@mantine/[email protected]needs@mantine/[email protected], the project pins^9.4.1. It is shown here rather than hidden because it exercises finding 3 below - the root is reported cold and the provision exits 1.2. The pool guard was dead code
pool_key_ofderived the pool key fromcd "$wt/../..", which succeeds for very nearly any path, so the guard never fired: the script would runnpm installin any directory handed to it, includingprojects/<repo>- the read-only cloneAGENTS.mdrail 1 forbids writing to.It now verifies containment under
$TREEHOUSE_ROOTand the<pool>/<numeric-slot>/<repo>shape treehouse lays a slot out in, and refuses with a reason otherwise. A guard that cannot fail is not a guard.Case (i) asserted only
rc == 0and passed vacuously. It now asserts the installer did not run and no cache was written, and covers a misshapen in-root path (.../pool-x/notanumber/repo) as well as an outside-the-root one.3. A failed provision was reported as a warm slot
The provision's exit status was discarded, so an install that failed was logged
WARMEDandclear_blockedtold the disk-budget rail all was well. Before #44 an install failure surfaced through thetreehouse getrc asFAILED <name>; that path had no equivalent.The status is now captured and propagated:
FAILED <name>: <path> is free but COLD (provision exited N); the next crew installs for itself. The lease is still released either way - a cold slot belongs back in the pool. The evidence run above shows it firing on optiroq's real portal-ui failure.4. Fail-closed overshot into permanent exemption
The reaper sparing a directory on an unknown answer is right, but one unreadable subdir - or a file another process removed mid-walk - exempted that session dir forever and printed an unexplained alarm, so scratch would accumulate without bound.
"The probe cannot run at all" and "traversal hit one bad entry while otherwise answering" are now different states. The first is fatal to the whole sweep: nothing is reaped and the run says so. The second spares that one directory, names it, and is bounded by a hard ceiling (
--max-age-hoursx 7,FM_SCRATCH_HARD_CEILING_MULTIPLE) measured on the directory itself with-maxdepth 0, so no unreadable child can defeat it. Unknown is transient and diagnosable, not permanent.5.
can_clonecould not detect a silent non-clonecp -con macOS falls back tocopyfile(2)and exits 0 when cloning is impossible, so the probe's success proved nothing. On HFS+, exFAT, an external drive or a network mount the log would claimclone=yesand 96 MB while the box actually paid ~2.7 GB. It also probed only the destination, so a cross-volume pair was misjudged.Detection is now: same device for src and dst (
df -P), then that device's filesystem isapfs(mount), then a realcp -cprobe. All three must hold. When they do not it says so with the reason and installs without cloning - it never claims a saving it cannot prove. Linux keeps the property that made it safe there: GNUcphas no-c, so the probe fails cleanly.Case (o) stubs
df/mountto report a non-APFS device while realcp -cstill exits 0. Against the pre-fix code it reportsclone=yesand caches - the silent non-clone, reproduced.6. The provision deadline doubled the lease hold
The warm's timeout was taken after
treehouse getreturned, and the get is itself bounded by the same value - so a slow get plus a full provision budget held the treehouse lease and the pool lock for up to twice the bound the header promises. The lock is shared with every secondmate home pointing at that pool, so a second warmer waits out the doubled window.One deadline is now taken before the lease is asked for and passed down as
FM_PROVISION_DEADLINE. Case (r) drives a 4 s get against a 20 s bound and asserts the deadline handed to the provision is within 21 s of the start; against the pre-fix code it is 24 s.7.
-quitwas dropped on a justification that is factually wrongThe comment claimed BSD find does not accept
-quit. It does - on this box, today:The early exit is restored behind a capability probe (so a find that genuinely lacks it still works, just without the early exit), and the comment now says what is true. A wrong justification in a comment is worse than no comment, because the next reader will not revisit it.
The three PLAUSIBLE findings: all three implemented
clone_treedestroyed a usable cache on a failed refresh. It didrm -rf "$dst"before cloning. It now clones into a temp sibling and swaps, restoring the previous tree if the swap fails. Case (p) stubs acpthat fails only on-Rand asserts a canary in the cache survives.--max-age-hours 0gave-mmin -0. Where that matches nothing, every session dir including the live caller's reads as dead. It is now rejected with a reason. The check is textual (*[!0]*) rather than arithmetic, because$(( 08 ))is an octal error, not the eight the caller meant.Also here:
.fm/is excluded from the crew's worktreeAdjacent and small, but it cost a forced teardown today.
bin/fm-brief.shtells every crew to keep a running plan at.fm/progress.mdand never commit it - andbin/fm-teardown.shreads untracked files as unlanded work and refuses to release the worktree. A crew that follows its brief bricks its own teardown.fm-spawn.shalready excludes its harness hook files this way;.fm/now joins them, for every harness.exclude_pathneeded one fix to do that safely:git rev-parse --git-pathanswers relative to the repo it was asked about, and the spawn's cwd is not that repo, so on a plain clone it would have created a stray.git/info/wherever the spawn happened to be standing. It now resolves a relative answer against the worktree.What #44 measured still stands: disk, not speed
Unchanged from the merged PR, restated because it is the reason the feature exists. On optiroq, as
dfdeltas (ducannot see any of this - it counts every block a file references, shared or not):dfdelta)96.5% less real disk per additional slot, and essentially no time saved.
npm installdominates and the npm cache is already shared. Anyone deciding whether this is worth running should know it buys disk, not speed.Coverage
CI was green on #44's head, which is the plainest statement possible that the suite covered none of this. New coverage is part of the fix, not an extra - and every case below was run against the pre-fix code and confirmed to fail there:
git diffcannot see - is still restoredcp -cexits 0 on it--max-age-hours 0is refused.fm/progress.mdas briefed leaves a clean worktreebin/fm-lint.shclean.Test status, honestly
The full suite ran end to end: 69 of 74 suites passing in 541 s.
Four of the five failures are not this branch's doing - they fail identically against a pristine
origin/maincheckout in this environment, verified by extractingorigin/mainto a scratch dir and running them there:origin/mainfm-fleet-syncfm-graphfm-missionfm-watch-checkpointfm-missionis the known macOS BWK awk newline defect atbin/fm-mission.sh:191- deliberately not fixed here, worth its own task.fm-watch-checkpointis an artifact of thetimeoutstand-in this box needs to runbin/fm-test.shat all; CI has real coreutilstimeout.The fifth,
fm-bootstrap, flaked once under the parallel full-suite run on a 59 s timing assertion and passes 3/3 standalone on this branch (8 ok, 0 not ok), as it does onorigin/main. Reported rather than quietly re-run.