Skip to content

fix(bin): bind new Treehouse worker allocations to the spawning clone's Git common directory - #8

Merged
twilwa merged 12 commits into
mainfrom
fm/fm-local-only-secondmate-support
Sep 26, 2026
Merged

twilwa merged 12 commits into
mainfrom
fm/fm-local-only-secondmate-support

Conversation

@twilwa

@twilwa twilwa commented Sep 23, 2026 •

Copy link
Copy Markdown
Owner

Intent

New concrete provisioning blocker for the repo-orchestrator objective: sm-story-to-anime could not launch its bounded scout. Evidence ~/.treehouse/firstmate-e3a38d/9/firstmate/data/sta-future-gates/launch-blocker.json. fm-spawn allocated ~/.treehouse/story-to-anime-519e0f/4/story-to-anime with git-common-dir under PRIMARY projects/story-to-anime, while secondmate clone has a different .git; Claude trust pre-registration refused. No task metadata or worker launched; possible residual empty Herdr pane firstmate:w67:p3. Diagnose this supported multi-home pool/provenance path as part of enabling repo orchestration, before broad local-only changes. Load diagnostic-reasoning; reproduce only in isolated fixtures, separate trigger/mask/symptom, compare same-clone and different-clone cases plus history and disconfirming case. Need supported allocation/custody repair, never weaken trust or simply switch harness to evade it. Coordinate resulting scope and minimum safe fix; no production lifecycle experiments or pool cleanup without ownership proof. This can be an initial separable fix if broader local-only support is unnecessary to resolve it.

Primary has reviewed the pool-provenance diagnosis and accepts the bounded repair scope already released. Keep pool-custody repair evidence separately reviewable from the broader local-only provisioning change. Report the next immutable head, validation result and precise remaining adoption prerequisites when available; seven repo orchestrators and the anime retry depend on this. Preserve all existing custody and continue within current authorization.

The accepted bounded repair scopes new Treehouse worker allocations to the requesting clone's canonical Git common directory plus /firstmate-treehouse, explicitly overriding ambient pool-root configuration for those new allocations. Require an isolated linked worktree with that same canonical common directory before refresh, slot claims, hooks, trust registration, or worker launch. Preserve existing origin-based project locks, slot ownership, absolute-path returns, stale-read settling, primary/subdirectory/symlink refusals, and unchanged Claude trust. Validate recorded custody on legacy relaunch without silently reallocating. Preserve foreign, dirty, or unlanded work on refusal; do not migrate or clean existing pool slots or introduce automatic residual endpoint cleanup. Keep this allocation/custody repair separately reviewable; broader local-only provisioning and guarded-primary-landing support follow separately.

Preserve unlanded work, isolated homes, exact parent routing, lock ownership, transactional rollback, failure reporting and teardown safety across supported backends. No production lifecycle experiments, resets, forced convergence, paid access or merge authority. Use no-mistakes with yolo off and deliver a reviewable PR. Primary owns actual migration/provisioning after support is accepted.

What Changed

  • bin/fm-spawn.sh now resolves the spawning project's canonical Git common directory and uses it in two places. New Treehouse allocations get their per-clone --root ($HOME/.treehouse-fm/<hash>) from a hash of that directory instead of the clone path, overriding ambient Treehouse root config for new allocations only. Worktree isolation also requires a linked worktree sharing that common directory, so a different clone of the same origin is refused with the cause named. The check runs before base refresh, slot claims, hooks, trust registration and launch; relaunch validates the recorded worktree the same way without reallocating.
  • Custody refusals now preserve resources: an Orca allocation that fails the check keeps its worktree and terminal (with a warning naming both) instead of being removed/closed, and the global Kimi turn-end hook is installed only after the worker's worktree passes custody checks.
  • Adds regressions for pool isolation/freshness, the Orca foreign-allocation case and Kimi hook ordering, plus an opt-in live test (tests/fm-treehouse-clone-custody.test.sh) driving real Treehouse allocations across two clones of one origin; bin/fm-test-run.sh routes bin/fm-spawn.sh changes to these tests, docs/architecture.md and the secondmate-provisioning skill document the new root/custody rules, and bin/fm-quota-axi-lib.sh replaces the harness→provider lookup table with an equivalent case.

Risk Assessment

🚨 High: The custody guard is sound, but the chosen pool root puts every crew slot under a Firstmate home and removes upstream's reviewed guarantee against inherited operator instructions, and the merge also carries unrelated real-data fixtures that upstream deliberately removed, so explicit human approval is needed.

