The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 13:30 UTC
fix(web): deleting a thread with side chats offers to delete its worktree (#36800)
Co-authored-by: Alex Southwell <4596216+saphid@users.noreply.github.com>
Julius Marminge committed
Nov 14, 2026 at 09:04 UTC
76ae36ef8cced3bc0b3a47a9dab07b45fd9b5d38
2 files changed
+50
-9
apps/web/src/hooks/useThreadActions.permissions.test.ts
+39
-4
@@ -33,7 +33,12 @@ const state = vi.hoisted(() => ({
33
projectId: ProjectId;
34
title: string;
35
worktreePath: string | null;
36
- lineage: { parentThreadId: ThreadId | null; sideChat?: boolean };
36
+ lineage: {
37
+ parentThreadId: ThreadId | null;
38
+ relationshipToParent: "fork" | null;
39
+ rootThreadId: ThreadId;
40
+ sideChat?: boolean;
41
+ };
42
session: { status: "ready" | "stopped" } | null;
43
latestTurn: null;
44
}[],
@@ -269,7 +274,7 @@ beforeEach(() => {
274
projectId: ProjectId.make("project"),
275
title: "Thread",
276
worktreePath: null,
272
- lineage: { parentThreadId: null },
277
+ lineage: { parentThreadId: null, relationshipToParent: null, rootThreadId: target.threadId },
278
session: null,
279
latestTurn: null,
280
},
@@ -424,6 +429,32 @@ describe("thread action permissions", () => {
429
expect(threadPanelStatePresence(target)).toEqual(panelStateCleared);
430
});
431
432
+ it("offers to delete the worktree that only its side chats share", async () => {
433
+ state.scopes
434
+ .get(secondary)!
435
+ .add(AuthOrchestrationOperateScope)
436
+ .add(AuthSourceControlWriteScope);
437
+ state.threads[0]!.worktreePath = "/worktrees/thread";
438
+ state.threads.push({
439
+ ...state.threads[0]!,
440
+ id: ThreadId.make("side-chat"),
441
+ lineage: {
442
+ parentThreadId: target.threadId,
443
+ relationshipToParent: "fork",
444
+ rootThreadId: target.threadId,
445
+ sideChat: true,
446
+ },
447
+ });
448
+ expect((await useThreadActions().deleteThread(target))._tag).toBe("Success");
449
+ expect(state.confirm).toHaveBeenCalledOnce();
450
+ expect(state.requests.map((request) => request.action)).toEqual([
451
+ "stopSession",
452
+ "delete",
453
+ "removeWorktree",
454
+ "refreshStatus",
455
+ ]);
456
+ });
457
+
458
it("clears the drafts of the side chats deleted with it", async () => {
459
state.scopes.get(secondary)!.add(AuthOrchestrationOperateScope);
460
const parent = state.threads[0]!;
@@ -431,9 +462,13 @@ describe("thread action permissions", () => {
462
{
463
...parent,
464
id: ThreadId.make("side-chat"),
434
- lineage: { parentThreadId: parent.id, sideChat: true },
465
+ lineage: { ...parent.lineage, parentThreadId: parent.id, sideChat: true },
466
+ },
467
+ {
468
+ ...parent,
469
+ id: ThreadId.make("fork"),
470
+ lineage: { ...parent.lineage, parentThreadId: parent.id },
471
},
436
- { ...parent, id: ThreadId.make("fork"), lineage: { parentThreadId: parent.id } },
472
);
473
expect((await useThreadActions().deleteThread(target))._tag).toBe("Success");
474
expect(state.localEffects).toEqual(
apps/web/src/hooks/useThreadActions.ts
+11
-5
@@ -501,10 +501,16 @@ export function useThreadActions() {
501
}),
502
)
503
: undefined;
504
- const survivingThreads =
505
- deletedIds && deletedIds.size > 0
506
- ? threads.filter((entry) => entry.id === threadRef.threadId || !deletedIds.has(entry.id))
507
- : threads;
504
+ // Deleting a thread also deletes its side chats, which share its worktree.
505
+ const removedIds = new Set<ThreadId>(deletedIds);
506
+ for (const entry of threads) {
507
+ if (entry.lineage.sideChat === true && entry.lineage.parentThreadId === threadRef.threadId) {
508
+ removedIds.add(entry.id);
509
+ }
510
+ }
511
+ const survivingThreads = threads.filter(
512
+ (entry) => entry.id === threadRef.threadId || !removedIds.has(entry.id),
513
+ );
514
const environmentConfig = appAtomRegistry
515
.get(environmentServerConfigsAtom)
516
.get(threadRef.environmentId);
@@ -522,7 +528,7 @@ export function useThreadActions() {
528
if (
529
occupants._tag !== "Success" ||
530
occupants.value.threadIds.some(
525
- (threadId) => threadId !== threadRef.threadId && deletedIds?.has(threadId) !== true,
531
+ (threadId) => threadId !== threadRef.threadId && !removedIds.has(threadId),
532
)
533
) {
534
orphanedWorktreePath = null;