fix(desktop): fix creating workspace and worktree from existing branch#2982
fix(desktop): fix creating workspace and worktree from existing branch#2982vivishko wants to merge 6 commits intosuperset-sh:mainfrom
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds intent-aware telemetry, eager branch listing and domain-specific validation/error handling for creating workspaces from existing branches; introduces default worktree base-dir utilities, updates worktree-path resolution to use that utility, and surfaces open/create actions plus domain-error parsing in the NewWorkspaceModal UI. Changes
Sequence DiagramsequenceDiagram
actor User
participant UI as PromptGroup UI
participant Client as TRPC Client
participant Server as Workspace Create Procedure
participant Git as Git Ops
participant DB as Local DB
User->>UI: select branch / request create/open
UI->>Client: createWorkspace.mutateAsync({ branchName, useExistingBranch?, intent })
Client->>Server: RPC create workspace request
Server->>Git: listBranches (local + remote)
Git-->>Server: branch names
Server->>Server: existingBranches := branch names
alt useExistingBranch == true
Server->>Git: getBranchWorktreePath(branch)
Git-->>Server: existingWorktreePath (or null)
Server->>Server: validateExistingBranchCreate(branch, existingBranches, existingWorktreePath)
end
Server->>DB: persist workspace (if validated)
DB-->>Server: created
Server-->>Client: response or domain TRPC error
Client-->>UI: show success or parsed domain error toast
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 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.
3 issues found across 9 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsx">
<violation number="1" location="apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsx:478">
P2: `CommandItem.onSelect` now always selects compare-base, so keyboard item activation no longer opens existing/openable worktrees/workspaces.</violation>
<violation number="2" location="apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsx:1100">
P2: Existing-branch create path omits pending setup overrides, skipping agent launch/setup behavior used by normal workspace creation.</violation>
</file>
<file name="apps/desktop/src/lib/trpc/routers/workspaces/utils/default-worktree-base-dir.test.ts">
<violation number="1" location="apps/desktop/src/lib/trpc/routers/workspaces/utils/default-worktree-base-dir.test.ts:6">
P2: Test uses a hardcoded POSIX path string while implementation uses platform-dependent `path.join`, making the assertion brittle on Windows.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsx (1)
76-79: Consider sharing the error code type with the backend.The
WorkspaceCreateDomainErrorCodetype is duplicated here and increate-domain-errors.ts. If the backend adds new error codes, this frontend type won't automatically include them. Consider exporting the type from a shared location if the module boundaries allow it.🤖 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 76 - 79, The WorkspaceCreateDomainErrorCode type in PromptGroup.tsx is duplicated from create-domain-errors.ts which risks drifting when backend adds codes; remove the local declaration of WorkspaceCreateDomainErrorCode and instead import the exported type from the shared module (or move the type into a common/shared package and import it) so the frontend uses the single source of truth (update the import where PromptGroup.tsx references WorkspaceCreateDomainErrorCode and ensure create-domain-errors.ts exports the type).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsx`:
- Around line 76-79: The WorkspaceCreateDomainErrorCode type in PromptGroup.tsx
is duplicated from create-domain-errors.ts which risks drifting when backend
adds codes; remove the local declaration of WorkspaceCreateDomainErrorCode and
instead import the exported type from the shared module (or move the type into a
common/shared package and import it) so the frontend uses the single source of
truth (update the import where PromptGroup.tsx references
WorkspaceCreateDomainErrorCode and ensure create-domain-errors.ts exports the
type).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: c56703e6-d413-4de7-81bb-2d9d890d69c3
📒 Files selected for processing (9)
apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.tsapps/desktop/src/lib/trpc/routers/workspaces/procedures/utils/create-domain-errors.test.tsapps/desktop/src/lib/trpc/routers/workspaces/procedures/utils/create-domain-errors.tsapps/desktop/src/lib/trpc/routers/workspaces/utils/default-worktree-base-dir.test.tsapps/desktop/src/lib/trpc/routers/workspaces/utils/default-worktree-base-dir.tsapps/desktop/src/lib/trpc/routers/workspaces/utils/resolve-worktree-path.tsapps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsxapps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/utils/branchRowState/branchRowState.test.tsapps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/utils/branchRowState/branchRowState.ts
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsx (1)
1135-1168: Add explicitcloseAndResetoption for consistency withhandleCreate.This function passes no third argument to
runAsyncAction, relying on the default behavior to close and reset the modal. For consistency and clarity, explicitly pass{ closeAndReset: false }(matching line 1076) and add a.finally()block to callclearPendingWorkspace(pendingWorkspaceId)like the other workspace creation handlers.🤖 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 1135 - 1168, The call to runAsyncAction with createWorkspace.mutateAsyncWithPendingSetup should explicitly pass the third-argument options object { closeAndReset: false } (to match handleCreate behavior) and append a .finally() that calls clearPendingWorkspace(pendingWorkspaceId); update the invocation around runAsyncAction/createWorkspace.mutateAsyncWithPendingSetup to include the { closeAndReset: false } option and ensure a finally block invokes clearPendingWorkspace(pendingWorkspaceId) so pendingWorkspace cleanup happens consistently.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsx`:
- Around line 1135-1168: The call to runAsyncAction with
createWorkspace.mutateAsyncWithPendingSetup should explicitly pass the
third-argument options object { closeAndReset: false } (to match handleCreate
behavior) and append a .finally() that calls
clearPendingWorkspace(pendingWorkspaceId); update the invocation around
runAsyncAction/createWorkspace.mutateAsyncWithPendingSetup to include the {
closeAndReset: false } option and ensure a finally block invokes
clearPendingWorkspace(pendingWorkspaceId) so pendingWorkspace cleanup happens
consistently.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: db0e1b1b-bb99-4197-9b63-d8ac834014d5
📒 Files selected for processing (1)
apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsx
991161e to
5eddb26
Compare
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsx`:
- Around line 563-577: The "Create" button label currently shows an Enter hint
("↵") which is misleading because pressing Enter triggers CommandItem.onSelect()
and only updates compareBaseBranch instead of calling
onCreateFromExistingBranch(); remove the arrow hint by changing the span content
in the Button (inside the showCreate branch) to not include "↵" — e.g., render
only modKey when hasExistingWorkspace (or remove the span entirely) and keep the
existing onClick that calls onCreateFromExistingBranch(branch.name) and
setOpen(false).
- Around line 1116-1180: The handleCreateFromExistingBranch callback diverges
from handleCreate by not forwarding compareBaseBranch and by building the agent
launch request before running the same attachment/linked-issue preparation,
causing wrong base-branch and missing context; modify
handleCreateFromExistingBranch to reuse the same pre-launch preparation steps
used in handleCreate (run the attachment/linked-issue/file preparation that adds
attachments and linkedGitHubIssue and forwards compareBaseBranch) before calling
buildLaunchRequest(selectedPrompt), then pass the resulting launchRequest into
createWorkspace.mutateAsyncWithPendingSetup just like handleCreate does (keep
the same resolveInitialCommands behavior), ensuring compareBaseBranch and
attachment/linked-issue context are included.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: aa76ed9a-5919-47b2-af76-4d257d46dff3
📒 Files selected for processing (9)
apps/desktop/src/lib/trpc/routers/workspaces/procedures/create.tsapps/desktop/src/lib/trpc/routers/workspaces/procedures/utils/create-domain-errors.test.tsapps/desktop/src/lib/trpc/routers/workspaces/procedures/utils/create-domain-errors.tsapps/desktop/src/lib/trpc/routers/workspaces/utils/default-worktree-base-dir.test.tsapps/desktop/src/lib/trpc/routers/workspaces/utils/default-worktree-base-dir.tsapps/desktop/src/lib/trpc/routers/workspaces/utils/resolve-worktree-path.tsapps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsxapps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/utils/branchRowState/branchRowState.test.tsapps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/utils/branchRowState/branchRowState.ts
✅ Files skipped from review due to trivial changes (3)
- apps/desktop/src/lib/trpc/routers/workspaces/utils/default-worktree-base-dir.ts
- apps/desktop/src/lib/trpc/routers/workspaces/procedures/utils/create-domain-errors.test.ts
- apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/utils/branchRowState/branchRowState.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/utils/branchRowState/branchRowState.test.ts
- apps/desktop/src/lib/trpc/routers/workspaces/utils/resolve-worktree-path.ts
- apps/desktop/src/lib/trpc/routers/workspaces/utils/default-worktree-base-dir.test.ts
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsx">
<violation number="1" location="apps/desktop/src/renderer/components/NewWorkspaceModal/components/PromptGroup/PromptGroup.tsx:413">
P2: Early returns after preparing attachments skip the blob URL cleanup, so attachment URLs leak when prepareLaunchFiles or buildLaunchRequest fails in the existing-branch flow.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
851dd84 to
bb69d15
Compare
…lize worktree base dir
…create/open button-only actions
…ending setup for existing-branch create
…launch prep context
bb69d15 to
48e905d
Compare
Description
This PR makes Create behavior in the branch dropdown strict and explicit:
(useExistingBranch=true).
Backend hardening for existing-branch create was added:
Also fixed default worktree base-dir fallback:
(not workspace-name-scoped ~/.superset-/worktrees).
Related Issues
related to #2575
Type of Change
Testing
Manual verification (happy path):
Screenshots (if applicable)
Additional Notes
Summary by cubic
Fixes creating a workspace/worktree from an existing branch in the desktop app. The branch picker now has predictable actions (row click selects, Enter opens, Cmd/Ctrl+Enter creates), and backend validation returns clear domain errors.
Bug Fixes
WORKTREE_ALREADY_EXISTS_FOR_BRANCH,BRANCH_NOT_FOUND,GIT_OPERATION_FAILED) viatRPC. UI maps these using sharedWorkspaceCreateDomainErrorCodeto friendly messages.intent(create_from_existing_branch|create_new_branch) is recorded and auto-set when omitted.Refactors
WorkspaceCreateDomainErrorCodeis used end-to-end.Written for commit 48e905d. Summary will update on new commits.
Summary by CodeRabbit
New Features
Bug Fixes
Tests