TypeScript
fix(clients): show Waiting when a turn waits on another thread (#21500)
Julius Marmingeb0ed393c6c7c
diff --git a/apps/mobile/src/features/threads/threadListV2.test.ts b/apps/mobile/src/features/threads/threadListV2.test.tsindex cceb2e5f008..73c4faa7b71 100644--- a/apps/mobile/src/features/threads/threadListV2.test.ts+++ b/apps/mobile/src/features/threads/threadListV2.test.ts@@ -1,5 +1,6 @@import { presentThreadShell } from "@t3tools/client-runtime/state/models";import * as DateTime from "effect/DateTime";+import * as Schema from "effect/Schema";import { planPinnedMove } from "@t3tools/client-runtime/state/thread-sort";import {createPendingThreadOrder,@@ -17,6 +18,7 @@ import {CommandId,EnvironmentId,MessageId,+ OrchestrationV2ThreadShell,ProjectId,ProviderInstanceId,RunId,@@ -43,6 +45,7 @@ import {} from "./threadListV2";const environmentId = EnvironmentId.make("environment-1");+const decodeThreadShell = Schema.decodeUnknownSync(OrchestrationV2ThreadShell);function makeThread(input: Partial<EnvironmentThreadShell> & Pick<EnvironmentThreadShell, "id" | "title">,@@ -111,6 +114,30 @@ describe("resolveThreadListV2SnoozeMenuSelection", () => {});describe("resolveThreadListV2Status", () => {+ it("presents decoded thread waits as Waiting while preserving requests and older servers", () => {+ const raw = makeRawThreadShell({+ status: "running",+ activeRunId: RunId.make("run-wait"),+ latestRunId: RunId.make("run-wait"),+ });+ const present = (shell: unknown) => presentThreadShell(environmentId, decodeThreadShell(shell));++ expect(resolveThreadListV2Status(present(raw))).toBe("working");+ const blocked = present({ ...raw, blockedOnThreadWait: true });+ expect(+ resolveThreadListV2Status({+ ...blocked,+ hasPendingApprovals: true,+ hasPendingUserInput: true,+ }),+ ).toBe("approval");+ expect(resolveThreadListV2Status({ ...blocked, hasPendingUserInput: true })).toBe("input");+ expect(resolveThreadListV2Status(blocked)).toBe("waiting");+ expect(resolveThreadListV2Status(present({ ...raw, blockedOnThreadWait: false }))).toBe(+ "working",+ );+ });+it("distinguishes usage limits from ordinary failures and clears the label after recovery", () => {const thread = makeThread({id: ThreadId.make("limited"),diff --git a/apps/mobile/src/features/threads/threadListV2.ts b/apps/mobile/src/features/threads/threadListV2.tsindex 03a409e65ad..360fbe18f09 100644--- a/apps/mobile/src/features/threads/threadListV2.ts+++ b/apps/mobile/src/features/threads/threadListV2.ts@@ -154,7 +154,11 @@ export function threadHasUnseenCompletion(export function resolveThreadListV2Status(thread: Pick<EnvironmentThreadShell,- "hasPendingApprovals" | "hasPendingUserInput" | "pendingSubagentRequest" | "runtime"+ | "hasPendingApprovals"+ | "hasPendingUserInput"+ | "pendingSubagentRequest"+ | "runtime"+ | "blockedOnThreadWait">,): ThreadListV2Status {if (thread.hasPendingApprovals || thread.pendingSubagentRequest === "approval") {@@ -163,6 +167,9 @@ export function resolveThreadListV2Status(if (thread.hasPendingUserInput || thread.pendingSubagentRequest === "user_input") {return "input";}+ if (thread.runtime?.status === "running" && thread.blockedOnThreadWait === true) {+ return "waiting";+ }if (thread.runtime !== null &&["preparing", "queued", "starting", "running", "waiting"].includes(thread.runtime.status)diff --git a/apps/web/src/components/Sidebar.logic.test.ts b/apps/web/src/components/Sidebar.logic.test.tsindex 59d524e2540..bc093cb7547 100644--- a/apps/web/src/components/Sidebar.logic.test.ts+++ b/apps/web/src/components/Sidebar.logic.test.ts@@ -935,20 +935,31 @@ describe("resolveSidebarThreadStatus", () => {const idle = { hasPendingApprovals: false, hasPendingUserInput: false, runtime: null };it("prioritizes approval over a running runtime", () => {- expect(resolveSidebarThreadStatus({ ...idle, hasPendingApprovals: true, runtime })).toBe(- "approval",- );+ expect(+ resolveSidebarThreadStatus({+ ...idle,+ hasPendingApprovals: true,+ runtime,+ blockedOnThreadWait: true,+ }),+ ).toBe("approval");});it("prioritizes awaiting input over a running runtime, below approval", () => {- expect(resolveSidebarThreadStatus({ ...idle, hasPendingUserInput: true, runtime })).toBe(- "input",- );+ expect(+ resolveSidebarThreadStatus({+ ...idle,+ hasPendingUserInput: true,+ runtime,+ blockedOnThreadWait: true,+ }),+ ).toBe("input");expect(resolveSidebarThreadStatus({...idle,hasPendingApprovals: true,hasPendingUserInput: true,+ blockedOnThreadWait: true,runtime,}),).toBe("approval");@@ -960,6 +971,7 @@ describe("resolveSidebarThreadStatus", () => {resolveSidebarThreadStatus({...idle,runtime: { ...runtime, status: "starting" as const },+ blockedOnThreadWait: true,}),).toBe("working");});@@ -1283,6 +1295,7 @@ describe("resolveThreadStatusPill", () => {...baseThread,hasPendingApprovals: true,hasPendingUserInput: true,+ blockedOnThreadWait: true,},}),).toMatchObject({ label: "Pending Approval", pulse: false });@@ -1294,6 +1307,7 @@ describe("resolveThreadStatusPill", () => {thread: {...baseThread,hasPendingUserInput: true,+ blockedOnThreadWait: true,},}),).toMatchObject({ label: "Awaiting Input", pulse: false });@@ -1307,6 +1321,22 @@ describe("resolveThreadStatusPill", () => {).toMatchObject({ label: "Working", pulse: true });});+ it("shows an active thread wait without a pulse and resumes Working when it ends", () => {+ const blocked = { ...baseThread, blockedOnThreadWait: true };+ expect(resolveSidebarThreadStatus(blocked)).toBe("waiting");+ expect(resolveThreadStatusPill({ thread: blocked })).toMatchObject({+ label: "Waiting",+ pulse: false,+ });++ const resumed = { ...blocked, blockedOnThreadWait: false };+ expect(resolveSidebarThreadStatus(resumed)).toBe("working");+ expect(resolveThreadStatusPill({ thread: resumed })).toMatchObject({+ label: "Working",+ pulse: true,+ });+ });+it("shows waiting for an idle thread with pending background tasks", () => {expect(resolveThreadStatusPill({diff --git a/apps/web/src/components/Sidebar.logic.ts b/apps/web/src/components/Sidebar.logic.tsindex 6e80cfcd730..f802ce9c5df 100644--- a/apps/web/src/components/Sidebar.logic.ts+++ b/apps/web/src/components/Sidebar.logic.ts@@ -626,6 +626,7 @@ type ThreadStatusInput = Pick<> & {lastVisitedAt?: string | null | undefined;pendingBackgroundTasks?: SidebarThreadSummary["pendingBackgroundTasks"] | undefined;+ blockedOnThreadWait?: boolean | undefined;};export interface ThreadJumpHintVisibilityController {@@ -902,7 +903,11 @@ export function shouldRecedeSidebarThread(input: {type SidebarThreadStatusInput = Pick<SidebarThreadSummary,- "hasPendingApprovals" | "hasPendingUserInput" | "pendingSubagentRequest" | "runtime"+ | "hasPendingApprovals"+ | "hasPendingUserInput"+ | "pendingSubagentRequest"+ | "runtime"+ | "blockedOnThreadWait">;export function resolveSidebarThreadStatus(thread: SidebarThreadStatusInput): SidebarThreadStatus {@@ -912,6 +917,9 @@ export function resolveSidebarThreadStatus(thread: SidebarThreadStatusInput): Siif (thread.hasPendingUserInput || thread.pendingSubagentRequest === "user_input") {return "input";}+ if (thread.runtime?.status === "running" && thread.blockedOnThreadWait === true) {+ return "waiting";+ }if (thread.runtime !== null &&["preparing", "queued", "starting", "running", "waiting"].includes(thread.runtime.status)@@ -1104,7 +1112,10 @@ export function resolveThreadStatusPill(input: {};}- if (thread.runtime?.status === "running" || thread.runtime?.status === "waiting") {+ if (+ (thread.runtime?.status === "running" && thread.blockedOnThreadWait !== true) ||+ thread.runtime?.status === "waiting"+ ) {return {label: "Working",colorClass: "text-sky-600 dark:text-sky-300/80",@@ -1126,7 +1137,10 @@ export function resolveThreadStatusPill(input: {};}- if (backgroundWorkHoldsCompletion(thread.pendingBackgroundTasks ?? [])) {+ if (+ (thread.runtime?.status === "running" && thread.blockedOnThreadWait === true) ||+ backgroundWorkHoldsCompletion(thread.pendingBackgroundTasks ?? [])+ ) {return {label: "Waiting",colorClass: "text-sidebar-muted-foreground",diff --git a/packages/client-runtime/src/state/models.ts b/packages/client-runtime/src/state/models.tsindex 91fe95b8585..7fd2bfb39fb 100644--- a/packages/client-runtime/src/state/models.ts+++ b/packages/client-runtime/src/state/models.ts@@ -103,6 +103,7 @@ export interface EnvironmentThreadShell {readonly activeProviderThreadId: OrchestrationV2ThreadShell["activeProviderThreadId"];readonly latestRun: ThreadRunSummary | null;readonly runtime: ThreadRuntimeSummary | null;+ readonly blockedOnThreadWait?: boolean;readonly latestUserMessageAt: string | null;readonly latestUserAuthoredMessageAt?: string | null;readonly hasPendingApprovals: boolean;@@ -248,6 +249,7 @@ export function presentThreadShell(activeProviderThreadId: thread.activeProviderThreadId,latestRun,runtime,+ blockedOnThreadWait: thread.blockedOnThreadWait ?? false,latestUserMessageAt: nullableIso(thread.latestUserMessageAt),...(thread.latestUserAuthoredMessageAt === undefined? {}diff --git a/packages/client-runtime/src/t3ToolSummary.ts b/packages/client-runtime/src/t3ToolSummary.tsindex 668078191c4..df655c1d6c2 100644--- a/packages/client-runtime/src/t3ToolSummary.ts+++ b/packages/client-runtime/src/t3ToolSummary.ts@@ -59,7 +59,7 @@ function readResult(value: unknown, depth = 0): ToolResult {function readInput(value: unknown): Record<string, unknown> | undefined {const input = readResult(value).data;- // Cursor retains its MCP args envelope; other adapters retain the arguments directly.+ // Historical Cursor items retain the MCP args envelope.return input && typeof input.toolName === "string" ? asRecord(input.args) : input;}