Repository navigation
fix(bin): freshen remote-less pooled worktrees from the primary local copy - #8
Merged
Merged
Conversation
… 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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()inbin/fm-spawn.shnow takes the resolved primary checkout (PROJ_ABS_REAL) as a second argument and branches on whether the pooled worktree has anoriginremote. Pools withoriginkeep 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, readingrefs/heads/<default>rather than its HEAD, fetching+refs/heads/<default>intoFETCH_HEADonly (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 newlabelvariable so shared messages can name either base.tests/fm-spawn-pool-base-freshen.test.shgains amake_remoteless_casefixture (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.mdrestates the base-freshness boundary in terms of the project's current default branch and names both resolution sources; thebin/fm-spawn.shheader 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)
Evidence: E2E before/after remote-less spawn transcript + workaround check
Evidence: New test fails on pre-fix code (fail-before/pass-after proof)
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
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.shthen re-ran the test file - fails withnot ok - spawn should refresh a remote-less pooled worktree from the primary copy: expected exit 0, got 1while all origin-path cases still pass; restored to 6fe8185 and all passManual E2E before/after: drove the realbin/fm-spawn.shagainst a remote-less fixture (primary advanced past the pool's allocation base) - pre-fix exits 1 witherror: could not fetch origin for pooled worktree ..., post-fix reportsspawned fix-widget-a1 ...with pool HEAD == primary refs/heads/main, newest content present, and zero remotes/remote-tracking refs in the poolInterim-workaround compatibility: pool with hand-addedorigin file://<primary>remote spawns successfully via the unchanged origin path (refs/remotes/origin/main updated to the primary tip)Post-test hygiene: worktreegit status --porcelainclean at 6fe8185, all temp fixtures removedbin/fm-test-run.sh:472- bin/fm-test-run.sh's portable-serial duration hint recordstests/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.✅ **Push** - passed
✅ No issues found.