Skip to content

Commit b38f9d0

Browse files
committed
fix(web): stop counting a workflow coordinator as a working agent
1 parent 6ae9662 commit b38f9d0

2 files changed

Lines changed: 45 additions & 8 deletions

File tree

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

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,49 @@ describe("deriveAgentPanelModel", () => {
383383
it("counts idle deliberately and waiting as active", () => {
384384
const model = deriveAgentPanelModel({ agents: roster });
385385
expect(model.idleCount).toBe(1);
386-
// wf-1 coordinator + member 1 running.
387-
expect(model.runningCount).toBeGreaterThanOrEqual(1);
386+
// Member 1 is running; the wf-1 coordinator is a container, not a worker.
387+
expect(model.runningCount).toBe(1);
388+
// Every agent lands in exactly one bucket, except coordinators that stand
389+
// in for their members.
388390
expect(model.idleCount + model.runningCount + model.waitingCount + model.settledCount).toBe(
389-
roster.length,
391+
roster.length - 1,
390392
);
391393
});
392394

395+
it("omits a workflow coordinator from the working-agent count", () => {
396+
const model = deriveAgentPanelModel({ agents: roster });
397+
// One member still running plus one idle direct spawn. The coordinator
398+
// reports running for the whole workflow and must not inflate the banner.
399+
expect(model.liveCount).toBe(1);
400+
});
401+
402+
it("omits a finished workflow coordinator from the settled count", () => {
403+
const finished = fold([
404+
activity("task.started", { taskId: "wf-2", taskType: "local_workflow", title: "sweep" }),
405+
activity("task.progress", {
406+
taskId: "wf-2:wf:0",
407+
title: "sweep:a",
408+
status: "completed",
409+
parentAgentId: "wf-2",
410+
agentIndex: 0,
411+
phaseIndex: 0,
412+
}),
413+
activity("task.completed", {
414+
taskId: "wf-2:wf:0",
415+
status: "completed",
416+
parentAgentId: "wf-2",
417+
}),
418+
activity("task.completed", { taskId: "wf-2", status: "completed" }),
419+
]);
420+
421+
const model = deriveAgentPanelModel({ agents: finished });
422+
423+
// Only the member settled. The coordinator stands in for it, so counting
424+
// both would report two finished agents where one ran.
425+
expect(model.settledCount).toBe(1);
426+
expect(model.liveCount).toBe(0);
427+
});
428+
393429
it("keeps direct spawns in first-seen order as their activity changes", () => {
394430
const directRoster = fold([
395431
activity("task.started", { taskId: "direct-a", title: "First" }, "2026-08-01T11:00:00.000Z"),

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -826,15 +826,16 @@ export function deriveAgentPanelModel({
826826
let settledCount = 0;
827827
let totalTokens = 0;
828828
for (const agent of source) {
829+
// A workflow coordinator with members is a container for those members, not
830+
// work of its own: it reports running for the whole run and aggregates their
831+
// usage upstream in some providers. Counting it would report one more agent
832+
// working than there are, and double count tokens.
833+
if (agent.kind === "workflow" && (members.get(agent.id) ?? []).length > 0) continue;
829834
if (agent.status === "running" || agent.status === "pending") runningCount += 1;
830835
else if (agent.status === "waiting") waitingCount += 1;
831836
else if (agent.status === "idle") idleCount += 1;
832837
else settledCount += 1;
833-
// Workflow coordinators aggregate member usage upstream in some providers;
834-
// avoid double counting by only summing leaf agents when members exist.
835-
if (agent.kind !== "workflow" || (members.get(agent.id) ?? []).length === 0) {
836-
totalTokens += agent.usage?.totalTokens ?? 0;
837-
}
838+
totalTokens += agent.usage?.totalTokens ?? 0;
838839
}
839840

840841
return {

0 commit comments

Comments
 (0)