Skip to content

fix(desktop): stop the composer reusing another project's base branch - #8032

Open
XavierClavel wants to merge 3 commits into
ParadevAI:mainfrom
XavierClavel:fix/desktop-composer-base-branch
Open

XavierClavel wants to merge 3 commits into
ParadevAI:mainfrom
XavierClavel:fix/desktop-composer-base-branch

Conversation

@XavierClavel

@XavierClavel XavierClavel commented Oct 1, 2026 •

Copy link
Copy Markdown

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 local main) instead of a fresh origin/main. Git records it as branch: Created from HEAD.

The new-workspace draft is one global store, and the base branch rides along with it:

  1. After a create, the draft resets. While the screen is still mounted, it re-selects lastProjectId and re-applies that project's saved base (for example develop).
  2. The sidebar + (useOpenNewWorkspace) calls selectProject() and then navigates, so NewWorkspaceScreen mounts with the new project already selected. The reset effect seeded previousProjectIdRef with that project, so it only fired on a change after mount and never ran.
  3. The create went out with baseBranch: "develop" for a repo that has no develop. resolveStartPoint found neither ref and fell back to HEAD.

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 useBaseBranchReset hook 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: alpha with main and develop, and beta with only main, its local main (B1) behind the remote.

  1. In alpha, pick develop as the base and start a session (no agent).
  2. Click + next to beta in the sidebar and start a session.
Base shown for beta beta worktree branch (reflog) Commit
Before (main) develop Created from HEAD B1, the stale local main
After (this branch) main Created from origin/main B4, the latest remote commit

alpha forked from develop in 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's develop:

Before: composer for beta shows develop

After, it shows beta's default main:

After: composer for beta shows main

  • New 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. 7 deriveSandboxCredentials tests in @superset/trpc fail on the placeholder SANDBOX_GATE_SECRET from .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 on main.

Checklist

  • PR title follows conventional commits (type(scope): subject)
  • bun run lint and bun run typecheck pass (CI fails on lint warnings too)
  • "Allow edits from maintainers" is checked on fork PRs

Summary by CodeRabbit

  • Bug Fixes
    • New workspaces now use the selected project’s saved base branch and source when the project or host changes, rather than retaining a branch from a previous selection.
    • A branch selected while the workspace form is open is preserved until the project changes. If the selected project has no saved base branch, the branch and source are cleared.
    • Switching hosts re-applies the saved base branch for the current project.

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.
@coderabbitai

coderabbitai Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 40f23f8b-9172-42bf-854b-701501f7a140

📥 Commits

Reviewing files that changed from the base of the PR and between b57b573 and 70d1e24.

📒 Files selected for processing (1)
  • apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/NewWorkspaceScreen/hooks/useBaseBranchReset/useBaseBranchReset.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The workspace screen now uses useBaseBranchReset to seed draft branch and source values from persisted project defaults. The hook runs on mount and when the project or host changes. Tests cover applying defaults, clearing stale values, and retaining draft values while the project and host remain unchanged.

Changes

Workspace base-branch reset

Layer / File(s) Summary
Seed base-branch draft values
apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/NewWorkspaceScreen/hooks/useBaseBranchReset/*, apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/NewWorkspaceScreen/NewWorkspaceScreen.tsx
The hook reads the selected project’s persisted base-branch default and updates the draft branch and source on mount or when the project or host changes. The screen passes the selected project ID, draft host ID, and draft updater to the hook. Tests cover saved defaults, missing defaults, and changes to the project or host.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 70d1e

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 Review

Security architecture risk: 🔵 Low · up to 70d1e

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
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The changed operation affects branch/source selection in the shared desktop composer and the resulting workspace base. It does not itself grant authority: the inspected submission path retains the selected host and project, and agent configuration is assembled separately from the branch preference.

Trust Boundaries and Controls

  • observed — The hook consumes an existing locally persisted branch preference through the same project-keyed lookup previously used by the screen. It changes initialization timing, not authentication, host selection, credential handling, or the workspace-create interface in the inspected production diff.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 4 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title uses the required conventional commit format and clearly describes the fix for reusing another project's base branch.
Description check ✅ Passed The description includes the required What & why, How I tested it, and Checklist sections. It explains the problem, the change, test results, and checklist status.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Medium risk] Refactors base branch selection logic in workspace creation.

The PR appears safe to merge; adding host-change coverage would strengthen protection against future regressions.

Findings

  1. P2 Host changes remain untested ▶
Fix with agent prompt
### Issue 1
apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/NewWorkspaceScreen/hooks/useBaseBranchReset/useBaseBranchReset.test.ts:74
The new tests cover mounting and changing projects, but not changing hosts while the composer is open. The hook also resets the base branch when `hostId` changes, and the host picker can make that change without changing projects. A test for this path would catch future regressions in host-change behavior.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR moves base-branch reset logic into a hook that seeds the global draft from the selected project’s saved default on mount, fixing the stale branch carried into a composer opened from another project’s sidebar entry.

  • Adds hook tests for mount seeding and project changes.
  • Host-change behavior remains untested.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart LR
  A[Composer mounts or project/host changes] --> B[Read selected project's saved base]
  B --> C[Reset global draft base branch]
  C --> D[Create uses draft base branch]
Loading

Reviews (1) · Last reviewed commit: "fix(desktop): stop the composer reusing ..."

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed against the latest diff

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant