Repository navigation
fix(bin): place crew worktrees on the repo's own filesystem - #1
Merged
Merged
Conversation
* feat: add verified pi-signed adapter * no-mistakes(review): Correct pi-signed maintainer verification date * no-mistakes(review): Correct remaining pi-signed verification dates * no-mistakes(review): Preserve authoritative pi-signed runtime identity * no-mistakes(document): Document pi-signed shared adapter semantics * no-mistakes: apply CI fixes
* fix(pi): rearm watcher across same-process session transitions Pi emits session_shutdown for ordinary /new, /resume, and /fork replacement as well as terminal quit. The primary watcher extension latched a module-level stopping flag on every shutdown, so a replacement session in the same process could not arm monitoring until Pi restarted. Own arm authority per session generation so only the active live generation may start, stop, or rearm the child. Replacement sessions can arm again without restarting Pi, stale prior-generation callbacks cannot mutate the active cycle, and real quit still blocks late rearm. * no-mistakes(review): Preserve Pi generation isolation and exit cleanup * no-mistakes(document): Correct Pi watcher transition documentation
* Consume quota-axi pace signals in dispatch profile array selection. Add quota-array-dispatch as the single owner of the pace-aware candidate choice, keep AGENTS.md to the intake boundary and load trigger, and cover the acceptance cases with sanitized schemaVersion 3 fixtures. * no-mistakes(review): Stop and report genuine quota dispatch ties * no-mistakes(document): Document quota pace freshness and uncertainty
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)
CONTRIBUTING.md requires active empirical evidence in docs/verification/runtime-backends.md for changes to scripts that dispatch through bin/backends/, which includes bin/fm-teardown.sh. Records the 2026-07-28 reverification of projected-teardown focus restoration under the leased worktree-acquisition flow, run against Herdr 0.7.4 and Treehouse v2.1.0: tests/fm-backend-herdr-presentation-e2e.test.sh 22/22 ok across 3 consecutive runs (post-fix), plus the other seven real-Herdr suites and tests/fm-spawn-worktree-settle.test.sh, all green.
adibirzu
force-pushed
the
fm/fm-pool-relocation
branch
from
July 28, 2026 10:16
004d5ea to
149b811
Compare
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.
Retargeted from upstream to this fork per captain's instruction: firstmate work lands here first, not directly on kunchenguid/firstmate.
Supersedes kunchenguid#1142, which was opened against upstream only because
originin the checkout pointed at upstream rather than this fork. That remote layout is now corrected (origin=fork, upstream=canonical), so future PRs default here.Why
A linked worktree and the object store it points at must live on one filesystem. When split, git blocks in
read_gitfile_gentlyinsideopen(), sono-mistakes initandno-mistakes axi runhang forever and the crew can never run validation. Ordinary git reads inherit the open descriptor and look healthy, which makes it a trap rather than an obvious failure.Verification (local; CI is billing-blocked account-wide)