fix(tasks): sync cloud-started tasks into local workspace registry#2146
Merged
oliverb123 merged 3 commits intoMay 14, 2026
Merged
Conversation
Tasks created on other surfaces (web, CLI, another machine for the same user) were already returned by the /tasks/ API but hidden in the sidebar because useSidebarData filters to tasks with a matching local workspace row. Reconcile the local workspace registry against the polled task list by creating an idempotent cloud-mode workspace row for any task missing one, then invalidate the workspaces query so the sidebar picks them up. Generated-By: PostHog Code Task-Id: bad6d25e-1cb8-4bfe-b323-7c79f6654944
Contributor
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
apps/code/src/renderer/components/MainLayout.tsx:110-121
**Workspace query invalidated even when all mutations failed**
`queryClient.invalidateQueries` is called unconditionally in `.then()`, including when every mutation in the batch was rejected. This triggers a workspace refetch even though no new row was written. With React Query's default structural sharing the refetch won't change the `workspaces` reference, so the effect likely won't re-run; but if structural sharing is ever disabled, or tRPC's serialization returns a fresh object, the refetch would bump `workspaces`, re-trigger the effect, and start another mutation batch immediately — bypassing the intended 30-second poll cadence.
### Issue 2 of 2
apps/code/src/renderer/components/MainLayout.tsx:100-110
**`workspaceApi.create` already wraps this call**
`workspaceApi` (exported from `useWorkspace.ts`) exists specifically to provide an imperative surface over `trpcClient.workspace.create.mutate` with the same signature. Using it here would follow the OnceAndOnlyOnce principle and makes it easier to trace the mutation through the codebase.
```suggestion
void Promise.allSettled(
missing.map((t) =>
workspaceApi.create({
taskId: t.id,
mainRepoPath: "",
folderId: "",
folderPath: "",
mode: "cloud",
}),
),
).then((results) => {
```
Reviews (1): Last reviewed commit: "fix(tasks): sync cloud-started tasks int..." | Re-trigger Greptile |
- Use workspaceApi.create wrapper instead of trpcClient directly - Only invalidate workspaces query when at least one mutation succeeded Generated-By: PostHog Code Task-Id: bad6d25e-1cb8-4bfe-b323-7c79f6654944
Contributor
|
Reviews (2): Last reviewed commit: "refactor: address review on cloud worksp..." | Re-trigger Greptile |
Wraps the new workspace reconciliation effect in MainLayout behind the posthog-code-sync-cloud-tasks flag so it only runs for users explicitly enrolled. Avoids surprising external users with unfamiliar cloud tasks that may have been created by surfaces other than the desktop app. Generated-By: PostHog Code Task-Id: bad6d25e-1cb8-4bfe-b323-7c79f6654944
Contributor
|
Reviews (3): Last reviewed commit: "feat: gate cloud task reconciliation beh..." | Re-trigger Greptile |
adboio
approved these changes
May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/api/projects/{id}/tasks/poll, but the sidebar filter inuseSidebarData.tshides any task without a matching local SQLite workspace row, so they never appeared.useTasks()yields a new list, create an idempotentmode: "cloud"workspace row for each missing task, then invalidate the workspaces query so the existing filter passes them through.WorkspaceService.doCreateWorkspacealready short-circuits when a row exists, andcreateWorkspaceInputpermits empty paths for cloud mode (same shapetask-creation.tsuses for pure cloud tasks today).MainLayout.tsxwhereuseTasks()already lives; auseRef<Set>prevents duplicate in-flight calls between polls.Test plan
pnpm --filter code typecheckpassespnpm --filter code testpasses (one pre-existing unrelated git integration timeout)TaskDetailwithout errorsWorkspace already exists for task ...on subsequent polls — no duplicate row creation