Skip to content

fix(bin): prevent treehouse allocation from detaching live work - #25

Merged
sbracewell64 merged 8 commits into
mainfrom
fm/treehouse-lease-restart-durability
Aug 2, 2026
Merged

sbracewell64 merged 8 commits into
mainfrom
fm/treehouse-lease-restart-durability

Conversation

@sbracewell64

Copy link
Copy Markdown
Owner

In-fork mirror of kunchenguid/firstmate#1520, same head 0327bd03.
The fleet lands on this fork per the captain's 2026-07-31 ruling, while the upstream PR stays open as a contribution.
The no-mistakes pipeline raised and signed kunchenguid#1520 on this exact commit; the body below is reproduced verbatim from it, so the signature attests this identical code.

Intent

Stop firstmate's crewmate spawn from being handed a treehouse pool slot that still holds live work (upstream kunchenguid#1441). Twice on 2026-08-02, after host restarts wiped or staled treehouse's owner records, a slot holding an unlanded branch was allocated and detached.

Deliberate decisions behind this diff, reviewed and approved by firstmate before implementation - these are choices, not oversights:

  1. The guard runs BEFORE treehouse get, not after. The original task asked for a post-allocation check on the accepted worktree. I measured that treehouse get resets the slot while acquiring it (its own help: "Unlike 'get', enter does not acquire, reset, or return the worktree"), and fm-spawn only learns the worktree by polling the pane's current path afterwards - so a post-hoc check inspects a slot whose evidence is already erased and passes every time. Firstmate approved this deviation from the original wording.

  2. The stated defect is deliberately narrow: clean working tree PLUS commits unreachable from the default branch. Uncommitted content is already protected by treehouse itself, which reports such a slot dirty and refuses to reclaim one even when an exhausted pool is entirely dirty. The original report claimed uncommitted work was the exposure; that was measured false, and firstmate approved keeping the narrowed mechanism rather than widening it back.

  3. The guard reads treehouse's own available verdict from status --json instead of reimplementing eligibility, so a treehouse version bump cannot silently desync it. jq is required and its absence is a deliberate refusal: the human-readable status table abbreviates $HOME paths to a leading ~ and appends per-slot process continuation lines, so it is not a parseable contract. This is a knowing new dependency on the crewmate spawn path.

  4. It deliberately does NOT reuse work_is_landed() from bin/fm-teardown.sh, even though that is the repo's existing landed-work owner. That function fetches, calls gh pr view, and computes patch-ids - per candidate slot, per spawn - and answers a different question ("may I destroy this?") where a guard must be conservative. The guard asks the strictly weaker, offline question "is this slot demonstrably empty?" and never authorizes destruction, so it does not restate or weaken teardown's contract.

  5. The guard is refuse-only by design. Even an identity-verified dead owner does not release a slot holding unlanded work; bin/fm-teardown.sh remains the sole releaser. FM_WORKTREE_RECLAIM_OK is deliberately scoped to exact worktree paths so it cannot become a standing blanket bypass.

  6. Ownership is a process identity via fm_pid_identity, never a bare pid: a reboot reissues pid numbers, and recorded pre-reboot pids were measured resolving to unrelated live node processes. Empty owner fields deliberately read UNRESOLVED, never dead, so a missing record can never be mistaken for a released slot.

  7. The test changes are required, not incidental. Suites that spawn a crewmate stubbed treehouse as a silent exit 0, but the real binary prints [] for an empty pool and never nothing, so the guard correctly refuses that stub; tests/lib.sh gains fm_fake_treehouse so one faithful stub is shared instead of re-rolled. fm-secondmate-harness additionally revealed that fm-spawn never previously executed treehouse at all - it only typed treehouse get into the pane - so its BASE_PATH legitimately excluded the binary. The Herdr presentation test's normalize_meta gains the two new per-run owner fields alongside the per-run container ids, for the same reason those ids are normalized.

