The best way to control Claude Code, Codex and more from any computer or phone
fix(web): screen readers hear which background thread finished, even with the sidebar collapsed (#23839)
Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
shivam committed
Oct 24, 2026 at 17:43 UTC
a46f80ee28d9b498bb8b407c8b60bd4e93bbe2e3
9 files changed
+428
-30
apps/web/src/components/AppSidebarLayout.tsx
+2
@@ -37,6 +37,7 @@ import {
37
usePanelAnimationSettings,
38
usePanelNavigationSuppression,
39
} from "../panelAnimations";
40
+import { BackgroundThreadAnnouncer } from "./BackgroundThreadAnnouncer";
41
import LegacyThreadSidebar from "./LegacySidebar";
42
import { useThreadVisitedMigration } from "../hooks/useThreadVisitedMigration";
43
import ThreadSidebar from "./Sidebar";
@@ -434,6 +435,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
435
<SidebarRail onDoubleClick={resetSidebarWidth} />
436
</Sidebar>
437
{children}
438
+ <BackgroundThreadAnnouncer />
439
<SidebarControl />
440
<NavigationHistoryShortcuts />
441
{isOnSettings ? null : <ThreadUndoShortcut />}
apps/web/src/components/BackgroundThreadAnnouncer.tsx
new
+64
@@ -0,0 +1,64 @@
1
+import { useAtomValue } from "@effect/atom-react";
2
+import { scopeThreadRef, scopedThreadKey } from "@t3tools/client-runtime/environment";
3
+import { effectiveSnoozed } from "@t3tools/client-runtime/state/thread-settled";
4
+import { useEffect, useRef } from "react";
5
+
6
+import { useComposerDraftStore } from "../composerDraftStore";
7
+import { useLiveRegion } from "../hooks/useLiveRegion";
8
+import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget";
9
+import { useQuietThreadShells } from "../state/entities";
10
+import { liveShellEnvironmentIdsAtom } from "../state/shell";
11
+import { resolveActiveThreadRouteRef } from "../threadRoutes";
12
+import {
13
+ type BackgroundThreadMemory,
14
+ type BackgroundThreadSnapshot,
15
+ nextBackgroundThreadAnnouncement,
16
+ resolveBackgroundThreadRequest,
17
+} from "./backgroundThreadAnnouncement";
18
+
19
+/**
20
+ * Speaks status changes for threads other than the open one. It lives outside
21
+ * the sidebar because a collapsed sidebar is inert, which silences its rows.
22
+ */
23
+export function BackgroundThreadAnnouncer() {
24
+ const threads = useQuietThreadShells();
25
+ const liveEnvironmentIds = useAtomValue(liveShellEnvironmentIdsAtom);
26
+ const routeTarget = useThreadRouteTarget();
27
+ const routeDraftThread = useComposerDraftStore((store) =>
28
+ routeTarget?.kind === "draft" ? store.getDraftSession(routeTarget.draftId) : null,
29
+ );
30
+ const openThreadRef = resolveActiveThreadRouteRef(routeTarget, routeDraftThread);
31
+ const openThreadKey = openThreadRef === null ? null : scopedThreadKey(openThreadRef);
32
+ const { regionRef, announce } = useLiveRegion();
33
+ const memoryRef = useRef<BackgroundThreadMemory>(new Map());
34
+
35
+ useEffect(() => {
36
+ const now = new Date().toISOString();
37
+ const snapshots: BackgroundThreadSnapshot[] = [];
38
+ for (const thread of threads) {
39
+ // Subagents have no row of their own; their requests surface on the parent.
40
+ if (thread.archivedAt !== null || thread.lineage.relationshipToParent === "subagent")
41
+ continue;
42
+ if (!liveEnvironmentIds.has(thread.environmentId)) continue;
43
+ snapshots.push({
44
+ key: scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)),
45
+ title: thread.title,
46
+ ...resolveBackgroundThreadRequest(thread),
47
+ runId: thread.latestRun?.runId ?? null,
48
+ runStatus: thread.latestRun?.status ?? null,
49
+ activeRunId: thread.runtime?.activeRunId ?? null,
50
+ snoozed: effectiveSnoozed(thread, { now }),
51
+ });
52
+ }
53
+ const { memory, announcement } = nextBackgroundThreadAnnouncement(
54
+ memoryRef.current,
55
+ snapshots,
56
+ openThreadKey,
57
+ );
58
+ memoryRef.current = memory;
59
+ if (announcement !== null) announce(announcement);
60
+ }, [threads, liveEnvironmentIds, openThreadKey, announce]);
61
+
62
+ // No role="status": Orca 50 maps it to a status bar in Chromium and drops its updates.
63
+ return <div ref={regionRef} aria-live="polite" className="sr-only" />;
64
+}
apps/web/src/components/backgroundThreadAnnouncement.test.ts
new
+189
@@ -0,0 +1,189 @@
1
+import { RunId, RuntimeRequestId } from "@t3tools/contracts";
2
+import * as DateTime from "effect/DateTime";
3
+import { describe, expect, it } from "vite-plus/test";
4
+
5
+import {
6
+ type BackgroundThreadMemory,
7
+ type BackgroundThreadSnapshot,
8
+ nextBackgroundThreadAnnouncement,
9
+ resolveBackgroundThreadRequest,
10
+} from "./backgroundThreadAnnouncement";
11
+
12
+const firstRun = RunId.make("run-1");
13
+const secondRun = RunId.make("run-2");
14
+
15
+function thread(
16
+ key: string,
17
+ title: string,
18
+ state: Partial<Omit<BackgroundThreadSnapshot, "key" | "title">> = {},
19
+): BackgroundThreadSnapshot {
20
+ return {
21
+ key,
22
+ title,
23
+ request: null,
24
+ requestId: null,
25
+ runId: firstRun,
26
+ runStatus: "running",
27
+ activeRunId: null,
28
+ snoozed: false,
29
+ ...state,
30
+ };
31
+}
32
+const login = (state?: Partial<BackgroundThreadSnapshot>) =>
33
+ thread("env:login", "Fix login redirect", state);
34
+const docs = (state?: Partial<BackgroundThreadSnapshot>) =>
35
+ thread("env:docs", "Update docs", state);
36
+
37
+function speak(
38
+ frames: ReadonlyArray<{
39
+ readonly threads: ReadonlyArray<BackgroundThreadSnapshot>;
40
+ readonly open?: string;
41
+ }>,
42
+) {
43
+ let memory: BackgroundThreadMemory = new Map();
44
+ const spoken: string[] = [];
45
+ for (const frame of frames) {
46
+ const result = nextBackgroundThreadAnnouncement(memory, frame.threads, frame.open ?? null);
47
+ memory = result.memory;
48
+ if (result.announcement !== null) spoken.push(result.announcement);
49
+ }
50
+ return spoken;
51
+}
52
+
53
+describe("nextBackgroundThreadAnnouncement", () => {
54
+ it("names the thread with the same words the open thread uses", () => {
55
+ expect(
56
+ speak([
57
+ { threads: [login()] },
58
+ { threads: [login({ request: "approval" })] },
59
+ { threads: [login()] },
60
+ { threads: [login({ request: "input" })] },
61
+ { threads: [login({ runStatus: "completed" })] },
62
+ { threads: [login({ runId: secondRun, runStatus: "failed" })] },
63
+ { threads: [login({ runId: RunId.make("run-3"), runStatus: "interrupted" })] },
64
+ ]),
65
+ ).toEqual([
66
+ "Needs approval: Fix login redirect",
67
+ "Needs your input: Fix login redirect",
68
+ "Done: Fix login redirect",
69
+ "Failed: Fix login redirect",
70
+ "Stopped: Fix login redirect",
71
+ ]);
72
+ });
73
+
74
+ it("announces each run's ending once", () => {
75
+ expect(
76
+ speak([
77
+ { threads: [login()] },
78
+ { threads: [login({ runStatus: "completed" })] },
79
+ // Marking the thread unread or renaming it changes nothing about the run.
80
+ { threads: [login({ runStatus: "completed", title: "Fix the login redirect" })] },
81
+ // The next run can finish between two updates, so it never looks busy here.
82
+ { threads: [login({ runId: secondRun, runStatus: "completed" })] },
83
+ { threads: [login({ runId: RunId.make("run-3"), runStatus: "rolled_back" })] },
84
+ ]),
85
+ ).toEqual(["Done: Fix login redirect", "Done: Fix login redirect"]);
86
+ });
87
+
88
+ it("announces a second request of the same kind", () => {
89
+ expect(
90
+ speak([
91
+ { threads: [login()] },
92
+ { threads: [login({ request: "approval", requestId: "request-1" })] },
93
+ { threads: [login({ request: "approval", requestId: "request-2" })] },
94
+ ]),
95
+ ).toEqual(["Needs approval: Fix login redirect", "Needs approval: Fix login redirect"]);
96
+ });
97
+
98
+ it("doesn't call a thread stopped when a queued message is cancelled while it works", () => {
99
+ expect(
100
+ speak([
101
+ { threads: [login({ activeRunId: firstRun })] },
102
+ {
103
+ threads: [login({ runId: secondRun, runStatus: "cancelled", activeRunId: firstRun })],
104
+ },
105
+ { threads: [login({ runId: secondRun, runStatus: "cancelled" })] },
106
+ ]),
107
+ ).toEqual([]);
108
+ });
109
+
110
+ it("stays quiet for threads it sees for the first time, like on launch or reconnect", () => {
111
+ expect(
112
+ speak([
113
+ { threads: [login({ runStatus: "completed" }), docs({ request: "approval" })] },
114
+ { threads: [login({ runStatus: "completed" }), docs({ request: "approval" })] },
115
+ // The environment drops out while it resyncs, then comes back changed.
116
+ { threads: [] },
117
+ {
118
+ threads: [
119
+ login({ runId: secondRun, runStatus: "failed" }),
120
+ docs({ runStatus: "completed" }),
121
+ ],
122
+ },
123
+ ]),
124
+ ).toEqual([]);
125
+ });
126
+
127
+ it("leaves the open thread to its own announcer", () => {
128
+ expect(
129
+ speak([
130
+ { threads: [login(), docs()], open: "env:login" },
131
+ { threads: [login({ runStatus: "completed" }), docs()], open: "env:login" },
132
+ // Switching away from a thread doesn't replay its ending.
133
+ { threads: [login({ runStatus: "completed" }), docs()], open: "env:docs" },
134
+ {
135
+ threads: [login({ runStatus: "completed" }), docs({ request: "input" })],
136
+ open: "env:login",
137
+ },
138
+ ]),
139
+ ).toEqual(["Needs your input: Update docs"]);
140
+ });
141
+
142
+ it("keeps a snoozed thread quiet, even after it wakes", () => {
143
+ expect(
144
+ speak([
145
+ { threads: [login({ snoozed: true })] },
146
+ { threads: [login({ snoozed: true, runStatus: "completed" })] },
147
+ { threads: [login({ runStatus: "completed" })] },
148
+ ]),
149
+ ).toEqual([]);
150
+ });
151
+
152
+ it("speaks threads that change together in one announcement", () => {
153
+ expect(
154
+ speak([
155
+ { threads: [login(), docs()] },
156
+ { threads: [login({ runStatus: "completed" }), docs({ request: "approval" })] },
157
+ ]),
158
+ ).toEqual(["Done: Fix login redirect. Needs approval: Update docs"]);
159
+ });
160
+});
161
+
162
+describe("resolveBackgroundThreadRequest", () => {
163
+ const question = (id: string) => ({
164
+ id: RuntimeRequestId.make(id),
165
+ kind: "user_input" as const,
166
+ createdAt: DateTime.makeUnsafe(0),
167
+ });
168
+ const childApproval = (parentQuestion: string | null) =>
169
+ resolveBackgroundThreadRequest({
170
+ hasPendingApprovals: false,
171
+ hasPendingUserInput: parentQuestion !== null,
172
+ pendingSubagentRequest: "approval",
173
+ source: { pendingRuntimeRequest: parentQuestion === null ? null : question(parentQuestion) },
174
+ });
175
+
176
+ it("raises a subagent's request on the parent without borrowing the parent's request id", () => {
177
+ expect(childApproval(null)).toEqual({ request: "approval", requestId: null });
178
+ // The parent's own questions come and go while the child's approval waits.
179
+ expect(
180
+ speak([
181
+ { threads: [login()] },
182
+ { threads: [login(childApproval(null))] },
183
+ { threads: [login(childApproval("question-1"))] },
184
+ { threads: [login(childApproval("question-2"))] },
185
+ { threads: [login(childApproval(null))] },
186
+ ]),
187
+ ).toEqual(["Needs approval: Fix login redirect"]);
188
+ });
189
+});
apps/web/src/components/backgroundThreadAnnouncement.ts
new
+88
@@ -0,0 +1,88 @@
1
+import type { OrchestrationV2RunStatus, RunId } from "@t3tools/contracts";
2
+
3
+import type { SidebarThreadSummary } from "../types";
4
+import { runOutcomeText, THREAD_STATUS_TEXT } from "./chat/threadActivityAnnouncement";
5
+
6
+export interface BackgroundThreadSnapshot {
7
+ readonly key: string;
8
+ readonly title: string;
9
+ readonly request: "approval" | "input" | null;
10
+ /** Null for a subagent's request, which the parent's shell only knows by kind. */
11
+ readonly requestId: string | null;
12
+ readonly runId: RunId | null;
13
+ readonly runStatus: OrchestrationV2RunStatus | null;
14
+ /** The run doing work now, which can be older than a queued run cancelled while it ran. */
15
+ readonly activeRunId: RunId | null;
16
+ /** A snoozed thread stays hidden until its timer, so it stays quiet too. */
17
+ readonly snoozed: boolean;
18
+}
19
+
20
+/** The request and its id come from the same source, so a subagent's request never takes the parent's id. */
21
+export function resolveBackgroundThreadRequest(
22
+ thread: Pick<
23
+ SidebarThreadSummary,
24
+ "hasPendingApprovals" | "hasPendingUserInput" | "pendingSubagentRequest"
25
+ > & {
26
+ readonly source: Pick<SidebarThreadSummary["source"], "pendingRuntimeRequest">;
27
+ },
28
+): Pick<BackgroundThreadSnapshot, "request" | "requestId"> {
29
+ const ownRequestId = thread.source.pendingRuntimeRequest?.id ?? null;
30
+ if (thread.hasPendingApprovals) return { request: "approval", requestId: ownRequestId };
31
+ if (thread.pendingSubagentRequest === "approval") return { request: "approval", requestId: null };
32
+ if (thread.hasPendingUserInput) return { request: "input", requestId: ownRequestId };
33
+ if (thread.pendingSubagentRequest === "user_input") return { request: "input", requestId: null };
34
+ return { request: null, requestId: null };
35
+}
36
+
37
+interface BackgroundThreadMemoryEntry {
38
+ readonly request: BackgroundThreadSnapshot["request"];
39
+ readonly requestId: string | null;
40
+ /** The last run whose ending is known, so each run's ending is announced once. */
41
+ readonly settledRunId: RunId | null;
42
+}
43
+
44
+export type BackgroundThreadMemory = ReadonlyMap<string, BackgroundThreadMemoryEntry>;
45
+
46
+/**
47
+ * Decides what a screen reader hears when a thread other than the open one
48
+ * asks for something or ends a run. `threads` holds only threads whose
49
+ * environment is live, so a thread is silent the first time it's seen:
50
+ * opening the app or reconnecting takes a baseline instead of reading out
51
+ * every thread.
52
+ */
53
+export function nextBackgroundThreadAnnouncement(
54
+ previous: BackgroundThreadMemory,
55
+ threads: ReadonlyArray<BackgroundThreadSnapshot>,
56
+ openThreadKey: string | null,
57
+): { readonly memory: BackgroundThreadMemory; readonly announcement: string | null } {
58
+ const memory = new Map<string, BackgroundThreadMemoryEntry>();
59
+ const announcements: string[] = [];
60
+ for (const thread of threads) {
61
+ const before = previous.get(thread.key);
62
+ const outcome = runOutcomeText(thread.runStatus);
63
+ const settled = outcome !== null || thread.runStatus === "rolled_back";
64
+ memory.set(thread.key, {
65
+ request: thread.request,
66
+ requestId: thread.requestId,
67
+ settledRunId: settled ? thread.runId : (before?.settledRunId ?? null),
68
+ });
69
+ if (before === undefined || thread.key === openThreadKey || thread.snoozed) continue;
70
+ if (
71
+ thread.request !== null &&
72
+ (thread.request !== before.request || thread.requestId !== before.requestId)
73
+ ) {
74
+ announcements.push(`${THREAD_STATUS_TEXT[thread.request]}: ${thread.title}`);
75
+ }
76
+ // While another run still works, the latest run's ending (a queued message
77
+ // cancelled before it started) isn't the thread finishing. The shell then
78
+ // only reports the latest run, so the working run's own ending stays quiet.
79
+ const anotherRunWorking = thread.activeRunId !== null && thread.activeRunId !== thread.runId;
80
+ if (outcome !== null && thread.runId !== before.settledRunId && !anotherRunWorking) {
81
+ announcements.push(`${outcome}: ${thread.title}`);
82
+ }
83
+ }
84
+ return {
85
+ memory,
86
+ announcement: announcements.length === 0 ? null : announcements.join(". "),
87
+ };
88
+}
apps/web/src/components/chat/ThreadActivityAnnouncer.tsx
+8
-16
@@ -1,15 +1,14 @@
1
import { memo, useEffect, useRef } from "react";
2
3
+import { useLiveRegion } from "../../hooks/useLiveRegion";
4
+
5
import {
6
nextThreadAnnouncement,
7
type ThreadActivitySnapshot,
8
type ThreadAnnouncementMemory,
9
} from "./threadActivityAnnouncement";
10
9
-/**
10
- * One polite live region for the open thread. Text is written straight to the
11
- * DOM so an announcement never re-renders the timeline.
12
- */
11
+/** One polite live region for the open thread. */
12
export const ThreadActivityAnnouncer = memo(function ThreadActivityAnnouncer({
13
threadKey,
14
status,
@@ -23,14 +22,13 @@ export const ThreadActivityAnnouncer = memo(function ThreadActivityAnnouncer({
22
/** See isDetailBehindShell. */
23
readonly detailBehind: boolean;
24
}) {
26
- const regionRef = useRef<HTMLDivElement>(null);
25
+ const { regionRef, announce, clear } = useLiveRegion();
26
const memoryRef = useRef<{ threadKey: string; memory: ThreadAnnouncementMemory } | null>(null);
27
28
useEffect(() => {
30
- const region = regionRef.current;
29
if (threadKey === null) {
30
memoryRef.current = null;
33
- if (region !== null) region.textContent = "";
31
+ clear();
32
return;
33
}
34
if (detailBehind) return;
@@ -42,15 +40,9 @@ export const ThreadActivityAnnouncer = memo(function ThreadActivityAnnouncer({
40
runStatus,
41
});
42
memoryRef.current = { threadKey, memory };
45
- if (region === null) return;
46
- if (previous === null) {
47
- region.textContent = "";
48
- } else if (announcement !== null) {
49
- // Screen readers ignore a write that leaves the text unchanged, so a
50
- // repeated "Done" gets a trailing non-breaking space to count as new.
51
- region.textContent = region.textContent === announcement ? `${announcement} ` : announcement;
52
- }
53
- }, [threadKey, status, requestId, runId, runStatus, detailBehind]);
43
+ if (previous === null) clear();
44
+ else if (announcement !== null) announce(announcement);
45
+ }, [threadKey, status, requestId, runId, runStatus, detailBehind, announce, clear]);
46
47
// No role="status": Orca 50 maps it to a status bar in Chromium and drops its updates.
48
return <div ref={regionRef} aria-live="polite" className="sr-only" />;
apps/web/src/components/chat/threadActivityAnnouncement.ts
+15
-6
@@ -3,6 +3,15 @@ import { latestExecutedRun } from "@t3tools/shared/orchestrationV2ThreadError";
3
4
export type ThreadActivityStatus = "working" | "approval" | "input" | "idle";
5
6
+/** Background threads say these too, so a status sounds the same wherever it's heard. */
7
+export const THREAD_STATUS_TEXT = {
8
+ approval: "Needs approval",
9
+ input: "Needs your input",
10
+ done: "Done",
11
+ failed: "Failed",
12
+ stopped: "Stopped",
13
+} as const;
14
+
15
export interface ThreadActivitySnapshot {
16
readonly status: ThreadActivityStatus;
17
/** The pending approval or question, when there is one. */
@@ -37,15 +46,15 @@ const STARTING_RUN_STATUSES: ReadonlySet<OrchestrationV2RunStatus | null> = new
46
"starting",
47
]);
48
40
-function runOutcomeText(status: OrchestrationV2RunStatus | null): string | null {
49
+export function runOutcomeText(status: OrchestrationV2RunStatus | null): string | null {
50
switch (status) {
51
case "completed":
43
- return "Done";
52
+ return THREAD_STATUS_TEXT.done;
53
case "failed":
45
- return "Failed";
54
+ return THREAD_STATUS_TEXT.failed;
55
case "interrupted":
56
case "cancelled":
48
- return "Stopped";
57
+ return THREAD_STATUS_TEXT.stopped;
58
default:
59
return null;
60
}
@@ -129,11 +138,11 @@ export function nextThreadAnnouncement(
138
next.status === "approval"
139
? previous.snapshot.status === "approval" && previous.snapshot.requestId === next.requestId
140
? null
132
- : "Needs approval"
141
+ : THREAD_STATUS_TEXT.approval
142
: next.status === "input"
143
? previous.snapshot.status === "input" && previous.snapshot.requestId === next.requestId
144
? null
136
- : "Needs your input"
145
+ : THREAD_STATUS_TEXT.input
146
: turnStarted
147
? "Working"
148
: null;
apps/web/src/components/sidebar/SidebarThreadRow.tsx
+4
-8
@@ -1342,14 +1342,10 @@ const SidebarThreadRow = memo(function SidebarThreadRow(props: SidebarThreadRowP
1342
) : topStatus.icon === "done" ? (
1343
<CircleCheckIcon aria-hidden className="size-4 shrink-0" />
1344
) : null}
1345
- {/* The label alone is the live region: a role="status"
1346
- wrapper around the ticking duration would make
1347
- screen readers announce every second. The open
1348
- thread announces its own status, so its row stays
1349
- quiet instead of saying everything twice. */}
1350
- <span role={props.isRouteThread ? undefined : "status"}>
1351
- {topStatus.label}
1352
- </span>
1345
+ {/* Not a live region: a collapsed sidebar is inert, so
1346
+ BackgroundThreadAnnouncer and the open thread's
1347
+ timeline speak status changes instead. */}
1348
+ {topStatus.label}
1349
{status === "working" ? (
1350
<span aria-hidden>
1351
<WorkingDuration startedAt={resolveWorkingStartedAt(thread)} />
apps/web/src/hooks/useLiveRegion.ts
new
+41
@@ -0,0 +1,41 @@
1
+import { useEffect, useRef } from "react";
2
+
3
+// NVDA reads a polite region's leftover text again when focus returns from a
4
+// dialog, so an announcement is cleared once it has had time to be spoken.
5
+// Clearing doesn't cut off speech that already started.
6
+const CLEAR_AFTER_MS = 7_000;
7
+
8
+/** A polite live region written straight to the DOM, so speaking never re-renders. */
9
+export function useLiveRegion() {
10
+ const regionRef = useRef<HTMLDivElement>(null);
11
+ const clearTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
12
+
13
+ const cancelClear = () => {
14
+ if (clearTimerRef.current !== null) clearTimeout(clearTimerRef.current);
15
+ clearTimerRef.current = null;
16
+ };
17
+
18
+ const clear = () => {
19
+ cancelClear();
20
+ if (regionRef.current !== null) regionRef.current.textContent = "";
21
+ };
22
+
23
+ const announce = (text: string) => {
24
+ const region = regionRef.current;
25
+ if (region === null) return;
26
+ cancelClear();
27
+ // Screen readers ignore a write that leaves the text unchanged, so a repeat
28
+ // gets a trailing non-breaking space to count as new.
29
+ region.textContent = region.textContent === text ? `${text} ` : text;
30
+ clearTimerRef.current = setTimeout(clear, CLEAR_AFTER_MS);
31
+ };
32
+
33
+ useEffect(
34
+ () => () => {
35
+ if (clearTimerRef.current !== null) clearTimeout(clearTimerRef.current);
36
+ },
37
+ [],
38
+ );
39
+
40
+ return { regionRef, announce, clear };
41
+}
apps/web/src/state/shell.ts
+17
@@ -49,6 +49,23 @@ export function useEnvironmentShellHasSnapshot(environmentId: EnvironmentId | nu
49
);
50
}
51
52
+let previousLiveEnvironmentIds: ReadonlySet<EnvironmentId> = new Set();
53
+/** Environments whose threads reflect the server now, not a cache or a resync in flight. */
54
+export const liveShellEnvironmentIdsAtom = Atom.make((get) => {
55
+ const next = new Set<EnvironmentId>();
56
+ for (const environmentId of enabledEnvironmentIds(get(environmentCatalog.catalogValueAtom))) {
57
+ if (get(environmentShell.statusAtom(environmentId)) === "live") next.add(environmentId);
58
+ }
59
+ if (
60
+ next.size === previousLiveEnvironmentIds.size &&
61
+ [...next].every((environmentId) => previousLiveEnvironmentIds.has(environmentId))
62
+ ) {
63
+ return previousLiveEnvironmentIds;
64
+ }
65
+ previousLiveEnvironmentIds = next;
66
+ return next;
67
+}).pipe(Atom.withLabel("web-live-shell-environment-ids"));
68
+
69
export const allEnvironmentShellsBootstrappedAtom = Atom.make((get) => {
70
const catalog = AsyncResult.value(get(environmentCatalog.catalogAtom));
71
if (Option.isNone(catalog)) {