Skip to content

Commit 4bac132

Browse files
PR Batch Testerclaude
andcommitted
fix(web): a run starting while the thread looks idle is the next turn
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 25dd632 commit 4bac132

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,30 @@ describe("nextThreadAnnouncement", () => {
8383
).toEqual(["Working"]);
8484
});
8585

86+
it("treats a run that starts while the thread looks idle as the next turn", () => {
87+
const thirdRun = RunId.make("run-3");
88+
// A resume or a turn started from another device.
89+
expect(
90+
speak([
91+
idle(firstRun, "completed"),
92+
idle(secondRun, "starting"),
93+
busy("working", secondRun, "running"),
94+
idle(secondRun, "completed"),
95+
]),
96+
).toEqual(["Working", "Done"]);
97+
// A queued message waiting to start after the last turn.
98+
expect(
99+
speak([
100+
idle(firstRun, "completed"),
101+
busy(),
102+
idle(thirdRun, "queued"),
103+
idle(thirdRun, "starting"),
104+
busy("working", thirdRun, "running"),
105+
idle(thirdRun, "completed"),
106+
]),
107+
).toEqual(["Working", "Working", "Done"]);
108+
});
109+
86110
it("stays silent when a thread opens mid-turn or after one", () => {
87111
expect(speak([idle(firstRun, "completed"), idle(firstRun, "completed")])).toEqual([]);
88112
expect(speak([busy(), busy()])).toEqual([]);

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ const ACTIVE_RUN_STATUSES: ReadonlySet<OrchestrationV2RunStatus | null> = new Se
2828
"waiting",
2929
]);
3030

31+
const STARTING_RUN_STATUSES: ReadonlySet<OrchestrationV2RunStatus | null> = new Set([
32+
"queued",
33+
"preparing",
34+
"starting",
35+
]);
36+
3137
function runOutcomeText(status: OrchestrationV2RunStatus | null): string | null {
3238
switch (status) {
3339
case "completed":
@@ -52,7 +58,10 @@ export function nextThreadAnnouncement(
5258
next: ThreadActivitySnapshot,
5359
): { readonly memory: ThreadAnnouncementMemory; readonly announcement: string | null } {
5460
const idle = next.status === "idle";
55-
const idleRunId = idle ? next.runId : (previous?.idleRunId ?? null);
61+
// A run still starting up while the thread looks idle (a queued message,
62+
// a resume) is the next turn's, not a leftover from the last one.
63+
const idleRunId =
64+
idle && !STARTING_RUN_STATUSES.has(next.runStatus) ? next.runId : (previous?.idleRunId ?? null);
5665
// A run doing new work; the run left over from the last turn doesn't count.
5766
const newRunId =
5867
!idle && ACTIVE_RUN_STATUSES.has(next.runStatus) && next.runId !== idleRunId

0 commit comments

Comments
 (0)