fix(desktop): restore changes sidebar base diff for sourced workspaces#2790
Conversation
📝 WalkthroughWalkthroughRenamed the workspace "baseBranch" concept to "compareBaseBranch" across backend and frontend, added optional Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Client
participant CreateProc as Create Procedure
participant DB as Database
participant WTService as Worktree Service
participant Init as Workspace Init
participant Git as Git
Client->>CreateProc: create({ projectId, compareBaseBranch?, sourceWorkspaceId? })
CreateProc->>DB: getWorkspace(sourceWorkspaceId)
alt sourceWorkspaceId provided but not found
DB-->>CreateProc: null
CreateProc-->>Client: throw Error
else source workspace found
DB-->>CreateProc: sourceWorkspace
CreateProc->>DB: getWorktree(sourceWorkspace.worktreeId)
DB-->>CreateProc: sourceWorktreeWorktree
CreateProc->>CreateProc: resolve compareBaseBranch (source.baseBranch or project default)
CreateProc->>Init: initializeWorkspaceWorktree({ startPointBranch: sourceWorkspace.branch, compareBaseBranch })
Init->>Git: resolve effectiveStartPoint, check origin/<ref>, fetch if needed
Init->>Git: create or use branch/worktree
Git-->>Init: worktree created
Init-->>CreateProc: init success
CreateProc->>DB: insert new workspace/worktree rows (baseBranch: compareBaseBranch)
DB-->>CreateProc: insertion result
CreateProc-->>Client: created workspace
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/desktop/src/lib/trpc/routers/workspaces/utils/workspace-init.ts (1)
329-329:⚠️ Potential issue | 🟡 MinorInconsistent variable in warning message.
The warning message references
effectiveBaseBranchbut the surrounding context useseffectiveStartPoint. This may confuse debugging when the two values differ.Suggested fix
} else { console.warn( - `[workspace-init] Remote branch "${effectiveBaseBranch}" exists but local tracking ref "${originRef}" not found. Falling back to local ref.`, + `[workspace-init] Remote branch "${effectiveStartPoint}" exists but local tracking ref "${originRef}" not found. Falling back to local ref.`, );🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/desktop/src/lib/trpc/routers/workspaces/utils/workspace-init.ts` at line 329, The warning string in workspace-init uses the wrong variable name: replace `effectiveBaseBranch` with `effectiveStartPoint` in the message that currently reads `[workspace-init] Remote branch "${effectiveBaseBranch}" exists but local tracking ref "${originRef}" not found. Falling back to local ref.` so the log matches the surrounding logic (ensure the message uses `effectiveStartPoint` and keep `originRef` unchanged); verify other nearby log messages in the same block reference `effectiveStartPoint` consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@apps/desktop/src/lib/trpc/routers/workspaces/utils/workspace-init.ts`:
- Line 329: The warning string in workspace-init uses the wrong variable name:
replace `effectiveBaseBranch` with `effectiveStartPoint` in the message that
currently reads `[workspace-init] Remote branch "${effectiveBaseBranch}" exists
but local tracking ref "${originRef}" not found. Falling back to local ref.` so
the log matches the surrounding logic (ensure the message uses
`effectiveStartPoint` and keep `originRef` unchanged); verify other nearby log
messages in the same block reference `effectiveStartPoint` consistently.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5e57b519-dd6e-40e1-bad4-e1f40af0c5bd
📒 Files selected for processing (4)
apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.test.tsapps/desktop/src/lib/trpc/routers/workspaces/procedures/create.tsapps/desktop/src/lib/trpc/routers/workspaces/utils/workspace-init.tsapps/desktop/src/renderer/routes/_authenticated/components/AgentHooks/hooks/useCommandWatcher/tools/create-worktree.ts
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/desktop/src/lib/trpc/routers/workspaces/utils/workspace-init.ts (1)
322-355:⚠️ Potential issue | 🟠 MajorLet the fetch phase resolve missing remote start points.
When
branchExistsOnRemote()returns"exists"butorigin/${effectiveStartPoint}is missing locally, this branch says it will fetch later and then returns early as soon asresolveLocalRef()can't find a local branch. That makes a valid remotestartPointBranchfail on repos that just haven't fetched that ref yet, and Line 429 never gets a chance to populate it.💡 Suggested fix
if (branchCheck.status === "exists") { const originRef = `origin/${effectiveStartPoint}`; // VALIDATION: Verify the remote-tracking ref actually exists locally // branchExistsOnRemote checks the remote, but the local ref might not be fetched yet if (await refExistsLocally(mainRepoPath, originRef)) { startPoint = originRef; } else { console.warn( `[workspace-init] Remote branch "${effectiveStartPoint}" exists but local tracking ref "${originRef}" not found. Falling back to local ref.`, ); manager.updateProgress( workspaceId, "verifying", "Using local reference", `Remote tracking reference not found locally. Will fetch before creating worktree.`, ); - - const ref = await resolveLocalRef({ - reason: "Remote tracking ref not found locally", - checkOriginRefs: false, // Don't check origin refs since we just confirmed it doesn't exist - progressStep: "verifying", - }); - - if (!ref) { - manager.updateProgress( - workspaceId, - "failed", - "No local reference available", - requestedStartPoint || compareBaseBranchWasExplicit - ? `Branch "${effectiveStartPoint}" exists on remote but has not been fetched yet, and no local branch exists. Please run "git fetch origin ${effectiveStartPoint}" and try again.` - : `Branch "${effectiveStartPoint}" not found locally. Please run "git fetch" and try again.`, - ); - return; - } - startPoint = ref; + startPoint = originRef; } } else {🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/desktop/src/lib/trpc/routers/workspaces/utils/workspace-init.ts` around lines 322 - 355, The current logic returns early when branchExistsOnRemote() is "exists" but refExistsLocally(mainRepoPath, `origin/${effectiveStartPoint}`) is false and resolveLocalRef() yields no ref; instead, change it to defer to the fetch phase by not returning: when origin/{effectiveStartPoint} is missing locally, update progress via manager.updateProgress(...) as you already do, but do not call return — leave startPoint unset (or set to undefined) so the later fetch/populate logic (the code around the fetch phase and the block that sets startPoint from the fetched remote ref) can resolve the remote branch; keep resolveLocalRef usage for best-effort local resolution but ensure branchExistsOnRemote(), refExistsLocally(), resolveLocalRef(), and startPoint handling permit proceeding to the fetch step rather than bailing out early.
🧹 Nitpick comments (2)
apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsx (1)
265-293: ExtractCompareBaseBranchPickerInlineinto its own file.This picker has grown large enough that keeping it inline makes
PromptGroup.tsxharder to scan and test, and it keeps this components-path file in a multi-component layout.As per coding guidelines,
**/{components,hooks,stores,providers}/**/*.{ts,tsx}: Use one component per file, no multi-component files.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsx` around lines 265 - 293, Extract the CompareBaseBranchPickerInline component into its own file: create a new component file (e.g., CompareBaseBranchPickerInline.tsx) that exports the CompareBaseBranchPickerInline function as the default export, move its entire function body and the prop type annotations there, and also export or import any related types used (e.g., OpenableWorktreeAction) so the new file compiles; then replace the in-file definition in PromptGroup.tsx with an import of CompareBaseBranchPickerInline and ensure any helper functions, constants, and used props (effectiveCompareBaseBranch, defaultBranch, isBranchesLoading, isBranchesError, branches, worktreeBranches, openableWorktrees, activeWorkspacesByBranch, externalWorktreeBranches, modKey, onSelectCompareBaseBranch, onOpenWorktree, onOpenActiveWorkspace) are passed through unchanged.apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.ts (1)
312-319: Take the start point from the validated source worktree.This path already resolves
sourceWorktree, so using itsbranchavoids depending on duplicated workspace metadata for the Git ref. If those two rows ever drift, the new workspace will branch from the wrong ref.♻️ Suggested tweak
initializeWorkspaceWorktree({ workspaceId: workspace.id, projectId: input.projectId, worktreeId: worktree.id, worktreePath, branch, mainRepoPath: project.mainRepoPath, - startPointBranch: sourceWorkspace?.branch, + startPointBranch: sourceWorktree?.branch, namingPrompt: input.prompt, useExistingBranch: input.useExistingBranch, });Also applies to: 515-523
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.ts` around lines 312 - 319, The code currently uses the Git ref/branch from sourceWorkspace metadata which can drift from the resolved worktree; instead, when a sourceWorktree exists (resolved via getWorktree(sourceWorkspace.worktreeId)), take the branch/ref from that validated sourceWorktree object (e.g., use sourceWorktree.branch) rather than sourceWorkspace.branch when determining the start point for the new workspace; apply the same change to the other similar block later in this file that also checks sourceWorkspace/sourceWorktree before creating the branch.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@apps/desktop/src/lib/trpc/routers/workspaces/utils/workspace-init.ts`:
- Around line 322-355: The current logic returns early when
branchExistsOnRemote() is "exists" but refExistsLocally(mainRepoPath,
`origin/${effectiveStartPoint}`) is false and resolveLocalRef() yields no ref;
instead, change it to defer to the fetch phase by not returning: when
origin/{effectiveStartPoint} is missing locally, update progress via
manager.updateProgress(...) as you already do, but do not call return — leave
startPoint unset (or set to undefined) so the later fetch/populate logic (the
code around the fetch phase and the block that sets startPoint from the fetched
remote ref) can resolve the remote branch; keep resolveLocalRef usage for
best-effort local resolution but ensure branchExistsOnRemote(),
refExistsLocally(), resolveLocalRef(), and startPoint handling permit proceeding
to the fetch step rather than bailing out early.
---
Nitpick comments:
In `@apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.ts`:
- Around line 312-319: The code currently uses the Git ref/branch from
sourceWorkspace metadata which can drift from the resolved worktree; instead,
when a sourceWorktree exists (resolved via
getWorktree(sourceWorkspace.worktreeId)), take the branch/ref from that
validated sourceWorktree object (e.g., use sourceWorktree.branch) rather than
sourceWorkspace.branch when determining the start point for the new workspace;
apply the same change to the other similar block later in this file that also
checks sourceWorkspace/sourceWorktree before creating the branch.
In
`@apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsx`:
- Around line 265-293: Extract the CompareBaseBranchPickerInline component into
its own file: create a new component file (e.g.,
CompareBaseBranchPickerInline.tsx) that exports the
CompareBaseBranchPickerInline function as the default export, move its entire
function body and the prop type annotations there, and also export or import any
related types used (e.g., OpenableWorktreeAction) so the new file compiles; then
replace the in-file definition in PromptGroup.tsx with an import of
CompareBaseBranchPickerInline and ensure any helper functions, constants, and
used props (effectiveCompareBaseBranch, defaultBranch, isBranchesLoading,
isBranchesError, branches, worktreeBranches, openableWorktrees,
activeWorkspacesByBranch, externalWorktreeBranches, modKey,
onSelectCompareBaseBranch, onOpenWorktree, onOpenActiveWorkspace) are passed
through unchanged.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 840b38d1-2ba2-4ff6-935b-6db3e5205c95
📒 Files selected for processing (13)
apps/desktop/src/lib/trpc/routers/changes/branches.tsapps/desktop/src/lib/trpc/routers/workspaces/procedures/create.tsapps/desktop/src/lib/trpc/routers/workspaces/utils/base-branch-config.tsapps/desktop/src/lib/trpc/routers/workspaces/utils/workspace-creation.tsapps/desktop/src/lib/trpc/routers/workspaces/utils/workspace-init.tsapps/desktop/src/renderer/components/NewWorkspaceModal/NewWorkspaceModalDraftContext.tsxapps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsxapps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/components/PromptGroupAdvancedOptions/PromptGroupAdvancedOptions.tsxapps/desktop/src/renderer/routes/_authenticated/_dashboard/project/$projectId/page.tsxapps/desktop/src/renderer/routes/_authenticated/components/AgentHooks/hooks/useCommandWatcher/tools/create-worktree.tsapps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/DashboardNewWorkspaceDraftContext.tsxapps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/components/PromptGroup/PromptGroup.tsxapps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/components/PromptGroup/components/PromptGroupAdvancedOptions/PromptGroupAdvancedOptions.tsx
✅ Files skipped from review due to trivial changes (1)
- apps/desktop/src/lib/trpc/routers/workspaces/utils/workspace-creation.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- apps/desktop/src/renderer/routes/_authenticated/components/AgentHooks/hooks/useCommandWatcher/tools/create-worktree.ts
Summary
Against mainandCommitsin the Changes sidebarcompareBaseBranchfor the diff base andstartPointBranchfor the branch/ref to create fromWhy The Diff Looks Bigger Than The Behavior Change
branch.<name>.base,worktrees.baseBranch) unchangedTesting
bun test apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.test.tsbunx biome check apps/desktop/src/lib/trpc/routers/changes/branches.ts apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.ts apps/desktop/src/lib/trpc/routers/workspaces/utils/base-branch-config.ts apps/desktop/src/lib/trpc/routers/workspaces/utils/workspace-creation.ts apps/desktop/src/lib/trpc/routers/workspaces/utils/workspace-init.ts apps/desktop/src/renderer/components/NewWorkspaceModal/NewWorkspaceModalDraftContext.tsx apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsx apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/components/PromptGroupAdvancedOptions/PromptGroupAdvancedOptions.tsx apps/desktop/src/renderer/routes/_authenticated/_dashboard/project/$projectId/page.tsx apps/desktop/src/renderer/routes/_authenticated/components/AgentHooks/hooks/useCommandWatcher/tools/create-worktree.ts apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/DashboardNewWorkspaceDraftContext.tsx apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/components/PromptGroup/PromptGroup.tsx apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/components/DashboardNewWorkspaceForm/components/PromptGroup/components/PromptGroupAdvancedOptions/PromptGroupAdvancedOptions.tsxNotes
bunx tsc -p apps/desktop/tsconfig.json --noEmit --pretty false --ignoreDeprecations 6.0is still blocked by existing repo issues, including missingapps/desktop/src/renderer/routeTree.gen, current TanStack route typing failures, and the existingfile-iconsmanifest type error