Testing

The Test agent exceeded its invocation budget before live validation completed; no evidence was gathered for this head.

  • Outcome: ⏭️ skipped across 1 run (30m1s)

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 5 issues (1 error, 2 warnings, 2 infos)
  • 🚨 bin/fm-spawn.sh:4038 - The clone-scoped pool root puts every crew slot inside a Firstmate home, which makes the home's and the primary checkout's AGENTS.md/CLAUDE.md ancestors of worker directories. New allocations run treehouse --root &lt;PROJ_COMMON_REAL&gt;/firstmate-treehouse get. Project clones live at $FM_HOME/projects/<repo> (bin/fm-bootstrap.sh:165, bin/fm-fleet-snapshot.sh:133), so a slot resolves to <home>/projects/<repo>/.git/firstmate-treehouse/.treehouse/<pool>/<n>/<repo>. Concrete path: a Claude ship/scout spawned from <home>/projects/story-to-anime starts in that slot. Claude Code loads CLAUDE.md from every parent directory, so the worker ingests <home>/CLAUDE.md (@AGENTS.md, the firstmate operator instructions) and the primary checkout's own AGENTS.md/CLAUDE.md, which may be a different version from the slot's branch. Upstream fix(bin): isolate Treehouse crew pools per project clone #14 (1698a36) deliberately moved roots to $HOME/.treehouse-fm/<hash> so that no Firstmate home's AGENTS.md/CLAUDE.md is an ancestor of a crew slot, and its review asserted this in assert_pool_root_outside_homes. This merge deletes that assertion (tests/fm-spawn-pool-base-freshen.test.sh:62-71, replaced by assert_clone_pool_root) and the invariant sentence in docs/architecture.md:276. Other sites that must change together: the fm-spawn.sh header at 226-230, docs/architecture.md:276-277, .agents/skills/secondmate-provisioning/SKILL.md:164-165, tests/fm-treehouse-clone-custody.test.sh:81-84, and in tests/fm-spawn-pool-base-freshen.test.sh assert_clone_pool_root and test_allocation_root_uses_canonical_clone_custody. The user intent names '<canonical common dir>/firstmate-treehouse' as the root, so choosing between that location and upstream's outside-home invariant needs a user decision. One option that keeps both guarantees: key the root by the canonical common dir but place it outside homes, e.g. $HOME/.treehouse-fm/<hash of PROJ_COMMON_REAL>.
  • ⚠️ tests/fixtures/pr-review-ledger/github--twilwa--engineering-workflow-study--1.json:1 - The merge carries fork-only, out-of-scope content, including unused real-data PR-ledger fixtures that upstream deliberately replaced with synthetic ones. Intent: 'Keep this allocation/custody repair separately reviewable; broader local-only provisioning and guarded-primary-landing support follow separately.' Relative to origin/main (c4fa12f), the merge adds five fixtures that no test reads: tests/fixtures/pr-review-ledger/github--twilwa--{engineering-workflow-study--1,firstmate--2,firstmate--3,jev-code--1,story-to-anime--1}.json. tests/fm-pr-review.test.sh:424-450 uses only held.json and undispositioned.json. The five files hold real PR URLs, head SHAs and internal hold reasons, for example 'whether the repository keeps its private remote', 'an unresolved licence rights gate' and 'five unresolved episode-one product decisions'. Upstream feat(bin): add head-keyed PR review ledger with opt-in reviewed-head merge handoff #16 (2044333) review commit 'synthesize ledger fixtures' replaced exactly these with synthetic ones. The merge also brings unrelated changes at bin/fm-quota-axi-lib.sh:137-143 (a fork CI fix) and bin/fm-brief-heading-lib.sh:94 (trailing newline). Recommended remedy, pending the user's decision: drop the five fixtures from this PR and split the non-custody changes out.
  • ⚠️ bin/fm-spawn.sh:4133 - The Kimi global-hook refusal now happens after pane creation, slot allocation and base refresh, and its error does not name the leftover endpoint. The install of fm-kimi-turnend-hook.sh moved from the pre-pane preflight (old line ~2569) to after freshen_spawn_worktree_base. Concrete path: with a malformed ~/.kimi-code/config.toml, a Kimi ship spawn opens a tmux/herdr window, runs treehouse get (the pane's shell keeps the slot's process lease), refreshes the slot to base, then exits with 'refusing Kimi spawn because the global turn-end hook could not be installed safely'. Before this change the same spawn was refused before any pane existed, which the replaced test_kimi_spawn_refuses_unsafe_global_config_before_pane_creation asserted. The abort trap releases the slot claim, but the window and its leased slot stay behind. The neighbouring claude-trust refusal includes 'inspect window $T'; this message does not, so the operator is not told which endpoint was left. Moving the hook install after the custody check is required by the intent. Keeping an early refusal would need a new read-only validation mode in fm-kimi-turnend-hook.sh, which extends the change, so that remedy needs authorization. Appending '; inspect window $T' to the message at bin/fm-spawn.sh:4135 is a mechanical fix.
  • ℹ️ bin/fm-claude-trust.sh:114 - Some comments are now stale, and one common-dir recheck is now redundant, because spawn_worktree_isolated gained the custody comparison. It now refuses any worktree whose common dir differs from PROJ_COMMON_REAL (bin/fm-spawn.sh:3085). The comment at bin/fm-claude-trust.sh:114-116 still says fm-spawn's validate_spawn_worktree never compares common dirs, and docs/orca-backend.md:78 describes the same gap. In bin/fm-spawn.sh:4117-4124, the else-branch fm_same_git_common_dir &#34;$PROJ_ABS&#34; &#34;$WT&#34; can no longer fail after validate_spawn_worktree runs at 4097, and its comment ('that check proves isolation, not this home's Git ownership') is now false. Update the comments and either drop the redundant recheck or annotate it as defensive.