Scope was deliberately limited to allocation safety: no re-anchoring of mis-rooted panes, no teardown policy change, no attempt to repair treehouse itself. treehouse get --lease was considered and rejected as the larger alternative - it is the real durability fix, but it restructures acquisition across five backends and every lease needs a treehouse return or the pool leaks permanently, which is teardown policy and out of scope.

Nine failures in the full 105-test run were triaged before submitting: seven reproduce identically on a clean origin/main checkout and are pre-existing (Node.js ESM environment failures and supervision/tmux suites affected by the live fleet); two were mine and are fixed.

What Changed

  • Add a fail-closed pre-allocation guard that refuses crewmate spawns when an available Treehouse slot contains commits unreachable from the default branch.
  • Record process identities for allocated worktrees, validate Treehouse’s JSON schema, and support path-scoped operator authorization without resetting or releasing slots.
  • Add regression coverage, faithful Treehouse test fakes, and maintainer documentation for allocation safety and dependency requirements.

Risk Assessment

✅ Low: The schema-validation fix now fails closed for non-array payloads and malformed entries, preserves valid empty-pool behavior, and the cumulative change conforms to the stated allocation-safety scope.

Testing

Focused guard and spawn-path tests passed; a captured CLI simulation showed a clean available slot with an unlanded commit and stale owner identity was refused after only treehouse status --json, while its branch, HEAD, and clean state remained unchanged. No visual artifact was applicable because this is a CLI-only change.

Evidence: Restart-stale slot refusal transcript
Scenario: treehouse marks a clean slot available after its recorded owner identity became stale across restart.

BEFORE
branch=fm/restart-survivor
head=1389c0bb3cb232de031748d642801ea714da40a6
working_tree=clean

OPERATOR COMMAND
$ bin/fm-worktree-guard.sh check /tmp/no-mistakes-evidence/01KZ1EGQ49T4BJN72GNJAVMKZN/restart-guard.Odg4WO/project
error: refusing to spawn - a pool slot treehouse would hand out still holds live work.
  slot 1: /tmp/no-mistakes-evidence/01KZ1EGQ49T4BJN72GNJAVMKZN/restart-guard.Odg4WO/slot-1
    found: branch fm/restart-survivor with 1 commit not on heads/main
    owner: task pre-restart-task recorded this slot; its worker is gone (recorded process identity no longer matches)
    to release: land or discard pre-restart-task's work, then bin/fm-teardown.sh pre-restart-task
    Nothing was reset, cleaned, or discarded. This spawn simply did not run.
    Authorize one exact slot with FM_WORKTREE_RECLAIM_OK=<worktree-path> only after its work is safe.
exit=1

TREEHOUSE INVOCATIONS
$ treehouse status --json

AFTER
branch=fm/restart-survivor
head=1389c0bb3cb232de031748d642801ea714da40a6
working_tree=clean
preserved=yes

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 2 issues found → auto-fixed (2) ✅
  • 🚨 bin/fm-worktree-guard.sh:137 - The authoritative intent limits this guard to “clean working tree PLUS commits unreachable from the default branch,” but this also refuses a clean named branch whose HEAD is fully reachable from the default branch. Confirm that zero-ahead named branches are intentionally in scope, or remove this additional refusal.
  • 🚨 bin/fm-worktree-guard.sh:290 - An available JSON entry with a missing, null, or empty .path becomes an empty TSV field and is silently skipped, allowing the fail-closed guard to approve a pool slot it never inspected. Reject available rows unless required fields—especially an absolute, non-empty string path—are valid.

🔧 Fix: Align worktree guard with allocation safety contract
1 error still open:

  • 🚨 bin/fm-worktree-guard.sh:269 - The fail-closed parser still accepts malformed but valid JSON as an empty/safe pool: null, &#34;&#34;, or {} all have length == 0, and entries missing .status are silently excluded. Validate that the top level is an array and every entry has the required schema before treating length zero or filtering available slots; otherwise a treehouse schema change can bypass the guard.

