Skip to content

fix(bin): freshen remote-less pooled worktrees from the primary local copy - #8

Merged
adonis-garcia-git merged 3 commits into
mainfrom
fm/fm-local-only-spawn-fix
Aug 24, 2026
Merged

adonis-garcia-git merged 3 commits into
mainfrom
fm/fm-local-only-spawn-fix

Conversation

@adonis-garcia-git

Copy link
Copy Markdown
Owner

Intent

Fix the pool-freshen guard in bin/fm-spawn.sh so spawns work for remote-less local-only projects.

BUG: freshen_spawn_worktree_base() unconditionally ran 'git fetch origin', 'remote set-head origin --auto', and reset the pooled worktree to origin/. Local-only projects registered with no remote (helm, disc-importer, dom-voter-roster, natddp-demo in this fleet) have no 'origin' in their treehouse pool clones, so every ship/scout spawn for them failed at the freshen step with 'could not fetch origin'. The guard arrived in an upstream merge; the interim field workaround was hand-pointing an 'origin' remote at the primary clone.

DECIDED FIX (chosen at intake, not open for redesign): when the pooled worktree has no 'origin' remote (or no remote at all), base the freshen on the primary clone instead of a network remote - resolve the primary clone's default branch and current head, fetch/update from that local path, and apply the same cleanliness + reset + verification steps against that target. The existing origin-based path must remain EXACTLY as-is for projects that do have a remote (deliberately byte-identical commands and refusal messages; the added 'label' variable exists solely to keep those origin-path strings unchanged while letting the shared tail describe either base).

Required safety properties, all preserved on both paths: never proceed on a dirty pooled worktree (no discarding uncommitted work); never launch from a stale or unverifiable base (fail loudly with a clear error naming the worktree); the post-reset HEAD verification against the expected commit stays in force.

Deliberate design decisions made while implementing:

  • The primary clone path is passed in explicitly as a second argument (PROJ_ABS_REAL, the project dir the spawn already resolved and canonicalized), never guessed from a naming convention.
  • The primary's default-branch REF (refs/heads/) is read rather than its HEAD, so a primary parked on a non-default/feature branch refuses instead of seeding the wrong base - the same rationale as fm-ff-lib.sh's primary_head_commit.
  • The primary must be a readable git repository ROOT (rev-parse --show-toplevel resolved through real_path_or_raw must equal the passed path), so an unreadable primary, or a project dir that is merely nested inside some other repo, refuses loudly rather than adopting a parent repo's history.
  • The remote-less fetch writes only FETCH_HEAD (refspec '+refs/heads/' with no destination), leaving no persistent synthetic remote-tracking refs in the pool; the fetched tip is then cross-checked against the primary's own ref commit before any reset, and refuses on disagreement.
  • Detection uses 'git remote get-url origin', so a pool with some other remote name but no origin also takes the primary path.

Verification approach: the bug was first reproduced end-to-end through the real fm-spawn path with a remote-less fixture (failing with the exact field error) before any edit.

