Skip to content

fix(bin): resolve Treehouse locks for remote secondmate homes - #3883

Merged
kunchenguid merged 2 commits into
mainfrom
fm/fm-treehouse-remote-lock-fix-r1
Sep 7, 2026
Merged

kunchenguid merged 2 commits into
mainfrom
fm/fm-treehouse-remote-lock-fix-r1

Conversation

@kunchenguid

Copy link
Copy Markdown
Owner

Intent

Fix the fleet-wide regression where PR 3837's shared Treehouse lock cannot resolve a local root across the remote secondmate boundary, failing every remote spawn and teardown closed. Remote work is fully blocked until this lands.

Context for the PR 3837 reference above: PR 3837 ("verify Treehouse slot ownership before teardown") introduced a per-project lock that serializes Treehouse pool-slot allocation and return across linked firstmate homes, so a cleanup cannot return a pool slot that a different live task has already been handed. That lock is anchored in the root firstmate home's state directory, resolved by walking a home's .fm-secondmate-parent bindings upward until a home with no parent binding is reached. Both bin/fm-spawn.sh and bin/fm-teardown.sh refuse outright when that lock path cannot be resolved.

The regression: a home seeded onto another machine records a parent binding whose route is "remote", and the upward walk treats any non-local route as an error. So inside a remote-seeded secondmate home - and inside every local secondmate home beneath it, whose own chain terminates at that same remote record - the lock never resolves, and every Treehouse-backed spawn and every pool-slot teardown refuses. That is the whole of remote secondmate work.

What Changed

  • Treat remote parent bindings as the machine-local root when resolving Treehouse project locks, allowing remote-seeded homes and their local descendants to share spawn and teardown serialization.
  • Document the machine-local locking boundary and add regression coverage for remote pool allocation, slot returns, collision safety, and lock contention.

Risk Assessment

✅ Low: The change is narrowly scoped to treating a valid remote parent binding as the local traversal boundary and includes behavioral coverage for resolution, teardown, collision refusal, and lock contention.

Testing

Targeted spawn and teardown suites passed; end-to-end fixtures showed a remote-seeded home successfully spawning and returning its Treehouse slot, preserving both records and the slot on cross-home collision, sharing the lock with local descendants, and changing the reported regression from base failure to local-root resolution. Focused behavioral coverage and reviewer-visible CLI transcripts were added; no broad suite, lint, formatter, or static analysis was run.

Evidence: Remote-seeded Treehouse spawn transcript

Source: Remote-seeded Treehouse spawn transcript

# remote-seeded Treehouse spawn command
$ FM_HOME=/private/var/folders/0k/bf8mwt2n5qddzk24r20gfk0c0000gn/T/fm-spawn-pool-base-freshen.tX7id0/remote-seeded/home bin/fm-spawn.sh pool-remote-seeded-r13 /private/var/folders/0k/bf8mwt2n5qddzk24r20gfk0c0000gn/T/fm-spawn-pool-base-freshen.tX7id0/remote-seeded/project --scout
spawned pool-remote-seeded-r13 harness=codex kind=scout window=firstmate:fm-pool-remote-seeded-r13 worktree=/private/var/folders/0k/bf8mwt2n5qddzk24r20gfk0c0000gn/T/fm-spawn-pool-base-freshen.tX7id0/remote-seeded/pool
exit=0
published worktree=/private/var/folders/0k/bf8mwt2n5qddzk24r20gfk0c0000gn/T/fm-spawn-pool-base-freshen.tX7id0/remote-seeded/pool
resolved project lock=/private/var/folders/0k/bf8mwt2n5qddzk24r20gfk0c0000gn/T/fm-spawn-pool-base-freshen.tX7id0/remote-seeded/home/state/.treehouse-project-54ac1ebe2805f8d49f40cee3f8f57ec9c82a5a3c.lock
ok - a remote-seeded secondmate home allocates and launches from its Treehouse pool
Evidence: Remote-seeded teardown success and collision-refusal transcript

Source: Remote-seeded teardown success and collision-refusal transcript

