Skip to content

Commit 024200f

Browse files
PR Batch Testerclaude
andcommitted
fix(web): opening a running thread stays quiet, and a cancelled queued message isn't "Stopped"
The announcer took its silent baseline from whatever frame came first. On the web that is often a detail that hasn't loaded, or a cached one showing an older run, so opening a running thread said "Working" and reopening one whose runs finished while away said "Done". It now waits until the detail agrees with the live thread shell. A queued message cancelled before it started keeps its place in line, so it became the thread's latest run when the turn ended, and the turn read as "Stopped". The announcer now reads the last run that actually ran. Drops the reopen test that copied the component's frame filter. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6a003fc commit 024200f

5 files changed

Lines changed: 74 additions & 48 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ScrollToEndButton, WorkspaceFileDropOverlay } from "./chat/TimelineOverlays";
22
import { usePasteToFocusComposer } from "./chat/usePasteToFocusComposer";
3-
import { isDetailRunBehindShell } from "./chat/threadActivityAnnouncement";
3+
import { announcedRun, isDetailBehindShell } from "./chat/threadActivityAnnouncement";
44
import {
55
deriveAvailableRevertTurnCounts,
66
deriveThreadPendingBackgroundTasks,
@@ -3327,9 +3327,14 @@ export default function ChatView(props: ChatViewProps) {
33273327
listRef={legendListRef}
33283328
runs={paintOnlyDisplayedTimeline ? [] : (serverProjection?.runs ?? [])}
33293329
latestRun={paintOnlyDisplayedTimeline ? null : activeActivityRun}
3330-
latestRunBehind={
3330+
announcedRun={
3331+
paintOnlyDisplayedTimeline
3332+
? null
3333+
: announcedRun(activeActivityRun, serverProjection?.runs ?? [])
3334+
}
3335+
detailBehindShell={
33313336
!paintOnlyDisplayedTimeline &&
3332-
isDetailRunBehindShell(activeActivityRun, activeThreadShell?.latestRun ?? null)
3337+
isDetailBehindShell(activeLatestRun, activeThreadShell?.latestRun ?? null)
33333338
}
33343339
runningRunId={paintOnlyDisplayedTimeline ? null : activeRunningTurnId}
33353340
turnDiffSummaries={

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,10 @@ interface MessagesTimelineProps {
201201
listRef: React.RefObject<LegendListRef | null>;
202202
timelineEntries: ReadonlyArray<TimelineEntry>;
203203
latestRun: TimelineLatestRun | null;
204-
/** The live shell saw latestRun end before this thread's detail did. */
205-
latestRunBehind?: boolean;
204+
/** The run the screen reader announcer follows; see announcedRun. */
205+
announcedRun?: { readonly runId: RunId; readonly status: TimelineLatestRun["status"] } | null;
206+
/** See isDetailBehindShell. */
207+
detailBehindShell?: boolean;
206208
runningRunId?: RunId | null;
207209
turnDiffSummaries: ReadonlyArray<TurnDiffSummary>;
208210
routeThreadKey: string;
@@ -316,7 +318,8 @@ const ConversationTimeline = memo(function ConversationTimeline({
316318
findNavigationId = 0,
317319
findPositionReaderRef,
318320
latestRun,
319-
latestRunBehind = false,
321+
announcedRun = null,
322+
detailBehindShell = false,
320323
runningRunId = null,
321324
turnDiffSummaries,
322325
routeThreadKey,
@@ -968,9 +971,9 @@ const ConversationTimeline = memo(function ConversationTimeline({
968971
threadKey={paintOnly || !announceTurnStatus ? null : listIdentityKey}
969972
status={awaitingUser ?? (isWorking ? "working" : "idle")}
970973
requestId={awaitingRequestId}
971-
runId={latestRun?.runId ?? null}
972-
runStatus={latestRun?.status ?? null}
973-
detailBehind={latestRunBehind}
974+
runId={announcedRun?.runId ?? null}
975+
runStatus={announcedRun?.status ?? null}
976+
detailBehind={detailBehindShell}
974977
/>
975978
);
976979
const listHeaderLeadingContent =

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export const ThreadActivityAnnouncer = memo(function ThreadActivityAnnouncer({
2020
}: ThreadActivitySnapshot & {
2121
/** Null while the timeline shows another thread during a switch. */
2222
readonly threadKey: string | null;
23-
/** The thread's detail hasn't caught up with how its run ended; see isDetailRunBehindShell. */
23+
/** See isDetailBehindShell. */
2424
readonly detailBehind: boolean;
2525
}) {
2626
const regionRef = useRef<HTMLDivElement>(null);

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

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
import { RunId } from "@t3tools/contracts";
1+
import {
2+
MessageId,
3+
type OrchestrationV2Run,
4+
ProviderInstanceId,
5+
RunId,
6+
ThreadId,
7+
} from "@t3tools/contracts";
8+
import * as DateTime from "effect/DateTime";
29
import { describe, expect, it } from "vite-plus/test";
310

411
import {
5-
isDetailRunBehindShell,
12+
announcedRun,
613
nextThreadAnnouncement,
714
type ThreadActivitySnapshot,
815
type ThreadAnnouncementMemory,
@@ -118,27 +125,32 @@ describe("nextThreadAnnouncement", () => {
118125
expect(speak([busy(), idle(secondRun, "failed")])).toEqual(["Failed"]);
119126
});
120127

121-
it("stays silent when a thread reopens after its turn ended while it was closed", () => {
122-
// The cached detail still shows the run working until it catches up with the live shell.
123-
const frames = [busy(), idle(secondRun, "completed")];
124-
const shellRun = { runId: secondRun, status: "completed" } as const;
125-
const current = frames.filter(
126-
(frame) =>
127-
!isDetailRunBehindShell(
128-
frame.runId === null || frame.runStatus === null
129-
? null
130-
: { runId: frame.runId, status: frame.runStatus },
131-
shellRun,
132-
),
133-
);
134-
expect(speak(current)).toEqual([]);
135-
expect(isDetailRunBehindShell({ runId: secondRun, status: "running" }, null)).toBe(false);
136-
expect(
137-
isDetailRunBehindShell(
138-
{ runId: secondRun, status: "running" },
139-
{ runId: firstRun, status: "completed" },
140-
),
141-
).toBe(false);
128+
it("says how the turn ended when a queued message was cancelled before it started", () => {
129+
const now = DateTime.makeUnsafe("2026-06-20T00:00:00.000Z");
130+
const run = (id: RunId, ordinal: number, status: OrchestrationV2Run["status"]) =>
131+
({
132+
id,
133+
threadId: ThreadId.make("thread-1"),
134+
ordinal,
135+
providerInstanceId: ProviderInstanceId.make("codex"),
136+
modelSelection: { instanceId: ProviderInstanceId.make("codex"), model: "gpt-5.4" },
137+
providerThreadId: null,
138+
userMessageId: MessageId.make(`message-${ordinal}`),
139+
rootNodeId: null,
140+
activeAttemptId: null,
141+
status,
142+
requestedAt: now,
143+
startedAt: status === "cancelled" ? null : now,
144+
completedAt: now,
145+
checkpointId: null,
146+
contextHandoffId: null,
147+
}) satisfies OrchestrationV2Run;
148+
const cancelledRun = RunId.make("run-3");
149+
const ended = announcedRun({ runId: cancelledRun, status: "cancelled", startedAt: null }, [
150+
run(secondRun, 1, "completed"),
151+
run(cancelledRun, 2, "cancelled"),
152+
]);
153+
expect(speak([busy(), idle(ended?.runId ?? null, ended?.status ?? null)])).toEqual(["Done"]);
142154
});
143155

144156
it("waits for the run to settle before announcing how the turn ended", () => {

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

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import type { OrchestrationV2RunStatus, RunId } from "@t3tools/contracts";
1+
import type { OrchestrationV2Run, OrchestrationV2RunStatus, RunId } from "@t3tools/contracts";
2+
import { latestExecutedRun } from "@t3tools/shared/orchestrationV2ThreadError";
23

34
export type ThreadActivityStatus = "working" | "approval" | "input" | "idle";
45

@@ -55,27 +56,32 @@ interface RunState {
5556
readonly status: OrchestrationV2RunStatus;
5657
}
5758

58-
const hasEnded = (status: OrchestrationV2RunStatus) =>
59-
runOutcomeText(status) !== null || status === "rolled_back";
60-
6159
/**
62-
* Reopening a thread can paint its cached detail, still working on a run the
63-
* live thread shell already saw end. Reading that frame as the baseline would
64-
* announce the ending once the detail catches up, so it's skipped instead.
60+
* The thread's detail hasn't caught up with the live thread shell: it isn't
61+
* loaded yet, or a cached copy still shows an older run or state. Reading such
62+
* a frame as the baseline replays what already happened, so it's skipped.
6563
*/
66-
export function isDetailRunBehindShell(
67-
detailRun: RunState | null,
68-
shellRun: RunState | null,
69-
): boolean {
64+
export function isDetailBehindShell(detailRun: RunState | null, shellRun: RunState | null) {
7065
return (
71-
detailRun !== null &&
7266
shellRun !== null &&
73-
detailRun.runId === shellRun.runId &&
74-
hasEnded(shellRun.status) &&
75-
!hasEnded(detailRun.status)
67+
(detailRun?.runId !== shellRun.runId || detailRun.status !== shellRun.status)
7668
);
7769
}
7870

71+
/**
72+
* A queued message cancelled before it started keeps its place in line, so it
73+
* shows up as the thread's latest run. It never ran, so the turn ended however
74+
* the last run that did ran.
75+
*/
76+
export function announcedRun(
77+
activityRun: (RunState & { readonly startedAt: string | null }) | null,
78+
runs: ReadonlyArray<OrchestrationV2Run>,
79+
): RunState | null {
80+
if (activityRun?.status !== "cancelled" || activityRun.startedAt !== null) return activityRun;
81+
const run = latestExecutedRun(runs);
82+
return run === null ? null : { runId: run.id, status: run.status };
83+
}
84+
7985
/**
8086
* Decides what a screen reader hears when the open thread's turn changes state.
8187
* The first snapshot of a thread is a silent baseline, so opening or switching

0 commit comments

Comments
 (0)