fix(server): fetch worktree base branch's own remote during bootstrap #9341
main fromrefs/pull/9341/head·opened View on GitHubNew worktree threads based on upstream/main (or any non-origin remote base) sit with no useful progress for ~1min on remote servers. Fixes #9340 (server half; step-level progress UI tracked there).
The problem: dispatchBootstrapTurnStart hardcoded remoteName: "origin". With base upstream/main it paid for a slow, irrelevant git fetch origin, then checked remoteBranchExists({ refName: "upstream/main", remoteName: "origin" }) — i.e. refs/remotes/origin/upstream/main, a ref that can never exist — so it always fell back to the unfetched local ref. The upstream remote was never fetched, so the worktree could also be based on a stale commit.
How fixed: resolve the fetch target from the base ref. If the segment before the first / names a configured remote, fetch that remote; otherwise keep the existing origin behavior. The existence lookup strips the remote prefix (upstream/main on upstream looks up main), which also repairs literal origin/main bases that previously looked up origin/origin/main. Local-only branches still fall back to the local ref exactly as before.
Verified: new it.effect.each cases in server.test.ts (upstream/main, origin/main) assert fetch/check/resolve/createWorktree args; existing bootstrap tests (including the local-fallback cases) pass unchanged; server typecheck clean.
Note
Medium Risk Touches thread bootstrap git workflow on the server; incorrect remote resolution could still mis-base worktrees, but behavior is narrowed with tests and preserves local-only fallback paths.
Overview
Fixes bootstrap worktree preparation when start from remote is enabled but the base branch is not on origin (e.g. upstream/main). Previously the server always fetched origin and probed the wrong remote-tracking ref, so the real remote was never updated and worktrees could hang on stale local SHAs.
ws.ts now derives fetchRemoteName from the prefix before the first / when that remote exists, otherwise keeps the origin fallback. Remote branch checks strip that prefix so lookups hit refs/remotes/upstream/main instead of refs/remotes/origin/upstream/main (and the same fix applies to literal origin/main bases). server.test.ts adds parameterized coverage for upstream/main and origin/main, asserting fetch, branch existence, commit resolution, and worktree creation arguments.
Note
Fix worktree bootstrap to fetch base branch's own remote#
Adds a parameterized integration test in server.test.ts that verifies the server router bootstrap seam fetches and checks the correct remote for the worktree base branch. The test covers both upstream-qualified and origin-qualified bases, confirming that fetch, remote branch lookup, tracking-commit resolution, and worktree creation receive the expected remote-specific arguments using the unqualified branch name.
Macroscope summarized a81f93a.- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
Note: GPT-6 on behalf of shivam (@shivamhwp).
The first-slash split still selects the wrong remote for valid names containing a slash. With remote
team/upstreamand baseteam/upstream/main, the code probesteam, then fetchesoriginand leaves the intended base stale. Ifteamalso exists, it fetches that shorter remote instead.Resolve the longest configured remote prefix before stripping it from the branch name. Keep the existing origin and local-base fallbacks. The issue's step-level progress and cancellation gap remains separate from this fetch correction.
juliusmarminge added labelsmacroscope-review
macroscopeapp[bot](GitHub profile, opens in a new tab) approved these changes
Note
Written by
claude-opus-5-5on behalf of MariaHi! We are cleaning up open PRs, and this one does not say which model or harness was used to create it. If this change is really important, we recommend rebuilding the PR with a newer model and noting the model and harness in the PR description.
maria-rcks closed this
Sign in to join this conversation.
Approvability#
Verdict: Approved at
a81f93aMacroscope's review found this PR approvable — This is a focused server bug fix that selects and fetches the worktree base branch’s configured remote without altering unrelated bootstrap paths. Parameterized integration coverage verifies upstream-qualified and origin-qualified bases, while the other changed file is test-only.
Notes:
- Diff unchanged. Approvability was decided on eligibility alone.
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).