Repository navigation
fix(desktop): stop the composer reusing another project's base branch - #8032
XavierClavel wants to merge 3 commits into
Conversation
Opening the composer from a project's "+" selects that project in the global draft before the screen mounts. The base-branch reset only ran when the project changed after mount, so the draft kept the previous project's base (re-seeded after every create from lastProjectId's saved default). The host found no such branch in the new repo and forked the worktree from the primary checkout's HEAD, often a stale local main. Seed the base branch from the selected project's saved default on mount too, not only on a project or host change.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe workspace screen now uses ChangesWorkspace base-branch reset
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix Merge Risk: ⚪ Minimal · up to The change applies the selected project’s saved base branch when the workspace context changes and avoids replacing an in-progress choice otherwise. No actionable merge-blocking risk is evident. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change corrects project-specific branch selection without adding permissions or an external entrypoint. No security regression was identified in the inspected flow, but runtime interleavings and saved-branch availability across hosts remain incompletely established. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
Review completed against the latest diff
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
There was a problem hiding this comment.
All reported issues were addressed across 4 files
Architecture diagram
sequenceDiagram
participant UI as NewWorkspaceScreen
participant Hook as useBaseBranchReset
participant Draft as NewWorkspaceDraftStore
participant Defaults as V2WorkspaceCreateDefaultsStore
participant Sidebar as Sidebar "+" action
Note over UI,Defaults: Workspace composer base branch selection flow
Sidebar->>Draft: selectProject(projectId)
Sidebar->>UI: mount NewWorkspaceScreen
UI->>Hook: render with projectId, hostId
Hook->>Defaults: read baseBranchesByProjectId[projectId]
Defaults-->>Hook: saved default (branchName, source) or null
alt First mount or project/host changed
Hook->>Hook: check seededForRef against projectId/hostId
Hook->>Draft: updateDraft({ baseBranch, baseBranchSource })
Draft-->>UI: re-render with fresh base branch
else Same project and host (already seeded)
Hook->>Hook: skip - preserve current selection
end
Note over UI,Draft: User selects a different branch while composer is open
UI->>Defaults: setBaseBranchDefault(projectId, branch, source)
UI->>Draft: updateDraft({ baseBranch, baseBranchSource })
Hook->>Hook: seededForRef unchanged - no reset
Note over UI,Draft: User switches project or host
alt Project changes
Sidebar->>Draft: selectProject(newProjectId)
Hook->>Defaults: read baseBranchesByProjectId[newProjectId]
Defaults-->>Hook: saved default or null
Hook->>Draft: updateDraft({ baseBranch, baseBranchSource })
else Host changes
Hook->>Defaults: read baseBranchesByProjectId[currentProjectId]
Defaults-->>Hook: saved default or null
Hook->>Draft: updateDraft({ baseBranch, baseBranchSource })
end
Note over UI,Draft: Draft carries baseBranch into workspace creation flow
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
… saved-default change
What & why
Since desktop 1.30.0, starting a session from a project's + in the sidebar can fork the new worktree from the project's local checkout (
HEAD, usually a stale localmain) instead of a freshorigin/main. Git records it asbranch: Created from HEAD.The new-workspace draft is one global store, and the base branch rides along with it:
lastProjectIdand re-applies that project's saved base (for exampledevelop).useOpenNewWorkspace) callsselectProject()and then navigates, soNewWorkspaceScreenmounts with the new project already selected. The reset effect seededpreviousProjectIdRefwith that project, so it only fired on a change after mount and never ran.baseBranch: "develop"for a repo that has nodevelop.resolveStartPointfound neither ref and fell back toHEAD.The pre-selection in step 2 came with #7485, which is why this started with 1.30.0. Whether it bites depends on which project you created in last, so it looks random.
This moves the reset into a
useBaseBranchResethook that seeds the draft from the selected project's saved default on mount as well as on every project or host change. A branch picked while the composer is open stays, since picking it also saves it as the project's default.Not in this PR: the host still turns a base that exists nowhere into a fork of
HEAD. That is its own change, and #7657 already proposes one.How I tested it
Dev app built from this branch, driven over CDP with real clicks. Two throwaway repos:
alphawithmainanddevelop, andbetawith onlymain, its localmain(B1) behind the remote.alpha, pickdevelopas the base and start a session (no agent).betain the sidebar and start a session.betabetaworktree branch (reflog)main)developCreated from HEADmainmainCreated from origin/mainalphaforked fromdevelopin both runs, so a base you pick yourself is still honored.Composer opened from
beta's + (UI in French):Before, the base pill shows
alpha'sdevelop:After, it shows
beta's defaultmain:useBaseBranchReset.test.ts(4 tests, happy-dom): the two mount cases fail with the old seeding, and the host-change case fails if the hook ignores the host. All pass with the fix.bun run lint: clean.bun run typecheck: 42/42 tasks.bun run test: the only failures were not from this change. 7deriveSandboxCredentialstests in@superset/trpcfail on the placeholderSANDBOX_GATE_SECRETfrom.env.local.example, and 37 git/watcher tests in desktop and host-service timed out under the parallel run. Those 37 pass when their files run alone, on this branch and onmain.Checklist
type(scope): subject)bun run lintandbun run typecheckpass (CI fails on lint warnings too)Summary by CodeRabbit