# remote-seeded Treehouse teardown command
$ FM_HOME=/private/var/folders/0k/bf8mwt2n5qddzk24r20gfk0c0000gn/T/fm-teardown-endpoint-safety.COxXd2/remote-home-teardown/home bin/fm-teardown.sh remote-task --force
stdout:
teardown remote-task complete (window firstmate:fm-remote-task, worktree /private/var/folders/0k/bf8mwt2n5qddzk24r20gfk0c0000gn/T/fm-teardown-endpoint-safety.COxXd2/remote-home-teardown/worktree)
Backlog: remote-task just finished (this home keeps no backlog at /private/var/folders/0k/bf8mwt2n5qddzk24r20gfk0c0000gn/T/fm-teardown-endpoint-safety.COxXd2/remote-home-teardown/home/data/backlog.md). Update /private/var/folders/0k/bf8mwt2n5qddzk24r20gfk0c0000gn/T/fm-teardown-endpoint-safety.COxXd2/remote-home-teardown/home/data/backlog.md - move remote-task to Done, keep Done to the 10 most recent, then re-scan Queued and dispatch only work whose blockers are gone and date is due.
stderr:
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
●  This is a supervision warning only; the guarded operation WILL still run.
●  repair a missing or failed watcher cycle with the Pi tool fm_watch_arm_pi, or restart Pi with -e ~/.no-mistakes/worktrees/016d88035d58/01M1WM3507QDKRBT1PF23FQV7A/.pi/extensions/fm-primary-turnend-guard.ts -e ~/.no-mistakes/worktrees/016d88035d58/01M1WM3507QDKRBT1PF23FQV7A/.pi/extensions/fm-primary-pi-watch.ts if the extensions are not loaded.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
exit=0
runtime calls:
treehouse <return> <--force> </private/var/folders/0k/bf8mwt2n5qddzk24r20gfk0c0000gn/T/fm-teardown-endpoint-safety.COxXd2/remote-home-teardown/worktree>
tmux <kill-window> <-t> <=firstmate:=fm-remote-task>
task metadata=removed
slot sentinel=present
ok - fm-teardown: a remote-seeded secondmate home returns its own uncontested pool slot
# remote-seeded cross-home collision command
$ FM_HOME=/private/var/folders/0k/bf8mwt2n5qddzk24r20gfk0c0000gn/T/fm-teardown-endpoint-safety.COxXd2/remote-home-collision/home bin/fm-teardown.sh remote-stale --force
stderr:
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  1 task(s) in flight, but no watcher has a fresh beacon (last beat: never, grace 300s).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
●  This is a supervision warning only; the guarded operation WILL still run.
●  repair a missing or failed watcher cycle with the Pi tool fm_watch_arm_pi, or restart Pi with -e ~/.no-mistakes/worktrees/016d88035d58/01M1WM3507QDKRBT1PF23FQV7A/.pi/extensions/fm-primary-turnend-guard.ts -e ~/.no-mistakes/worktrees/016d88035d58/01M1WM3507QDKRBT1PF23FQV7A/.pi/extensions/fm-primary-pi-watch.ts if the extensions are not loaded.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
REFUSED: task remote-stale's recorded worktree /private/var/folders/0k/bf8mwt2n5qddzk24r20gfk0c0000gn/T/fm-teardown-endpoint-safety.COxXd2/remote-home-collision/pool/1/project is also task child-task's recorded worktree.
Returning that pool slot would kill child-task's processes and reset its copy, so nothing was changed - not even with --force.
Reconcile whichever record is wrong (bin/fm-crew-state.sh remote-stale; bin/fm-crew-state.sh child-task), then re-run teardown.
exit=1
runtime calls=none
remote metadata=preserved
child metadata=preserved
slot sentinel=preserved
ok - fm-teardown: slot ownership across a remote-seeded home and its local child still refuses
Evidence: Executable base-versus-fix lock-resolution comparison

Source: Executable base-versus-fix lock-resolution comparison

# Remote-boundary Treehouse lock regression: executable before/after comparison
fixture parent binding:
schema=fm-secondmate-parent.v1
route=remote
parent_host=parent-machine

base 29015a2 result: exit=1 output=<none>
fixed 5ebf85b result: exit=0 output=/private/var/folders/0k/bf8mwt2n5qddzk24r20gfk0c0000gn/T/fm-remote-lock-before-after.s4q1pK/remote-home/state/.treehouse-project-301eabc8091173ae630ea5dfc8e6023bb43857cf.lock
observable result: lock anchored in remote-seeded home state

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

✅ **Review** - passed

✅ No issues found.

✅ **Test** - passed

✅ No issues found.

  • Inspected the target diff from 29015a2604c990233010ee864e9a4d4d14a08b21 to 5ebf85b8c94f3695c7f784c7598607cdde5da9df.
  • bash tests/fm-teardown-endpoint-safety.test.sh
  • Added and ran focused executable spawn coverage with bash tests/fm-spawn-pool-base-freshen.test.sh.
  • FM_TEST_EVIDENCE=1 bash tests/fm-spawn-pool-base-freshen.test.sh
  • FM_TEST_EVIDENCE=1 bash tests/fm-teardown-endpoint-safety.test.sh
  • Executed fm_treehouse_project_lock_path against the base and fixed wake libraries using the same remote-parent fixture; the base refused while the fix resolved the home-local state lock.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…ondmate homes

Every spawn and teardown inside a remote-seeded secondmate home refused,
because the project lock's anchor could not be resolved there.

fm_firstmate_root_home walks a home's parent bindings upward to find the
anchor the lock lives in, and treated a remote parent binding as an error.
A remote-seeded home's parent is on another machine, so that walk can never
succeed from there - and neither can the home's own local descendants, whose
chain terminates at the same record. Both fail closed on every Treehouse-backed
spawn and every pool-slot teardown.

A remote parent now terminates the walk at the home holding it, which is the
correct anchor: a lock taken on this filesystem is neither held nor observable
across that boundary, and that home is already the top of the local tree
teardown's collect_local_firstmate_states enumerates, since that walk skips
remote registry entries for the same reason. Mutual exclusion is unchanged -
every home reachable through local parent links still derives one identical
lock file per project, and an unreadable binding, an unsupported route, an
unreachable local parent, a cycle, and an over-deep chain all still refuse.
Origin-less local-only projects keep resolving through their worktree top.

Regression coverage pins the anchor for the main-home layout, a local
secondmate, a remote-seeded home, and its local child; drives teardown
end-to-end in a remote-seeded home; keeps the cross-home slot-ownership
refusal across that boundary; and proves two homes still serialize on the
one shared lock file.
@greptile-apps

greptile-apps Bot commented Sep 7, 2026

Copy link
Copy Markdown

Confidence Score: 5/5

The PR appears safe to merge, with the changed lock boundary matching remote-home provisioning and Treehouse pool ownership.

Remote-seeded homes and their project clones are independently provisioned, while each local descendant resolves the same root lock and ownership-state tree; no blocking failure remains.

Reviews (1): Last reviewed commit: "no-mistakes(document): Clarify machine-l..." | Re-trigger Greptile

@kunchenguid
kunchenguid merged commit 64d3905 into main Sep 7, 2026
15 checks passed
@kunchenguid
kunchenguid deleted the fm/fm-treehouse-remote-lock-fix-r1 branch September 7, 2026 01:00