The best way to control Claude Code, Codex and more from any computer or phone
fix(web): archiving or deleting a thread expires its earlier Undos (#25444)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Victor Vogel committed
Oct 30, 2026 at 16:14 UTC
f048a9b617f6b34e2c6937b719fe67c7681fc6d2
2 files changed
+80
-1
apps/web/src/hooks/useThreadActions.ts
+10
@@ -229,6 +229,13 @@ export function useAcknowledgeThreadWoke() {
229
};
230
}
231
232
+// These Undos restore a thread's place in the list, which archiving or deleting it ends.
233
+const LIST_PLACEMENT_UNDO_KINDS = ["settle", "snooze", "pin"];
234
+
235
+function expireThreadUndos(target: ScopedThreadRef, kinds: readonly string[]) {
236
+ for (const kind of kinds) ThreadUndo.invalidate(kind, scopedThreadKey(target));
237
+}
238
+
239
/** A No project thread that already has its own folder, on a server that can promote it. */
240
export function canTurnThreadIntoProject(threadRef: ScopedThreadRef): boolean {
241
const thread = readThreadShell(threadRef);
@@ -388,6 +395,7 @@ export function useThreadActions() {
395
action.finish();
396
return archiveResult;
397
}
398
+ expireThreadUndos(threadRef, LIST_PLACEMENT_UNDO_KINDS);
399
const wokeAt = threadWokeAt(thread, { now: new Date().toISOString() });
400
if (wokeAt !== null) {
401
markThreadVisited(scopedThreadKey(threadRef), wokeAt);
@@ -427,6 +435,7 @@ export function useThreadActions() {
435
input: { threadId: target.threadId },
436
});
437
if (result._tag === "Success") {
438
+ expireThreadUndos(target, [...LIST_PLACEMENT_UNDO_KINDS, "archive"]);
439
refreshArchivedThreadsForEnvironment(target.environmentId);
440
clearThreadPreviewState(target);
441
}
@@ -543,6 +552,7 @@ export function useThreadActions() {
552
if (deleteResult._tag === "Failure") {
553
return deleteResult;
554
}
555
+ expireThreadUndos(threadRef, [...LIST_PLACEMENT_UNDO_KINDS, "archive"]);
556
refreshArchivedThreadsForEnvironment(threadRef.environmentId);
557
releaseComposerDraftUploads(threadRef);
558
clearComposerDraftForThread(threadRef);
apps/web/src/hooks/useThreadActions.undo.test.ts
+70
-1
@@ -12,6 +12,7 @@ const commands = vi.hoisted(() => ({
12
unpin: vi.fn(),
13
archive: vi.fn(),
14
unarchive: vi.fn(),
15
+ delete: vi.fn(),
16
settle: vi.fn(),
17
unsettle: vi.fn(),
18
snooze: vi.fn(),
@@ -40,6 +41,7 @@ vi.mock("./useHandleNewThread", () => ({
41
},
42
}));
43
vi.mock("../composerDraftStore", () => ({ useComposerDraftStore: () => vi.fn() }));
44
+vi.mock("../lib/composerDraftUploads", () => ({ releaseComposerDraftUploads: vi.fn() }));
45
vi.mock("../terminalUiStateStore", () => ({ useTerminalUiStateStore: () => vi.fn() }));
46
vi.mock("../uiStateStore", () => ({ useUiStateStore: () => vi.fn() }));
47
vi.mock("../lib/archivedThreadsState", () => ({ refreshArchivedThreadsForEnvironment: vi.fn() }));
@@ -52,10 +54,12 @@ const threadShell = vi.hoisted(() => ({
54
environmentId: "undo-env",
55
session: null,
56
}));
57
+// Archived rows have no loaded shell, so deleting one takes the unresolved path.
58
+const shellLoaded = vi.hoisted(() => ({ current: true }));
59
vi.mock("../state/entities", async (original) => ({
60
...(await original<typeof import("../state/entities")>()),
61
readEnvironmentServerConfigLoaded: () => true,
58
- readThreadShell: () => threadShell,
62
+ readThreadShell: () => (shellLoaded.current ? threadShell : null),
63
}));
64
vi.mock("../state/use-atom-command", () => ({
65
useAtomCommand: (command: unknown) => {
@@ -68,6 +72,8 @@ vi.mock("../state/use-atom-command", () => ({
72
return commands.archive;
73
case threadEnvironment.unarchive:
74
return commands.unarchive;
75
+ case threadEnvironment.delete:
76
+ return commands.delete;
77
case threadEnvironment.settle:
78
return commands.settle;
79
case threadEnvironment.unsettle:
@@ -102,6 +108,7 @@ beforeEach(() => {
108
router.state.matches[0]!.params = {};
109
threadShell.pinnedAt = null;
110
threadShell.snoozedUntil = null;
111
+ shellLoaded.current = true;
112
});
113
afterEach(() => {
114
vi.runAllTimers();
@@ -298,3 +305,65 @@ describe("settle and snooze Undo", () => {
305
});
306
});
307
});
308
+
309
+describe("archive and delete Undo expiry", () => {
310
+ const otherThread = { environmentId: target.environmentId, threadId: ThreadId.make("other") };
311
+ const otherEnvironment = {
312
+ environmentId: EnvironmentId.make("other-env"),
313
+ threadId: target.threadId,
314
+ };
315
+ const failure = { _tag: "Failure", cause: Cause.fail(new Error("Request failed")) };
316
+
317
+ describe.each(["archiveThread", "deleteThread"] as const)("%s", (lifecycle) => {
318
+ it.each([
319
+ ["settleThread", "unsettle"],
320
+ ["snoozeThread", "unsnooze"],
321
+ ["unpinThread", "pin"],
322
+ ] as const)(
323
+ "expires an earlier %s Undo for that thread only, across hook instances",
324
+ async (handler, inverse) => {
325
+ const sidebar = useThreadActions();
326
+ const header = useThreadActions();
327
+ for (const ref of [otherThread, otherEnvironment, target]) {
328
+ await (handler === "snoozeThread"
329
+ ? sidebar.snoozeThread(ref, "2099-01-01T09:00:00.000Z")
330
+ : sidebar[handler](ref));
331
+ }
332
+ const staleUndo = currentUndo();
333
+ await header[lifecycle](target);
334
+ await staleUndo();
335
+ expect(commands[inverse]).toHaveBeenCalledTimes(2);
336
+ expect(commands[inverse]).not.toHaveBeenCalledWith(
337
+ expect.objectContaining({
338
+ environmentId: target.environmentId,
339
+ input: expect.objectContaining({ threadId: target.threadId }),
340
+ }),
341
+ );
342
+ },
343
+ );
344
+
345
+ it("keeps the earlier Undo when the request fails", async () => {
346
+ const actions = useThreadActions();
347
+ await actions.settleThread(target);
348
+ commands[lifecycle === "archiveThread" ? "archive" : "delete"].mockResolvedValue(failure);
349
+ await actions[lifecycle](target);
350
+ expect(useThreadUndoNotice.getState().notice).toMatchObject({ action: "Settled" });
351
+ await currentUndo()();
352
+ expect(commands.unsettle).toHaveBeenCalledOnce();
353
+ });
354
+ });
355
+
356
+ it.each([true, false])(
357
+ "expires the Archived Undo when deleting with shell loaded: %s",
358
+ async (loaded) => {
359
+ const actions = useThreadActions();
360
+ await actions.archiveThread(target);
361
+ const staleUndo = currentUndo();
362
+ shellLoaded.current = loaded;
363
+ await actions.deleteThread(target);
364
+ expect(useThreadUndoNotice.getState().notice).toBeNull();
365
+ await staleUndo();
366
+ expect(commands.unarchive).not.toHaveBeenCalled();
367
+ },
368
+ );
369
+});