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 22, 09:30 UTC
fix(web): thread alerts missed during a disconnect fire on reconnect (#24493)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Victor Vogel committed
Oct 31, 2026 at 03:43 UTC
7cd9a73b2f38f9e5efc134f97550adf33278b841
3 files changed
+83
-3
apps/web/src/components/ThreadNotificationCoordinator.badge.browser.test.ts
+70
@@ -260,3 +260,73 @@ it("holds a completion through a continuation gap and notifies once it settles",
260
await vi.advanceTimersByTimeAsync(1);
261
expect(TestNotification.sent.map((sent) => sent.title)).toEqual(["Thread completed"]);
262
});
263
+
264
+it.each(["hasPendingApprovals", "hasPendingUserInput"] as const)(
265
+ "notifies for offline completion and %s once across reconnects",
266
+ async (flag) => {
267
+ await using app = setup();
268
+ const asking = { id: "asking", hasPendingApprovals: true };
269
+ const offline = { id: "offline", [flag]: true };
270
+ const done = {
271
+ id: "done",
272
+ latestTurn: {
273
+ turnId: "done-turn",
274
+ state: "completed",
275
+ completedAt: "2026-09-13T07:00:00.000Z",
276
+ },
277
+ };
278
+ state.shells.set("one", shell({ id: "working" }, { id: "asking" }, { id: "offline" }, done));
279
+ app.start();
280
+ using _timers = fakeTimers();
281
+ state.shells.set("one", shell({ id: "working" }, asking, { id: "offline" }, done));
282
+ state.shells.set("one", {
283
+ ...shell({ id: "working" }, asking, { id: "offline" }, done),
284
+ status: "cached",
285
+ });
286
+
287
+ const completed = {
288
+ id: "working",
289
+ latestTurn: { turnId: "turn", state: "completed", completedAt: "2026-09-13T07:05:00.000Z" },
290
+ };
291
+ state.shells.set("one", {
292
+ ...shell(completed, asking, offline, done),
293
+ status: "synchronizing",
294
+ });
295
+ state.shells.set("one", shell(completed, asking, offline, done));
296
+
297
+ expect(TestNotification.sent.map(({ title }) => title)).toEqual([
298
+ "Approval needed",
299
+ flag === "hasPendingApprovals" ? "Approval needed" : "Input needed",
300
+ ]);
301
+ await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS);
302
+ state.shells.set("one", { ...shell(completed, asking, offline, done), status: "cached" });
303
+ state.shells.set("one", shell(completed, asking, offline, done));
304
+ await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS);
305
+ expect(TestNotification.sent.map(({ title }) => title)).toEqual([
306
+ "Approval needed",
307
+ flag === "hasPendingApprovals" ? "Approval needed" : "Input needed",
308
+ "Thread completed",
309
+ ]);
310
+ },
311
+);
312
+
313
+it.each([false, true])(
314
+ "rechecks a pending completion after reconnect (continued: %s)",
315
+ async (continued) => {
316
+ await using app = setup();
317
+ app.start();
318
+ using _timers = fakeTimers();
319
+ const completed = shell({
320
+ latestTurn: { turnId: "turn", state: "completed", completedAt: "2026-09-13T07:05:00.000Z" },
321
+ });
322
+ state.shells.set("one", completed);
323
+ state.shells.set("one", { ...completed, status: "cached" });
324
+ await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS);
325
+ expect(TestNotification.sent).toEqual([]);
326
+ state.shells.set("one", continued ? shell() : completed);
327
+ await vi.advanceTimersByTimeAsync(WORKING_EXIT_GRACE_MS);
328
+ expect(TestNotification.sent.map(({ title }) => title)).toEqual(
329
+ continued ? [] : ["Thread completed"],
330
+ );
331
+ },
332
+);
apps/web/src/components/ThreadNotificationCoordinator.logic.ts
+3
@@ -69,6 +69,9 @@ export function createThreadNotificationGate<Key>(
69
for (const key of handled.keys()) if (!keys.has(key)) handled.delete(key);
70
for (const key of lastSettled.keys()) if (!keys.has(key)) lastSettled.delete(key);
71
},
72
+ cancelPending(): void {
73
+ for (const key of pending.keys()) cancel(key);
74
+ },
75
clear(): void {
76
for (const key of pending.keys()) cancel(key);
77
handled.clear();
apps/web/src/components/ThreadNotificationCoordinator.tsx
+10
-3
@@ -47,6 +47,7 @@ interface NotificationState extends ThreadNotificationObservation {
47
interface WatchedEnvironment {
48
unsubscribe: () => void;
49
previous: Map<ThreadId, NotificationState>;
50
+ reconnecting: boolean;
51
readonly gate: ReturnType<typeof createThreadNotificationGate<ThreadId>>;
52
}
53
@@ -192,7 +193,11 @@ export function startThreadNotifications(
193
}
194
const prior = previous.get(rawThread.id);
195
const subagentRequest = subagentRequests.get(rawThread.id) ?? null;
195
- if (prior?.raw === rawThread && prior.subagentRequest === subagentRequest) {
196
+ if (
197
+ !entry.reconnecting &&
198
+ prior?.raw === rawThread &&
199
+ prior.subagentRequest === subagentRequest
200
+ ) {
201
next.set(rawThread.id, prior);
202
continue;
203
}
@@ -221,6 +226,7 @@ export function startThreadNotifications(
226
next.set(thread.id, state);
227
changed.push([prior, state]);
228
}
229
+ entry.reconnecting = false;
230
entry.previous = next;
231
entry.gate.retain(new Set(next.keys()));
232
for (const [prior, state] of changed) {
@@ -234,6 +240,7 @@ export function startThreadNotifications(
240
const watchEnvironment = (environmentId: EnvironmentId): WatchedEnvironment => {
241
const entry: WatchedEnvironment = {
242
previous: new Map(),
243
+ reconnecting: false,
244
unsubscribe: () => {},
245
gate: createThreadNotificationGate<ThreadId>((threadId, kind) => {
246
const state = entry.previous.get(threadId);
@@ -252,8 +259,8 @@ export function startThreadNotifications(
259
observeThreads(environmentId, entry, threads);
260
return;
261
}
255
- entry.gate.clear();
256
- entry.previous = new Map();
262
+ entry.gate.cancelPending();
263
+ entry.reconnecting = true;
264
},
265
{ immediate: true },
266
);