🔧 Fix: Validate treehouse JSON schema before allocation
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • bash tests/fm-worktree-guard.test.sh
  • bash tests/fm-spawn-worktree-settle.test.sh
  • bash tests/fm-tangle-guard.test.sh
  • Manual real-Git-worktree restart simulation invoking bin/fm-worktree-guard.sh check, logging treehouse calls and comparing branch, HEAD, and working-tree state before and after refusal
  • git status --short to confirm testing left no transient worktree changes
⚠️ **Document** - 1 error
  • 🚨 bin/fm-backend.sh:313 - The new guard requires jq for every Treehouse-backed spawn, but the bootstrap dependency set still omits jq for tmux. Fixing this requires executable and test changes, which this documentation-only task forbids.
✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

`treehouse status` reports a pool slot as available when it has no lease,
no live process, and a clean working tree.
It does not consider whether HEAD carries commits unreachable from the
default branch, so a slot holding a finished-but-unlanded branch is
allocatable and the next `treehouse get` detaches it.
Restarts make this reachable: they leave slot ownership recorded as either
nothing or a stale value, and both read as free.

The check has to run before allocation.
`treehouse get` resets the slot while acquiring it, before it returns a
path, and fm-spawn only learns the worktree by polling the pane's current
path afterwards, so a check placed there inspects a slot whose evidence
has already been erased.

Add bin/fm-worktree-guard.sh, called from bin/fm-spawn.sh before any
endpoint exists.
It reads treehouse's own available verdict from `status --json` rather than
reimplementing eligibility, then applies an offline emptiness test per slot
using --no-optional-locks so another lane's index is never written.
On evidence it refuses and names the slot, the evidence, the apparent
owning task, and what would release it.

Ownership resolves through fm_pid_identity, never a bare pid: fm-spawn now
records worktree_owner_pid and worktree_owner_identity into the existing
state/<id>.meta.
Only an identity match reads alive, only a recorded identity that no longer
matches reads dead, and an absent record reads unresolved rather than as a
released slot, so a post-reboot reused pid cannot read as a live owner.

The guard never resets, cleans, forces, discards, or releases anything.
bin/fm-teardown.sh remains the sole releaser of a slot holding work and the
owner of the complete landed-work test.

Uncommitted content is separately protected by treehouse itself, which
reports such a slot dirty and refuses to reclaim one even when every slot
in an exhausted pool is dirty, so the exposure closed here is specifically
a clean working tree plus commits not on the default branch.

Suites that spawn a crewmate stubbed treehouse as a silent exit 0, which
the guard correctly refuses because the real binary prints [] for an empty
pool and never nothing. Add fm_fake_treehouse to tests/lib.sh so that one
faithful stub is shared rather than re-rolled per suite.

Empirical basis: docs/verification/worktree-allocation.md.
fm-secondmate-harness builds its fakebin without any treehouse stub and
runs with a BASE_PATH that excludes the real binary. That was invisible
while fm-spawn only typed `treehouse get` into the pane; the guard runs
`treehouse status` from fm-spawn's own environment before allocating.

The Herdr presentation comparison normalizes per-run container ids; the
worktree owner pid and identity vary per run for the same reason, so they
belong in that normalization.
@sbracewell64
sbracewell64 force-pushed the fm/treehouse-lease-restart-durability branch from 0327bd0 to 7dee31e Compare August 2, 2026 16:24
CI pins Treehouse v2.0.1 via bin/fm-install-treehouse.sh, and that build has
no `status --json` flag at all: passing it exits 1 with "unknown flag".
The guard required that flag, so every Treehouse-backed spawn refused on the
pinned build and four real-herdr-gated suites failed.

The same defect exists on v2.0.1 - it also reports a clean slot holding an
unlanded branch as available - so the guard must still inspect the pool there
rather than refuse every spawn.

