Skip to content

fix(desktop): restore changes sidebar base diff for sourced workspaces#2790

Merged
Kitenite merged 2 commits into
superset-sh:mainfrom
Kitenite:kitenite/fix-diff-sidebar-regression
Mar 23, 2026
Merged

fix(desktop): restore changes sidebar base diff for sourced workspaces#2790
Kitenite merged 2 commits into
superset-sh:mainfrom
Kitenite:kitenite/fix-diff-sidebar-regression

Conversation

@Kitenite
Copy link
Copy Markdown
Collaborator

@Kitenite Kitenite commented Mar 23, 2026

Summary

  • fix the regression where a workspace created from another workspace compared against the source branch instead of the inherited compare base, which hid Against main and Commits in the Changes sidebar
  • keep the git start point separate from the compare base when initializing a sourced workspace
  • follow up with a naming refactor so workspace creation consistently uses compareBaseBranch for the diff base and startPointBranch for the branch/ref to create from

Why The Diff Looks Bigger Than The Behavior Change

  • the actual behavior change is small and lives in the workspace creation/init path
  • the extra churn is mostly mechanical rename work across every workspace-creation surface: the main New Workspace modal, the dashboard/onboarding flow, and the command-watcher create-workspace tool
  • I also renamed the branch-base config helper inputs/outputs to match the new terminology, while keeping the persisted git/db field names (branch.<name>.base, worktrees.baseBranch) unchanged

Testing

  • bun test apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.test.ts
  • bunx 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.tsx

Notes

  • bunx tsc -p apps/desktop/tsconfig.json --noEmit --pretty false --ignoreDeprecations 6.0 is still blocked by existing repo issues, including missing apps/desktop/src/renderer/routeTree.gen, current TanStack route typing failures, and the existing file-icons manifest type error

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 23, 2026

📝 Walkthrough

Walkthrough

Renamed the workspace "baseBranch" concept to "compareBaseBranch" across backend and frontend, added optional sourceWorkspaceId to the create procedure (with validation), threaded a new startPointBranch through workspace initialization, and extended tests with a richer in-file mock DB (inner-join, nested column reads) plus new source-workspace creation tests.

Changes

Cohort / File(s) Summary
Procedure & API
apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.ts
Added sourceWorkspaceId?: string, replaced baseBranch with compareBaseBranch in input, added Zod mutual-exclusion refinements, source workspace/worktree lookup and validation, and pass startPointBranch into init flow.
Workspace init & utils
apps/desktop/src/lib/trpc/routers/workspaces/utils/workspace-init.ts, apps/desktop/src/lib/trpc/routers/workspaces/utils/workspace-creation.ts, apps/desktop/src/lib/trpc/routers/workspaces/utils/base-branch-config.ts
Added startPointBranch to params, replaced effective base-branch naming with compare-base/start-point, updated resolution/fallbacks and all branch-existence/fetch checks to use effectiveStartPoint / compareBaseBranch, and renamed exported config fields to compareBaseBranch.
Changes & Branch UI logic
apps/desktop/src/lib/trpc/routers/changes/branches.ts
Switched config reads/writes to use compareBaseBranch while leaving DB column worktrees.baseBranch unchanged.
Frontend: New workspace UIs & contexts
apps/desktop/src/renderer/components/NewWorkspaceModal/..., apps/desktop/src/renderer/routes/_authenticated/.../PromptGroup*.tsx, apps/desktop/src/renderer/routes/_authenticated/_dashboard/project/$projectId/page.tsx, apps/desktop/src/renderer/routes/_authenticated/components/DashboardNewWorkspaceModal/...
Renamed draft/context fields and UI props/state from baseBranchcompareBaseBranch, updated effective-value resolution and selection handlers, and wired compareBaseBranch through create mutation payloads.
Command watcher integration
apps/desktop/src/renderer/routes/_authenticated/components/AgentHooks/hooks/useCommandWatcher/tools/create-worktree.ts
Stop deriving baseBranch from the source workspace; forward compareBaseBranch and sourceWorkspaceId directly to the create mutation.
Tests & Mocks
apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.test.ts
Expanded in-file mock DB to support joined rows, richer predicates, projection of nested table rows, and innerJoin. Added tests for "Workspace creation from source workspace" and Bun mocks for analytics/workspace-init/worktree initialization.

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
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰
From source branch I softly hop,
I copy roots and never stop,
compareBase set, startPoint traced,
New worktrees spring in tidy haste,
Hooray — a branching carrot crop! 🥕

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing a regression where the changes sidebar displayed the wrong base diff for workspaces created from another workspace.
Description check ✅ Passed The pull request description is complete and well-structured, covering all required template sections including summary, type of change, testing, and additional notes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

Copy link
Copy Markdown
Contributor

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

Choose a reason for hiding this comment

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

No issues found across 4 files

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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 | 🟡 Minor

Inconsistent variable in warning message.

The warning message references effectiveBaseBranch but the surrounding context uses effectiveStartPoint. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 51daebc and 3d93e84.

📒 Files selected for processing (4)
  • apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.test.ts
  • apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.ts
  • apps/desktop/src/lib/trpc/routers/workspaces/utils/workspace-init.ts
  • apps/desktop/src/renderer/routes/_authenticated/components/AgentHooks/hooks/useCommandWatcher/tools/create-worktree.ts

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

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 | 🟠 Major

Let the fetch phase resolve missing remote start points.

When branchExistsOnRemote() returns "exists" but origin/${effectiveStartPoint} is missing locally, this branch says it will fetch later and then returns early as soon as resolveLocalRef() can't find a local branch. That makes a valid remote startPointBranch fail 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: Extract CompareBaseBranchPickerInline into its own file.

This picker has grown large enough that keeping it inline makes PromptGroup.tsx harder 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 its branch avoids 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d93e84 and b2206bc.

📒 Files selected for processing (13)
  • 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.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

@Kitenite Kitenite merged commit 71ffa27 into superset-sh:main Mar 23, 2026
6 of 7 checks passed
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