feat(fork): optimistic sidebar entry + Fork | prefix for forked tasks#4353
feat(fork): optimistic sidebar entry + Fork | prefix for forked tasks#4353waleedlatif1 merged 2 commits intostagingfrom
Conversation
Adds the forked task to the sidebar immediately by writing an optimistic
entry into the task list cache in onSuccess, before the background refetch
arrives. Without this, the sidebar showed no new task until the invalidation
refetch completed after navigation.
Also moves the Fork prefix to the front of the name ('Fork | Chat Name')
so it is immediately scannable in the sidebar.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview On the client, Reviewed by Cursor Bugbot for commit b4de030. Configure here. |
Greptile SummaryThis PR improves the fork UX in two ways: it changes the forked-task naming convention from a suffix ( Confidence Score: 5/5Safe to merge — no P0/P1 issues found; the previously flagged race condition was fixed in this revision. Both changed files have focused, consistent changes. The optimistic write correctly populates all required No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant UI as Sidebar UI
participant Hook as useForkTask
participant QC as QueryClient Cache
participant API as POST /fork
participant DB as Database
UI->>Hook: mutate({ chatId, upToMessageId })
Hook->>API: POST /api/mothership/chats/{chatId}/fork
API->>DB: INSERT copilotChats (title = "Fork | {name}")
DB-->>API: { id: newId }
API-->>Hook: { success: true, id: newId }
Note over Hook,QC: onSuccess
Hook->>QC: cancelQueries(taskKeys.list(workspaceId))
Hook->>QC: getQueryData → existing[]
Hook->>QC: setQueryData([optimisticTask, ...existing])
QC-->>UI: Sidebar re-renders with fork entry
Note over Hook,QC: onSettled
Hook->>QC: invalidateQueries(taskKeys.list(workspaceId))
QC->>API: GET /tasks (background refetch)
API-->>QC: Full task list (includes real fork row)
QC-->>UI: Sidebar re-renders with server data
Reviews (2): Last reviewed commit: "fix(fork): cancel in-flight queries befo..." | Re-trigger Greptile |
|
@greptile |
|
@cursor review |
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.
Reviewed by Cursor Bugbot for commit b4de030. Configure here.
…#4353) * feat(fork): optimistic sidebar entry + rename to 'Fork | Chat Name' Adds the forked task to the sidebar immediately by writing an optimistic entry into the task list cache in onSuccess, before the background refetch arrives. Without this, the sidebar showed no new task until the invalidation refetch completed after navigation. Also moves the Fork prefix to the front of the name ('Fork | Chat Name') so it is immediately scannable in the sidebar. * fix(fork): cancel in-flight queries before optimistic sidebar write

Summary
setQueryDatainuseForkTask.onSuccesswrites the new entry to the cache before the background refetch arrives, so navigation lands on a sidebar that already shows the forkFork | Chat Name(prefix instead of suffix) for faster scannability; re-forking a fork strips the prefix first to avoidFork | Fork | ...useForkTasklist invalidation to the current workspace (taskKeys.list(workspaceId)) instead of all workspacesuseCallbackdeps in sidebar (deleteTaskMutation,deleteTasksMutation,markTaskReadMutation,markTaskUnreadMutation) —.mutate()is stable in TanStack Query v5Type of Change
Testing
Tested manually
Checklist