Skip to content

Commit 2296f20

Browse files
PR Batch Testerclaude
andcommitted
fix(web): announce only turn status, once per thread
Activity labels move to a follow-up with a setting, and the open thread's sidebar row stops repeating the status the thread already announces. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 8697fce commit 2296f20

6 files changed

Lines changed: 66 additions & 191 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ import { V2EventTimelineRow } from "./TimelineV2EventRow";
113113
import { useTimelinePositionRestore } from "./useTimelinePositionRestore";
114114
import { useThreadFindPositionReader } from "./useThreadFindPositionReader";
115115
import { ThreadActivityAnnouncer } from "./ThreadActivityAnnouncer";
116-
import { liveActivityAnnouncementLabel } from "./threadActivityAnnouncement";
117116
import { useStableHandoffRuns, useIncrementalTimelineRows, useStableRows } from "./useTimelineRows";
118117

119118
function timelineListStateFor(identity: string): {
@@ -959,7 +958,6 @@ const ConversationTimeline = memo(function ConversationTimeline({
959958
<ThreadActivityAnnouncer
960959
threadKey={paintOnly ? null : listIdentityKey}
961960
status={awaitingUser ?? (isWorking ? "working" : "idle")}
962-
activity={isWorking ? liveActivityAnnouncementLabel(rows, workspaceRoot) : null}
963961
runId={latestRun?.runId ?? null}
964962
runStatus={latestRun?.status ?? null}
965963
/>

‎apps/web/src/components/chat/ThreadActivityAnnouncer.browser.test.tsx‎

Lines changed: 0 additions & 36 deletions
This file was deleted.

‎apps/web/src/components/chat/ThreadActivityAnnouncer.tsx‎

Lines changed: 9 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@ import {
66
type ThreadAnnouncementMemory,
77
} from "./threadActivityAnnouncement";
88

9-
// Long enough for a screen reader to finish a short label before the next one.
10-
const ACTIVITY_ANNOUNCEMENT_INTERVAL_MS = 2_000;
11-
129
/**
1310
* One polite live region for the open thread. Text is written straight to the
1411
* DOM so an announcement never re-renders the timeline.
1512
*/
1613
export const ThreadActivityAnnouncer = memo(function ThreadActivityAnnouncer({
1714
threadKey,
1815
status,
19-
activity,
2016
runId,
2117
runStatus,
2218
}: ThreadActivitySnapshot & {
@@ -25,71 +21,29 @@ export const ThreadActivityAnnouncer = memo(function ThreadActivityAnnouncer({
2521
}) {
2622
const regionRef = useRef<HTMLDivElement>(null);
2723
const memoryRef = useRef<{ threadKey: string; memory: ThreadAnnouncementMemory } | null>(null);
28-
const lastSpokenRef = useRef({ at: Number.NEGATIVE_INFINITY, text: "" });
29-
const pendingRef = useRef<ReturnType<typeof setTimeout> | null>(null);
3024

3125
useEffect(() => {
32-
const cancelPending = () => {
33-
if (pendingRef.current !== null) clearTimeout(pendingRef.current);
34-
pendingRef.current = null;
35-
};
36-
const speak = (text: string) => {
37-
const region = regionRef.current;
38-
if (region === null) return;
39-
lastSpokenRef.current = { at: Date.now(), text };
40-
// Screen readers ignore a write that leaves the text unchanged, so a
41-
// repeated "Done" gets a trailing space to count as new.
42-
region.textContent = region.textContent === text ? `${text} ` : text;
43-
};
44-
26+
const region = regionRef.current;
4527
if (threadKey === null) {
4628
memoryRef.current = null;
47-
cancelPending();
4829
return;
4930
}
5031
const previous = memoryRef.current?.threadKey === threadKey ? memoryRef.current.memory : null;
51-
const { memory, announcements } = nextThreadAnnouncement(previous, {
32+
const { memory, announcement } = nextThreadAnnouncement(previous, {
5233
status,
53-
activity,
5434
runId,
5535
runStatus,
5636
});
5737
memoryRef.current = { threadKey, memory };
38+
if (region === null) return;
5839
if (previous === null) {
59-
cancelPending();
60-
if (regionRef.current) regionRef.current.textContent = "";
61-
lastSpokenRef.current = { at: Number.NEGATIVE_INFINITY, text: "" };
62-
return;
63-
}
64-
if (announcements.length === 0) {
65-
// A queued label is stale once nothing is live, e.g. during compaction or
66-
// while a finished turn waits for its run to settle.
67-
if (status !== "working" || activity === null) cancelPending();
68-
return;
69-
}
70-
// A newer update replaces one still waiting, so only current activity is read.
71-
cancelPending();
72-
for (const announcement of announcements) {
73-
if (announcement.kind === "status") {
74-
speak(announcement.text);
75-
continue;
76-
}
77-
const wait = lastSpokenRef.current.at + ACTIVITY_ANNOUNCEMENT_INTERVAL_MS - Date.now();
78-
const speakActivity = () => {
79-
pendingRef.current = null;
80-
if (lastSpokenRef.current.text !== announcement.text) speak(announcement.text);
81-
};
82-
if (wait <= 0) speakActivity();
83-
else pendingRef.current = setTimeout(speakActivity, wait);
40+
region.textContent = "";
41+
} else if (announcement !== null) {
42+
// Screen readers ignore a write that leaves the text unchanged, so a
43+
// repeated "Done" gets a trailing non-breaking space to count as new.
44+
region.textContent = region.textContent === announcement ? `${announcement} ` : announcement;
8445
}
85-
}, [threadKey, status, activity, runId, runStatus]);
86-
87-
useEffect(
88-
() => () => {
89-
if (pendingRef.current !== null) clearTimeout(pendingRef.current);
90-
},
91-
[],
92-
);
46+
}, [threadKey, status, runId, runStatus]);
9347

9448
return <div ref={regionRef} role="status" aria-live="polite" className="sr-only" />;
9549
});

‎apps/web/src/components/chat/threadActivityAnnouncement.test.ts‎

Lines changed: 29 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,57 +13,51 @@ const secondRun = RunId.make("run-2");
1313
const idle = (
1414
runId: RunId | null,
1515
runStatus: ThreadActivitySnapshot["runStatus"],
16-
): ThreadActivitySnapshot => ({ status: "idle", activity: null, runId, runStatus });
17-
const working = (activity: string | null, runId: RunId | null = secondRun) =>
18-
({ status: "working", activity, runId, runStatus: "running" }) as const;
16+
): ThreadActivitySnapshot => ({ status: "idle", runId, runStatus });
17+
const busy = (
18+
status: Exclude<ThreadActivitySnapshot["status"], "idle"> = "working",
19+
runId: RunId | null = secondRun,
20+
runStatus: ThreadActivitySnapshot["runStatus"] = "running",
21+
): ThreadActivitySnapshot => ({ status, runId, runStatus });
1922

2023
function speak(snapshots: ReadonlyArray<ThreadActivitySnapshot>) {
2124
let memory: ThreadAnnouncementMemory | null = null;
2225
const spoken: string[] = [];
2326
for (const snapshot of snapshots) {
2427
const result = nextThreadAnnouncement(memory, snapshot);
2528
memory = result.memory;
26-
spoken.push(...result.announcements.map((announcement) => announcement.text));
29+
if (result.announcement !== null) spoken.push(result.announcement);
2730
}
2831
return spoken;
2932
}
3033

3134
describe("nextThreadAnnouncement", () => {
3235
it("follows a turn from start to finish", () => {
3336
expect(
34-
speak([
35-
idle(firstRun, "completed"),
36-
working(null, firstRun),
37-
working("Thinking"),
38-
working("Reading ChatView.tsx"),
39-
working("Reading ChatView.tsx"),
40-
working("Running vp"),
41-
idle(secondRun, "completed"),
42-
]),
43-
).toEqual(["Working", "Thinking", "Reading ChatView.tsx", "Running vp", "Done"]);
37+
speak([idle(firstRun, "completed"), busy(), busy(), idle(secondRun, "completed")]),
38+
).toEqual(["Working", "Done"]);
4439
});
4540

46-
it("announces the label that is already live when a turn starts", () => {
47-
expect(speak([idle(firstRun, "completed"), working("Running vp")])).toEqual([
48-
"Working",
49-
"Running vp",
50-
]);
41+
it("says Working once when a send looks idle before its run appears", () => {
42+
expect(
43+
speak([idle(null, null), busy(), idle(null, null), busy(), idle(secondRun, "completed")]),
44+
).toEqual(["Working", "Done"]);
5145
});
5246

5347
it("stays silent when a thread opens mid-turn or after one", () => {
5448
expect(speak([idle(firstRun, "completed"), idle(firstRun, "completed")])).toEqual([]);
55-
expect(speak([working("Running vp"), working("Running vp")])).toEqual([]);
49+
expect(speak([busy(), busy()])).toEqual([]);
5650
});
5751

5852
it("announces the end of a turn that was already running when the thread opened", () => {
59-
expect(speak([working("Running vp"), idle(secondRun, "failed")])).toEqual(["Failed"]);
53+
expect(speak([busy(), idle(secondRun, "failed")])).toEqual(["Failed"]);
6054
});
6155

6256
it("waits for the run to settle before announcing how the turn ended", () => {
6357
expect(
6458
speak([
6559
idle(firstRun, "completed"),
66-
working(null),
60+
busy(),
6761
idle(secondRun, "running"),
6862
idle(secondRun, "interrupted"),
6963
]),
@@ -72,32 +66,33 @@ describe("nextThreadAnnouncement", () => {
7266

7367
it("does not report the previous turn's ending when work stops before a new run exists", () => {
7468
expect(
75-
speak([idle(firstRun, "completed"), working(null, firstRun), idle(firstRun, "completed")]),
69+
speak([
70+
idle(firstRun, "completed"),
71+
busy("working", firstRun, "completed"),
72+
idle(firstRun, "completed"),
73+
]),
7674
).toEqual(["Working"]);
7775
// The previous run finished while this client looked idle.
7876
expect(
7977
speak([
8078
idle(firstRun, "completed"),
8179
idle(secondRun, "completed"),
82-
{ ...working(null), runStatus: "completed" },
80+
busy("working", secondRun, "completed"),
8381
idle(secondRun, "completed"),
8482
]),
8583
).toEqual(["Working"]);
8684
});
8785

88-
it("announces requests once and resumes activity after them", () => {
89-
const approval = { ...working("Running vp"), status: "approval" } as const;
90-
const input = { ...working(null), status: "input" } as const;
86+
it("announces each request once without repeating that work resumed", () => {
9187
expect(
9288
speak([
93-
working("Running vp"),
94-
approval,
95-
approval,
96-
working("Running vp"),
97-
working("Editing ChatView.tsx"),
98-
input,
89+
busy(),
90+
busy("approval"),
91+
busy("approval"),
92+
busy(),
93+
busy("input"),
9994
idle(secondRun, "completed"),
10095
]),
101-
).toEqual(["Needs approval", "Editing ChatView.tsx", "Needs your input", "Done"]);
96+
).toEqual(["Needs approval", "Needs your input", "Done"]);
10297
});
10398
});

0 commit comments

Comments
 (0)