Skip to content

Commit c8db8be

Browse files
fix(web): a run waiting on foreground subagents says so instead of Thinking (#36334)
1 parent 5f95653 commit c8db8be

5 files changed

Lines changed: 161 additions & 5 deletions

File tree

‎apps/mobile/src/lib/threadActivity.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import { linkRequestTargetName } from "@t3tools/client-runtime/link-request";
66
import { turnItemIsWorkspacePreparation } from "@t3tools/client-runtime/state/turn-item-presentation";
77
import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints";
88
import { formatSubagentDisplayTitle } from "@t3tools/client-runtime/state/subagent-display";
9-
import { isLiveSubagentTurnItem } from "@t3tools/client-runtime/state/subagentRuntime";
9+
import {
10+
isLiveSubagentTurnItem,
11+
waitingOnSubagentsLabel,
12+
} from "@t3tools/client-runtime/state/subagentRuntime";
1013
import { extractToolActivityPresentation } from "@t3tools/client-runtime/work-log/tool-presentation";
1114
import {
1215
turnItemDetailRevision,
@@ -1817,11 +1820,12 @@ export function deriveThreadFeedPresentation(
18171820
row.activities[0]?.projectedItem.item.status === "running"),
18181821
)
18191822
) {
1823+
const waitingOn = activeRunId === null ? 0 : runningSubagentsAtRunTail(feed, activeRunId);
18201824
result.push(
18211825
thinkingRow(
18221826
activeWorkStartedAt,
18231827
activeRunId,
1824-
zen ? liveAnswerPreview(feed) : null,
1828+
waitingOn > 0 ? waitingOnSubagentsLabel(waitingOn) : zen ? liveAnswerPreview(feed) : null,
18251829
latestRun?.providerStartingLabel,
18261830
),
18271831
);
@@ -1928,6 +1932,19 @@ function isWorkLogFeedRow(row: ThreadFeedEntry | undefined): boolean {
19281932

19291933
const LIVE_ACTIVITY_ROW_ID = "live-activity-row";
19301934

1935+
/** Reads the feed before tool visibility filters it, so hidden newer parent work still counts. */
1936+
function runningSubagentsAtRunTail(feed: ReadonlyArray<ThreadFeedEntry>, runId: RunId): number {
1937+
let running = 0;
1938+
for (let index = feed.length - 1; index >= 0; index -= 1) {
1939+
const entry = feed[index]!;
1940+
if (entry.type !== "activity-group" || entry.runId !== runId) break;
1941+
const items = entry.activities.map((activity) => activity.projectedItem.item);
1942+
if (items.some((item) => item.type !== "subagent")) break;
1943+
running += items.filter(isLiveSubagentTurnItem).length;
1944+
}
1945+
return running;
1946+
}
1947+
19311948
function thinkingRow(
19321949
createdAt: string,
19331950
runId: RunId | null,

‎apps/web/src/components/chat/MessagesTimeline.logic.test.ts‎

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4888,6 +4888,113 @@ describe("live subagents after their parent turn settles", () => {
48884888
});
48894889
});
48904890

4891+
describe("parent run waiting on foreground subagents", () => {
4892+
const runId = RunId.make("parent-run");
4893+
const threadId = ThreadId.make("parent-thread");
4894+
const at = (second: number) =>
4895+
DateTime.makeUnsafe(`2026-10-06T10:00:${String(second).padStart(2, "0")}Z`);
4896+
const base = (id: string, second: number) => ({
4897+
id: TurnItemId.make(id),
4898+
threadId,
4899+
runId,
4900+
nodeId: null,
4901+
providerThreadId: null,
4902+
providerTurnId: ProviderTurnId.make("parent-provider-turn"),
4903+
nativeItemRef: null,
4904+
parentItemId: null,
4905+
ordinal: second,
4906+
title: null,
4907+
startedAt: at(second),
4908+
completedAt: at(second),
4909+
updatedAt: at(second),
4910+
});
4911+
const child = (id: string, second: number): OrchestrationV2TurnItem => ({
4912+
...base(id, second),
4913+
status: "running",
4914+
completedAt: null,
4915+
type: "subagent",
4916+
subagentId: NodeId.make(id),
4917+
origin: "provider_native",
4918+
driver: ProviderDriverKind.make("opencode"),
4919+
providerInstanceId: ProviderInstanceId.make("opencode"),
4920+
childThreadId: null,
4921+
prompt: `Read ${id}`,
4922+
result: null,
4923+
});
4924+
4925+
const liveRow = (later: ReadonlyArray<OrchestrationV2TurnItem>, toolCallVisibility?: "hideAll") =>
4926+
deriveMessagesTimelineRows({
4927+
timelineEntries: deriveTimelineEntriesFromVisibleTurnItems({
4928+
visibleTurnItems: (
4929+
[
4930+
{
4931+
...base("user", 0),
4932+
status: "completed",
4933+
type: "user_message",
4934+
messageId: MessageId.make("user"),
4935+
createdBy: "user",
4936+
creationSource: "web",
4937+
inputIntent: "turn_start",
4938+
text: "Research these in parallel",
4939+
attachments: [],
4940+
},
4941+
{
4942+
...base("assistant", 1),
4943+
status: "completed",
4944+
type: "assistant_message",
4945+
messageId: MessageId.make("assistant"),
4946+
text: "Dispatching three subagents.",
4947+
streaming: false,
4948+
},
4949+
child("a", 2),
4950+
{ ...child("b", 3), status: "completed", completedAt: at(3) },
4951+
child("c", 4),
4952+
...later,
4953+
] satisfies OrchestrationV2TurnItem[]
4954+
).map((item) => ({
4955+
position: item.ordinal,
4956+
visibility: "local" as const,
4957+
sourceThreadId: threadId,
4958+
sourceItemId: item.id,
4959+
item,
4960+
})),
4961+
optimisticMessages: [],
4962+
}),
4963+
latestRun: {
4964+
runId,
4965+
status: "running",
4966+
startedAt: DateTime.formatIso(at(0)),
4967+
completedAt: null,
4968+
},
4969+
isWorking: true,
4970+
activeTurnStartedAt: DateTime.formatIso(at(0)),
4971+
turnDiffSummaries: [],
4972+
supportsConversationRollback: false,
4973+
...(toolCallVisibility ? { toolCallVisibility } : {}),
4974+
}).find((row) => row.id === "live-activity-row");
4975+
const thinking = {
4976+
kind: "thinking",
4977+
id: "live-activity-row",
4978+
createdAt: DateTime.formatIso(at(0)),
4979+
};
4980+
4981+
it("names the running children while the open run has done nothing since launching them", () => {
4982+
expect(liveRow([])).toEqual({ ...thinking, label: "Waiting on 2 subagents" });
4983+
expect(liveRow([], "hideAll")).toEqual({ ...thinking, label: "Waiting on 2 subagents" });
4984+
});
4985+
4986+
it("keeps Thinking when a hidden newer parent command follows the children", () => {
4987+
const command: OrchestrationV2TurnItem = {
4988+
...base("command", 5),
4989+
status: "running",
4990+
completedAt: null,
4991+
type: "command_execution",
4992+
input: "sleep 5",
4993+
};
4994+
expect(liveRow([command], "hideAll")).toEqual(thinking);
4995+
});
4996+
});
4997+
48914998
describe("subagent continued by a later turn", () => {
48924999
const threadId = ThreadId.make("parent-thread");
48935000
const run1 = RunId.make("run-1");

‎apps/web/src/components/chat/MessagesTimeline.logic.ts‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import * as DateTime from "effect/DateTime";
22
import { worktreeSetupAgentStarted } from "@t3tools/client-runtime/worktree-setup";
33
import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message";
4-
import { isLiveSubagentTurnItem } from "@t3tools/client-runtime/state/subagentRuntime";
4+
import {
5+
isLiveSubagentTurnItem,
6+
waitingOnSubagentsLabel,
7+
} from "@t3tools/client-runtime/state/subagentRuntime";
58
import * as Equal from "effect/Equal";
69
import { shallow } from "zustand/vanilla/shallow";
710
import { claudeResumeCompactionAge } from "@t3tools/shared/claudeCompaction";
@@ -532,6 +535,8 @@ type MessagesTimelineRowContent =
532535
kind: "thinking";
533536
id: string;
534537
createdAt: string | null;
538+
/** Replaces "Thinking" while the run has done nothing since launching children that still run. */
539+
label?: string;
535540
groupId?: string;
536541
expanded?: boolean;
537542
}
@@ -1451,6 +1456,19 @@ export function liveAnswerPreview(entries: ReadonlyArray<TimelineEntry>): string
14511456
return null;
14521457
}
14531458

1459+
/** Reads entries before tool visibility filters them, so hidden newer parent work still counts. */
1460+
function runningSubagentsAtRunTail(entries: ReadonlyArray<TimelineEntry>, runId: RunId): number {
1461+
let running = 0;
1462+
for (let index = entries.length - 1; index >= 0; index -= 1) {
1463+
const entry = entries[index]!;
1464+
if (entry.kind !== "event") break;
1465+
const { item } = entry.projectedItem;
1466+
if (item.type !== "subagent" || item.runId !== runId) break;
1467+
if (isLiveSubagentTurnItem(item)) running += 1;
1468+
}
1469+
return running;
1470+
}
1471+
14541472
function timelineRowEntries(
14551473
input: Pick<
14561474
MessagesTimelineRowsInput,
@@ -2316,10 +2334,15 @@ export function deriveMessagesTimelineRows(input: {
23162334
}
23172335
nextRows.push(...viewedImagesRows(groupId, failedGroupAnchor.createdAt, groupedEntries));
23182336
} else {
2337+
const waitingOn =
2338+
unsettledRunId === null
2339+
? 0
2340+
: runningSubagentsAtRunTail(input.timelineEntries, unsettledRunId);
23192341
nextRows.push({
23202342
kind: "thinking",
23212343
id: LIVE_ACTIVITY_ROW_ID,
23222344
createdAt: input.activeTurnStartedAt ?? null,
2345+
...(waitingOn > 0 ? { label: waitingOnSubagentsLabel(waitingOn) } : {}),
23232346
});
23242347
}
23252348
}
@@ -2679,7 +2702,12 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
26792702
);
26802703
case "thinking": {
26812704
const bt = b as typeof a;
2682-
return a.createdAt === bt.createdAt && a.groupId === bt.groupId && a.expanded === bt.expanded;
2705+
return (
2706+
a.createdAt === bt.createdAt &&
2707+
a.groupId === bt.groupId &&
2708+
a.expanded === bt.expanded &&
2709+
a.label === bt.label
2710+
);
26832711
}
26842712
case "worktree-setup":
26852713
return a.snapshot === (b as typeof a).snapshot;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ export function ThinkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind:
435435
const live = ctx.pendingApprovals.size === 0;
436436
const activity = (
437437
<LiveActivityRow
438-
label={providerStartingLabel ?? liveAnswerPreview ?? "Thinking"}
438+
label={providerStartingLabel ?? row.label ?? liveAnswerPreview ?? "Thinking"}
439439
iconName="brain"
440440
active={live}
441441
shimmer={live}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ export function isLiveSubagentTurnItem(item: OrchestrationV2TurnItem): boolean {
9797
return item.type === "subagent" && isOrchestrationV2WorkActive(item.status);
9898
}
9999

100+
export function waitingOnSubagentsLabel(count: number): string {
101+
return count === 1 ? "Waiting on a subagent" : `Waiting on ${count} subagents`;
102+
}
103+
100104
export interface SubagentWorkflowGroup {
101105
readonly workflow: RuntimeSubagent;
102106
readonly phases: ReadonlyArray<{

0 commit comments

Comments
 (0)