The best way to control Claude Code, Codex and more from any computer or phone
fix(web): removing an environment dismisses its notification toasts (#36726)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Wout Stiens committed
Nov 14, 2026 at 14:21 UTC
acd192fc64a3f18c026583e1a0b663698f1110b5
4 files changed
+143
-9
apps/web/src/components/ThreadNotificationCoordinator.badge.browser.test.ts
+5
-5
@@ -419,7 +419,7 @@ it.each([false, true])(
419
},
420
);
421
422
-it("opening a thread closes only its in-app toasts, and disabling notifications closes the rest", async () => {
422
+it("opening a thread or removing its environment closes only its in-app toasts, and disabling notifications closes the rest", async () => {
423
await using app = setup();
424
state.inApp = true;
425
focused = true;
@@ -445,11 +445,11 @@ it("opening a thread closes only its in-app toasts, and disabling notifications
445
app.openThread("one", "thread");
446
expect(state.closeToast.mock.calls).toEqual([["one-completed"], ["one-approval"]]);
447
448
+ app.setEnvironmentIds(["one"]);
449
+ expect(state.closeToast.mock.calls.slice(2)).toEqual([["two-completed"]]);
450
+
451
state.mode = "off";
452
state.inApp = false;
453
app.changeSettings();
451
- expect(state.closeToast.mock.calls.slice(2).flat().toSorted()).toEqual([
452
- "one-other",
453
- "two-completed",
454
- ]);
454
+ expect(state.closeToast.mock.calls.slice(3)).toEqual([["one-other"]]);
455
});
apps/web/src/components/ThreadNotificationCoordinator.tsx
+3
-2
@@ -5,7 +5,7 @@ import {
5
} from "@t3tools/client-runtime/state/models";
6
import { isShownUnderParent } from "@t3tools/client-runtime/state/threads";
7
import type { AnyRouter } from "@tanstack/react-router";
8
-import { threadKey } from "@t3tools/client-runtime/state/entities";
8
+import { parseThreadKey, threadKey } from "@t3tools/client-runtime/state/entities";
9
import type { EnvironmentId, OrchestrationV2ThreadShell, ThreadId } from "@t3tools/contracts";
10
import { monitorHoldsWakeCompletion } from "@t3tools/shared/orchestrationV2PendingBackgroundWork";
11
import type { ClientSettings } from "@t3tools/contracts/settings";
@@ -79,7 +79,7 @@ export function startThreadNotifications(
79
pending.set(notification.tag, { environmentId, threadId, notification });
80
setNotificationBadge(pending.size);
81
};
82
- // Toast ids by thread key, so hiding or opening a thread can close its open toasts.
82
+ // Toast ids by thread key, so hiding or opening a thread, or removing its environment, closes them.
83
const openToasts = new Map<string, Array<ToastId>>();
84
const forgetToast = (key: string, toastId: ToastId) => {
85
const remaining = (openToasts.get(key) ?? []).filter((id) => id !== toastId);
@@ -373,6 +373,7 @@ export function startThreadNotifications(
373
374
const pruneRemovedEnvironments = () => {
375
const activeIds = new Set(registry.get(environmentSummaries.environmentIdsAtom));
376
+ closeToasts((key) => !activeIds.has(parseThreadKey(key).environmentId));
377
const count = pending.size;
378
for (const [tag, entry] of pending) {
379
if (activeIds.has(entry.environmentId)) continue;
scripts/scenarios/removed-environment-closes-its-toasts.e2e.ts
new
+133
@@ -0,0 +1,133 @@
1
+import * as NodeServices from "@effect/platform-node/NodeServices";
2
+import * as HostProcess from "@t3tools/shared/HostProcess";
3
+import * as NetService from "@t3tools/shared/Net";
4
+import { expect } from "e2e";
5
+import * as Deferred from "effect/Deferred";
6
+import * as Effect from "effect/Effect";
7
+import * as Fiber from "effect/Fiber";
8
+import * as Path from "effect/Path";
9
+
10
+import { APP_DIR, T3_HOME } from "../e2e.config.ts";
11
+import { prepareHome, start } from "./start-app.ts";
12
+import { makeState, runPromise, test, WEB } from "./t3.ts";
13
+
14
+const SECOND_HOME = `${T3_HOME}-second-environment`;
15
+
16
+/** A second server on its own T3 home, running until interrupted. `--dev-url` admits the web
17
+ * origin through CORS and registers the replay agent; `paired` gets the Add environment input. */
18
+const runSecondServer = Effect.fn("scenario.secondServer")(function* (
19
+ devUrl: string,
20
+ paired: (target: { readonly host: string; readonly token: string }) => void,
21
+) {
22
+ const path = yield* Path.Path;
23
+ const node = yield* HostProcess.ExecutablePath;
24
+ const hostEnvironment = yield* HostProcess.Environment;
25
+ const port = yield* (yield* NetService.NetService).reserveLoopbackPort();
26
+ yield* prepareHome(SECOND_HOME);
27
+ const token = yield* Deferred.make<string>();
28
+ yield* start({
29
+ cwd: APP_DIR,
30
+ command: node,
31
+ args: [
32
+ "apps/server/src/bin.ts",
33
+ "serve",
34
+ "--host",
35
+ "127.0.0.1",
36
+ "--port",
37
+ String(port),
38
+ "--base-dir",
39
+ SECOND_HOME,
40
+ "--dev-url",
41
+ devUrl,
42
+ ],
43
+ env: {
44
+ PATH: `${path.join(SECOND_HOME, "bin")}:${hostEnvironment.PATH ?? ""}`,
45
+ HOME: hostEnvironment.HOME,
46
+ T3CODE_AUTO_BOOTSTRAP_PROJECT_FROM_CWD: "0",
47
+ },
48
+ onLine: (line) => {
49
+ const value = /^Token:\s*(\S+)/.exec(line)?.[1];
50
+ return value === undefined ? Effect.void : Deferred.succeed(token, value).pipe(Effect.asVoid);
51
+ },
52
+ });
53
+ paired({ host: `http://127.0.0.1:${port}`, token: yield* Deferred.await(token) });
54
+ return yield* Effect.never;
55
+});
56
+
57
+test(
58
+ "Removing an environment closes the in-app notifications it raised",
59
+ WEB,
60
+ async ({ t3, app, screen, browser }) => {
61
+ const project = await t3.project("demo");
62
+ const primaryThread = await t3.thread({
63
+ project,
64
+ title: "Finished here",
65
+ messages: ["first"],
66
+ });
67
+ const primary = makeState(T3_HOME);
68
+ const second = makeState(SECOND_HOME);
69
+ const pairing = Promise.withResolvers<{ host: string; token: string }>();
70
+ const server = Effect.runFork(
71
+ runSecondServer(app.baseUrl ?? "", pairing.resolve).pipe(
72
+ Effect.scoped,
73
+ Effect.provide([NodeServices.layer, NetService.layer]),
74
+ ),
75
+ );
76
+ server.addObserver(() => pairing.reject(new Error("The second server stopped.")));
77
+ try {
78
+ const { host, token } = await pairing.promise;
79
+ const project = await second.state.project("remote-demo");
80
+ const thread = await second.state.thread({
81
+ project,
82
+ title: "Finished elsewhere",
83
+ messages: ["first"],
84
+ });
85
+
86
+ await t3.open("/settings/general");
87
+ await screen.getByRole("switch", "In-app notifications").check();
88
+ await app.open("/settings/connections");
89
+ await screen.getByRole("button", "Add environment").tap();
90
+ const dialog = screen.getByRole("dialog");
91
+ await dialog.getByPlaceholder("backend.example.com").fill(host);
92
+ await dialog.getByPlaceholder("PAIRCODE").fill(token);
93
+ await dialog.getByRole("button", "Add environment").tap();
94
+ const moreActions = screen.getByRole("button", "More actions for Scenario");
95
+ await expect(moreActions).toBeVisible({ timeout: 60_000 });
96
+
97
+ // The client announces only a change it saw happen, so it must hold the thread first.
98
+ await expect(screen.getByText("Finished elsewhere").first()).toBeVisible({ timeout: 60_000 });
99
+ await runPromise(
100
+ primary.cli(["thread", "send", primaryThread.threadId, "second", "--wait", "--json"]),
101
+ );
102
+ const primaryToast = browser.locator(
103
+ '[data-slot="toast-description"]:has-text("Finished here")',
104
+ );
105
+ await expect(primaryToast).toBeVisible({ timeout: 60_000 });
106
+ await primaryToast.hover();
107
+ await runPromise(
108
+ second.cli(["thread", "send", thread.threadId, "second", "--wait", "--json"]),
109
+ );
110
+ const toast = browser.locator(
111
+ '[data-slot="toast-description"]:has-text("Finished elsewhere")',
112
+ );
113
+ await expect(toast).toBeVisible({ timeout: 60_000 });
114
+
115
+ // A hovered toast does not time out. The removal goes by keyboard so the pointer stays.
116
+ await toast.hover();
117
+ await moreActions.press("Enter");
118
+ await screen.getByRole("menuitem", "Remove from this device…").press("Enter");
119
+ await expect(toast).toBeVisible();
120
+ await screen.getByRole("button", "Confirm").press("Enter");
121
+ try {
122
+ await expect(toast).toBeHidden();
123
+ // Both timers pause together; an older surviving toast rules out auto-dismissal.
124
+ await expect(primaryToast).toBeVisible();
125
+ } finally {
126
+ await app.screenshot("after-removal");
127
+ }
128
+ await expect(moreActions).toBeHidden({ timeout: 30_000 });
129
+ } finally {
130
+ await Effect.runPromise(Fiber.interrupt(server));
131
+ }
132
+ },
133
+);
scripts/scenarios/start-app.ts
+2
-2
@@ -52,7 +52,7 @@ esac
52
53
const encodeSettings = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
54
55
-const prepareHome = Effect.fn("startApp.prepareHome")(function* (home: string) {
55
+export const prepareHome = Effect.fn("startApp.prepareHome")(function* (home: string) {
56
const fs = yield* FileSystem.FileSystem;
57
const path = yield* Path.Path;
58
yield* fs.remove(home, { recursive: true, force: true });
@@ -85,7 +85,7 @@ const prepareHome = Effect.fn("startApp.prepareHome")(function* (home: string) {
85
});
86
87
/** Starts a process in the caller's scope and hands each line it prints to `onLine`. */
88
-const start = Effect.fn("startApp.start")(function* (input: {
88
+export const start = Effect.fn("startApp.start")(function* (input: {
89
readonly cwd: string;
90
readonly command: string;
91
readonly args: ReadonlyArray<string>;