From 5ecf807001c1f6239d50446bb7b9509e43fb8fc0 Mon Sep 17 00:00:00 2001 From: Theo Browne Date: Tue, 21 Jul 2026 23:25:49 -0700 Subject: [PATCH] Show working status for new threads --- apps/web/src/components/Sidebar.logic.test.ts | 53 +++++++++++++++++++ apps/web/src/components/Sidebar.logic.ts | 29 +++++++++- 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/apps/web/src/components/Sidebar.logic.test.ts b/apps/web/src/components/Sidebar.logic.test.ts index a9b32a887c..f16b16daef 100644 --- a/apps/web/src/components/Sidebar.logic.test.ts +++ b/apps/web/src/components/Sidebar.logic.test.ts @@ -170,6 +170,7 @@ describe("hasUnseenCompletion", () => { hasPendingUserInput: false, interactionMode: "default", latestTurn: makeLatestTurn(), + latestUserMessageAt: null, lastVisitedAt: "2026-03-09T10:04:00.000Z", session: null, }), @@ -184,6 +185,7 @@ describe("hasUnseenCompletion", () => { hasPendingUserInput: false, interactionMode: "default", latestTurn: makeLatestTurn(), + latestUserMessageAt: null, lastVisitedAt: undefined, session: null, }), @@ -737,6 +739,7 @@ describe("resolveThreadStatusPill", () => { hasPendingUserInput: false, interactionMode: "plan" as const, latestTurn: null, + latestUserMessageAt: null, lastVisitedAt: undefined, session: { threadId: ThreadId.make("thread-1"), @@ -781,6 +784,56 @@ describe("resolveThreadStatusPill", () => { ).toMatchObject({ label: "Working", pulse: true }); }); + it("shows working while a new thread turn is waiting for its first session update", () => { + expect( + resolveThreadStatusPill({ + thread: { + ...baseThread, + latestUserMessageAt: "2026-03-09T10:00:01.000Z", + session: null, + }, + }), + ).toMatchObject({ label: "Working", pulse: true }); + }); + + it("keeps showing working through a ready session before the turn starts", () => { + expect( + resolveThreadStatusPill({ + thread: { + ...baseThread, + latestUserMessageAt: "2026-03-09T10:00:01.000Z", + session: { + ...baseThread.session, + status: "ready", + activeTurnId: null, + updatedAt: "2026-03-09T10:00:02.000Z", + }, + }, + }), + ).toMatchObject({ label: "Working", pulse: true }); + }); + + it("does not show stale pending work after the turn acknowledges the message", () => { + expect( + resolveThreadStatusPill({ + thread: { + ...baseThread, + latestUserMessageAt: "2026-03-09T10:00:01.000Z", + latestTurn: { + ...makeLatestTurn(), + requestedAt: "2026-03-09T10:00:02.000Z", + }, + session: { + ...baseThread.session, + status: "ready", + activeTurnId: null, + updatedAt: "2026-03-09T10:05:00.000Z", + }, + }, + }), + ).toBeNull(); + }); + it("shows plan ready when a settled plan turn has a proposed plan ready for follow-up", () => { expect( resolveThreadStatusPill({ diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.ts index b8ae19c3e5..5c1a0d852d 100644 --- a/apps/web/src/components/Sidebar.logic.ts +++ b/apps/web/src/components/Sidebar.logic.ts @@ -115,6 +115,7 @@ type ThreadStatusInput = Pick< | "hasPendingUserInput" | "interactionMode" | "latestTurn" + | "latestUserMessageAt" | "session" > & { lastVisitedAt?: string | undefined; @@ -223,6 +224,32 @@ export function hasUnseenCompletion(thread: ThreadStatusInput): boolean { return completedAt > lastVisitedAt; } +function hasPendingTurnStart(thread: ThreadStatusInput): boolean { + if (!thread.latestUserMessageAt) return false; + const latestUserMessageAt = Date.parse(thread.latestUserMessageAt); + if (Number.isNaN(latestUserMessageAt)) return false; + + const latestTurnRequestedAt = thread.latestTurn + ? Date.parse(thread.latestTurn.requestedAt) + : Number.NaN; + if (!Number.isNaN(latestTurnRequestedAt) && latestTurnRequestedAt >= latestUserMessageAt) { + return false; + } + + // Session bootstrap may pass through starting/ready before the provider + // creates the turn; only terminal states can acknowledge a failed start. + const session = thread.session; + if ( + !session || + (session.status !== "error" && session.status !== "interrupted" && session.status !== "stopped") + ) { + return true; + } + + const sessionUpdatedAt = Date.parse(session.updatedAt); + return Number.isNaN(sessionUpdatedAt) || sessionUpdatedAt < latestUserMessageAt; +} + export function shouldClearThreadSelectionOnMouseDown(target: HTMLElement | null): boolean { if (target === null) return true; return !target.closest(THREAD_SELECTION_SAFE_SELECTOR); @@ -505,7 +532,7 @@ export function resolveThreadStatusPill(input: { }; } - if (thread.session?.status === "running") { + if (thread.session?.status === "running" || hasPendingTurnStart(thread)) { return { label: "Working", colorClass: "text-sky-600 dark:text-sky-300/80",