Probe capability from `status --help` advertising --json, not from the error
text or a version string, and fall back to the human-readable table. That
table needs two compensations: a path under $HOME is abbreviated with a
leading tilde, and a slot may be followed by indented process continuation
lines. Every non-blank, non-indented line must parse or the guard refuses,
so a dropped row cannot leave a slot uninspected.

jq is now required only on the --json path.
The guard probes `status --help` for --json before choosing a format, so a
stub that answers every `status` invocation with [] makes the probe see no
--json, fall back to the human-readable table, and then fail to parse [] as a
table row.

Model all three shapes the guard uses: help advertising --json, --json
returning [] for an empty pool, and plain status printing nothing, which is
what an empty pool looks like in that format.
bin/fm-lint.sh pins shellcheck and refuses to run under any other version, so
local and CI cannot diverge on lint. Treehouse has no equivalent: CI installs
the version pinned in bin/fm-install-treehouse.sh while a developer machine
runs whatever is on PATH, and nothing reconciles them.

This is a fleet-wide property of how suites are verified, not a detail of any
one change, and it has already cost one red CI run.
@sbracewell64
sbracewell64 merged commit abc2e7b into main Aug 2, 2026
10 checks passed
sbracewell64 added a commit that referenced this pull request Aug 9, 2026
* fix(bin): refuse spawns that would reclaim a still-owned pool slot

`treehouse status` reports a pool slot as available when it has no lease,
no live process, and a clean working tree.
It does not consider whether HEAD carries commits unreachable from the
default branch, so a slot holding a finished-but-unlanded branch is
allocatable and the next `treehouse get` detaches it.
Restarts make this reachable: they leave slot ownership recorded as either
nothing or a stale value, and both read as free.

The check has to run before allocation.
`treehouse get` resets the slot while acquiring it, before it returns a
path, and fm-spawn only learns the worktree by polling the pane's current
path afterwards, so a check placed there inspects a slot whose evidence
has already been erased.

Add bin/fm-worktree-guard.sh, called from bin/fm-spawn.sh before any
endpoint exists.
It reads treehouse's own available verdict from `status --json` rather than
reimplementing eligibility, then applies an offline emptiness test per slot
using --no-optional-locks so another lane's index is never written.
On evidence it refuses and names the slot, the evidence, the apparent
owning task, and what would release it.

Ownership resolves through fm_pid_identity, never a bare pid: fm-spawn now
records worktree_owner_pid and worktree_owner_identity into the existing
state/<id>.meta.
Only an identity match reads alive, only a recorded identity that no longer
matches reads dead, and an absent record reads unresolved rather than as a
released slot, so a post-reboot reused pid cannot read as a live owner.

The guard never resets, cleans, forces, discards, or releases anything.
bin/fm-teardown.sh remains the sole releaser of a slot holding work and the
owner of the complete landed-work test.

Uncommitted content is separately protected by treehouse itself, which
reports such a slot dirty and refuses to reclaim one even when every slot
in an exhausted pool is dirty, so the exposure closed here is specifically
a clean working tree plus commits not on the default branch.

Suites that spawn a crewmate stubbed treehouse as a silent exit 0, which
the guard correctly refuses because the real binary prints [] for an empty
pool and never nothing. Add fm_fake_treehouse to tests/lib.sh so that one
faithful stub is shared rather than re-rolled per suite.

Empirical basis: docs/verification/worktree-allocation.md.

* test: model treehouse status in the remaining spawn fakes

fm-secondmate-harness builds its fakebin without any treehouse stub and
runs with a BASE_PATH that excludes the real binary. That was invisible
while fm-spawn only typed `treehouse get` into the pane; the guard runs
`treehouse status` from fm-spawn's own environment before allocating.

The Herdr presentation comparison normalizes per-run container ids; the
worktree owner pid and identity vary per run for the same reason, so they
belong in that normalization.

