@devries-cameron20 / t3code Mirror · read-only / commits / c8db8be305
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 16:00 UTC

fix(web): a run waiting on foreground subagents says so instead of Thinking (#36334)

Julius Marminge committed Nov 13, 2026 at 14:45 UTC c8db8be305056bda6f82f96a43c65db178e62d36
5 files changed +161 -5
apps/mobile/src/lib/threadActivity.ts
+19 -2
@@ -6,7 +6,10 @@ import { linkRequestTargetName } from "@t3tools/client-runtime/link-request";
6 import { turnItemIsWorkspacePreparation } from "@t3tools/client-runtime/state/turn-item-presentation";
7 import type { ThreadCheckpointSummary } from "@t3tools/client-runtime/state/thread-checkpoints";
8 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";
13 import { extractToolActivityPresentation } from "@t3tools/client-runtime/work-log/tool-presentation";
14 import {
15 turnItemDetailRevision,
@@ -1817,11 +1820,12 @@ export function deriveThreadFeedPresentation(
1820 row.activities[0]?.projectedItem.item.status === "running"),
1821 )
1822 ) {
1823 + const waitingOn = activeRunId === null ? 0 : runningSubagentsAtRunTail(feed, activeRunId);
1824 result.push(
1825 thinkingRow(
1826 activeWorkStartedAt,
1827 activeRunId,
1824 - zen ? liveAnswerPreview(feed) : null,
1828 + waitingOn > 0 ? waitingOnSubagentsLabel(waitingOn) : zen ? liveAnswerPreview(feed) : null,
1829 latestRun?.providerStartingLabel,
1830 ),
1831 );
@@ -1928,6 +1932,19 @@ function isWorkLogFeedRow(row: ThreadFeedEntry | undefined): boolean {
1932
1933 const LIVE_ACTIVITY_ROW_ID = "live-activity-row";
1934
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 +
1948 function thinkingRow(
1949 createdAt: string,
1950 runId: RunId | null,
apps/web/src/components/chat/MessagesTimeline.logic.test.ts
+107
@@ -4888,6 +4888,113 @@ describe("live subagents after their parent turn settles", () => {
4888 });
4889 });
4890
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 +
4998 describe("subagent continued by a later turn", () => {
4999 const threadId = ThreadId.make("parent-thread");
5000 const run1 = RunId.make("run-1");
apps/web/src/components/chat/MessagesTimeline.logic.ts
+30 -2
@@ -1,7 +1,10 @@
1 import * as DateTime from "effect/DateTime";
2 import { worktreeSetupAgentStarted } from "@t3tools/client-runtime/worktree-setup";
3 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";
8 import * as Equal from "effect/Equal";
9 import { shallow } from "zustand/vanilla/shallow";
10 import { claudeResumeCompactionAge } from "@t3tools/shared/claudeCompaction";
@@ -532,6 +535,8 @@ type MessagesTimelineRowContent =
535 kind: "thinking";
536 id: string;
537 createdAt: string | null;
538 + /** Replaces "Thinking" while the run has done nothing since launching children that still run. */
539 + label?: string;
540 groupId?: string;
541 expanded?: boolean;
542 }
@@ -1451,6 +1456,19 @@ export function liveAnswerPreview(entries: ReadonlyArray<TimelineEntry>): string
1456 return null;
1457 }
1458
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 +
1472 function timelineRowEntries(
1473 input: Pick<
1474 MessagesTimelineRowsInput,
@@ -2316,10 +2334,15 @@ export function deriveMessagesTimelineRows(input: {
2334 }
2335 nextRows.push(...viewedImagesRows(groupId, failedGroupAnchor.createdAt, groupedEntries));
2336 } else {
2337 + const waitingOn =
2338 + unsettledRunId === null
2339 + ? 0
2340 + : runningSubagentsAtRunTail(input.timelineEntries, unsettledRunId);
2341 nextRows.push({
2342 kind: "thinking",
2343 id: LIVE_ACTIVITY_ROW_ID,
2344 createdAt: input.activeTurnStartedAt ?? null,
2345 + ...(waitingOn > 0 ? { label: waitingOnSubagentsLabel(waitingOn) } : {}),
2346 });
2347 }
2348 }
@@ -2679,7 +2702,12 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
2702 );
2703 case "thinking": {
2704 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 + );
2711 }
2712 case "worktree-setup":
2713 return a.snapshot === (b as typeof a).snapshot;
apps/web/src/components/chat/TimelineWorkGroupRows.tsx
+1 -1
@@ -435,7 +435,7 @@ export function ThinkingTimelineRow({ row }: { row: Extract<TimelineRow, { kind:
435 const live = ctx.pendingApprovals.size === 0;
436 const activity = (
437 <LiveActivityRow
438 - label={providerStartingLabel ?? liveAnswerPreview ?? "Thinking"}
438 + label={providerStartingLabel ?? row.label ?? liveAnswerPreview ?? "Thinking"}
439 iconName="brain"
440 active={live}
441 shimmer={live}
packages/client-runtime/src/state/subagentRuntime.ts
+4
@@ -97,6 +97,10 @@ export function isLiveSubagentTurnItem(item: OrchestrationV2TurnItem): boolean {
97 return item.type === "subagent" && isOrchestrationV2WorkActive(item.status);
98 }
99
100 +export function waitingOnSubagentsLabel(count: number): string {
101 + return count === 1 ? "Waiting on a subagent" : `Waiting on ${count} subagents`;
102 +}
103 +
104 export interface SubagentWorkflowGroup {
105 readonly workflow: RuntimeSubagent;
106 readonly phases: ReadonlyArray<{