Skip to content

Commit 62d1993

Browse files
T3 Code Testshivamhwp
authored andcommitted
fix(web): distinguish idle agents from completed agents
1 parent c3a7106 commit 62d1993

4 files changed

Lines changed: 79 additions & 15 deletions

File tree

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3454,6 +3454,33 @@ function deriveRows(entries: TimelineEntry[], summarizeSubagents = true) {
34543454
}
34553455

34563456
describe("subagent summary rows", () => {
3457+
it.each([
3458+
{ statuses: [], count: 1, working: 0, failed: 0 },
3459+
{ statuses: ["completed"], count: 2, working: 0, failed: 0 },
3460+
{ statuses: ["running"], count: 2, working: 1, failed: 0 },
3461+
{ statuses: ["failed"], count: 2, working: 0, failed: 1 },
3462+
] as const)(
3463+
"keeps idle agents distinct alongside $statuses",
3464+
({ statuses, count, working, failed }) => {
3465+
const result = deriveRows([
3466+
subagentTimelineEntry("idle-agent", "run-1", "idle"),
3467+
...statuses.map((status, index) =>
3468+
subagentTimelineEntry(`agent-${index}`, "run-1", status),
3469+
),
3470+
]);
3471+
3472+
expect(result).toMatchObject([
3473+
{
3474+
kind: "agent-spawn",
3475+
count,
3476+
idle: 1,
3477+
working,
3478+
failed,
3479+
},
3480+
]);
3481+
},
3482+
);
3483+
34573484
it("groups local agents by run without swallowing inherited or unowned entries", () => {
34583485
const result = deriveRows([
34593486
subagentTimelineEntry("agent-a", "run-1", "running"),
@@ -3481,6 +3508,21 @@ describe("subagent summary rows", () => {
34813508
]);
34823509
});
34833510

3511+
it("refreshes a cached summary when an idle agent completes", () => {
3512+
const idle = computeStableMessagesTimelineRows(
3513+
deriveRows([subagentTimelineEntry("agent", "run-1", "idle")]),
3514+
{ byId: new Map(), result: [] },
3515+
);
3516+
const completed = computeStableMessagesTimelineRows(
3517+
deriveRows([subagentTimelineEntry("agent", "run-1", "completed")]),
3518+
idle,
3519+
);
3520+
3521+
expect(idle.result).toMatchObject([{ idle: 1, working: 0 }]);
3522+
expect(completed.result).toMatchObject([{ idle: 0, working: 0 }]);
3523+
expect(completed.result[0]).not.toBe(idle.result[0]);
3524+
});
3525+
34843526
it("keeps superseded and replacement attempts in separate rosters", () => {
34853527
const runId = "run-steered" as never;
34863528
const supersededAttempt = {

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ const LIVE_ACTIVITY_ROW_ID = "live-activity-row";
315315
interface AgentSpawnSummary {
316316
count: number;
317317
working: number;
318+
idle: number;
318319
failed: number;
319320
stopped: number;
320321
}
@@ -339,7 +340,7 @@ function deriveAgentSpawnSummaries(entries: ReadonlyArray<TimelineEntry>) {
339340
: `run:${item.runId}`;
340341
let summary = groups.get(key);
341342
if (!summary) {
342-
summary = { count: 0, working: 0, failed: 0, stopped: 0 };
343+
summary = { count: 0, working: 0, idle: 0, failed: 0, stopped: 0 };
343344
groups.set(key, summary);
344345
byItemId.set(item.id, summary);
345346
} else {
@@ -348,6 +349,8 @@ function deriveAgentSpawnSummaries(entries: ReadonlyArray<TimelineEntry>) {
348349
summary.count += 1;
349350
if (item.status === "pending" || item.status === "running" || item.status === "waiting") {
350351
summary.working += 1;
352+
} else if (item.status === "idle") {
353+
summary.idle += 1;
351354
} else if (item.status === "failed") {
352355
summary.failed += 1;
353356
} else if (item.status === "cancelled" || item.status === "interrupted") {
@@ -1561,6 +1564,7 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
15611564
a.createdAt === bs.createdAt &&
15621565
a.count === bs.count &&
15631566
a.working === bs.working &&
1567+
a.idle === bs.idle &&
15641568
a.failed === bs.failed &&
15651569
a.stopped === bs.stopped
15661570
);

‎apps/web/src/components/chat/MessagesTimeline.test.tsx‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,26 @@ describe("MessagesTimeline", () => {
17001700
expect(markup.match(/data-agent-spawn-cta="true"/gu)).toHaveLength(1);
17011701
});
17021702

1703+
it.each(["idle", "completed", "running", "failed"] as const)(
1704+
"shows resumable idle agents without a completion checkmark alongside %s agents",
1705+
(status) => {
1706+
const markup = renderToStaticMarkup(
1707+
<MessagesTimeline
1708+
{...buildProps()}
1709+
onOpenAgents={() => {}}
1710+
timelineEntries={[
1711+
buildSubagentEntry("idle-agent", "idle"),
1712+
buildSubagentEntry("other-agent", status),
1713+
]}
1714+
/>,
1715+
);
1716+
1717+
expect(markup).toContain(`${status === "idle" ? 2 : 1} idle`);
1718+
expect(markup).not.toContain("✓");
1719+
expect(markup).not.toContain("completed");
1720+
},
1721+
);
1722+
17031723
it("discloses the full Codex subagent result without projecting child events", async () => {
17041724
const { MessagesTimeline } = await import("./MessagesTimeline");
17051725
const markup = renderToStaticMarkup(

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

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,16 +2052,16 @@ const AgentSpawnCtaRow = memo(function AgentSpawnCtaRow({
20522052
}) {
20532053
const { onOpenAgents } = use(TimelineRowCtx);
20542054
const live = row.working > 0;
2055-
const lead = `${live ? "Kicked off" : "Ran"} ${row.count} agent${row.count === 1 ? "" : "s"}`;
2056-
const status = live
2057-
? row.failed > 0
2058-
? `${row.working} working · ${row.failed} failed`
2059-
: `${row.working} working`
2060-
: row.failed > 0
2061-
? `${row.failed} failed`
2062-
: row.stopped > 0
2063-
? `${row.stopped} stopped`
2064-
: "completed";
2055+
const lead = `${live || row.idle > 0 ? "Kicked off" : "Ran"} ${row.count} agent${row.count === 1 ? "" : "s"}`;
2056+
const settled = !live && row.idle === 0 && row.failed === 0 && row.stopped === 0;
2057+
const progress = [
2058+
...(live ? [`${row.working} working`] : []),
2059+
...(row.idle > 0 ? [`${row.idle} idle`] : []),
2060+
...(row.stopped > 0 ? [`${row.stopped} stopped`] : []),
2061+
].join(" · ");
2062+
const status = settled
2063+
? "completed"
2064+
: [progress, ...(row.failed > 0 ? [`${row.failed} failed`] : [])].filter(Boolean).join(" · ");
20652065

20662066
return (
20672067
<button
@@ -2076,10 +2076,8 @@ const AgentSpawnCtaRow = memo(function AgentSpawnCtaRow({
20762076
<span className="min-w-0 truncate font-medium">{lead}</span>
20772077
<span className="ml-auto flex min-w-0 items-center gap-2 font-mono text-[.7rem] text-muted-foreground">
20782078
<span className="truncate">
2079-
{!live && row.failed === 0 && row.stopped === 0 ? (
2080-
<span aria-hidden="true">✓ </span>
2081-
) : null}
2082-
{live && row.failed > 0 ? `${row.working} working · ` : row.failed > 0 ? null : status}
2079+
{settled ? <span aria-hidden="true">✓ </span> : null}
2080+
{row.failed > 0 ? (progress ? `${progress} · ` : null) : status}
20832081
{row.failed > 0 ? <span className="text-destructive">{row.failed} failed</span> : null}
20842082
</span>
20852083
<span className="shrink-0 text-info-foreground">{live ? "Open Agents ▸" : "View ▸"}</span>

0 commit comments

Comments
 (0)