🔧 Fix applied.
5 issues (1 error, 2 warnings, 2 infos) still open:

  • 🚨 bin/fm-spawn.sh:4038 - The clone-scoped pool root puts every crew slot inside a Firstmate home, which makes the home's and the primary checkout's AGENTS.md/CLAUDE.md ancestors of worker directories. New allocations run treehouse --root &lt;PROJ_COMMON_REAL&gt;/firstmate-treehouse get. Project clones live at $FM_HOME/projects/<repo> (bin/fm-bootstrap.sh:165, bin/fm-fleet-snapshot.sh:133), so a slot resolves to <home>/projects/<repo>/.git/firstmate-treehouse/.treehouse/<pool>/<n>/<repo>. Concrete path: a Claude ship/scout spawned from <home>/projects/story-to-anime starts in that slot. Claude Code loads CLAUDE.md from every parent directory, so the worker ingests <home>/CLAUDE.md (@AGENTS.md, the firstmate operator instructions) and the primary checkout's own AGENTS.md/CLAUDE.md, which may be a different version from the slot's branch. Upstream fix(bin): isolate Treehouse crew pools per project clone #14 (1698a36) deliberately moved roots to $HOME/.treehouse-fm/<hash> so that no Firstmate home's AGENTS.md/CLAUDE.md is an ancestor of a crew slot, and its review asserted this in assert_pool_root_outside_homes. This merge deletes that assertion (tests/fm-spawn-pool-base-freshen.test.sh:62-71, replaced by assert_clone_pool_root) and the invariant sentence in docs/architecture.md:276. Other sites that must change together: the fm-spawn.sh header at 226-230, docs/architecture.md:276-277, .agents/skills/secondmate-provisioning/SKILL.md:164-165, tests/fm-treehouse-clone-custody.test.sh:81-84, and in tests/fm-spawn-pool-base-freshen.test.sh assert_clone_pool_root and test_allocation_root_uses_canonical_clone_custody. The user intent names '<canonical common dir>/firstmate-treehouse' as the root, so choosing between that location and upstream's outside-home invariant needs a user decision. One option that keeps both guarantees: key the root by the canonical common dir but place it outside homes, e.g. $HOME/.treehouse-fm/<hash of PROJ_COMMON_REAL>.
  • ⚠️ tests/fixtures/pr-review-ledger/github--twilwa--engineering-workflow-study--1.json:1 - The merge carries fork-only, out-of-scope content, including unused real-data PR-ledger fixtures that upstream deliberately replaced with synthetic ones. Intent: 'Keep this allocation/custody repair separately reviewable; broader local-only provisioning and guarded-primary-landing support follow separately.' Relative to origin/main (c4fa12f), the merge adds five fixtures that no test reads: tests/fixtures/pr-review-ledger/github--twilwa--{engineering-workflow-study--1,firstmate--2,firstmate--3,jev-code--1,story-to-anime--1}.json. tests/fm-pr-review.test.sh:424-450 uses only held.json and undispositioned.json. The five files hold real PR URLs, head SHAs and internal hold reasons, for example 'whether the repository keeps its private remote', 'an unresolved licence rights gate' and 'five unresolved episode-one product decisions'. Upstream feat(bin): add head-keyed PR review ledger with opt-in reviewed-head merge handoff #16 (2044333) review commit 'synthesize ledger fixtures' replaced exactly these with synthetic ones. The merge also brings unrelated changes at bin/fm-quota-axi-lib.sh:137-143 (a fork CI fix) and bin/fm-brief-heading-lib.sh:94 (trailing newline). Recommended remedy, pending the user's decision: drop the five fixtures from this PR and split the non-custody changes out.
  • ⚠️ bin/fm-spawn.sh:4133 - The Kimi global-hook refusal now happens after pane creation, slot allocation and base refresh, and its error does not name the leftover endpoint. The install of fm-kimi-turnend-hook.sh moved from the pre-pane preflight (old line ~2569) to after freshen_spawn_worktree_base. Concrete path: with a malformed ~/.kimi-code/config.toml, a Kimi ship spawn opens a tmux/herdr window, runs treehouse get (the pane's shell keeps the slot's process lease), refreshes the slot to base, then exits with 'refusing Kimi spawn because the global turn-end hook could not be installed safely'. Before this change the same spawn was refused before any pane existed, which the replaced test_kimi_spawn_refuses_unsafe_global_config_before_pane_creation asserted. The abort trap releases the slot claim, but the window and its leased slot stay behind. The neighbouring claude-trust refusal includes 'inspect window $T'; this message does not, so the operator is not told which endpoint was left. Moving the hook install after the custody check is required by the intent. Keeping an early refusal would need a new read-only validation mode in fm-kimi-turnend-hook.sh, which extends the change, so that remedy needs authorization. Appending '; inspect window $T' to the message at bin/fm-spawn.sh:4135 is a mechanical fix.
  • ℹ️ bin/fm-claude-trust.sh:114 - Some comments are now stale, and one common-dir recheck is now redundant, because spawn_worktree_isolated gained the custody comparison. It now refuses any worktree whose common dir differs from PROJ_COMMON_REAL (bin/fm-spawn.sh:3085). The comment at bin/fm-claude-trust.sh:114-116 still says fm-spawn's validate_spawn_worktree never compares common dirs, and docs/orca-backend.md:78 describes the same gap. In bin/fm-spawn.sh:4117-4124, the else-branch fm_same_git_common_dir &#34;$PROJ_ABS&#34; &#34;$WT&#34; can no longer fail after validate_spawn_worktree runs at 4097, and its comment ('that check proves isolation, not this home's Git ownership') is now false. Update the comments and either drop the redundant recheck or annotate it as defensive.
  • ℹ️ bin/fm-spawn.sh:4043 - Switching the hash input from PROJ_ABS_REAL (the base commit's upstream fix(bin): isolate Treehouse crew pools per project clone #14 scheme) to PROJ_COMMON_REAL changes the root for every existing primary clone: it now hashes &lt;clone&gt;/.git instead of &lt;clone&gt;. After merge, the first new allocation from each clone lands in a fresh $HOME/.treehouse-fm/&lt;new hash&gt; pool. Idle slots in the previous per-clone roots are not reused or cleaned. Recorded tasks keep working, because relaunch validates the recorded worktree and returns use absolute paths. This matches the user's instruction and the intent's no-migration/no-cleanup constraint, and docs/architecture.md:277 says older pools are left in place. It is listed only as an adoption prerequisite: Primary owns reclaiming the orphaned idle slots once it has proven who owns them.
⏭️ **Test** - skipped
  • ⚠️ The Test agent did not finish within its invocation budget. Reported: agent run tests timed out after 30m0s: agent last produced output 515ms ago (123 observed); agent reported: claude parse events: context deadline exceeded. This is a budget or provider-slowness cut, not a code failure. Re-running the same request costs another full budget, so no further attempt is made automatically. If this repository's targeted tests or evidence gathering routinely approach the default 30m0s, raise test_agent_timeout in global config. Respond with fix to spend another budget: a repair turn runs only for selected findings other than this budget cut, then validation re-runs. Or abort and retry after raising the budget.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Summary by Sourcery

Enforce clone custody for new worker allocations while preserving existing task resources and legacy pool ownership.

Bug Fixes:

  • Bind new Treehouse worker allocations to the requesting clone’s canonical Git common directory, preventing same-origin foreign clones from supplying worktrees.
  • Preserve unverified Orca allocations and Kimi worktrees when custody or hook validation fails instead of removing resources or launching workers.

Enhancements:

  • Require custody validation before refresh, slot claims, hooks, trust registration, or worker launch while preserving recorded worktrees on relaunch.
  • Keep new Treehouse pools outside Firstmate homes, override ambient root configuration, and retain legacy pool ownership and absolute-path return behavior.

CI:

  • Route fm-spawn changes to the pool and clone-custody regression suites and classify the live Treehouse custody test as opt-in.

Documentation:

  • Document clone-scoped Treehouse roots, custody requirements, relaunch behavior, and cross-clone allocation rules.

Tests:

  • Add regression coverage for foreign clone refusal, canonical root selection, legacy relaunch preservation, Orca resource custody, Kimi hook ordering, and real Treehouse allocations across independent clones.

Chores:

  • Replace the quota harness-to-provider lookup table with an equivalent case mapping.

twilwa and others added 6 commits September 20, 2026 01:19
)

