diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts index 09cbfe4e7775a..d7ade5b63fd4f 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.test.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.test.ts @@ -4668,6 +4668,83 @@ describe("live subagents after their parent turn settles", () => { }); expect(rows.map((row) => row.id)).toEqual([`attempt-fold:${attempt.id}`, "child"]); }); + + const openTurnRows = (after: ReadonlyArray) => + deriveMessagesTimelineRows({ + timelineEntries: deriveTimelineEntriesFromVisibleTurnItems({ + visibleTurnItems: ( + [ + { + ...base("user", 0), + status: "completed", + type: "user_message", + messageId: MessageId.make("user"), + createdBy: "user", + creationSource: "web", + inputIntent: "turn_start", + text: "Run three foreground subagents", + attachments: [], + }, + child("child", 3, "running", "provider_native"), + ...after, + ] satisfies OrchestrationV2TurnItem[] + ).map(projected), + optimisticMessages: [], + }), + latestRun: { + runId, + status: "running", + startedAt: DateTime.formatIso(at(0)), + completedAt: null, + }, + isWorking: true, + activeTurnStartedAt: DateTime.formatIso(at(0)), + turnDiffSummaries: [], + supportsConversationRollback: false, + }); + + const assistant = (streaming: boolean): OrchestrationV2TurnItem => ({ + ...base("assistant", 4), + status: streaming ? "running" : "completed", + type: "assistant_message", + messageId: MessageId.make("assistant"), + text: "Started three subagents; waiting for their results.", + streaming, + }); + + it.each([ + { name: "nothing", after: [] }, + { name: "the parent's finished launch message", after: [assistant(false)] }, + ])("shows a waiting row when $name follows the running child", ({ after }) => { + const rows = openTurnRows(after); + expect(rows.find((row) => row.id === "child")).toBeDefined(); + expect(rows.at(-1)).toMatchObject({ kind: "thinking", waitingOnSubagents: 1 }); + }); + + it.each([ + { + name: "a steer", + item: { + ...base("steer", 4), + status: "completed", + type: "user_message", + messageId: MessageId.make("steer"), + createdBy: "user", + creationSource: "web", + inputIntent: "steer", + text: "Also check the docs", + attachments: [], + }, + }, + { name: "a streaming parent reply", item: assistant(true) }, + ] satisfies ReadonlyArray<{ name: string; item: OrchestrationV2TurnItem }>)( + "still shows Thinking when $name follows the running child", + ({ item }) => { + const last = openTurnRows([item]).at(-1); + expect(last?.kind).toBe("thinking"); + expect(last).not.toHaveProperty("waitingOnSubagents"); + }, + ); }); describe("subagent continued by a later turn", () => { diff --git a/apps/web/src/components/chat/MessagesTimeline.logic.ts b/apps/web/src/components/chat/MessagesTimeline.logic.ts index c422656647863..040c47dd60168 100644 --- a/apps/web/src/components/chat/MessagesTimeline.logic.ts +++ b/apps/web/src/components/chat/MessagesTimeline.logic.ts @@ -531,6 +531,7 @@ type MessagesTimelineRowContent = createdAt: string | null; groupId?: string; expanded?: boolean; + waitingOnSubagents?: number; } | { kind: "work-toggle"; @@ -2267,6 +2268,29 @@ export function deriveMessagesTimelineRows(input: { } } + // The open run is only waiting when its subagent group is its newest work; finished text the + // parent wrote after launching them does not count as work. + let waitingOnSubagents = 0; + for (let index = timelineEntries.length - 1; input.isWorking && index >= 0; index -= 1) { + const entry = timelineEntries[index]!; + if ( + entry.kind === "message" && + entry.message.role === "assistant" && + !entry.message.streaming && + entry.message.runId === unsettledRunId + ) { + continue; + } + if ( + entry.kind !== "event" || + entry.projectedItem.item.type !== "subagent" || + entry.projectedItem.item.runId == null || + entry.projectedItem.item.runId !== unsettledRunId + ) { + break; + } + if (isLiveSubagentTurnItem(entry.projectedItem.item)) waitingOnSubagents += 1; + } const hasWorkingRow = nextRows.some((row) => row.kind === "working"); if (input.isWorking && !hasWorkingRow && activeTurnHeaderIndex === timelineEntries.length) { appendWorkingRow(); @@ -2300,6 +2324,7 @@ export function deriveMessagesTimelineRows(input: { kind: "thinking", id: LIVE_ACTIVITY_ROW_ID, createdAt: input.activeTurnStartedAt ?? null, + ...(waitingOnSubagents > 0 ? { waitingOnSubagents } : {}), }); } } diff --git a/apps/web/src/components/chat/TimelineWorkGroupRows.tsx b/apps/web/src/components/chat/TimelineWorkGroupRows.tsx index 2791c9b714901..05529b8e26e0d 100644 --- a/apps/web/src/components/chat/TimelineWorkGroupRows.tsx +++ b/apps/web/src/components/chat/TimelineWorkGroupRows.tsx @@ -378,10 +378,15 @@ export function ThinkingTimelineRow({ row }: { row: Extract; // A failed group keeps this disclosure while an approval waits, but nothing is thinking then. const live = ctx.pendingApprovals.size === 0; + const waiting = row.waitingOnSubagents; const activity = (