The best way to control Claude Code, Codex and more from any computer or phone
fix(web): deleting a thread clears its side chats' drafts (#29832)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>
Alex Southwell committed
Nov 10, 2026 at 01:46 UTC
b8c2cfad6b3363c4da144a859073b41ec77579ab
4 files changed
+134
-15
apps/web/src/components/chat/SideChatPane.tsx
+4
@@ -14,8 +14,10 @@ import {
14
import { Trash2Icon, XIcon } from "lucide-react";
15
import { useEffect, useState } from "react";
16
17
+import { useComposerDraftStore } from "../../composerDraftStore";
18
import { ComposerHandleContext } from "../../composerHandleContext";
19
import { useClientSettings } from "../../hooks/useSettings";
20
+import { releaseComposerDraftUploads } from "../../lib/composerDraftUploads";
21
import type { SideChatParentPanel } from "../../lib/sideChatPane";
22
import { readLocalApi } from "../../localApi";
23
import { hostRightPanel, useRightPanelStore } from "../../rightPanelStore";
@@ -111,6 +113,8 @@ export default function SideChatPane(props: {
113
});
114
setDeleting(false);
115
if (result._tag === "Success") {
116
+ releaseComposerDraftUploads(threadRef);
117
+ useComposerDraftStore.getState().clearDraftThread(threadRef);
118
useRightPanelStore.getState().closeSurface(parentRef, `side-chat:${threadId}`);
119
} else if (!isAtomCommandInterrupted(result)) {
120
const error = squashAtomCommandFailure(result);
apps/web/src/hooks/useThreadActions.permissions.test.ts
+85
-13
@@ -24,6 +24,8 @@ function deferred<T>() {
24
}
25
26
const state = vi.hoisted(() => ({
27
+ serverConfig: { shellThreadFamilies: false },
28
+ familyLookupFails: false,
29
scopes: new Map<string, Set<string>>(),
30
threads: [] as {
31
environmentId: EnvironmentId;
@@ -31,9 +33,14 @@ const state = vi.hoisted(() => ({
33
projectId: ProjectId;
34
title: string;
35
worktreePath: string | null;
36
+ lineage: { parentThreadId: ThreadId | null; sideChat?: boolean };
37
session: { status: "ready" | "stopped" } | null;
38
latestTurn: null;
39
}[],
40
+ familyThreads: [] as {
41
+ id: ThreadId;
42
+ lineage: { parentThreadId: ThreadId | null; sideChat?: boolean };
43
+ }[],
44
requests: [] as { action: string; environmentId: string; input: { threadId?: string } }[],
45
localEffects: [] as string[],
46
confirm: vi.fn<(message: string) => Promise<boolean>>(),
@@ -70,15 +77,30 @@ vi.mock("../state/use-atom-command", () => ({
77
},
78
}));
79
vi.mock("../state/use-atom-query-runner", () => ({
73
- useAtomQueryRunner: () => async (environmentId: string) =>
74
- state.sessionLookupFails
75
- ? AsyncResult.failure(Cause.fail(new Error("Session lookup failed")))
76
- : AsyncResult.success({
77
- authenticated: true,
78
- scopes: [...(state.scopes.get(environmentId) ?? [])],
79
- auth: { serverUpdateScope: "environment:maintain" },
80
- }),
80
+ useAtomQueryRunner: (family: unknown) => async (environmentId: string) =>
81
+ family === "threadFamily"
82
+ ? state.familyLookupFails
83
+ ? AsyncResult.failure(Cause.fail(new Error("Family lookup failed")))
84
+ : AsyncResult.success({ threads: state.familyThreads })
85
+ : state.sessionLookupFails
86
+ ? AsyncResult.failure(Cause.fail(new Error("Session lookup failed")))
87
+ : AsyncResult.success({
88
+ authenticated: true,
89
+ scopes: [...(state.scopes.get(environmentId) ?? [])],
90
+ auth: { serverUpdateScope: "environment:maintain" },
91
+ }),
92
+}));
93
+vi.mock("../state/orchestration", () => ({
94
+ orchestrationEnvironment: { threadFamily: "threadFamily" },
95
}));
96
+vi.mock("../state/server", async (importOriginal) => {
97
+ const actual = await importOriginal<typeof import("../state/server")>();
98
+ const { Atom } = await import("effect/reactivity");
99
+ return {
100
+ ...actual,
101
+ environmentServerConfigsAtom: Atom.make(new Map([["secondary", state.serverConfig]])),
102
+ };
103
+});
104
vi.mock("../state/threads", () => ({
105
threadEnvironment: Object.fromEntries(
106
[
@@ -119,7 +141,8 @@ vi.mock("../components/Sidebar.logic", () => ({
141
vi.mock("../composerDraftStore", () => ({
142
useComposerDraftStore: (select: (store: unknown) => unknown) =>
143
select({
122
- clearDraftThread: () => state.localEffects.push("clear-draft"),
144
+ clearDraftThread: (ref: ScopedThreadRef) =>
145
+ state.localEffects.push(`clear-draft:${ref.threadId}`),
146
clearProjectDraftThreadById: () => state.localEffects.push("clear-project-draft"),
147
}),
148
}));
@@ -139,7 +162,8 @@ vi.mock("../lib/archivedThreadsState", () => ({
162
refreshArchivedThreadsForEnvironment: () => state.localEffects.push("refresh-archive"),
163
}));
164
vi.mock("../lib/composerDraftUploads", () => ({
142
- releaseComposerDraftUploads: () => state.localEffects.push("release-uploads"),
165
+ releaseComposerDraftUploads: (ref: ScopedThreadRef) =>
166
+ state.localEffects.push(`release-uploads:${ref.threadId}`),
167
}));
168
vi.mock("../localApi", () => ({
169
readLocalApi: () => ({ dialogs: { confirm: state.confirm } }),
@@ -227,6 +251,9 @@ const operations = [
251
] as const;
252
253
beforeEach(() => {
254
+ state.serverConfig.shellThreadFamilies = false;
255
+ state.familyLookupFails = false;
256
+ state.familyThreads = [];
257
state.scopes = new Map([
258
[primary, new Set([AuthOrchestrationOperateScope])],
259
[secondary, new Set<string>()],
@@ -238,6 +265,7 @@ beforeEach(() => {
265
projectId: ProjectId.make("project"),
266
title: "Thread",
267
worktreePath: null,
268
+ lineage: { parentThreadId: null },
269
session: null,
270
latestTurn: null,
271
},
@@ -320,6 +348,18 @@ describe("thread action permissions", () => {
348
});
349
350
it("deletes an archived thread only with its own environment's grant", async () => {
351
+ state.serverConfig.shellThreadFamilies = true;
352
+ state.familyThreads = [
353
+ {
354
+ id: ThreadId.make("side-chat"),
355
+ lineage: { parentThreadId: target.threadId, sideChat: true },
356
+ },
357
+ { id: ThreadId.make("fork"), lineage: { parentThreadId: target.threadId } },
358
+ {
359
+ id: ThreadId.make("other-side-chat"),
360
+ lineage: { parentThreadId: ThreadId.make("other-parent"), sideChat: true },
361
+ },
362
+ ];
363
state.threads = [];
364
seedThreadPanelState(target);
365
const actions = useThreadActions();
@@ -331,13 +371,27 @@ describe("thread action permissions", () => {
371
expect(state.requests).toEqual([
372
expect.objectContaining({ action: "delete", environmentId: secondary }),
373
]);
374
+ expect(threadPanelStatePresence(target)).toEqual(panelStateCleared);
375
expect(state.localEffects).toEqual([
376
+ "release-uploads:thread",
377
+ "clear-draft:thread",
378
+ "release-uploads:side-chat",
379
+ "clear-draft:side-chat",
380
"refresh-archive",
336
- "release-uploads",
337
- "clear-draft",
381
"clear-terminal-ui",
382
]);
340
- expect(threadPanelStatePresence(target)).toEqual(panelStateCleared);
383
+ expect(state.localEffects).not.toContain("clear-draft:fork");
384
+ expect(state.localEffects).not.toContain("clear-draft:other-side-chat");
385
+
386
+ // The family read only finds drafts to clear; it never blocks the delete.
387
+ state.familyLookupFails = true;
388
+ state.requests = [];
389
+ state.localEffects = [];
390
+ expect((await actions.deleteThread(target))._tag).toBe("Success");
391
+ expect(state.requests).toEqual([
392
+ expect.objectContaining({ action: "delete", environmentId: secondary }),
393
+ ]);
394
+ expect(state.localEffects).toContain("clear-draft:thread");
395
});
396
397
it("stops before delete and local cleanup when permission is revoked during session stop", async () => {
@@ -366,6 +420,24 @@ describe("thread action permissions", () => {
420
expect(threadPanelStatePresence(target)).toEqual(panelStateCleared);
421
});
422
423
+ it("clears the drafts of the side chats deleted with it", async () => {
424
+ state.scopes.get(secondary)!.add(AuthOrchestrationOperateScope);
425
+ const parent = state.threads[0]!;
426
+ state.threads.push(
427
+ {
428
+ ...parent,
429
+ id: ThreadId.make("side-chat"),
430
+ lineage: { parentThreadId: parent.id, sideChat: true },
431
+ },
432
+ { ...parent, id: ThreadId.make("fork"), lineage: { parentThreadId: parent.id } },
433
+ );
434
+ expect((await useThreadActions().deleteThread(target))._tag).toBe("Success");
435
+ expect(state.localEffects).toEqual(
436
+ expect.arrayContaining(["release-uploads:side-chat", "clear-draft:side-chat"]),
437
+ );
438
+ expect(state.localEffects).not.toContain("clear-draft:fork");
439
+ });
440
+
441
it("does not request worktree removal after its grant is revoked during delete", async () => {
442
state.scopes
443
.get(secondary)!
apps/web/src/hooks/useThreadActions.ts
+39
-2
@@ -325,6 +325,10 @@ export function useThreadActions() {
325
reportFailure: false,
326
refresh: true,
327
});
328
+ const loadThreadFamily = useAtomQueryRunner(orchestrationEnvironment.threadFamily, {
329
+ reportFailure: false,
330
+ refresh: true,
331
+ });
332
const refreshVcsStatus = useAtomCommand(vcsEnvironment.refreshStatus, {
333
reportFailure: false,
334
});
@@ -440,15 +444,39 @@ export function useThreadActions() {
444
if (permissionFailure) return permissionFailure;
445
const resolved = resolveThreadTarget(target);
446
if (!resolved) {
447
+ let threads = readEnvironmentThreadRefs(target.environmentId).flatMap((ref) => {
448
+ const shell = readThreadShell(ref);
449
+ return shell === null ? [] : [{ id: shell.id, lineage: shell.lineage }];
450
+ });
451
+ if (
452
+ appAtomRegistry.get(environmentServerConfigsAtom).get(target.environmentId)
453
+ ?.shellThreadFamilies
454
+ ) {
455
+ const family = await loadThreadFamily({
456
+ environmentId: target.environmentId,
457
+ input: { threadId: target.threadId },
458
+ });
459
+ if (family._tag === "Success") threads = [...family.value.threads];
460
+ }
461
const result = await deleteThreadMutation({
462
environmentId: target.environmentId,
463
input: { threadId: target.threadId },
464
});
465
if (result._tag === "Success") {
466
+ for (const ref of [
467
+ target,
468
+ ...threads
469
+ .filter(
470
+ (entry) =>
471
+ entry.lineage.sideChat === true && entry.lineage.parentThreadId === target.threadId,
472
+ )
473
+ .map((entry) => scopeThreadRef(target.environmentId, entry.id)),
474
+ ]) {
475
+ releaseComposerDraftUploads(ref);
476
+ clearComposerDraftForThread(ref);
477
+ }
478
expireThreadUndos(target, [...LIST_PLACEMENT_UNDO_KINDS, "archive"]);
479
refreshArchivedThreadsForEnvironment(target.environmentId);
450
- releaseComposerDraftUploads(target);
451
- clearComposerDraftForThread(target);
480
clearTerminalUiState(target);
481
clearDeletedThreadPanelState(target);
482
}
@@ -570,6 +598,15 @@ export function useThreadActions() {
598
refreshArchivedThreadsForEnvironment(threadRef.environmentId);
599
releaseComposerDraftUploads(threadRef);
600
clearComposerDraftForThread(threadRef);
601
+ // The server deletes the thread's side chats with it.
602
+ for (const entry of threads) {
603
+ if (entry.lineage.sideChat !== true || entry.lineage.parentThreadId !== threadRef.threadId) {
604
+ continue;
605
+ }
606
+ const sideChatRef = scopeThreadRef(threadRef.environmentId, entry.id);
607
+ releaseComposerDraftUploads(sideChatRef);
608
+ clearComposerDraftForThread(sideChatRef);
609
+ }
610
clearProjectDraftThreadById(
611
scopeProjectRef(threadRef.environmentId, thread.projectId),
612
threadRef,
packages/client-runtime/src/state/orchestration.ts
+6
@@ -218,6 +218,12 @@ export function createOrchestrationEnvironmentAtoms<R, E>(
218
label: "environment-data:orchestration:archived-shell-snapshot",
219
tag: ORCHESTRATION_V2_WS_METHODS.getArchivedShellSnapshot,
220
}),
221
+ threadFamily: createEnvironmentRpcQueryAtomFamily(runtime, {
222
+ label: "environment-data:orchestration:thread-family-for-delete",
223
+ tag: ORCHESTRATION_V2_WS_METHODS.getThreadFamily,
224
+ staleTimeMs: 0,
225
+ idleTtlMs: 0,
226
+ }),
227
// Read right before deleting a worktree, so never served from cache.
228
worktreeThreadIds: createEnvironmentRpcQueryAtomFamily(runtime, {
229
label: "environment-data:orchestration:worktree-thread-ids",