* Fix dispatch resolver model and receipts

* no-mistakes(review): Drop model-drift branch, harden receipt lock and brief join

* no-mistakes(review): Scope receipt recording to clear, report failed joins, measure latency

* no-mistakes(review): Narrow dispatch clause and concurrency test, shrink lock budget

* no-mistakes(review): Accept --project on the join, assert drop-or-append concurrency

* no-mistakes(review): Split lock budgets by path, drop receipt size bound

* no-mistakes(review): Record brief_path as spelled, drop abs_path normalization

* no-mistakes(review): Pin model in contract, bound receipt latency, record reason

* no-mistakes(review): Report dropped resolution receipts, project profile agreement, drop dispatch_id

* no-mistakes(review): Enforce append-only cmp, complete join example, govern latency bound

* no-mistakes(review): Keep no-rules exit 0 without jq, dedupe error default

* no-mistakes(review): Refuse symlinked receipts path, drop dead no_rules jq argument

* no-mistakes(document): Document receipt identity, symlink refusal, jq exit narrowing
* fix(bin): refuse an unrecognised fm-send flag instead of sending it as text

fm-send's option loop ended in an unconditional `*) break ;;`, so any token
it did not recognise - including one obviously shaped as a flag - fell out of
the loop and became the positional message body. A steer invoked with a flag
that does not exist was durably written into a live worker's steering inbox as
the literal flag string while fm-send exited 0, so the worker was mis-steered
and the caller got a success code and no diagnostic.

