Skip to content

Commit 08235b8

Browse files
PR Batch Testerclaude
andcommitted
fix(web): drop stale queued labels and runs that settled unseen
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 0eb4d4a commit 08235b8

4 files changed

Lines changed: 56 additions & 2 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { RunId } from "@t3tools/contracts";
2+
import { type ComponentProps } from "react";
3+
import { describe, expect, it, vi } from "vite-plus/test";
4+
5+
import { act, fakeTimers, render } from "../../../test/render";
6+
import { ThreadActivityAnnouncer } from "./ThreadActivityAnnouncer";
7+
8+
const announcer = (props: Partial<ComponentProps<typeof ThreadActivityAnnouncer>>) => (
9+
<ThreadActivityAnnouncer
10+
threadKey="thread-1"
11+
status="working"
12+
activity={null}
13+
runId={RunId.make("run-1")}
14+
runStatus="running"
15+
{...props}
16+
/>
17+
);
18+
19+
describe("ThreadActivityAnnouncer", () => {
20+
it("drops a queued label once nothing is live", async () => {
21+
// The announcer reads no route.
22+
await using screen = await render(announcer({ status: "idle", runStatus: "completed" }), {
23+
router: false,
24+
});
25+
using _timers = fakeTimers();
26+
const region = screen.getByRole("status").element();
27+
28+
await screen.rerender(announcer({}));
29+
await screen.rerender(announcer({ activity: "Reading ChatView.tsx" }));
30+
await screen.rerender(announcer({ activity: null }));
31+
await act(() => vi.advanceTimersByTime(5_000));
32+
33+
expect(region.textContent).toBe("Working");
34+
});
35+
});

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ export const ThreadActivityAnnouncer = memo(function ThreadActivityAnnouncer({
6161
lastSpokenRef.current = { at: Number.NEGATIVE_INFINITY, text: "" };
6262
return;
6363
}
64-
if (announcement === null) return;
64+
if (announcement === null) {
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+
}
6570
// A newer update replaces one still waiting, so only current activity is read.
6671
cancelPending();
6772
if (announcement.kind === "status") {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,15 @@ describe("nextThreadAnnouncement", () => {
6767
expect(
6868
speak([idle(firstRun, "completed"), working(null, firstRun), idle(firstRun, "completed")]),
6969
).toEqual(["Working"]);
70+
// The previous run finished while this client looked idle.
71+
expect(
72+
speak([
73+
idle(firstRun, "completed"),
74+
idle(secondRun, "completed"),
75+
{ ...working(null), runStatus: "completed" },
76+
idle(secondRun, "completed"),
77+
]),
78+
).toEqual(["Working"]);
7079
});
7180

7281
it("announces requests once and resumes activity after them", () => {

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ export function nextThreadAnnouncement(
103103

104104
// Work can stop a moment before the run settles; the ending waits for the run.
105105
const outcome = runOutcomeText(next.runStatus);
106-
if (!previous.outcomePending || outcome === null || next.runId === previous.settledRunId) {
106+
if (!previous.outcomePending) {
107+
// A run that settled unseen is history too, or the next failed send would claim it.
108+
const settledRunId = outcome === null ? previous.settledRunId : next.runId;
109+
return { memory: { ...memory, settledRunId }, announcement: null };
110+
}
111+
if (outcome === null || next.runId === previous.settledRunId) {
107112
return { memory, announcement: null };
108113
}
109114
return {

0 commit comments

Comments
 (0)