Tests (colocated in the existing tests/fm-spawn-pool-base-freshen.test.sh, fm-test-run.sh conventions, stubbing tmux/treehouse the same way the existing cases do): remote-less freshen success (pool starts from the primary's advanced default-branch tip and its newest content), remote-less dirty refusal (refuses, HEAD unmoved, uncommitted work preserved), and remote-less unresolvable-base refusal covering both a primary on a non-standard branch name with no remote and a primary that is not a readable git repository root (refusal names the pooled worktree, HEAD unmoved). All six pre-existing origin-path tests still pass unchanged, proving the remote path behaves as before.

Docs: docs/architecture.md's base-freshness boundary sentence was updated to cover both resolution sources; bin/fm-spawn.sh's header (the mechanics owner) documents the new refusal cases. No migration is performed for the interim workaround: a hand-added 'origin file://' remote was empirically verified to still fetch, resolve its head, and refresh fine on the unchanged origin path, so it is harmless and simply unnecessary - that is stated in the PR description rather than migrated.

Repo conventions followed (firstmate shared tracked material): one sentence per line in tracked Markdown, plain dash never em dash, shellcheck-clean bin scripts (bin/fm-lint.sh passes), colocated tests, no agent co-author on the commit.

What Changed

  • freshen_spawn_worktree_base() in bin/fm-spawn.sh now takes the resolved primary checkout (PROJ_ABS_REAL) as a second argument and branches on whether the pooled worktree has an origin remote. Pools with origin keep the existing byte-identical fetch / remote set-head --auto / reset-to-origin/<default> path; pools without one resolve the base from the primary local copy instead - verifying it is a readable git repository root, reading refs/heads/<default> rather than its HEAD, fetching +refs/heads/<default> into FETCH_HEAD only (no synthetic remote-tracking refs), and cross-checking the fetched tip against the primary's ref before any reset. Both paths converge on the same cleanliness refusal, hard reset, and post-reset HEAD verification, with a new label variable so shared messages can name either base.
  • tests/fm-spawn-pool-base-freshen.test.sh gains a make_remoteless_case fixture (no remote at all, primary advanced past the pool's allocation base) and three cases driving the real spawn path: successful refresh onto the primary's advanced tip and content, dirty-pool refusal with HEAD unmoved and uncommitted work intact, and unresolvable-base refusal covering both a primary on a non-standard branch name and a project dir that is not a git repository root. The six pre-existing origin-path tests are unchanged.
  • docs/architecture.md restates the base-freshness boundary in terms of the project's current default branch and names both resolution sources; the bin/fm-spawn.sh header documents the added refusal cases (unresolvable primary default branch, unreadable primary copy, unverifiable fetched tip).

Note on the interim field workaround: a hand-added origin file://<primary> remote on an affected pool still fetches, resolves its head, and refreshes correctly on the unchanged origin path, so no migration is performed - those remotes are harmless, just no longer necessary.

Risk Assessment

✅ Low: Well-bounded guard fix that keeps the pre-existing origin path byte-identical, adds a defensively verified local-path fallback preserving every stated safety property (dirty-pool refusal, unverifiable-base refusal, post-reset HEAD verification), and ships behavioral regression tests through the real spawn path; both findings are informational notes on inherited helper semantics, not defects introduced by this change.

Testing

Ran the colocated regression suite (6 origin-path + 3 new remote-less cases, all passing), proved the new remote-less test fails against the base-commit fm-spawn.sh and passes after the fix, and captured a manual end-to-end before/after transcript through the real spawn path: pre-fix a remote-less project fails with the exact field error and a stale pool, post-fix the same spawn succeeds with pool HEAD at the primary's refs/heads/main, the primary's newest content present, no remotes or remote-tracking refs left in the pool, and a hand-added origin file://<primary> workaround remote still freshening via the unchanged origin path; worktree restored clean and temp fixtures removed.

Evidence: Regression suite run (all 9 cases, evidence mode)
FM_TEST_BEGIN 2026-08-24T16:08:26Z tests/fm-spawn-pool-base-freshen.test.sh family=unclassified expected_gate_skip=none
# observed spawn: spawned pool-current-base-r1 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-pool-current-base-r1 worktree=/var/folders/1l/wdrkcwtj7mq7gtx9k8qcp1g00000gn/T//fm-spawn-pool-base-freshen.13EpQi/current-base/pool
# observed base: HEAD=6a07bc82192b1e6ca5c1bc1e96376c0ee6f39f31 origin/main=6a07bc82192b1e6ca5c1bc1e96376c0ee6f39f31 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=/var/folders/1l/wdrkcwtj7mq7gtx9k8qcp1g00000gn/T//fm-spawn-pool-base-freshen.13EpQi/direct-pr/pool
# observed scout spawn: spawned pool-scout-r3 harness=codex kind=scout window=firstmate:fm-pool-scout-r3 worktree=/var/folders/1l/wdrkcwtj7mq7gtx9k8qcp1g00000gn/T//fm-spawn-pool-base-freshen.13EpQi/scout/pool
ok - direct-PR ships and scouts both refresh stale pooled worktrees before launch
# observed dirty refusal: error: pooled worktree '/var/folders/1l/wdrkcwtj7mq7gtx9k8qcp1g00000gn/T//fm-spawn-pool-base-freshen.13EpQi/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
# observed unresolved-default refusal: error: could not resolve origin's current default branch for pooled worktree '/var/folders/1l/wdrkcwtj7mq7gtx9k8qcp1g00000gn/T//fm-spawn-pool-base-freshen.13EpQi/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 '/var/folders/1l/wdrkcwtj7mq7gtx9k8qcp1g00000gn/T//fm-spawn-pool-base-freshen.13EpQi/unreachable-origin/pool'; refusing to launch from a potentially stale base
ok - an unreachable origin refuses a potentially stale pooled worktree
# observed remote-less spawn: spawned pool-local-only-r6 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-pool-local-only-r6 worktree=/var/folders/1l/wdrkcwtj7mq7gtx9k8qcp1g00000gn/T//fm-spawn-pool-base-freshen.13EpQi/local-only/pool
# observed remote-less base: HEAD=3c54ae454fea960bd376f1dfa08f91e254ca44a1 primary main=3c54ae454fea960bd376f1dfa08f91e254ca44a1
ok - a remote-less pooled worktree refreshes from the primary local copy before launch
ok - a dirty remote-less pooled worktree is refused without discarding its local work
# observed unresolvable primary-base refusal: error: pooled worktree '/var/folders/1l/wdrkcwtj7mq7gtx9k8qcp1g00000gn/T//fm-spawn-pool-base-freshen.13EpQi/local-only-unreadable/pool' has no 'origin' remote and its local copy '/private/var/folders/1l/wdrkcwtj7mq7gtx9k8qcp1g00000gn/T/fm-spawn-pool-base-freshen.13EpQi/local-only-unreadable/not-a-repo' is not a readable git repository root; refusing to launch from a potentially stale base
ok - an unresolvable or unreadable primary base refuses the remote-less pooled worktree
# all fm-spawn-pool-base-freshen tests passed
FM_TEST_END 2026-08-24T16:08:53Z tests/fm-spawn-pool-base-freshen.test.sh exit=0 duration_ms=27078 gate_skip=false
FM_TEST_SUMMARY total=1 failed=0 skipped_gate=0 duration_ms=27145
FM_TEST_SUMMARY_FAMILY family=unclassified count=1 duration_ms=27078 failed=0
FM_TEST_SLOWEST rank=1 script=tests/fm-spawn-pool-base-freshen.test.sh duration_ms=27078
Evidence: E2E before/after remote-less spawn transcript + workaround check
A local-only project (no git remote anywhere, like helm / disc-importer in the fleet)
with a pooled worktree allocated before the primary's main advanced.

=== BEFORE FIX (bin/fm-spawn.sh at base d9701ad) ===
warning: /var/folders/1l/wdrkcwtj7mq7gtx9k8qcp1g00000gn/T//fm-remoteless-repro.D5J2DG/before/home/data/fix-widget-a1/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
fatal: 'origin' does not appear to be a git repository
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
error: could not fetch origin for pooled worktree '/var/folders/1l/wdrkcwtj7mq7gtx9k8qcp1g00000gn/T//fm-remoteless-repro.D5J2DG/before/pool'; refusing to launch from a potentially stale base
exit=1
pool HEAD unchanged at stale allocation base: 5f8f3a6d2e9d1f19bec35b3bf69f578fd99cbde3
primary refs/heads/main (the tip it should have): 47e30460ac465ee0d43267d0fbbfe57b54350cf8

=== AFTER FIX (bin/fm-spawn.sh at 6fe8185), identical fresh fixture ===
warning: /var/folders/1l/wdrkcwtj7mq7gtx9k8qcp1g00000gn/T//fm-remoteless-repro.D5J2DG/after/home/data/fix-widget-a1/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
spawned fix-widget-a1 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-fix-widget-a1 worktree=/var/folders/1l/wdrkcwtj7mq7gtx9k8qcp1g00000gn/T//fm-remoteless-repro.D5J2DG/after/pool
exit=0
pool HEAD:               ff719021a65010731a4d2c5633ab74f6697d14ad
primary refs/heads/main: ff719021a65010731a4d2c5633ab74f6697d14ad
pool now has primary's newest file: newest primary content
pool remotes after spawn (still none, no synthetic remote left behind): []
pool remote-tracking refs after spawn: []
=== Interim workaround compatibility: pool with hand-added 'origin file://<primary>' remote, fixed fm-spawn.sh ===
warning: /var/folders/1l/wdrkcwtj7mq7gtx9k8qcp1g00000gn/T//fm-workaround-check.uh4N7z/wk/home/data/fix-widget-b2/brief.md records no delivery contract line (scaffolded before ship briefs recorded one); launching on the explicit --mode no-mistakes - confirm its definition of done matches
spawned fix-widget-b2 harness=codex kind=ship mode=no-mistakes yolo=off window=firstmate:fm-fix-widget-b2 worktree=/var/folders/1l/wdrkcwtj7mq7gtx9k8qcp1g00000gn/T//fm-workaround-check.uh4N7z/wk/pool
exit=0
pool HEAD:               e6c2d987170bba14373be83fd65cf3b2ca71c2e2
primary refs/heads/main: e6c2d987170bba14373be83fd65cf3b2ca71c2e2
took origin path (origin/main tracking ref exists): e6c2d987170bba14373be83fd65cf3b2ca71c2e2
Evidence: New test fails on pre-fix code (fail-before/pass-after proof)
# bin/fm-spawn.sh reverted to base d9701ad, same test file:
ok - a dirty pooled worktree is refused without discarding its local work
ok - an unresolved remote default branch refuses the pooled worktree
ok - an unreachable origin refuses a potentially stale pooled worktree
not ok - spawn should refresh a remote-less pooled worktree from the primary copy: expected exit 0, got 1
# restored to 6fe8185: all 9 cases pass

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • ℹ️ bin/fm-spawn.sh:1778 - In the remote-less path, default_branch (fm-ff-lib.sh:38) falls back to preferring refs/heads/main over refs/heads/master when no origin/HEAD exists. A remote-less repo whose real default branch is 'master' but which also carries a stale stray 'main' branch would silently seed the pool from the stray 'main' tip without erroring. This is pre-existing shared-helper semantics (identical to primary_head_commit used by secondmate sync) that the intent explicitly adopts, and such projects could not spawn at all before this fix, so no action is required - noting the inherited limitation.
  • ℹ️ bin/fm-spawn.sh:141 - The header comment states a primary parked on a feature branch 'refuses rather than seeding the wrong base', but the implementation (correctly) seeds from the default-branch ref in that case; refusal only fires when the default branch is unresolvable or the ref is missing. The behavior is right and matches the intent's design; the comment (which mirrors the intent's own wording) slightly overstates the refusal condition.
✅ **Test** - passed

✅ No issues found.

  • FM_TEST_EVIDENCE=1 bin/fm-test-run.sh tests/fm-spawn-pool-base-freshen.test.sh - all 9 cases pass (6 pre-existing origin-path + 3 new remote-less)
  • Regression proof: git checkout d9701ad -- bin/fm-spawn.sh then re-ran the test file - fails with not ok - spawn should refresh a remote-less pooled worktree from the primary copy: expected exit 0, got 1 while all origin-path cases still pass; restored to 6fe8185 and all pass
  • Manual E2E before/after: drove the real bin/fm-spawn.sh against a remote-less fixture (primary advanced past the pool's allocation base) - pre-fix exits 1 with error: could not fetch origin for pooled worktree ..., post-fix reports spawned fix-widget-a1 ... with pool HEAD == primary refs/heads/main, newest content present, and zero remotes/remote-tracking refs in the pool
  • Interim-workaround compatibility: pool with hand-added origin file://&lt;primary&gt; remote spawns successfully via the unchanged origin path (refs/remotes/origin/main updated to the primary tip)
  • Post-test hygiene: worktree git status --porcelain clean at 6fe8185, all temp fixtures removed
⚠️ **Document** - 1 info
  • ℹ️ bin/fm-test-run.sh:472 - bin/fm-test-run.sh's portable-serial duration hint records tests/fm-spawn-pool-base-freshen.test.sh 13257, but this change grew that script from 6 to 9 cases, so the recorded lane-balance duration is now understated. It is an executable balance hint refreshed from CI timing, not documentation, so fixing it here would change executable behavior and is out of this phase's scope. It is stale-tolerant by design (lane partitioning only) and self-corrects on the next CI timing refresh; flagged only so the drift is visible.
⚠️ **Lint** - 1 warning
  • ⚠️ linter found issues (exit code 1)
✅ **Push** - passed

✅ No issues found.

… copy

Ship and scout spawns for a local-only project failed at the base-freshen
step: the guard unconditionally fetched `origin`, which does not exist in
those projects' pool clones.

A pooled worktree that has an `origin` remote keeps the existing network
path unchanged, command for command and message for message. One with no
`origin` now resolves its base from the primary local copy instead: it
reads that copy's default-branch ref rather than its HEAD, fetches it by
path, and verifies the fetched tip against the primary's own ref before
resetting.

Every safety property of the guard is preserved on both paths, which share
one cleanliness refusal, one hard reset, and one post-reset HEAD
verification: a dirty pool is never discarded, and an unreadable primary,
an unresolvable default branch, or an unverifiable tip refuses loudly
naming the worktree instead of launching from stale history.
@adonis-garcia-git
adonis-garcia-git merged commit ec74533 into main Aug 24, 2026
13 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