* no-mistakes(review): Align worktree guard with allocation safety contract

* no-mistakes(review): Validate treehouse JSON schema before allocation

* no-mistakes(document): Document safe Treehouse allocation

* fix(bin): inspect Treehouse pools on builds without status --json

CI pins Treehouse v2.0.1 via bin/fm-install-treehouse.sh, and that build has
no `status --json` flag at all: passing it exits 1 with "unknown flag".
The guard required that flag, so every Treehouse-backed spawn refused on the
pinned build and four real-herdr-gated suites failed.

The same defect exists on v2.0.1 - it also reports a clean slot holding an
unlanded branch as available - so the guard must still inspect the pool there
rather than refuse every spawn.

Probe capability from `status --help` advertising --json, not from the error
text or a version string, and fall back to the human-readable table. That
table needs two compensations: a path under $HOME is abbreviated with a
leading tilde, and a slot may be followed by indented process continuation
lines. Every non-blank, non-indented line must parse or the guard refuses,
so a dropped row cannot leave a slot uninspected.

jq is now required only on the --json path.

* test: model the treehouse status capability probe in spawn fakes

The guard probes `status --help` for --json before choosing a format, so a
stub that answers every `status` invocation with [] makes the probe see no
--json, fall back to the human-readable table, and then fail to parse [] as a
table row.

Model all three shapes the guard uses: help advertising --json, --json
returning [] for an empty pool, and plain status printing nothing, which is
what an empty pool looks like in that format.

* docs: record that local Treehouse verification does not prove CI green

bin/fm-lint.sh pins shellcheck and refuses to run under any other version, so
local and CI cannot diverge on lint. Treehouse has no equivalent: CI installs
the version pinned in bin/fm-install-treehouse.sh while a developer machine
runs whatever is on PATH, and nothing reconciles them.

This is a fleet-wide property of how suites are verified, not a detail of any
one change, and it has already cost one red CI run.
sbracewell64 added a commit that referenced this pull request Aug 10, 2026
* fix(bin): refuse spawns that would reclaim a still-owned pool slot

`treehouse status` reports a pool slot as available when it has no lease,
no live process, and a clean working tree.
It does not consider whether HEAD carries commits unreachable from the
default branch, so a slot holding a finished-but-unlanded branch is
allocatable and the next `treehouse get` detaches it.
Restarts make this reachable: they leave slot ownership recorded as either
nothing or a stale value, and both read as free.

The check has to run before allocation.
`treehouse get` resets the slot while acquiring it, before it returns a
path, and fm-spawn only learns the worktree by polling the pane's current
path afterwards, so a check placed there inspects a slot whose evidence
has already been erased.

Add bin/fm-worktree-guard.sh, called from bin/fm-spawn.sh before any
endpoint exists.
It reads treehouse's own available verdict from `status --json` rather than
reimplementing eligibility, then applies an offline emptiness test per slot
using --no-optional-locks so another lane's index is never written.
On evidence it refuses and names the slot, the evidence, the apparent
owning task, and what would release it.

Ownership resolves through fm_pid_identity, never a bare pid: fm-spawn now
records worktree_owner_pid and worktree_owner_identity into the existing
state/<id>.meta.
Only an identity match reads alive, only a recorded identity that no longer
matches reads dead, and an absent record reads unresolved rather than as a
released slot, so a post-reboot reused pid cannot read as a live owner.

The guard never resets, cleans, forces, discards, or releases anything.
bin/fm-teardown.sh remains the sole releaser of a slot holding work and the
owner of the complete landed-work test.

Uncommitted content is separately protected by treehouse itself, which
reports such a slot dirty and refuses to reclaim one even when every slot
in an exhausted pool is dirty, so the exposure closed here is specifically
a clean working tree plus commits not on the default branch.

Suites that spawn a crewmate stubbed treehouse as a silent exit 0, which
the guard correctly refuses because the real binary prints [] for an empty
pool and never nothing. Add fm_fake_treehouse to tests/lib.sh so that one
faithful stub is shared rather than re-rolled per suite.