The accepted set is now an allowlist rather than a pattern. --key is a real,
supported flag parsed after this loop and must keep falling through it
untouched, so a blanket "starts with -- and matched no case arm, therefore
refuse" rule would have broken it.

A bare -- ends flag parsing, which is how a message whose text starts with --
is sent. That separator is threaded to the two --key dispatch points so text
after it is text everywhere rather than being re-parsed as a flag. A
single-dash word was never a flag here and still needs no separator.

The refusal exits before anything is marked, recorded, rung, or typed, the
same discipline the header already applies to an empty message.

* no-mistakes(review): drop -- end-of-flags separator, keep pure flag allowlist

* no-mistakes(document): document fm-send's flag allowlist and leading-`--` message limit

* docs(bin): drop the flag-allowlist commentary from fm-send's source

The header block in bin/fm-send.sh is that script's documented contract.
Recording the no-end-of-flags-separator limitation there amends that
contract and turns a deliberate, narrow behaviour change into a
documented guarantee the project would then owe. The rationale comment
above the option loop goes for the same reason: the limitation describes
a decision, which belongs in the pull request, not in the source, where
it reads as a promise.

Removes only those thirteen comment lines. The refusal itself is
unchanged: the option loop remains a pure allowlist, --key still falls
through to its own plane untouched, there is no end-of-flags handling,
the usage line is unmodified, and the tests are untouched.

* fix(bin): refuse trailing arguments after fm-send's --key

The option loop breaks at --key without consuming what follows it, and
the key path reads only the key itself, so every remaining argument was
discarded in silence while the key was still delivered and the command
still exited 0. `fm-send.sh lane --key Enter --not-a-real-flag` sent
Enter and reported success. That is the same silent-delivery shape the
unknown-flag refusal in this change exists to remove, so the key path
contradicted the contract on that one path.

