fix(sidebar): preserve task project during create flow#1319
fix(sidebar): preserve task project during create flow#1319rabanspiegel merged 4 commits intomainfrom
Conversation
Ensure sidebar task creation uses the intended project even before selectedProject state catches up. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Greptile SummaryThis PR fixes a race condition in the sidebar task-creation flow where Key changes:
Issue found:
Confidence Score: 3/5
|
| Filename | Overview |
|---|---|
| src/renderer/hooks/useTaskManagement.ts | Introduces pendingTaskProjectRef to fix a race condition between sidebar project selection and task creation; however, the ref is not cleared on modal dismissal, which can cause tasks to be created under the wrong project in subsequent non-sidebar modal flows. |
Sequence Diagram
sequenceDiagram
participant User
participant Sidebar
participant useTaskManagement
participant pendingTaskProjectRef
participant ModalProvider
participant handleCreateTask
User->>Sidebar: Click '+' on Project A
Sidebar->>useTaskManagement: handleStartCreateTaskFromSidebar(ProjectA)
useTaskManagement->>pendingTaskProjectRef: set(ProjectA)
useTaskManagement->>useTaskManagement: activateProjectView(ProjectA)
useTaskManagement->>ModalProvider: openTaskModal()
alt User submits the modal
ModalProvider-->>handleCreateTask: onSuccess(result)
handleCreateTask->>pendingTaskProjectRef: read → ProjectA
handleCreateTask->>pendingTaskProjectRef: clear (set null) ✅
handleCreateTask->>useTaskManagement: createTaskMutation(ProjectA)
else User dismisses the modal (bug path)
ModalProvider-->>useTaskManagement: onClose() — no handler wired
Note over pendingTaskProjectRef: ref still holds ProjectA ⚠️
User->>useTaskManagement: opens modal via handleNewTask (ProjectB selected)
ModalProvider-->>handleCreateTask: onSuccess(result)
handleCreateTask->>pendingTaskProjectRef: read → ProjectA (stale!)
handleCreateTask->>useTaskManagement: createTaskMutation(ProjectA) ❌ wrong project
end
Comments Outside Diff (1)
-
src/renderer/hooks/useTaskManagement.ts, line 951-967 (link)Stale
pendingTaskProjectRefwhen modal is dismissedpendingTaskProjectRef.currentis set inhandleStartCreateTaskFromSidebarand only cleared insidehandleCreateTask(on line 915). However, if the user opens the modal via the sidebar and then dismisses it (without submitting), the ref is never cleared.ModalProvidersupports an optionalonClosecallback, but none is provided here.This creates the following bug scenario:
- User clicks sidebar '+' for Project A →
pendingTaskProjectRef.current = ProjectA - User dismisses the modal (presses Escape or clicks ✕) →
onClosefires, modal closes, but ref is stillProjectA - User switches to Project B (
selectedProjectis nowProjectB) - User opens the modal through any other path (e.g.
handleNewTask, keyboard shortcut, orautoOpenTaskModalTrigger) - User submits →
handleCreateTaskreadspendingTaskProjectRef.current→ task is silently created under Project A instead of Project B
The fix is to pass an
onClosecallback that clears the ref:openTaskModalImplRef.current = () => { showModal('taskModal', { onSuccess: (result) => handleCreateTask( result.name, result.initialPrompt, result.agentRuns, result.linkedLinearIssue ?? null, result.linkedGithubIssue ?? null, result.linkedJiraIssue ?? null, result.autoApprove, result.useWorktree, result.baseRef, result.nameGenerated ), onClose: () => { pendingTaskProjectRef.current = null; }, }); }; - User clicks sidebar '+' for Project A →
Last reviewed commit: 007d68b
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Clear the pending sidebar project when the create-task modal closes so later task creation flows use the current selection. Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
…v-version-9j0 # Conflicts: # src/renderer/hooks/useTaskManagement.ts
Summary
Validation
Note
Medium Risk
Touches the task creation flow by decoupling it from
selectedProjecttiming; mistakes here could create tasks under the wrong project or leave the UI in an inconsistent state, but the change is small and localized to the modal/create path.Overview
Fixes a race in the sidebar “create task” flow by capturing the clicked project in a
pendingTaskProjectRefbefore navigating/opening the modal, and then using that project whenhandleCreateTasksubmits.Also ensures the pending project is cleared after submission and when the
taskModalcloses (viashowModal(..., { onClose })), preventing stale project state from leaking into later task creations.Written by Cursor Bugbot for commit 4475cd4. This will update automatically on new commits. Configure here.