fix(web): stop counting a workflow coordinator as a working agent (#6672)
This commit is contained in:
1 parent
4db50757c0
commit
9bdd912933
2 files changed
+45
-8
No files matched your search
@@ -383,13 +383,49 @@ describe("deriveAgentPanelModel", () => {
|
||||
it("counts idle deliberately and waiting as active", () => {
|
||||
const model = deriveAgentPanelModel({ agents: roster });
|
||||
expect(model.idleCount).toBe(1);
|
||||
// wf-1 coordinator + member 1 running.
|
||||
expect(model.runningCount).toBeGreaterThanOrEqual(1);
|
||||
// Member 1 is running; the wf-1 coordinator is a container, not a worker.
|
||||
expect(model.runningCount).toBe(1);
|
||||
// Every agent lands in exactly one bucket, except coordinators that stand
|
||||
// in for their members.
|
||||
expect(model.idleCount + model.runningCount + model.waitingCount + model.settledCount).toBe(
|
||||
roster.length,
|
||||
roster.length - 1,
|
||||
);
|
||||
});
|
||||
|
||||
it("omits a workflow coordinator from the working-agent count", () => {
|
||||
const model = deriveAgentPanelModel({ agents: roster });
|
||||
// One member still running plus one idle direct spawn. The coordinator
|
||||
// reports running for the whole workflow and must not inflate the banner.
|
||||
expect(model.liveCount).toBe(1);
|
||||
});
|
||||
|
||||
it("omits a finished workflow coordinator from the settled count", () => {
|
||||
const finished = fold([
|
||||
activity("task.started", { taskId: "wf-2", taskType: "local_workflow", title: "sweep" }),
|
||||
activity("task.progress", {
|
||||
taskId: "wf-2:wf:0",
|
||||
title: "sweep:a",
|
||||
status: "completed",
|
||||
parentAgentId: "wf-2",
|
||||
agentIndex: 0,
|
||||
phaseIndex: 0,
|
||||
}),
|
||||
activity("task.completed", {
|
||||
taskId: "wf-2:wf:0",
|
||||
status: "completed",
|
||||
parentAgentId: "wf-2",
|
||||
}),
|
||||
activity("task.completed", { taskId: "wf-2", status: "completed" }),
|
||||
]);
|
||||
|
||||
const model = deriveAgentPanelModel({ agents: finished });
|
||||
|
||||
// Only the member settled. The coordinator stands in for it, so counting
|
||||
// both would report two finished agents where one ran.
|
||||
expect(model.settledCount).toBe(1);
|
||||
expect(model.liveCount).toBe(0);
|
||||
});
|
||||
|
||||
it("keeps direct spawns in first-seen order as their activity changes", () => {
|
||||
const directRoster = fold([
|
||||
activity("task.started", { taskId: "direct-a", title: "First" }, "2026-08-01T11:00:00.000Z"),
|
||||
|
||||
@@ -826,15 +826,16 @@ export function deriveAgentPanelModel({
|
||||
let settledCount = 0;
|
||||
let totalTokens = 0;
|
||||
for (const agent of source) {
|
||||
// A workflow coordinator with members is a container for those members, not
|
||||
// work of its own: it reports running for the whole run and aggregates their
|
||||
// usage upstream in some providers. Counting it would report one more agent
|
||||
// working than there are, and double count tokens.
|
||||
if (agent.kind === "workflow" && (members.get(agent.id) ?? []).length > 0) continue;
|
||||
if (agent.status === "running" || agent.status === "pending") runningCount += 1;
|
||||
else if (agent.status === "waiting") waitingCount += 1;
|
||||
else if (agent.status === "idle") idleCount += 1;
|
||||
else settledCount += 1;
|
||||
// Workflow coordinators aggregate member usage upstream in some providers;
|
||||
// avoid double counting by only summing leaf agents when members exist.
|
||||
if (agent.kind !== "workflow" || (members.get(agent.id) ?? []).length === 0) {
|
||||
totalTokens += agent.usage?.totalTokens ?? 0;
|
||||
}
|
||||
totalTokens += agent.usage?.totalTokens ?? 0;
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in new issue
Block a user