The same ordering bypassed the --fire-and-forget incompatibility:
FIRE_AND_FORGET_ID is only set when the flag precedes --key, so
`--key Enter --fire-and-forget x` passed both existing guards.

The key path now refuses any trailing argument before delivering the
key, naming the offending token in the wording already used for an
unknown flag in flag position, and names --fire-and-forget specifically
so that incompatibility holds on either ordering. Adds regression
coverage for both orderings and for a trailing plain word; both new
tests fail before this commit and pass after it.
* Add head-keyed PR review policy ledger

* Add post-merge browser QA gate

* Fix PR review and post-merge gates

* Close remaining PR review gate gaps

* Harden migration risk and QA evidence parsing

* Close PR review guard bypasses

* Tighten review evidence boundaries

* Bind final review authorization

* Invalidate stale review dispositions

* Harden review evidence validation
* Add keyed decision defer mode

* no-mistakes(review): Fix defer date identity, hold age, parent channel, reporting

* no-mistakes(review): Derive board defer from the option's until alone

* no-mistakes(review): Show the defer date on the board card

* Fix deferred decision lifecycle edges

* no-mistakes(review): Drop fabricated defer hold reason fallback

* no-mistakes(document): Correct stale captain-defer docs for the recorded answer path

* Fix defer intake failure edges

* Require future dates for decision defers

* no-mistakes(review): Narrow UTC day parsing; fix elapsed-defer recovery guidance

* no-mistakes(review): Refuse duplicate board option values; fix defer recovery wording

* Stabilize chat defer hold assertion

* Keep chat defer date stable across midnight

* Refactor defer validation for bounded lint
* fix(brief): forbid validation auto-accept

* no-mistakes(review): restore fleet-wide --yes ban, add ask-user routing sentence

* no-mistakes(ci): Fixed a flaky test that failed the "Behavior portable serial 4" shard. Failure: tests/fm-pi-branch-extension.test.sh -> test_captain_outcome_processing_turn_is_sequence_keyed_and_re_presented, with "Error: supervision branch prompt settled but produced no durable outcome for its claimed wake rows" (thrown at .pi/extensions/fm-branch-supervision.ts:1548). Nothing in this PR's diff (the --yes DoD line, the harness-adapters sentence, three brief assertions) touches that extension or test; the other two check runs on the same head commit (99a0187) passed. It is a pre-existing race that surfaces on a slow/loaded runner. Root cause: in fm-branch-supervision.ts a wake builds the branch session (ensureBranch), then runs several awaited subprocesses (flushMirror, actingAsOwner, scopeForUnreadWake, writeEligibleRowsSnapshot, away-posture read-back) and only then snapshots reportRevisionBeforePrompt immediately before session.prompt(...); after the prompt settles it requires that revision to have advanced. The test synchronized on the wrong point: `settle(() => __fmSessions.length === 2, "replacement branch session")`. Session creation precedes that snapshot, so when the extension's pre-prompt work is slower than the test's report append, report2's durable append lands before the snapshot and the wake rejects its own settled prompt as outcome-less. The routine wake earlier in the same test already waits on __fmPrompts.length === 1 and is unaffected. Fix (tests/fm-pi-branch-extension.test.sh:1377, 9 insertions / 1 deletion): wait for the wake prompt as well as the replacement session, matching the routine wake's own idiom, with a comment naming why the built session is not the synchronization point. No production code changed; no new machinery. Verification: reproduced the exact CI error deterministically by temporarily injecting a delay ahead of reportRevisionBeforePrompt (delays 100/200/300/400/500/700 ms all failed with the identical message); that injection was reverted (git status shows only the test file modified). With the fix the test passes under injected delays of 100, 400 and 1500 ms. Full file run: exit 0, 45 tests passing. 24 parallel runs of the target test: 24/24 pass. shellcheck -x on the changed file is clean, and this PR's own tests (tests/fm-brief.test.sh, tests/fm-ask-user-authority.test.sh) still pass. The change is left uncommitted in the worktree, since prior rounds' commits on this branch were made by the executor rather than this phase
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @twilwa, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 3 days and 23 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@sourcery-ai

sourcery-ai Bot commented Sep 23, 2026

Copy link
Copy Markdown

Reviewer's Guide

The PR repairs multi-clone worker custody by deriving clone-specific Treehouse roots, validating that allocated or recorded worktrees share the requester’s canonical Git common directory before any mutating or launch side effects, preserving foreign and legacy resources on refusal, and adding broad regression coverage. Live validation confirms allocation identity, independent clone separation, and legacy-pool preservation; foreign-custody refusal and legacy relaunch mismatch scenarios remain non-live.