Empirical basis: docs/verification/worktree-allocation.md.

* test: model treehouse status in the remaining spawn fakes

fm-secondmate-harness builds its fakebin without any treehouse stub and
runs with a BASE_PATH that excludes the real binary. That was invisible
while fm-spawn only typed `treehouse get` into the pane; the guard runs
`treehouse status` from fm-spawn's own environment before allocating.

The Herdr presentation comparison normalizes per-run container ids; the
worktree owner pid and identity vary per run for the same reason, so they
belong in that normalization.

* no-mistakes(review): Align worktree guard with allocation safety contract

* no-mistakes(review): Validate treehouse JSON schema before allocation

* no-mistakes(document): Document safe Treehouse allocation

* fix(bin): inspect Treehouse pools on builds without status --json

CI pins Treehouse v2.0.1 via bin/fm-install-treehouse.sh, and that build has
no `status --json` flag at all: passing it exits 1 with "unknown flag".
The guard required that flag, so every Treehouse-backed spawn refused on the
pinned build and four real-herdr-gated suites failed.

The same defect exists on v2.0.1 - it also reports a clean slot holding an
unlanded branch as available - so the guard must still inspect the pool there
rather than refuse every spawn.

Probe capability from `status --help` advertising --json, not from the error
text or a version string, and fall back to the human-readable table. That
table needs two compensations: a path under $HOME is abbreviated with a
leading tilde, and a slot may be followed by indented process continuation
lines. Every non-blank, non-indented line must parse or the guard refuses,
so a dropped row cannot leave a slot uninspected.

jq is now required only on the --json path.

* test: model the treehouse status capability probe in spawn fakes

The guard probes `status --help` for --json before choosing a format, so a
stub that answers every `status` invocation with [] makes the probe see no
--json, fall back to the human-readable table, and then fail to parse [] as a
table row.

Model all three shapes the guard uses: help advertising --json, --json
returning [] for an empty pool, and plain status printing nothing, which is
what an empty pool looks like in that format.

* docs: record that local Treehouse verification does not prove CI green

bin/fm-lint.sh pins shellcheck and refuses to run under any other version, so
local and CI cannot diverge on lint. Treehouse has no equivalent: CI installs
the version pinned in bin/fm-install-treehouse.sh while a developer machine
runs whatever is on PATH, and nothing reconciles them.

This is a fleet-wide property of how suites are verified, not a detail of any
one change, and it has already cost one red CI run.
sbracewell64 added a commit that referenced this pull request Aug 11, 2026
* fix(bin): refuse spawns that would reclaim a still-owned pool slot

`treehouse status` reports a pool slot as available when it has no lease,
no live process, and a clean working tree.
It does not consider whether HEAD carries commits unreachable from the
default branch, so a slot holding a finished-but-unlanded branch is
allocatable and the next `treehouse get` detaches it.
Restarts make this reachable: they leave slot ownership recorded as either
nothing or a stale value, and both read as free.

The check has to run before allocation.
`treehouse get` resets the slot while acquiring it, before it returns a
path, and fm-spawn only learns the worktree by polling the pane's current
path afterwards, so a check placed there inspects a slot whose evidence
has already been erased.

Add bin/fm-worktree-guard.sh, called from bin/fm-spawn.sh before any
endpoint exists.
It reads treehouse's own available verdict from `status --json` rather than
reimplementing eligibility, then applies an offline emptiness test per slot
using --no-optional-locks so another lane's index is never written.
On evidence it refuses and names the slot, the evidence, the apparent
owning task, and what would release it.

Ownership resolves through fm_pid_identity, never a bare pid: fm-spawn now
records worktree_owner_pid and worktree_owner_identity into the existing
state/<id>.meta.
Only an identity match reads alive, only a recorded identity that no longer
matches reads dead, and an absent record reads unresolved rather than as a
released slot, so a post-reboot reused pid cannot read as a live owner.

