fix(host-service): refresh non-default base branches before forking new workspaces
Summary
resolveNewBranchStartPoint only upgraded local→remote-tracking + fetched the base ref when the base was the default branch. For any other base branch — sticky localStorage default, explicit picker choice, an AI-suggested branch — the local ref was used as-is with no fetch. A shared branch that hadn't been touched in weeks silently forked new workspaces from a stale tip.
Concrete case that motivated this: workspace created with baseBranch: mirror-flier; local mirror-flier was 44 days behind origin/mirror-flier, producing a new workspace ~1700 commits behind current work. Reproduced from the git reflog in the affected worktree (branch: Created from mirror-flier at a June 9 commit, worktree pointer touched July 23).
Change
- Extract
resolveNewBranchStartPointfromworkspaces.tsintoworkspace-creation/utils/resolve-new-branch-start-point.tsso it can be unit-tested. - Drop the
startPoint.shortName === defaultBranchNamegate — the upgrade + fetch now applies to any local base branch that has a configured upstream. Default-branch behavior is unchanged.
Local branches without an upstream (workspace branches, purely-local dev branches) and cases where the remote-tracking ref doesn't exist locally continue to use the local ref unchanged — same behavior as before.
Test plan
- New unit tests in
resolve-new-branch-start-point.test.tscover: non-default branch with upstream (regression), default branch (unchanged), no upstream, remote ref missing, silent fetch failure. - Manual: open a new workspace with a non-default base branch that's stale locally; verify the new worktree tip matches
origin/<base>and not the pre-existing local ref. -
bun test packages/host-servicepasses. -
bun run lintandbun run typecheckclean.
Known follow-ups (not in this PR)
Adjacent causes surfaced during the same investigation, deliberately left as separate work:
- Sticky base-branch default.
apps/desktop/src/renderer/stores/v2-workspace-create-defaults.tspersists the last-picked base branch per project in localStorage indefinitely (baseBranchesByProjectId), andPromptGroup.tsx:96-98pre-fills it silently. A one-time accidental pick of a non-default branch becomes the sticky default forever, with no UI signal. Fix has design choices (drop persistence, badge inherited defaults, add a reset affordance) worth discussing on its own PR. With this PR merged the resulting workspaces at least fork from a fresh tip of the stuck branch, so the symptom drops from "weeks behind" to "sometimes notmain." - Picker source hint dropped.
buildStartPointFromHint(packages/host-service/src/trpc/router/workspace-creation/shared/start-point.ts:12) is documented inapps/desktop/docs/V2_WORKSPACE_CREATION.mdas the way the picker's explicitlocal/remote-trackingrow choice reaches the server, but it's never called.createInputSchemahas nobaseBranchSourcefield anduseSubmitWorkspace.ts:117only sendsbaseBranch. So clicking theorigin/mainrow can still resolve to localmainon the server. Wiring the hint end-to-end is a small but cross-package change.
Summary by CodeRabbit
-
New Features
- Improved new branch creation to recognize configured upstream branches and use available remote-tracking references.
- Automatically refreshes remote branch information when resolving a branch’s starting point.
-
Bug Fixes
- Branch creation now safely falls back to local references when upstream information is unavailable.
- Fetch failures no longer prevent branch creation.