Sequence diagram for clone-custodied worker allocation

sequenceDiagram
    participant Spawn as fm-spawn.sh
    participant Git as Git
    participant Treehouse as Treehouse
    participant Worktree as LinkedWorktree
    participant Trust as ClaudeTrust
    participant Worker as Worker

    Spawn->>Git: rev-parse --git-common-dir
    Git-->>Spawn: canonical common directory
    Spawn->>Treehouse: treehouse --root canonical-common-dir/firstmate-treehouse get
    Treehouse-->>Spawn: allocated worktree
    Spawn->>Git: validate worktree custody
    Git-->>Spawn: linked worktree shares canonical common directory
    Spawn->>Worktree: refresh and validate
    Spawn->>Trust: register workspace trust
    Spawn->>Worker: launch
Loading

Flow diagram for custody refusal before worker launch

flowchart TD
    A[Resolve requesting clone canonical Git common directory] --> B[Read allocated or recorded worktree custody]
    B --> C{Linked worktree and matching common directory?}
    C -- No --> D[Refuse before refresh claims hooks trust metadata or launch]
    D --> E[Preserve foreign or unverified allocation and terminal]
    C -- Yes --> F[Continue with refresh and worker launch]
Loading

File-Level Changes

Change Details Files
Constrain new Treehouse worker allocation and validation to the requesting clone’s canonical Git common directory.
  • Resolve canonical common-directory custody for non-secondmate projects.
  • Override ambient Treehouse roots with the clone-scoped /firstmate-treehouse root for new allocations.
  • Require returned paths to be linked worktrees of the same clone, rejecting primary, foreign, alias, and subdirectory paths before mutation or launch.
  • Keep legacy recorded worktrees on their existing paths and validate custody on relaunch without reallocating or refreshing.
bin/fm-spawn.sh
.agents/skills/secondmate-provisioning/SKILL.md
Preserve foreign or unverified resources and defer side effects until custody validation succeeds.
  • Disable Orca cleanup for allocations that fail custody validation, preserving terminals, worktrees, claims, and local changes.
  • Move Kimi global hook installation until after allocation and custody checks.
  • Retain unchanged Claude trust behavior while preventing trust registration, metadata publication, hooks, refresh, or worker launch for refused custody.
bin/fm-spawn.sh
tests/fm-backend-orca.test.sh
tests/fm-kimi-harness.test.sh
Add regression coverage for clone-scoped allocation, refusal safety, and legacy compatibility.
  • Cover foreign clone and primary refusal across worker backends before refresh, claims, hooks, trust, or launch.
  • Verify canonical roots for primary, linked-worktree, symlink, quoted-path, and independent-clone cases.
  • Verify legacy relaunch preserves committed and unfinished work and refuses mismatched recorded custody without reallocation.
  • Add live Treehouse custody coverage and register the relevant tests with the test runner and tangle guard.
tests/fm-spawn-pool-base-freshen.test.sh
tests/fm-treehouse-clone-custody.test.sh
tests/fm-backend-orca.test.sh
tests/fm-kimi-harness.test.sh
tests/fm-test-run.sh
tests/fm-tangle-guard.test.sh

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@twilwa

twilwa commented Sep 23, 2026

Copy link
Copy Markdown
Owner Author

Validation decision for 2895ff40f0ab4fadcf1175bb68b72203dbfab4e6: the supervising Firstmate explicitly approved no-mistakes finding test-1 for this bounded repair. The authorized evidence consists of isolated real Treehouse allocation and clone-identity checks, executable fixture coverage, and ten passing focused regression suites.

Only three of five scenarios have live-product evidence. Foreign-custody refusal and legacy relaunch preservation have executable fixture evidence only. The live validation verdict remains inconclusive; full live backend lifecycle validation is not claimed. No production lifecycle experiment was authorized or performed.

Adoption remains separate: primary must integrate accepted support while preserving host-local commits before any production retry. The seven local-only lanes still require separately accepted seed/handoff and guarded-primary-landing support before provisioning.

