Skip to content

Commit 157f45b

Browse files
fix(web): a settled turn keeps its duration when a background subagent delegates later
AI-assisted; verified with the tests and tools listed above.
1 parent b9b728c commit 157f45b

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

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

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {
3232
shouldCollapseUserMessage,
3333
resolveAssistantMessageCopyState,
3434
type MessagesTimelineRow,
35+
type TimelineLatestRun,
3536
workEntryDisplayLabel,
3637
} from "./MessagesTimeline.logic";
3738

@@ -4479,7 +4480,16 @@ describe("live subagents after their parent turn settles", () => {
44794480
prompt: `Inspect ${id}`,
44804481
result: null,
44814482
});
4482-
const rowsFor = (children: ReadonlyArray<OrchestrationV2TurnItem>) =>
4483+
const rowsFor = (
4484+
children: ReadonlyArray<OrchestrationV2TurnItem>,
4485+
afterReply: ReadonlyArray<OrchestrationV2TurnItem> = [],
4486+
latestRun: TimelineLatestRun = {
4487+
runId,
4488+
status: "completed",
4489+
startedAt: DateTime.formatIso(at(0)),
4490+
completedAt: DateTime.formatIso(at(8)),
4491+
},
4492+
) =>
44834493
deriveMessagesTimelineRows({
44844494
timelineEntries: deriveTimelineEntriesFromVisibleTurnItems({
44854495
visibleTurnItems: (
@@ -4519,16 +4529,12 @@ describe("live subagents after their parent turn settles", () => {
45194529
text: "Both children are running.",
45204530
streaming: false,
45214531
},
4532+
...afterReply,
45224533
] satisfies OrchestrationV2TurnItem[]
45234534
).map(projected),
45244535
optimisticMessages: [],
45254536
}),
4526-
latestRun: {
4527-
runId,
4528-
status: "completed",
4529-
startedAt: DateTime.formatIso(at(0)),
4530-
completedAt: DateTime.formatIso(at(8)),
4531-
},
4537+
latestRun,
45324538
isWorking: false,
45334539
turnDiffSummaries: [],
45344540
supportsConversationRollback: false,
@@ -4547,6 +4553,19 @@ describe("live subagents after their parent turn settles", () => {
45474553
},
45484554
);
45494555

4556+
it("keeps the turn's duration when a background child delegates after it settles", () => {
4557+
// The child's completion woke a later run, so this run's duration comes from its entries.
4558+
const rows = rowsFor([], [child("late", 50, "completed")], {
4559+
runId: RunId.make("wake-run"),
4560+
status: "completed",
4561+
startedAt: DateTime.formatIso(at(55)),
4562+
completedAt: DateTime.formatIso(at(58)),
4563+
});
4564+
expect(rows.find((row) => row.kind === "turn-fold")).toMatchObject({
4565+
label: "Worked for 8s",
4566+
});
4567+
});
4568+
45504569
it("keeps a launch batch visible while any member is still running", () => {
45514570
const rows = rowsFor([child("done", 3, "completed"), child("live", 4, "running")]);
45524571
expect(rows.map((row) => row.id)).toEqual(["user", `turn-fold:${runId}`, "done", "assistant"]);

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,8 +1179,16 @@ function deriveTurnFolds(input: {
11791179
const isLatestInterruptedTurn =
11801180
input.latestRun?.runId === runId && input.latestRun.status === "interrupted";
11811181
// A turn cut short by a steer leaves trailing work entries behind its
1182-
// terminal message — take whichever ended last.
1183-
const lastEntryEnd = timelineEntryEnd(lastEntry);
1182+
// terminal message — take whichever ended last. A subagent card after it was
1183+
// spawned by background work once the turn settled, so it adds no turn time.
1184+
const lastTurnEntry =
1185+
group.entries.findLast(
1186+
(entry, index) =>
1187+
index <= terminalEntryIndex ||
1188+
entry.kind !== "event" ||
1189+
entry.projectedItem.item.type !== "subagent",
1190+
) ?? lastEntry;
1191+
const lastEntryEnd = timelineEntryEnd(lastTurnEntry);
11841192
const elapsedMs =
11851193
input.latestRun?.runId === runId && input.latestRun.startedAt && input.latestRun.completedAt
11861194
? computeElapsedMs(input.latestRun.startedAt, input.latestRun.completedAt)

0 commit comments

Comments
 (0)