@devries-cameron20 / t3code-1 / commits / 196c397b1b
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): keep thread notification tags within the Windows toast limit (#12289)

Co-authored-by: Julius Marminge <julius0216@outlook.com>

Satyal Yadav committed Oct 19, 2026 at 11:10 UTC 196c397b1b6130a92951a47c21472ec79577c94a
4 files changed +60 -12
apps/web/src/components/ThreadNotificationCoordinator.badge.browser.test.tsx
+40 -9
@@ -145,10 +145,14 @@ function toV2ThreadShell(input: typeof thread) {
145 };
146 }
147
148 -function shell(overrides: Partial<typeof thread> = {}) {
148 +function shell(overrides: Partial<typeof thread> = {}, ...others: Partial<typeof thread>[]) {
149 return {
150 status: "live",
151 - snapshot: Option.some({ threads: [toV2ThreadShell({ ...thread, ...overrides })] }),
151 + snapshot: Option.some({
152 + threads: [overrides, ...others].map((override) =>
153 + toV2ThreadShell({ ...thread, ...override }),
154 + ),
155 + }),
156 };
157 }
158 function complete(environment = "one", completedAt = "2026-09-13T08:00:00Z") {
@@ -197,16 +201,43 @@ afterEach(async () => {
201 vi.unstubAllGlobals();
202 });
203
200 -it("counts notifying threads across environments, replaces repeat alerts, and clears on focus", async () => {
204 +it("uses bounded tags across threads and environments, replaces repeat alerts, and clears on focus", async () => {
205 + const environmentId = "fd6fff30-f90b-4ee7-9812-4cf497791b90";
206 + const otherEnvironmentId = "25b62992-b996-4ee3-8d82-d988840e45c1";
207 + const threadId = "a8395a98-a186-4fe7-9d4c-fb8ba63b7588";
208 + const otherThreadId = "257598ad-ae4f-4422-a073-e03f4b4f5f0d";
209 + const completed = (id: string, completedAt = "2026-09-13T08:00:00Z") => ({
210 + id,
211 + latestTurn: { turnId: "turn", state: "completed", completedAt },
212 + });
213 + state.environmentIds = [environmentId, otherEnvironmentId];
214 + state.shells.set(environmentId, shell({ id: threadId }, { id: otherThreadId }));
215 + state.shells.set(otherEnvironmentId, shell({ id: threadId }));
216 await render();
202 - complete();
217 + state.shells.set(environmentId, shell(completed(threadId), { id: otherThreadId }));
218 await render();
219 expect(state.badge).toHaveBeenLastCalledWith(1);
205 - complete("one", "2026-09-13T08:01:00Z");
206 - complete("two");
220 + state.shells.set(environmentId, shell(completed(threadId), completed(otherThreadId)));
221 + state.shells.set(otherEnvironmentId, shell(completed(threadId)));
222 await render();
208 - expect(state.badge).toHaveBeenLastCalledWith(2);
209 - expect(TestNotification.sent[0]!.close).toHaveBeenCalledOnce();
223 + expect(state.badge).toHaveBeenLastCalledWith(3);
224 + state.shells.set(
225 + environmentId,
226 + shell(completed(threadId, "2026-09-13T08:01:00Z"), completed(otherThreadId)),
227 + );
228 + await render();
229 + expect(state.badge).toHaveBeenLastCalledWith(3);
230 + expect(TestNotification.sent).toHaveLength(4);
231 + const [first, otherThread, otherEnvironment, replacement] = TestNotification.sent;
232 + for (const notification of TestNotification.sent) {
233 + expect(notification.tag).toMatch(/^[0-9a-f]{16}$/);
234 + }
235 + expect(new Set([first!.tag, otherThread!.tag, otherEnvironment!.tag]).size).toBe(3);
236 + expect(replacement!.tag).toBe(first!.tag);
237 + expect(first!.close).toHaveBeenCalledOnce();
238 + expect(otherThread!.close).not.toHaveBeenCalled();
239 + expect(otherEnvironment!.close).not.toHaveBeenCalled();
240 + expect(replacement!.close).not.toHaveBeenCalled();
241 focused = true;
242 window.dispatchEvent(new Event("focus"));
243 expect(state.badge).toHaveBeenLastCalledWith(0);
@@ -214,7 +245,7 @@ it("counts notifying threads across environments, replaces repeat alerts, and cl
245 TestNotification.sent.every((notification) => notification.close.mock.calls.length > 0),
246 ).toBe(true);
247 focused = false;
217 - complete("two", "2026-09-13T08:02:00Z");
248 + state.shells.set(otherEnvironmentId, shell(completed(threadId, "2026-09-13T08:02:00Z")));
249 await render();
250 expect(state.badge).toHaveBeenLastCalledWith(1);
251 });
apps/web/src/components/ThreadNotificationCoordinator.browser.test.tsx
+2 -2
@@ -282,7 +282,7 @@ describe("thread notifications", () => {
282 expect(state.notification).toHaveBeenCalledTimes(1);
283 expect(state.notification).toHaveBeenCalledWith(title, {
284 body: "Fix the login form",
285 - tag: "env-1:thread-1",
285 + tag: expect.any(String),
286 silent: true,
287 });
288 });
@@ -355,7 +355,7 @@ describe("thread notifications", () => {
355 expect(state.add).not.toHaveBeenCalled();
356 expect(state.notification).toHaveBeenCalledWith("Thread completed", {
357 body: "Fix the login form",
358 - tag: "env-1:thread-1",
358 + tag: expect.any(String),
359 silent: true,
360 });
361 });
apps/web/src/components/ThreadNotificationCoordinator.tsx
+2 -1
@@ -23,6 +23,7 @@ import {
23 hasNotificationSound,
24 playNotificationSound,
25 setNotificationBadge,
26 + threadNotificationTag,
27 unlockNotificationAudio,
28 } from "../threadNotifications";
29 import { resolveSidebarThreadStatus } from "./Sidebar.logic";
@@ -218,7 +219,7 @@ function EnvironmentNotifications({
219 try {
220 const notification = new Notification(title, {
221 body: thread.title,
221 - tag: `${environmentId}:${thread.id}`,
222 + tag: threadNotificationTag(environmentId, thread.id),
223 silent: true,
224 });
225 onNotification(environmentId, notification);
apps/web/src/threadNotifications.ts
+16
@@ -1,3 +1,4 @@
1 +import type { EnvironmentId, ThreadId } from "@t3tools/contracts";
2 import type { ClientSettings } from "@t3tools/contracts/settings";
3
4 import completionUrl from "./assets/notification-completion.mp3";
@@ -19,6 +20,21 @@ export function hasDesktopNotifications(mode: NotificationMode) {
20 return mode === "notifications" || mode === "notifications-and-sound";
21 }
22
23 +const TAG_HASH_OFFSET_BASIS = 0xcbf29ce484222325n;
24 +const TAG_HASH_PRIME = 0x100000001b3n;
25 +const TAG_HASH_MASK = 0xffffffffffffffffn;
26 +
27 +/** Windows drops toast notifications with the 73-character environment/thread tag. */
28 +export function threadNotificationTag(environmentId: EnvironmentId, threadId: ThreadId): string {
29 + const key = `${environmentId}:${threadId}`;
30 + let hash = TAG_HASH_OFFSET_BASIS;
31 + for (let index = 0; index < key.length; index += 1) {
32 + hash ^= BigInt(key.charCodeAt(index));
33 + hash = (hash * TAG_HASH_PRIME) & TAG_HASH_MASK;
34 + }
35 + return hash.toString(16).padStart(16, "0");
36 +}
37 +
38 let originalFavicon: HTMLLinkElement | undefined;
39 let badgeFavicon: HTMLLinkElement | undefined;
40