Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(desktop): archive tasks optimistically in parallel (#86984)

Shy Altera29be9369380
diff --git a/products/desktop/packages/core/src/archive/archiveOrchestration.test.ts b/products/desktop/packages/core/src/archive/archiveOrchestration.test.ts
index 7c71da03bcbc..92613560c5c7 100644
--- a/products/desktop/packages/core/src/archive/archiveOrchestration.test.ts
+++ b/products/desktop/packages/core/src/archive/archiveOrchestration.test.ts
@@ -243,6 +243,25 @@ describe("archiveTasks", () => {
failed: 0,
});
});
+
+ it("archives tasks in parallel", async () => {
+ const harness = makeDeps();
+ let releaseFirst: (() => void) | undefined;
+ harness.deps.archive = vi.fn().mockImplementation((taskId: string) => {
+ if (taskId !== "a") return Promise.resolve();
+ return new Promise<void>((resolve) => {
+ releaseFirst = resolve;
+ });
+ });
+
+ const result = archiveTasks(["a", "b"], harness.deps);
+ await vi.waitFor(() => {
+ expect(harness.deps.archive).toHaveBeenCalledWith("b");
+ });
+ releaseFirst?.();
+
+ await expect(result).resolves.toEqual({ archived: 2, failed: 0 });
+ });
});
describe("shouldNavigateAwayForBulkArchive", () => {
diff --git a/products/desktop/packages/core/src/archive/archiveOrchestration.ts b/products/desktop/packages/core/src/archive/archiveOrchestration.ts
index 10a8982d09e5..2eadda7c31b4 100644
--- a/products/desktop/packages/core/src/archive/archiveOrchestration.ts
+++ b/products/desktop/packages/core/src/archive/archiveOrchestration.ts
@@ -167,17 +167,14 @@ export async function archiveTasks(
): Promise<ArchiveTasksResult> {
if (taskIds.length === 0) return { archived: 0, failed: 0 };
- let archived = 0;
- let failed = 0;
- for (const id of taskIds) {
- try {
- await archiveTask(id, deps, { skipNavigate: true });
- archived++;
- } catch {
- failed++;
- }
- }
- return { archived, failed };
+ const results = await Promise.allSettled(
+ taskIds.map((id) => archiveTask(id, deps, { skipNavigate: true })),
+ );
+ const archived = results.filter((result) => result.status === "fulfilled");
+ return {
+ archived: archived.length,
+ failed: results.length - archived.length,
+ };
}
export function shouldNavigateAwayForBulkArchive(
diff --git a/products/desktop/packages/ui/src/features/archive/useArchiveTask.ts b/products/desktop/packages/ui/src/features/archive/useArchiveTask.ts
index 3d5887110225..4d1435ce10a5 100644
--- a/products/desktop/packages/ui/src/features/archive/useArchiveTask.ts
+++ b/products/desktop/packages/ui/src/features/archive/useArchiveTask.ts
@@ -228,10 +228,7 @@ export function useArchiveTask(options?: {
const { restore } = useUnarchiveTask();
const archiveTask = async ({ taskId }: { taskId: string }) => {
- // Non-optimistic: keep the row in place (with a spinner) until the archive
- // is confirmed, rather than removing it instantly and rolling back on error.
await archiveTaskImperative(taskId, queryClient, keys, {
- optimistic: false,
navigateSpace: options?.navigateSpace,
});
const toastId = `archive-undo-${taskId}`;
diff --git a/products/desktop/packages/ui/src/features/sidebar/components/TaskRow.tsx b/products/desktop/packages/ui/src/features/sidebar/components/TaskRow.tsx
index 15c9a25245d1..383d10e96014 100644
--- a/products/desktop/packages/ui/src/features/sidebar/components/TaskRow.tsx
+++ b/products/desktop/packages/ui/src/features/sidebar/components/TaskRow.tsx
@@ -67,6 +67,8 @@ export function TaskRow({
state.archivingTaskIds.has(task.id),
);
+ if (isArchiving) return null;
+
return (
<TaskItem
depth={depth}
@@ -75,7 +77,6 @@ export function TaskRow({
subtitle={subtitle}
isActive={isActive}
isSelected={isSelected}
- isArchiving={isArchiving}
hideHoverActions={hideHoverActions}
isEditing={isEditing}
workspaceMode={effectiveMode}
diff --git a/products/desktop/packages/ui/src/features/sidebar/useBulkArchiveConfirm.test.tsx b/products/desktop/packages/ui/src/features/sidebar/useBulkArchiveConfirm.test.tsx
index 19fe6f1030f3..9d7ea8935a07 100644
--- a/products/desktop/packages/ui/src/features/sidebar/useBulkArchiveConfirm.test.tsx
+++ b/products/desktop/packages/ui/src/features/sidebar/useBulkArchiveConfirm.test.tsx
@@ -66,6 +66,7 @@ describe("useBulkArchiveConfirm", () => {
await user.click(screen.getByRole("button", { name: "Archive" }));
expect(actions.archiveSelected).toHaveBeenCalledOnce();
+ expect(screen.queryByText("Archive 3 sessions?")).not.toBeInTheDocument();
});
// Archiving clears the selection, so a dialog reading the count live would
diff --git a/products/desktop/packages/ui/src/features/sidebar/useBulkArchiveConfirm.tsx b/products/desktop/packages/ui/src/features/sidebar/useBulkArchiveConfirm.tsx
index dbd46ccdeb65..4a6d74058d01 100644
--- a/products/desktop/packages/ui/src/features/sidebar/useBulkArchiveConfirm.tsx
+++ b/products/desktop/packages/ui/src/features/sidebar/useBulkArchiveConfirm.tsx
@@ -48,9 +48,9 @@ export function useBulkArchiveConfirm(
runningCount={confirm?.runningCount ?? 0}
stopsCloudSandbox={Boolean(confirm?.stopsCloudSandbox)}
isArchiving={actions.isArchiving}
- onConfirm={async () => {
- await actions.archiveSelected();
+ onConfirm={() => {
setConfirm(null);
+ void actions.archiveSelected();
}}
onCancel={() => setConfirm(null)}
/>
diff --git a/products/desktop/packages/ui/src/features/sidebar/useSidebarBulkActions.ts b/products/desktop/packages/ui/src/features/sidebar/useSidebarBulkActions.ts
index f43a86861c8f..f515eabfca8d 100644
--- a/products/desktop/packages/ui/src/features/sidebar/useSidebarBulkActions.ts
+++ b/products/desktop/packages/ui/src/features/sidebar/useSidebarBulkActions.ts
@@ -138,7 +138,6 @@ export function useSidebarBulkActions(
if (selectedCount === 0 || isArchiving) return;
setIsArchiving(true);
const store = useArchivingTasksStore.getState();
- // Spinner the rows for the whole sequential batch, not just the current one.
for (const id of taskIds) store.startArchiving(id);
try {
const { archived, failed } = await archiveTasksImperative(