Skip to content

fix(bin): refresh pooled Treehouse worktrees before launch - #18

Merged
dnth merged 4 commits into
mainfrom
fm/fm-spawn-pool-refresh
Aug 11, 2026
Merged

dnth merged 4 commits into
mainfrom
fm/fm-spawn-pool-refresh

Conversation

@dnth

@dnth dnth commented Aug 11, 2026

Copy link
Copy Markdown
Owner

Intent

Port upstream kunchenguid#2116 into this fork so that before a crewmate launches in a pooled treehouse worktree, the worktree base is refreshed from origin and crews never start on stale code. Fast-forward only when safe: the worktree must be clean and have no unique local commits; never force, stash, or discard work; dirty or non-fast-forwardable pooled bases must be reported and skipped or refused without clobbering them. Preserve the worktree-isolation contract, add the colocated pooled-base regression test and required test-harness helper updates, mirror the docs architecture note, and do not refactor unrelated fm-spawn logic. Keep the existing OMP and Herdr fork changes intact. The feature must pass its regression and existing spawn, tangle, backend, lint, and documentation checks and ship through no-mistakes to a green PR held for captain merge. The known nondeterministic live-Herdr presentation concurrency failure is shared-session environment contention and is out of scope; do not chase it.

What Changed

  • Refresh pooled Treehouse ship and scout worktrees to the current remote default-branch tip before launch.
  • Refuse launch when origin is unavailable or the pooled base is dirty, divergent, or becomes dirty after a fast-forward, preserving all local work.
  • Add architecture documentation, pooled-base regression coverage, and local-origin support to affected spawn fixtures.

Risk Assessment

✅ Low: Captain, the change is well-bounded and now satisfies the pooled Treehouse refresh, isolation, clean-worktree, and fast-forward-only invariants without affecting Orca, OMP, or Herdr behavior.

Testing

The targeted pooled-base regression, spawn/isolation paths, preserved OMP behavior, tangle guard, and affected backend coverage all passed; reviewer-visible CLI evidence was captured, and the only discovered test-harness defect was fixed and successfully retested.

Evidence: Pooled-base refresh and refusal transcript
# observed spawn: spawned pool-current-base-r1 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-pool-current-base-r1 worktree=/tmp/fm-spawn-pool-base-freshen.kUbPGH/current-base/pool
# observed base: HEAD=ecd687b86f0ec12040660597787289d007200f1c origin/main=ecd687b86f0ec12040660597787289d007200f1c advanced-main=must survive a newly spawned branch
ok - a stale pooled worktree refreshes to current origin/main before a crew branch is created
ok - a stale pooled worktree resolves and refreshes a non-main default branch
# observed direct-pr spawn: spawned pool-direct-pr-r3 harness=codex kind=ship mode=direct-PR yolo=off window=firstmate:fm-pool-direct-pr-r3 worktree=/tmp/fm-spawn-pool-base-freshen.kUbPGH/direct-pr/pool
# observed scout spawn: spawned pool-scout-r3 harness=codex kind=scout window=firstmate:fm-pool-scout-r3 worktree=/tmp/fm-spawn-pool-base-freshen.kUbPGH/scout/pool
ok - direct-PR ships and scouts both refresh stale pooled worktrees before launch
# observed dirty refusal: error: pooled worktree '/tmp/fm-spawn-pool-base-freshen.kUbPGH/dirty-refusal/pool' is not clean; refusing to discard uncommitted work while refreshing its base; preserved=keep this local work
ok - a dirty pooled worktree is refused without discarding its local work
ok - post-fast-forward dirtiness refuses launch
ok - a pooled worktree with unique commits is refused without discarding them
# observed unresolved-default refusal: error: could not resolve origin's current default branch for pooled worktree '/tmp/fm-spawn-pool-base-freshen.kUbPGH/unresolved-default/pool'; refusing to launch from a potentially stale base
ok - an unresolved remote default branch refuses the pooled worktree
# observed unreachable-origin refusal: error: could not fetch origin for pooled worktree '/tmp/fm-spawn-pool-base-freshen.kUbPGH/unreachable-origin/pool'; refusing to launch from a potentially stale base
ok - an unreachable origin refuses a potentially stale pooled worktree
# all fm-spawn-pool-base-freshen tests passed

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

🔧 **Review** - 3 issues found → auto-fixed (2) ✅
  • 🚨 bin/fm-spawn.sh:1737 - The required invariant says “the worktree must be clean,” but cleanliness is checked only before git merge --ff-only. A fast-forward that changes a submodule gitlink, or a post-merge hook that writes a file, can leave the worktree dirty while HEAD still equals expected, allowing the worker to launch. Re-check status --porcelain inside this shared freshening boundary after the merge and refuse launch if it is no longer clean.
  • ⚠️ bin/fm-spawn.sh:2195 - The intent scopes refreshing to “a pooled treehouse worktree” and forbids unrelated fm-spawn changes, but this condition also refreshes Orca-owned worktrees. A valid Orca spawn for a repository without origin now creates its worktree/terminal and then fails. Restrict this call to Treehouse-backed backends, or explicitly approve and test the Orca behavior expansion.
  • ⚠️ bin/fm-spawn.sh:116 - The edited usage header replaces the existing description of guarded secondmate pre-launch synchronization even though that behavior remains at lines 1498–1517. This makes --help incomplete and conflicts with CONTRIBUTING.md’s requirement that script usage headers remain accurate. Restore the removed secondmate-sync description alongside the new pooled-worktree contract.

🔧 Fix: Enforce safe pooled worktree refresh boundaries
1 warning still open:

  • ⚠️ docs/architecture.md:152 - The intent scopes refresh to “a pooled treehouse worktree,” and line 150 distinguishes Orca-owned worktrees, but this note and the usage header at bin/fm-spawn.sh:118 claim base freshening applies to every fresh ship/scout worktree. Since bin/fm-spawn.sh:2205 now correctly excludes Orca, narrow both descriptions to pooled Treehouse-backed worktrees.

🔧 Fix: Scope pooled refresh documentation to Treehouse
✅ Re-checked - no issues remain.

✅ **Test** - passed

✅ No issues found.

  • FM_TEST_EVIDENCE=1 bash tests/fm-spawn-pool-base-freshen.test.sh
  • bash tests/fm-spawn-worktree-settle.test.sh
  • bash tests/fm-spawn-batch.test.sh
  • bash tests/fm-spawn-dispatch-profile.test.sh
  • bash tests/fm-tangle-guard.test.sh
  • bash tests/fm-backend-autodetect-smoke.test.sh
  • bash tests/fm-backend-orca.test.sh
  • Manually verified the evidence transcript records refreshed HEAD == origin/main, preserved advanced content, dirty-worktree preservation, and actionable unreachable/default-branch refusals.
  • Removed transient test directories created under /tmp; retained only the dedicated reviewer evidence.
✅ **Document** - passed

✅ No issues found.

⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

@dnth
dnth merged commit bcd4523 into main Aug 11, 2026
@dnth
dnth deleted the fm/fm-spawn-pool-refresh branch August 11, 2026 13:26
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