The guard never resets, cleans, forces, discards, or releases anything.
bin/fm-teardown.sh remains the sole releaser of a slot holding work and the
owner of the complete landed-work test.

Uncommitted content is separately protected by treehouse itself, which
reports such a slot dirty and refuses to reclaim one even when every slot
in an exhausted pool is dirty, so the exposure closed here is specifically
a clean working tree plus commits not on the default branch.

Suites that spawn a crewmate stubbed treehouse as a silent exit 0, which
the guard correctly refuses because the real binary prints [] for an empty
pool and never nothing. Add fm_fake_treehouse to tests/lib.sh so that one
faithful stub is shared rather than re-rolled per suite.

Empirical basis: docs/verification/worktree-allocation.md.

* test: model treehouse status in the remaining spawn fakes

fm-secondmate-harness builds its fakebin without any treehouse stub and
runs with a BASE_PATH that excludes the real binary. That was invisible
while fm-spawn only typed `treehouse get` into the pane; the guard runs
`treehouse status` from fm-spawn's own environment before allocating.

The Herdr presentation comparison normalizes per-run container ids; the
worktree owner pid and identity vary per run for the same reason, so they
belong in that normalization.

* no-mistakes(review): Align worktree guard with allocation safety contract

* no-mistakes(review): Validate treehouse JSON schema before allocation

* no-mistakes(document): Document safe Treehouse allocation

* fix(bin): inspect Treehouse pools on builds without status --json

CI pins Treehouse v2.0.1 via bin/fm-install-treehouse.sh, and that build has
no `status --json` flag at all: passing it exits 1 with "unknown flag".
The guard required that flag, so every Treehouse-backed spawn refused on the
pinned build and four real-herdr-gated suites failed.

The same defect exists on v2.0.1 - it also reports a clean slot holding an
unlanded branch as available - so the guard must still inspect the pool there
rather than refuse every spawn.

Probe capability from `status --help` advertising --json, not from the error
text or a version string, and fall back to the human-readable table. That
table needs two compensations: a path under $HOME is abbreviated with a
leading tilde, and a slot may be followed by indented process continuation
lines. Every non-blank, non-indented line must parse or the guard refuses,
so a dropped row cannot leave a slot uninspected.

jq is now required only on the --json path.

* test: model the treehouse status capability probe in spawn fakes

The guard probes `status --help` for --json before choosing a format, so a
stub that answers every `status` invocation with [] makes the probe see no
--json, fall back to the human-readable table, and then fail to parse [] as a
table row.

Model all three shapes the guard uses: help advertising --json, --json
returning [] for an empty pool, and plain status printing nothing, which is
what an empty pool looks like in that format.

* docs: record that local Treehouse verification does not prove CI green

bin/fm-lint.sh pins shellcheck and refuses to run under any other version, so
local and CI cannot diverge on lint. Treehouse has no equivalent: CI installs
the version pinned in bin/fm-install-treehouse.sh while a developer machine
runs whatever is on PATH, and nothing reconciles them.

This is a fleet-wide property of how suites are verified, not a detail of any
one change, and it has already cost one red CI run.
sbracewell64 added a commit that referenced this pull request Aug 11, 2026
* fix(bin): refuse spawns that would reclaim a still-owned pool slot

`treehouse status` reports a pool slot as available when it has no lease,
no live process, and a clean working tree.
It does not consider whether HEAD carries commits unreachable from the
default branch, so a slot holding a finished-but-unlanded branch is
allocatable and the next `treehouse get` detaches it.
Restarts make this reachable: they leave slot ownership recorded as either
nothing or a stale value, and both read as free.

The check has to run before allocation.
`treehouse get` resets the slot while acquiring it, before it returns a
path, and fm-spawn only learns the worktree by polling the pane's current
path afterwards, so a check placed there inspects a slot whose evidence
has already been erased.

