Skip to content

Commit b0ed393

Browse files
fix(clients): show Waiting when a turn waits on another thread (pingdotgg#21500)
1 parent a3635a1 commit b0ed393

6 files changed

Lines changed: 91 additions & 11 deletions

File tree

‎apps/mobile/src/features/threads/threadListV2.test.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { presentThreadShell } from "@t3tools/client-runtime/state/models";
22
import * as DateTime from "effect/DateTime";
3+
import * as Schema from "effect/Schema";
34
import { planPinnedMove } from "@t3tools/client-runtime/state/thread-sort";
45
import {
56
createPendingThreadOrder,
@@ -17,6 +18,7 @@ import {
1718
CommandId,
1819
EnvironmentId,
1920
MessageId,
21+
OrchestrationV2ThreadShell,
2022
ProjectId,
2123
ProviderInstanceId,
2224
RunId,
@@ -43,6 +45,7 @@ import {
4345
} from "./threadListV2";
4446

4547
const environmentId = EnvironmentId.make("environment-1");
48+
const decodeThreadShell = Schema.decodeUnknownSync(OrchestrationV2ThreadShell);
4649

4750
function makeThread(
4851
input: Partial<EnvironmentThreadShell> & Pick<EnvironmentThreadShell, "id" | "title">,
@@ -111,6 +114,30 @@ describe("resolveThreadListV2SnoozeMenuSelection", () => {
111114
});
112115

113116
describe("resolveThreadListV2Status", () => {
117+
it("presents decoded thread waits as Waiting while preserving requests and older servers", () => {
118+
const raw = makeRawThreadShell({
119+
status: "running",
120+
activeRunId: RunId.make("run-wait"),
121+
latestRunId: RunId.make("run-wait"),
122+
});
123+
const present = (shell: unknown) => presentThreadShell(environmentId, decodeThreadShell(shell));
124+
125+
expect(resolveThreadListV2Status(present(raw))).toBe("working");
126+
const blocked = present({ ...raw, blockedOnThreadWait: true });
127+
expect(
128+
resolveThreadListV2Status({
129+
...blocked,
130+
hasPendingApprovals: true,
131+
hasPendingUserInput: true,
132+
}),
133+
).toBe("approval");
134+
expect(resolveThreadListV2Status({ ...blocked, hasPendingUserInput: true })).toBe("input");
135+
expect(resolveThreadListV2Status(blocked)).toBe("waiting");
136+
expect(resolveThreadListV2Status(present({ ...raw, blockedOnThreadWait: false }))).toBe(
137+
"working",
138+
);
139+
});
140+
114141
it("distinguishes usage limits from ordinary failures and clears the label after recovery", () => {
115142
const thread = makeThread({
116143
id: ThreadId.make("limited"),

‎apps/mobile/src/features/threads/threadListV2.ts‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,11 @@ export function threadHasUnseenCompletion(
154154
export function resolveThreadListV2Status(
155155
thread: Pick<
156156
EnvironmentThreadShell,
157-
"hasPendingApprovals" | "hasPendingUserInput" | "pendingSubagentRequest" | "runtime"
157+
| "hasPendingApprovals"
158+
| "hasPendingUserInput"
159+
| "pendingSubagentRequest"
160+
| "runtime"
161+
| "blockedOnThreadWait"
158162
>,
159163
): ThreadListV2Status {
160164
if (thread.hasPendingApprovals || thread.pendingSubagentRequest === "approval") {
@@ -163,6 +167,9 @@ export function resolveThreadListV2Status(
163167
if (thread.hasPendingUserInput || thread.pendingSubagentRequest === "user_input") {
164168
return "input";
165169
}
170+
if (thread.runtime?.status === "running" && thread.blockedOnThreadWait === true) {
171+
return "waiting";
172+
}
166173
if (
167174
thread.runtime !== null &&
168175
["preparing", "queued", "starting", "running", "waiting"].includes(thread.runtime.status)

‎apps/web/src/components/Sidebar.logic.test.ts‎

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -935,20 +935,31 @@ describe("resolveSidebarThreadStatus", () => {
935935
const idle = { hasPendingApprovals: false, hasPendingUserInput: false, runtime: null };
936936

937937
it("prioritizes approval over a running runtime", () => {
938-
expect(resolveSidebarThreadStatus({ ...idle, hasPendingApprovals: true, runtime })).toBe(
939-
"approval",
940-
);
938+
expect(
939+
resolveSidebarThreadStatus({
940+
...idle,
941+
hasPendingApprovals: true,
942+
runtime,
943+
blockedOnThreadWait: true,
944+
}),
945+
).toBe("approval");
941946
});
942947

943948
it("prioritizes awaiting input over a running runtime, below approval", () => {
944-
expect(resolveSidebarThreadStatus({ ...idle, hasPendingUserInput: true, runtime })).toBe(
945-
"input",
946-
);
949+
expect(
950+
resolveSidebarThreadStatus({
951+
...idle,
952+
hasPendingUserInput: true,
953+
runtime,
954+
blockedOnThreadWait: true,
955+
}),
956+
).toBe("input");
947957
expect(
948958
resolveSidebarThreadStatus({
949959
...idle,
950960
hasPendingApprovals: true,
951961
hasPendingUserInput: true,
962+
blockedOnThreadWait: true,
952963
runtime,
953964
}),
954965
).toBe("approval");
@@ -960,6 +971,7 @@ describe("resolveSidebarThreadStatus", () => {
960971
resolveSidebarThreadStatus({
961972
...idle,
962973
runtime: { ...runtime, status: "starting" as const },
974+
blockedOnThreadWait: true,
963975
}),
964976
).toBe("working");
965977
});
@@ -1283,6 +1295,7 @@ describe("resolveThreadStatusPill", () => {
12831295
...baseThread,
12841296
hasPendingApprovals: true,
12851297
hasPendingUserInput: true,
1298+
blockedOnThreadWait: true,
12861299
},
12871300
}),
12881301
).toMatchObject({ label: "Pending Approval", pulse: false });
@@ -1294,6 +1307,7 @@ describe("resolveThreadStatusPill", () => {
12941307
thread: {
12951308
...baseThread,
12961309
hasPendingUserInput: true,
1310+
blockedOnThreadWait: true,
12971311
},
12981312
}),
12991313
).toMatchObject({ label: "Awaiting Input", pulse: false });
@@ -1307,6 +1321,22 @@ describe("resolveThreadStatusPill", () => {
13071321
).toMatchObject({ label: "Working", pulse: true });
13081322
});
13091323

1324+
it("shows an active thread wait without a pulse and resumes Working when it ends", () => {
1325+
const blocked = { ...baseThread, blockedOnThreadWait: true };
1326+
expect(resolveSidebarThreadStatus(blocked)).toBe("waiting");
1327+
expect(resolveThreadStatusPill({ thread: blocked })).toMatchObject({
1328+
label: "Waiting",
1329+
pulse: false,
1330+
});
1331+
1332+
const resumed = { ...blocked, blockedOnThreadWait: false };
1333+
expect(resolveSidebarThreadStatus(resumed)).toBe("working");
1334+
expect(resolveThreadStatusPill({ thread: resumed })).toMatchObject({
1335+
label: "Working",
1336+
pulse: true,
1337+
});
1338+
});
1339+
13101340
it("shows waiting for an idle thread with pending background tasks", () => {
13111341
expect(
13121342
resolveThreadStatusPill({

‎apps/web/src/components/Sidebar.logic.ts‎

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ type ThreadStatusInput = Pick<
626626
> & {
627627
lastVisitedAt?: string | null | undefined;
628628
pendingBackgroundTasks?: SidebarThreadSummary["pendingBackgroundTasks"] | undefined;
629+
blockedOnThreadWait?: boolean | undefined;
629630
};
630631

631632
export interface ThreadJumpHintVisibilityController {
@@ -902,7 +903,11 @@ export function shouldRecedeSidebarThread(input: {
902903

903904
type SidebarThreadStatusInput = Pick<
904905
SidebarThreadSummary,
905-
"hasPendingApprovals" | "hasPendingUserInput" | "pendingSubagentRequest" | "runtime"
906+
| "hasPendingApprovals"
907+
| "hasPendingUserInput"
908+
| "pendingSubagentRequest"
909+
| "runtime"
910+
| "blockedOnThreadWait"
906911
>;
907912

908913
export function resolveSidebarThreadStatus(thread: SidebarThreadStatusInput): SidebarThreadStatus {
@@ -912,6 +917,9 @@ export function resolveSidebarThreadStatus(thread: SidebarThreadStatusInput): Si
912917
if (thread.hasPendingUserInput || thread.pendingSubagentRequest === "user_input") {
913918
return "input";
914919
}
920+
if (thread.runtime?.status === "running" && thread.blockedOnThreadWait === true) {
921+
return "waiting";
922+
}
915923
if (
916924
thread.runtime !== null &&
917925
["preparing", "queued", "starting", "running", "waiting"].includes(thread.runtime.status)
@@ -1104,7 +1112,10 @@ export function resolveThreadStatusPill(input: {
11041112
};
11051113
}
11061114

1107-
if (thread.runtime?.status === "running" || thread.runtime?.status === "waiting") {
1115+
if (
1116+
(thread.runtime?.status === "running" && thread.blockedOnThreadWait !== true) ||
1117+
thread.runtime?.status === "waiting"
1118+
) {
11081119
return {
11091120
label: "Working",
11101121
colorClass: "text-sky-600 dark:text-sky-300/80",
@@ -1126,7 +1137,10 @@ export function resolveThreadStatusPill(input: {
11261137
};
11271138
}
11281139

1129-
if (backgroundWorkHoldsCompletion(thread.pendingBackgroundTasks ?? [])) {
1140+
if (
1141+
(thread.runtime?.status === "running" && thread.blockedOnThreadWait === true) ||
1142+
backgroundWorkHoldsCompletion(thread.pendingBackgroundTasks ?? [])
1143+
) {
11301144
return {
11311145
label: "Waiting",
11321146
colorClass: "text-sidebar-muted-foreground",

‎packages/client-runtime/src/state/models.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ export interface EnvironmentThreadShell {
103103
readonly activeProviderThreadId: OrchestrationV2ThreadShell["activeProviderThreadId"];
104104
readonly latestRun: ThreadRunSummary | null;
105105
readonly runtime: ThreadRuntimeSummary | null;
106+
readonly blockedOnThreadWait?: boolean;
106107
readonly latestUserMessageAt: string | null;
107108
readonly latestUserAuthoredMessageAt?: string | null;
108109
readonly hasPendingApprovals: boolean;
@@ -248,6 +249,7 @@ export function presentThreadShell(
248249
activeProviderThreadId: thread.activeProviderThreadId,
249250
latestRun,
250251
runtime,
252+
blockedOnThreadWait: thread.blockedOnThreadWait ?? false,
251253
latestUserMessageAt: nullableIso(thread.latestUserMessageAt),
252254
...(thread.latestUserAuthoredMessageAt === undefined
253255
? {}

‎packages/client-runtime/src/t3ToolSummary.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function readResult(value: unknown, depth = 0): ToolResult {
5959

6060
function readInput(value: unknown): Record<string, unknown> | undefined {
6161
const input = readResult(value).data;
62-
// Cursor retains its MCP args envelope; other adapters retain the arguments directly.
62+
// Historical Cursor items retain the MCP args envelope.
6363
return input && typeof input.toolName === "string" ? asRecord(input.args) : input;
6464
}
6565

0 commit comments

Comments
 (0)