Repository navigation
Conversation
Owner
|
Automated reminder: thanks for the PR! This branch currently has a merge conflict with the base branch. When you get a chance, please rebase onto (or merge) the latest base branch, resolve the conflict, and push. After that, checks will re-run and the PR will get looked at again. Noted for firstmate#1142 at |
adibirzu
force-pushed
the
fm/fm-pool-relocation
branch
from
July 28, 2026 05:17
e470eac to
004d5ea
Compare
adibirzu
force-pushed
the
fm/fm-pool-relocation
branch
from
July 28, 2026 10:16
004d5ea to
149b811
Compare
adibirzu
force-pushed
the
fm/fm-pool-relocation
branch
from
July 29, 2026 03:45
7e7d3b9 to
ee0dba7
Compare
A firstmate home is routinely reachable through a symlinked ancestor, so one directory has two names. bin/ derives its root both ways: fm-arm-pretool-check.sh and fm-cd-pretool-check.sh resolve with pwd -P, while most scripts use a logical pwd. The watcher lock records fm-home and watcher-path as raw strings and every identity check compares them as raw strings, so a lock published under one name is never recognized when read under the other. The home then treats its own live watcher as somebody else's, and re-arming records the same divergent pair again, so nothing recovers on its own. Resolve both sides before comparing, in one shared comparison owner used by fm_watcher_lock_matches_pid and by the arm's stale-lock clear. Equal raw strings short-circuit, and a path that cannot be resolved keeps its raw value so two different removed homes still stay distinct. fm_lock_abs_path deliberately leaves the final component unresolved, which is right for the watcher-path file but leaves a symlinked home directory unresolved, so the home case resolves fully. Also derive fm-wake-lib.sh's default root and fm-watch-arm.sh's script dir with pwd -P, so the two scripts that publish this identity stop introducing the divergence at the source.
A linked worktree and the object store it points at must live on ONE filesystem. When they are split, git blocks in read_gitfile_gently inside open(), so `no-mistakes init` and `no-mistakes axi run` hang forever and the crew can never run the validation pipeline. Ordinary git reads inherit the open descriptor and look healthy, which is what makes it a trap. Repos on an external volume with the pool under $HOME are split by construction, so every crew worktree on such a fleet was unusable for validation. treehouse takes the pool root from a treehouse.toml in the REPO ROOT (no ancestor search) and otherwise defaults to $HOME. TREEHOUSE_DIR appears in the binary but does not select the pool - verified inert against both the v2.0.0 build and the v2.0.1 pin in bin/fm-install-treehouse.sh - so the only lever that does not write into a project repo is the HOME treehouse runs under. An interactive `treehouse get` runs the crew's shell as a child of treehouse, so that HOME would become the agent's HOME: wrong ~/.claude, wrong git config, wrong gh credentials (leak confirmed directly). Firstmate therefore leases the worktree itself with `treehouse get --lease` under a per-command HOME resolved from the repo, and sends the pane a plain cd - the one instruction every supported shell reads identically. Deriving the pool from the repo, not a fixed path, keeps this correct for a fleet holding repos on several volumes; a repo already on $HOME's filesystem keeps the default location unchanged. The lease also makes the acquisition deterministic: worktree= now comes from treehouse's own output rather than from polling the pane's cwd, so the transient stale pane_current_path some tmux/WSL setups report can no longer record another checkout as the worktree. Because a repo-root treehouse.toml still outranks that HOME, the invariant is also checked on the acquired worktree. Firstmate refuses to launch into a split worktree on the path it places, and reports rather than refuses on the Orca path, where `orca worktree create` takes no root argument and placement is not firstmate's to control. A lease is durable, so unlike the old interactive get the pool slot is not freed when the pane dies: fm-teardown.sh's existing `treehouse return --force` is what frees it, and a spawn that fails before publishing state/<id>.meta returns its own lease.
fm-spawn.sh now EXECUTES treehouse to lease the worktree instead of sending `treehouse get` to a fake pane, so a fixture whose fakebin has no treehouse stub falls through to the real binary and leases real pool slots against a test's throwaway repo. tests/fm-secondmate-harness.test.sh hit exactly that and its crew-unaffected case failed. Install the stub from fm_fakebin so every fakebin-based suite is covered at the source, and add it explicitly to the one fixture that builds its fakebin directly. Suites that want to record the invocation still call fm_fake_treehouse with their own arguments.
treehouse's prune and destroy operate on a pool, so one shared pool root means a cleanup aimed at one project can reach into another project's worktrees. That is not hypothetical: a pool currently holds worktrees carrying commits that exist nowhere else, and a prune to clear unrelated orphans would have taken them. Resolve each project to its own pool root under <filesystem>/.fm-pools/<slug>, where the slug is the repo's own directory name plus a discriminator derived from the canonical object-store path, so two projects that share a directory name still get separate pools. The filesystem is still chosen by the colocation rule, so this composes with the split-volume fix rather than replacing it. Existing pooled worktrees are unaffected: they keep their absolute paths, and fm-teardown.sh returns them by absolute path regardless of pool root.
…r leased acquisition The leased flow validates treehouse output before the armed isolation check, so the fake's bare 'exit 0 with no output' now dies on the new empty-path error and the fixture never reaches the validation it exists to pin. Yield the invoking project checkout instead: a path that exists but is not an isolated worktree, so the spawn proceeds past acquisition and the armed validation must stop it. Unmasks a further pre-existing failure in the same script (projected teardown focus restoration, case 9) that the case-8 abort previously hid; that defect is separate and still open.
…tree
teardown_task shape's projected teardown left the captain focused on an
unrelated workspace (w8, order-fail's trailing workspace) instead of
restoring w3/w3:t1, even though teardown itself exited 0.
Evidence (docs/prds/2026-07-28-fm1142-teardown-focus-prd.md, H2/H1):
- The only pane-close audit record for the projected pane
(herdr_pane_id=w4:p2 from on.meta) was:
pane-close w8/w8:t2 w8/w8:t2 w4:p2
Both the before and after focus snapshots already read w8/w8:t2 - the
live Herdr focus had already moved to the trailing workspace before this
call, and no earlier pane-close record for w4:p2 exists. This matches
the H2 discriminator row exactly (focus stolen before any presentation-
path Herdr call touched the pane).
- on-teardown.err contained:
warning: herdr presentation journal for shape remains quarantined; no
workspace cleanup was attempted
and home/state/shape.herdr-presentation survived teardown - the H1
mechanism signature (the retire-candidate gate went false and control
fell to the raw kill fallback).
- Journal fields (workspace_id/tab_id/pane_id = w4/w4:t2/w4:p2) matched
on.meta exactly, and every Herdr container id created during the run
(w1..wA) was monotonic with no reuse, refuting H3 and H4.
- assert_focus_is "$CAPTAIN_FOCUS" passed at 7+ points up to and including
immediately before teardown (:780); the branch does not touch
fm-teardown.sh, backends/herdr.sh, or the captain-fixture creation, and
CAPTAIN_FOCUS was last changed by pre-branch commits f9a89c3/c58cb0f -
refuting H5 (the fixture is correct, not stale).
- fm_backend_herdr_projection_close_pane_focus_preserving only runs inside
the retire-candidate branch (old :1180), which never became true here,
so the restore helper never ran at all - refuting H6 (it never got the
chance to hit its own failure mode).
Root cause (bin/fm-teardown.sh:1153 pre-fix / product code, not the test):
teardown_treehouse_return ran before the Herdr presentation retire-
candidate gate. Under this branch's leased worktree-acquisition flow
(bin/fm-spawn.sh:1301-1345), the task pane's own top-level shell has cwd
set to the worktree itself (a plain `cd`, not a treehouse child subshell
as under the old interactive `treehouse get` flow). `treehouse return
--force` kills that shell directly, collapsing the pane's workspace via
Herdr's own dead-pane cleanup before any firstmate code ran. The gate's
token-correlation check then failed (the workspace was already gone),
so control fell to the raw `fm_backend_kill` fallback - a bare
`herdr pane close` with no focus snapshot or restore, and a no-op besides
since the pane was already dead.
Fix: run the Herdr presentation retire-candidate gate and
fm_backend_herdr_projection_close_pane_focus_preserving before
teardown_treehouse_return, while the pane is still alive, so the existing
focus-snapshot/close/restore primitive gets the chance its own logic was
written for. The general non-presentation fallback kill and the journal
quarantine bookkeeping stay in their original position (after the
worktree return), unchanged, so no other backend's teardown ordering
moves.
Verification (all from /home/adi/.fm-1142-wt):
- tests/fm-backend-herdr-presentation-e2e.test.sh: 22/22 ok, exit 0,
3 consecutive runs (was: not ok at "projected teardown")
- tests/fm-backend-herdr.test.sh: 132/132 ok, exit 0
- tests/fm-backend-herdr-eventwait-smoke.test.sh: 3/3 ok, exit 0
- tests/fm-backend-herdr-prune-safety-e2e.test.sh: 6/6 ok, exit 0
- tests/fm-backend-herdr-respawn-idem-e2e.test.sh: 6/6 ok, exit 0
- tests/fm-backend-herdr-smoke.test.sh: 16/16 ok, exit 0
- tests/fm-backend-herdr-workspace-per-home-e2e.test.sh: 10/10 ok, exit 0
- tests/fm-spawn-worktree-settle.test.sh: 11/11 ok, exit 0
- bin/fm-lint.sh: exit 0 (ShellCheck 0.11.0)
BARF-AI
force-pushed
the
fm/fm-pool-relocation
branch
from
August 5, 2026 16:21
ee0dba7 to
0bfc331
Compare
Author
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
PR #1142 (per-project worktree pools): fix the two Behavior-tests-Herdr CI failures — post-create abort fixture updated for leased acquisition, and the projected-teardown focus regression root-caused (treehouse return --force killed the pane's shell before the presentation restore block) and fixed by closing the presentation pane before returning the worktree; 22/22 presentation e2e x3 + 132/132 backend suite green locally. Goal: green Herdr CI lane + the Require-no-mistakes signature on PR #1142.
What Changed
treehouse get --leasefrom a per-project pool placed on the repo's own filesystem. The newbin/fm-treehouse-lib.shselects the pool by running treehouse under a per-commandHOMEand verifies the acquired worktree is colocated with the object store, preventing the cross-filesystem split that madeno-mistakes init/axi runhang inside git's gitfile open.treehouse return --forcekilled the pane's shell first, letting Herdr's last-pane cleanup destroy the workspace and steal focus), and lease failures now surface treehouse's stderr instead of a generic error. Watcher lock checks also resolve identity paths before comparing.Risk Assessment
✅ Low: All three accepted round-1 findings are fixed correctly in 94148ff (abort-path pane-close-before-return ordering, teardown abort instead of focus-unsafe return under lock contention, lease stderr surfaced with proper temp-file hygiene), no test pins the replaced behaviors, and the only remaining item is an informational version-skew note that CI will confirm.
Testing
Ran the intent-targeted suites against the real Herdr 0.7.4 lab: the presentation e2e passed 22/22 in three consecutive runs with both previously-failing CI checks (post-create abort serialization with focus restoration, and task-pane close restoring the captain's workspace/tab after Herdr's focus steal) green every time; the leased-acquisition/pool-relocation suite passed 11/11; and the teardown, watcher-lock, and backend suites covering the other changed scripts all passed. No UI surface exists for this terminal-multiplexer change, so the real-Herdr lab transcripts serve as the product-level evidence; the full 132-test backend suite is owned by remote CI per repo policy and was deliberately not re-run locally.
Evidence: Distilled evidence summary (both fixed CI checks + x3 stability tally)
## The two previously-failing Herdr CI checks, now green in a real Herdr lab (Herdr 0.7.4): ok - real Herdr lab: concurrent post-create abort cleanup stays serialized with exact focus restoration ok - real Herdr lab: exact task-pane close restores the exact captain workspace/tab after Herdr's raw focus steal ## Presentation e2e stability, three consecutive full runs: run 1: 22/22 ok, 0 failures (duration_ms=72440) run 2: 22/22 ok, 0 failures (duration_ms=72315) run 3: 22/22 ok, 0 failures (duration_ms=72177)Evidence: Presentation e2e full transcript, run 1
Evidence: Presentation e2e full transcript, run 2
Evidence: Presentation e2e full transcript, run 3
Evidence: Leased acquisition / worktree settle transcript (11/11)
Evidence: Teardown, watcher-lock, and backend suite transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-spawn.sh:273- spawn_abort_cleanup returns the leased worktree before the herdr projection exact-pane close, reintroducing on the spawn-abort path the same ordering failure commit ab5cadf root-caused and fixed in fm-teardown.sh. Concrete path: projected herdr spawn arms HERDR_PROJECTION_ABORT_CLEANUP (~line 1043) and TREEHOUSE_LEASE_ABORT_CLEANUP (line 1309); after the pane lands in the leased worktree, any set -e failure before meta publication at line 1533 (hook-file write, TASK_TMP mkdir, exclude_path git call) fires the EXIT trap, which runstreehouse return --force $WT(line 276) first — killing the pane's top-level shell whose cwd is the worktree — so Herdr's last-pane cleanup destroys the workspace and steals focus before fm_backend_herdr_projection_cleanup_exact (line 289) can close the pane focus-preservingly. Fix at the shared boundary: perform the HERDR_PROJECTION_ABORT_CLEANUP blocks before the lease return inside spawn_abort_cleanup, mirroring the teardown ordering fix.bin/fm-teardown.sh:1179- When the presentation focus lock cannot be acquired within ~5s (50 x 0.1s), teardown skips the exact-pane close with a warning but still proceeds to teardown_treehouse_return, which kills the still-live pane shell — the same Herdr last-pane focus steal this branch fixes, now reachable only under lock contention. The fix's own invariant ('close the presentation pane before returning the worktree') is violated on this branch. Consider deferring/aborting the worktree return (or retrying the lock longer) instead of proceeding with an unclosed live pane; whether teardown should block on contention is the author's call.bin/fm-spawn.sh:1301- Thetreehouse get --leaseinvocation discards stderr (2>/dev/null), so every lease failure — pool exhaustion, unwritable mount-root .fm-pools directory (a real case when fm_treehouse_pool_home resolves to a filesystem mount point), unsupported --lease flag on an older treehouse — collapses into the same generic 'could not lease a worktree' message with no root cause for the operator. Capture treehouse's stderr (e.g. to a temp file or variable) and include it in the failure diagnostic.docs/verification/runtime-backends.md:199- The recorded reverification evidence for the teardown-ordering fix was gathered against Treehouse v2.1.0, while CI installs the v2.0.1 pin from bin/fm-install-treehouse.sh (FM_TREEHOUSE_CI_VERSION=2.0.1). The intent's narrative (only 2 of 22 presentation e2e tests failing in CI under the leased flow) evidences that v2.0.1 supportsget --lease, so this is a version skew in the evidence, not a demonstrated defect; the pipeline's CI step will confirm behavior on the pinned version.🔧 Fix: fix abort/teardown pane-close ordering and surface lease stderr
1 info still open:
docs/verification/runtime-backends.md:199- Carried forward from round 1 (unaddressed by the fix commit, informational only): the recorded reverification evidence for the teardown-ordering fix was gathered against Treehouse v2.1.0, while CI installs the v2.0.1 pin from bin/fm-install-treehouse.sh (FM_TREEHOUSE_CI_VERSION=2.0.1). The intent's narrative (only 2 of 22 presentation e2e tests failing in CI under the leased flow) evidences that v2.0.1 supportsget --lease, so this is a version skew in the evidence, not a demonstrated defect; the pipeline's CI step will confirm behavior on the pinned version.✅ **Test** - passed
✅ No issues found.
bin/fm-test-run.sh tests/fm-spawn-worktree-settle.test.sh— leased acquisition, per-project pools, and post-create abort/settle contract (11/11 ok)bin/fm-test-run.sh tests/fm-backend-herdr-presentation-e2e.test.shrun 1 — real Herdr 0.7.4 lab, 22/22 ok including 'concurrent post-create abort cleanup stays serialized with exact focus restoration' and 'exact task-pane close restores the exact captain workspace/tab after Herdr's raw focus steal'bin/fm-test-run.sh tests/fm-backend-herdr-presentation-e2e.test.shrun 2 — 22/22 ok (flake check)bin/fm-test-run.sh tests/fm-backend-herdr-presentation-e2e.test.shrun 3 — 22/22 ok (flake check)bin/fm-test-run.sh tests/fm-teardown.test.sh tests/fm-watcher-lock.test.sh tests/fm-backend.test.sh— remaining suites owning the changed scripts, all exit=0git status --porcelain— worktree clean, no transient test artifacts left behindbin/backends/zellij.sh:388- bin/backends/zellij.sh and bin/backends/cmux.sh current-path comments still narrate the old in-panetreehouse getforeground-subshell flow as the probe's rationale (and zellij.sh cites a docs/zellij-backend.md heading that no longer exists - a pre-existing mismatch). Left intact because they preserve verified empirical pitfall evidence; a follow-up comment refresh to the leased plain-cdflow would be reasonable.✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.