… v2.3.0 with official platform checksums. The Herdr failures were caused by v2.0.1 lacking the required `--root` capability. Verified installer download/checksum/version, `--root` support, lint, clone-custody regression, and dispatch-resolve regression. The portable failure was an unrelated transient broken-pipe race in unchanged code and passed locally
…axi-lib.sh by replacing the private process-substitution lookup with a direct case mapping. This preserves all provider mappings while preventing an early consumer exit from closing the producer pipe and leaking `printf: write error: Broken pipe` to stderr. Verified with tests/fm-dispatch-resolve.test.sh, bin/fm-lint.sh, and git diff --check; all passed
@twilwa

twilwa commented Sep 23, 2026

Copy link
Copy Markdown
Owner Author

Independent agent review of head 79817c97d206f0a505f3b882d9e2601bf1152331, against base c8e0ea6585835f92b00edd2165ac2e6d19fc8bbe.

Reviewer: Firstmate scout fm-pool-repair-review, dispatched with Claude claude-fable-5-1, high effort, independently of the implementation worker. This records the dispatch identity; it is not an exact-model no-mistakes attestation.

The reviewer accepts this bounded change with no blocking code defect. It verified clone common-directory custody before trust/hooks/launch, preservation of foreign allocations, relaunch checks, and root-less Treehouse return for clone-scoped pools. All six focused suites passed: Kimi, tangle guard, dispatch, pool freshening/custody, real Treehouse clone custody, and Orca. Lint, documentation links, and test coverage inventory checks also passed.

The quota-helper failure mechanism was independently reproduced with SIGPIPE ignored: the old helper emitted intermittent broken-pipe stderr (3/2000 calls), while the new helper emitted none (0/2000). Default SIGPIPE probes did not reproduce it. This strengthens the early-reader-exit explanation without proving the precise disposition of the original failing CI process.

Nonblocking observations for future scope:

  • The post-allocation Kimi malformed-config diagnostic should name its preserved endpoint.
  • Bootstrap checks Treehouse --lease, but not the new --root capability. Confirm a compatible Treehouse before adopting on another host; this review used 2.3.0.
  • The real independent-clone custody test was skipped in CI because Treehouse was absent from its serial shard. It passed in three separate local validation runs; the green Herdr CI lane exercises the emitted allocation command for same-clone spawns. A future CI change should execute the independent-clone test there too.

The existing validation limits remain: foreign-custody refusal and legacy relaunch have fixture evidence; the earlier serial-1 timeout cause is unproven. At this reviewed head the full check rollup was 21 passed, 0 failed, 1 skipped. That is distinct from required checks: this fork's target branch has no configured branch protection.

Merge remains held. The existing no-mistakes run 01M36PT27K76HAW8CX4J6EYY5A does not prove the policy's exact fable-5.1 model, and this independent review does not replace that proof. No merge, host adoption, policy relaxation, or pipeline reconfiguration is authorized by this review.

@twilwa twilwa changed the title fix(bin): bind worker allocations to clone custody fix(bin): bind new Treehouse worker allocations to the spawning clone's Git common directory Sep 26, 2026
…uard.test.sh still expected the old `treehouse get --root '<root>'` command, but this PR sends `treehouse --root '<root>' get` (bin/fm-spawn.sh:4049; `--root` is a global Treehouse flag, so both orders are valid). Updated the test to expect the new order; no production code changed. The failure reproduced locally before the fix and the script exits 0 after it. No other test, doc or script uses the old order. ci-2 (PR must be raised via no-mistakes): attestation failure because the pipeline's required `test` step is skipped (the Test agent timed out and the re-run was declined). Not caused by the code; the outer pipeline must re-run and complete the test step
@twilwa

twilwa commented Sep 26, 2026

Copy link
Copy Markdown
Owner Author

Final disposition for head cd7d99f:

  • High-stakes proof: no-mistakes run 01M3DS1A6BZQB2NFPNNN3TD1S8 recorded model claude-opus-5-5 (the configured high-stakes model); 0 independent reviews required by policy.
  • Independent review (5798651173): accepted with no blocking defect; addressed. Its three non-blocking observations (Kimi malformed-config diagnostic should name the preserved endpoint; bootstrap probes Treehouse --lease but not --root; the real independent-clone custody test is skipped in CI) are tracked as backlog task fm-treehouse-clone-custody-followups.
  • Sourcery budget notice, Codex usage-limit notice, Sourcery reviewer's guide, and the earlier-head validation record: informational, no actionable content on this head.
  • The red "PR must be raised via no-mistakes" check reflects only the skipped local test step for this fork-local change and is waived under standing policy; every other check is green.

@twilwa
twilwa merged commit 47099cc into main Sep 26, 2026
20 of 22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant