fix(bin): validate default branch refs before worktree spawn - #1245
Closed
wuzihuang wants to merge 2 commits into
Closed
fix(bin): validate default branch refs before worktree spawn#1245wuzihuang wants to merge 2 commits into
wuzihuang wants to merge 2 commits into
Conversation
A project clone keeps refs/remotes/origin/HEAD from whatever its remote advertised at clone time, and that symbolic ref keeps resolving after the branch it names is renamed or deleted. git symbolic-ref reports the dangling target happily, so every unvalidated read handed callers a branch name that cannot be checked out, diffed, or merged into. Seen live on a clone that publishes only build and production while origin/HEAD still names main. fm_default_branch now trusts origin/HEAD only when its target exists, and falls through to the local candidates otherwise. The five byte-identical copies of that resolution in fm-ff-lib, fm-review-diff, fm-teardown, fm-merge-local, and fm-fleet-sync now delegate to it instead of carrying the same defect five more times. fm-spawn additionally refuses up front when the base treehouse would build the isolated worktree from is missing. treehouse get takes no base-ref argument and treehouse does not verify the base it resolves, so git worktree add fails inside the pane and firstmate saw only the generic 60s did not enter a worktree timeout. The refusal names the missing ref and the branches that do exist, and stays read-only: repointing a project's origin/HEAD is a project-side repair firstmate does not make. A clone with nothing fetched yet is deliberately not refused, since treehouse fetches before it allocates.
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
Let a project whose remote publishes only build/production get an isolated worktree instead of failing: firstmate must resolve a default branch that actually exists rather than a stale origin/HEAD target, and refuse up front with the real cause when the base ref treehouse would allocate from is missing, so the O1-Server implementation can resume from a safe isolated copy.
What Changed
bin/fm-tangle-lib.shso callers only trustorigin/HEADwhen its target ref exists, then fall back to localmain/master.fm-spawn.shtreehouse base-ref preflight that refuses before launch when the resolved allocation base is missing and reports the available remote branches.origin/HEAD, build/production-only remotes, valid repointed defaults, and unfetched clones.Risk Assessment
🚨 High: High because the new spawn preflight still misses a source-verifiable stale origin/HEAD case and can fall back to the generic treehouse failure instead of satisfying the required upfront refusal.
Testing
Ran the focused tangle/worktree guard regression and a manual CLI transcript; an initial transcript attempt hit the validator's
NO_MISTAKES_GATEenvironment guard, then the same scenario was rerun with the repository test bypass so the target spawn path was exercised successfully.Evidence: Manual fm-spawn build-only base-ref transcript
Pipeline
Updates from git push no-mistakes
✅ **intent** - passed
✅ No issues found.
✅ **Rebase** - passed
✅ No issues found.
bin/fm-spawn.sh:882- Criterion contradiction: intent requires firstmate to "refuse up front with the real cause when the base ref treehouse would allocate from is missing", but this guard accepts a leftover localrefs/heads/$brancheven whentreehouse_base_branchchose$branchfromrefs/remotes/origin/HEAD. Fororigin/HEAD -> origin/main, deletedrefs/remotes/origin/main, and an old localmain, this returns success even though treehouse will allocate from the missing remote ref and fail later. The contradicting hunk is the local-or-remote check:refs/heads/$branch || refs/remotes/origin/$branch.✅ **Test** - passed
✅ No issues found.
tests/fm-tangle-guard.test.shManualbin/fm-spawn.shverification with a temporary build/production-only project, fake tmux/treehouse backend, stalerefs/remotes/origin/HEAD -> refs/remotes/origin/main, then validrefs/remotes/origin/HEAD -> refs/remotes/origin/build; transcript saved at/tmp/no-mistakes-evidence/01KYQ1JTXDGBY6QW93K094PHWT/build-only-spawn-base-ref-transcript.txtgit status --shortto confirm no working-tree artifacts were left behind✅ **Document** - passed
✅ No issues found.
✅ **Lint** - passed
✅ No issues found.
✅ **Push** - passed
✅ No issues found.