Add bin/fm-worktree-guard.sh, called from bin/fm-spawn.sh before any
endpoint exists.
It reads treehouse's own available verdict from `status --json` rather than
reimplementing eligibility, then applies an offline emptiness test per slot
using --no-optional-locks so another lane's index is never written.
On evidence it refuses and names the slot, the evidence, the apparent
owning task, and what would release it.

Ownership resolves through fm_pid_identity, never a bare pid: fm-spawn now
records worktree_owner_pid and worktree_owner_identity into the existing
state/<id>.meta.
Only an identity match reads alive, only a recorded identity that no longer
matches reads dead, and an absent record reads unresolved rather than as a
released slot, so a post-reboot reused pid cannot read as a live owner.

The guard never resets, cleans, forces, discards, or releases anything.
bin/fm-teardown.sh remains the sole releaser of a slot holding work and the
owner of the complete landed-work test.

Uncommitted content is separately protected by treehouse itself, which
reports such a slot dirty and refuses to reclaim one even when every slot
in an exhausted pool is dirty, so the exposure closed here is specifically
a clean working tree plus commits not on the default branch.

Suites that spawn a crewmate stubbed treehouse as a silent exit 0, which
the guard correctly refuses because the real binary prints [] for an empty
pool and never nothing. Add fm_fake_treehouse to tests/lib.sh so that one
faithful stub is shared rather than re-rolled per suite.

Empirical basis: docs/verification/worktree-allocation.md.

* test: model treehouse status in the remaining spawn fakes

fm-secondmate-harness builds its fakebin without any treehouse stub and
runs with a BASE_PATH that excludes the real binary. That was invisible
while fm-spawn only typed `treehouse get` into the pane; the guard runs
`treehouse status` from fm-spawn's own environment before allocating.

The Herdr presentation comparison normalizes per-run container ids; the
worktree owner pid and identity vary per run for the same reason, so they
belong in that normalization.

* no-mistakes(review): Align worktree guard with allocation safety contract

* no-mistakes(review): Validate treehouse JSON schema before allocation

* no-mistakes(document): Document safe Treehouse allocation

* fix(bin): inspect Treehouse pools on builds without status --json

CI pins Treehouse v2.0.1 via bin/fm-install-treehouse.sh, and that build has
no `status --json` flag at all: passing it exits 1 with "unknown flag".
The guard required that flag, so every Treehouse-backed spawn refused on the
pinned build and four real-herdr-gated suites failed.

The same defect exists on v2.0.1 - it also reports a clean slot holding an
unlanded branch as available - so the guard must still inspect the pool there
rather than refuse every spawn.

Probe capability from `status --help` advertising --json, not from the error
text or a version string, and fall back to the human-readable table. That
table needs two compensations: a path under $HOME is abbreviated with a
leading tilde, and a slot may be followed by indented process continuation
lines. Every non-blank, non-indented line must parse or the guard refuses,
so a dropped row cannot leave a slot uninspected.

jq is now required only on the --json path.

* test: model the treehouse status capability probe in spawn fakes

The guard probes `status --help` for --json before choosing a format, so a
stub that answers every `status` invocation with [] makes the probe see no
--json, fall back to the human-readable table, and then fail to parse [] as a
table row.

Model all three shapes the guard uses: help advertising --json, --json
returning [] for an empty pool, and plain status printing nothing, which is
what an empty pool looks like in that format.

* docs: record that local Treehouse verification does not prove CI green

bin/fm-lint.sh pins shellcheck and refuses to run under any other version, so
local and CI cannot diverge on lint. Treehouse has no equivalent: CI installs
the version pinned in bin/fm-install-treehouse.sh while a developer machine
runs whatever is on PATH, and nothing reconciles them.

This is a fleet-wide property of how suites are verified, not a detail of any
one change, and it has already cost one red CI run.
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