Repository navigation
fix(bin): isolate Treehouse crew pools per project clone - #14
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Reviewer's GuideThe PR prevents same-origin project clones in different Firstmate homes from sharing Treehouse slots by assigning each physical clone a hashed pool root outside the home tree, validating Git common-directory ownership before launch, and adding focused documentation and regression tests. Review the lifecycle implications of leaving hashed pools behind when homes are retired, and note that real Claude/Pi model sessions were not exercised. Sequence diagram for per-clone Treehouse slot acquisitionsequenceDiagram
participant Spawn as fm-spawn.sh
participant Treehouse
participant Pool as Hashed pool root
participant Git
participant Worker
Spawn->>Git: rev-parse --path-format=absolute --git-common-dir
Spawn->>Spawn: compute pool_hash from PROJ_ABS_REAL
Spawn->>Treehouse: treehouse get --root $HOME/.treehouse-fm/pool_hash
Treehouse->>Pool: allocate clone-specific slot
Spawn->>Git: fm_same_git_common_dir(PROJ_ABS, WT)
alt common directories match
Spawn->>Worker: publish metadata and launch worker
else common directories differ
Spawn-->>Worker: refuse launch before claim/metadata
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 186f9245c8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| else | ||
| pool_hash=$(printf '%s' "$PROJ_ABS_REAL" | cksum | awk '{printf "%08x", $1}') | ||
| fi | ||
| pool_root="$HOME/.treehouse-fm/$pool_hash" |
There was a problem hiding this comment.
Keep the pool root outside nested Firstmate homes
When HOME is equal to or nested beneath FM_HOME—a supported layout commonly used by containerized or isolated environments—this root remains inside the Firstmate home, so worker harnesses that discover ancestor instructions will still load that home's AGENTS.md/CLAUDE.md. This defeats the isolation this change is intended to provide and can inject the supervisor contract into ship/scout workers; canonicalize and reject or relocate the root whenever it falls beneath a Firstmate home.
AGENTS.md reference: AGENTS.md:L3-L5
Useful? React with 👍 / 👎.
… PR. bin/fm-spawn.sh now runs `treehouse get --root '<HOME>/.treehouse-fm/<hash>'`, but CI installs Treehouse v2.0.1 through bin/fm-install-treehouse.sh. That version rejects `--root` (checked against the real v2.0.1 release: `unknown flag: --root`; it doesn't read TREEHOUSE_ROOT either). The spawn pane never left the project directory, so all four failing tests (autodetect-smoke, launcher-workspace, presentation, workspace-per-home) timed out after 60s with "treehouse get did not enter an isolated worktree". Rule broken: the Treehouse that CI installs must support every flag fm-spawn.sh passes it. That installer is the only place CI installs Treehouse, so it is the only file changed. Fix: moved the pin to v2.3.0, the latest release, the version installed on this host, and the one docs/architecture.md already describes. Swapped in the four SHA-256 checksums published with the v2.3.0 release and updated the comments. Checked locally: the installer downloads, verifies and installs v2.3.0, and its `get --help` lists `--root`; a real `treehouse get --root <dir> --lease` makes the pool under <dir>/.treehouse/<pool>/1/<repo>; shellcheck passes; no test pins the old version. Not run locally: the real-Herdr tests, because the lab helper refuses to start unless exactly one default Herdr session is running and this host has none. The next CI run is the real check. ci-1 (Behavior portable serial 2): no change; not caused by this PR. The failing test, tests/fm-remote-secondmate-lifecycle-e2e.test.sh, never touches Treehouse or anything this PR changed; it only does secondmate spawns, which skip the new --root branch. In CI every assertion passed ("ALL TESTS PASSED"); only the final cleanup failed with `rm: cannot remove .../watch-liveness-unreachable: Directory not empty` because something was still writing into the temp directory. A local run failed at a different step ("the watcher did not exit on its auto-relaunch wake within the bound") and left a relaunched fm-watch.sh and an `fm-spawn.sh ios --secondmate` still writing to its temp directory, which fits the CI cleanup race. I confirmed those processes belonged to my run from their FM_HOME and state directory, then stopped them and deleted the directory. Recent main runs pass this test. It looks like a timing flake; making its cleanup wait for relaunched watchers would be a separate fix
Intent
In a secondmate home, Claude-harness spawns fail in fm-claude-trust.sh with 'is not a worktree of project', because that home's Treehouse pools are anchored to the main home's clones under ~/firstmate/projects/ and not to the home's own clones under /projects/. Pi spawns skip that check and are unaffected. Fix it: anchor pools per home, or have the trust check accept the pool's real git common dir. This is shared Firstmate tooling, so it ships through twilwa/firstmate's normal path and merges when green.
What Changed
bin/fm-spawn.shnow sendstreehouse get --root "$HOME/.treehouse-fm/<hash>", where the hash comes from the physical project clone path. Each clone, including a secondmate home's own clone under<home>/projects/, gets its own pool, even when it shares a remote with another home's clone. The root sits outside every Firstmate home, so no home'sAGENTS.md/CLAUDE.mdis an ancestor of a crew slot. The root also overrides any inheritedTREEHOUSE_ROOTor user-level Treehouse config.fm_same_git_common_dirhelper inbin/fm-wake-lib.sh, andfm_treehouse_pool_slotuses it too.docs/architecture.mdand thefm-spawn.shheader. A new regression intests/fm-spawn-pool-base-freshen.test.shcovers two homes cloned from the same origin: the foreign slot is refused, each home's own slot is accepted and claimed, and each clone gets a distinct pool root. To support the test,tests/fixtures.shgains anFM_TEST_USER_HOMEoverride, and the tangle-guard assertion now expects the--rootform.Risk Assessment
🚨 High: The fix resolves the trust-check failure, but moving every crew pool inside the Firstmate home makes Pi workers (verified from the installed Pi source) load the supervisor AGENTS.md in every project, which is a fleet-wide behavior regression that needs a human decision on where pools should live.
Testing
Drove the real fm-spawn.sh and fm-teardown.sh with the real treehouse v2.3.0 on a private tmux server, using a throwaway HOME and two Firstmate homes cloned from one origin. On base 51ccbfa, a Claude-harness spawn from the secondmate home reproduced the reported 'is not a worktree of project' failure. On target 582dd57, the same sequence gave each clone its own $HOME/.treehouse-fm/<hash> pool root, and the secondmate spawn got its own clone's slot, passed the Claude trust check, and launched. No slot has an AGENTS.md or CLAUDE.md ancestor, and the old ~/.treehouse pool was unchanged. A foreign slot planted into the secondmate's pool with real treehouse was refused before launch, leaving no metadata or claim. The two changed test suites pass. Real Claude and Pi model sessions were not started; the worker was a stand-in named claude. Overall: go.Evidence: Live lab transcript: base reproduction, target fix, ancestor walk, old-pool check, foreign-slot refusal
Source: Live lab transcript: base reproduction, target fix, ancestor walk, old-pool check, foreign-slot refusal
Evidence: tmux pane capture of the secondmate-home Claude worker launched in its per-clone slot
Source: tmux pane capture of the secondmate-home Claude worker launched in its per-clone slot
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-spawn.sh:4017- Crew pools nested inside the Firstmate home make Pi (and Claude) workers load the supervisor AGENTS.md/CLAUDE.md. The new root$(dirname "$PROJ_ABS_REAL")/.treehouseplaces every crew slot under the Firstmate home, e.g. ~/firstmate/projects/.treehouse/.treehouse/<pool>/1/<repo>, and for secondmate homes <home>/projects/.treehouse/... Both homes are checkouts of this repo with the 87K supervisor AGENTS.md and a CLAUDE.md that imports it at their root. The installed Pi harness (@earendil-works/pi-coding-agent, dist/core/resource-loader.js loadProjectContextFiles) walks every ancestor directory to / and loads AGENTS.md/CLAUDE.md from each. Its shadowing rule only drops the main-repo copy when the worktree is nested inside its own main repo, which is not the case here because the slot is a sibling of the project clone. So every Pi ship/scout worker, from the main home and every secondmate home, now loads the Firstmate supervisor contract as project instructions. Claude Code likewise loads ancestor CLAUDE.md files; its @AGENTS.md import is probably blocked by the external-import gate that fm-claude-trust.sh sets. Before this change slots lived under ~/.treehouse, with no AGENTS.md/CLAUDE.md in ~ or /home. The result is large context pollution and conflicting supervisor-vs-worker directives in other projects' workers. Remedy (a design choice, hence ask-user): keep the per-clone root but put it outside the home tree, e.g.--root "$HOME/.treehouse-fm/<hash of PROJ_ABS_REAL>", so no Firstmate instruction file is an ancestor of any slot. The same invariant applies to the documented location at docs/architecture.md:276 and the pane-log assertion at tests/fm-spawn-pool-base-freshen.test.sh:92.bin/fm-spawn.sh:4110- Extra refusal for a symlinked or non-file treehouse-state.json goes beyond the stated intent. The else branch adds a second new refusal: a slot whose$(dirname "$(dirname "$WT")")/treehouse-state.jsonexists as a symlink or directory. The intent (anchor pools per home, or accept the pool's real git common dir) needs only per-clone roots and, at most, the same-clone check at 4102-4109. This hardening path is not required. Recommend removing lines 4110-4114.bin/fm-spawn.sh:4102- The new same-clone check exits silently and repeats fm_treehouse_pool_slot's comparison. Lines 4102-4105 use a bare|| exit 1for the git rev-parse and cd steps. A failure there aborts the spawn with no diagnostic, unlike every other refusal in this block, which names the slot and window. The same common-dir resolution and comparison already exists in fm_treehouse_pool_slot (bin/fm-wake-lib.sh:1261-1273). Emit an error naming $WT and $T on these failures, or factor out a shared common-dir comparison helper.bin/fm-spawn.sh:4017---root <parent>/.treehouseyields a doubled .treehouse/.treehouse pool path. Treehouse v2.3 creates its own.treehouse/under the given --root; its help says '.' means an in-project pool. Verified with the installed binary:treehouse get --root X/.treehousecreates pools at X/.treehouse/.treehouse/<name>/<n>/<repo>. docs/architecture.md:276 describes only the argument, so it reads as if pools sit directly under<physical project parent>/.treehouse. Passing$(dirname "$PROJ_ABS_REAL")as the root gives the documented<parent>/.treehouse/<pool>layout. Update the test expectation at tests/fm-spawn-pool-base-freshen.test.sh:92 to match.🔧 Fix applied.
6 issues (2 errors, 2 warnings, 2 infos) still open:
bin/fm-spawn.sh:4017- Crew pools nested inside the Firstmate home make Pi (and Claude) workers load the supervisor AGENTS.md/CLAUDE.md. The new root$(dirname "$PROJ_ABS_REAL")/.treehouseplaces every crew slot under the Firstmate home, e.g. ~/firstmate/projects/.treehouse/.treehouse/<pool>/1/<repo>, and for secondmate homes <home>/projects/.treehouse/... Both homes are checkouts of this repo with the 87K supervisor AGENTS.md and a CLAUDE.md that imports it at their root. The installed Pi harness (@earendil-works/pi-coding-agent, dist/core/resource-loader.js loadProjectContextFiles) walks every ancestor directory to / and loads AGENTS.md/CLAUDE.md from each. Its shadowing rule only drops the main-repo copy when the worktree is nested inside its own main repo, which is not the case here because the slot is a sibling of the project clone. So every Pi ship/scout worker, from the main home and every secondmate home, now loads the Firstmate supervisor contract as project instructions. Claude Code likewise loads ancestor CLAUDE.md files; its @AGENTS.md import is probably blocked by the external-import gate that fm-claude-trust.sh sets. Before this change slots lived under ~/.treehouse, with no AGENTS.md/CLAUDE.md in ~ or /home. The result is large context pollution and conflicting supervisor-vs-worker directives in other projects' workers. Remedy (a design choice, hence ask-user): keep the per-clone root but put it outside the home tree, e.g.--root "$HOME/.treehouse-fm/<hash of PROJ_ABS_REAL>", so no Firstmate instruction file is an ancestor of any slot. The same invariant applies to the documented location at docs/architecture.md:276 and the pane-log assertion at tests/fm-spawn-pool-base-freshen.test.sh:92.bin/fm-spawn.sh:4110- Extra refusal for a symlinked or non-file treehouse-state.json goes beyond the stated intent. The else branch adds a second new refusal: a slot whose$(dirname "$(dirname "$WT")")/treehouse-state.jsonexists as a symlink or directory. The intent (anchor pools per home, or accept the pool's real git common dir) needs only per-clone roots and, at most, the same-clone check at 4102-4109. This hardening path is not required. Recommend removing lines 4110-4114.bin/fm-spawn.sh:4102- The new same-clone check exits silently and repeats fm_treehouse_pool_slot's comparison. Lines 4102-4105 use a bare|| exit 1for the git rev-parse and cd steps. A failure there aborts the spawn with no diagnostic, unlike every other refusal in this block, which names the slot and window. The same common-dir resolution and comparison already exists in fm_treehouse_pool_slot (bin/fm-wake-lib.sh:1261-1273). Emit an error naming $WT and $T on these failures, or factor out a shared common-dir comparison helper.bin/fm-spawn.sh:4017---root <parent>/.treehouseyields a doubled .treehouse/.treehouse pool path. Treehouse v2.3 creates its own.treehouse/under the given --root; its help says '.' means an in-project pool. Verified with the installed binary:treehouse get --root X/.treehousecreates pools at X/.treehouse/.treehouse/<name>/<n>/<repo>. docs/architecture.md:276 describes only the argument, so it reads as if pools sit directly under<physical project parent>/.treehouse. Passing$(dirname "$PROJ_ABS_REAL")as the root gives the documented<parent>/.treehouse/<pool>layout. Update the test expectation at tests/fm-spawn-pool-base-freshen.test.sh:92 to match.tests/fm-tangle-guard.test.sh:282- An existing test will now fail because the spawn sends different text to the pane.test_spawn_tmux_window_constructionchecks the tmux recorder log with a fixed-string grep forsend-keys -t @spawnwid treehouse get Enter.spawn_send_text_linerunstmux send-keys -t "$1" "$2" Enter(bin/backends/tmux.sh:121). bin/fm-spawn.sh:4029 now sendstreehouse get --root '<HOME>/.treehouse-fm/<hash>', so the recorded line becomestmux send-keys -t @spawnwid treehouse get --root '…' Enterand the grep no longer matches. The original commit introduced this and neither fix round updated it. Fix: have the assertion check thatsend-keys -t @spawnwid treehouse get --root 'goes to the stable window id and that the line ends withEnter.bin/fm-spawn.sh:4027- Crew pools for a secondmate home's project clones are left behind when that home is retired. The round-1 fix moved the pool root from beside the clone (inside the home) to$HOME/.treehouse-fm/<hash of PROJ_ABS_REAL>. That fix introduced this leak. Retiring a secondmate home deletes the home directory and itsprojects/clones (bin/fm-teardown.sh safe_rm_rf around 2508-2518). No code touches~/.treehouse-fm/<hash>/.treehouse/<pool>/<n>/<repo>, so every slot that home's crew used stays on disk as a full working tree whose.gitpoints at a deleted clone. With round-1 placement these were removed with the home. Reusing the same home path is harmless: I checked with Treehouse v2.3.0, and after the clone is recreated it skips the dead slot and makes a new one, so the old slot just stays stale. Disk use grows with each retired home. The smallest fix is new cleanup (drop the hashed root for each project clone when a home is retired), and it is that new cleanup, not the defect itself, that needs the user's approval. Note that the user's instruction not to migrate or destroy slots applies only to existing~/.treehouseslots.🔧 Fix applied.
1 warning still open:
bin/fm-spawn.sh:4027- Crew pools for a secondmate home's project clones are left behind when that home is retired. The round-1 fix moved the pool root from beside the clone (inside the home) to$HOME/.treehouse-fm/<hash of PROJ_ABS_REAL>. That fix introduced this leak. Retiring a secondmate home deletes the home directory and itsprojects/clones (bin/fm-teardown.sh safe_rm_rf around 2508-2518). No code touches~/.treehouse-fm/<hash>/.treehouse/<pool>/<n>/<repo>, so every slot that home's crew used stays on disk as a full working tree whose.gitpoints at a deleted clone. With round-1 placement these were removed with the home. Reusing the same home path is harmless: I checked with Treehouse v2.3.0, and after the clone is recreated it skips the dead slot and makes a new one, so the old slot just stays stale. Disk use grows with each retired home. The smallest fix is new cleanup (drop the hashed root for each project clone when a home is retired), and it is that new cleanup, not the defect itself, that needs the user's approval. Note that the user's instruction not to migrate or destroy slots applies only to existing~/.treehouseslots.✅ **Test** - passed
✅ No issues found.
git archive 51ccbfa/git archive HEADinto a throwaway lab, with HOME, TMUX_TMPDIR and FM_* overrides pointed at the labBase:fm-spawn.sh base-main-1 <main>/projects/proj --scout --harness claude --backend tmux, thenfm-teardown.sh base-main-1 --force, thenfm-spawn.sh base-sm1-1 <sm1>/projects/proj --scout --harness claude --backend tmux(reproduced the failure)Target: the same main spawn, force teardown and sm1 spawn sequence (tgt-main-1, tgt-sm1-1)git rev-parse --path-format=absolute --git-common-diron each slot,.fm-slot-ownerclaim,~/.claude.jsontrust entries, tmux capture-pane of the launched windowWalk from each new slot up to / looking for AGENTS.md or CLAUDE.mdCompare the old ~/.treehouse pool listing before and after the target runsAdversarial: realtreehouse get --root $HOME/.treehouse-fm/<sm1 hash>from the main clone to plant a foreign slot 2, thenfm-spawn.sh tgt-sm1-foreign ...(refused)bash tests/fm-spawn-pool-base-freshen.test.shbash tests/fm-tangle-guard.test.sh✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.
Summary by Sourcery
Isolate Treehouse pools per physical project clone and prevent workers from launching in slots owned by another clone.
Bug Fixes:
Enhancements:
Build:
Documentation:
Tests: