Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix(dashboard): hide deleted agents from usage leaderboard (MUL-3771) (#4637)

Jiayuan Zhangff0979008ba3
diff --git a/packages/views/dashboard/components/dashboard-page.tsx b/packages/views/dashboard/components/dashboard-page.tsx
index c522893961..93f897febb 100644
--- a/packages/views/dashboard/components/dashboard-page.tsx
+++ b/packages/views/dashboard/components/dashboard-page.tsx
@@ -12,6 +12,7 @@ import {
SelectValue,
} from "@multica/ui/components/ui/select";
import { useWorkspaceId } from "@multica/core/hooks";
+import type { Agent } from "@multica/core/types";
import { agentListOptions } from "@multica/core/workspace/queries";
import { projectListOptions } from "@multica/core/projects/queries";
import {
@@ -52,6 +53,7 @@ import {
aggregateWeeklyTasks,
aggregateWeeklyTime,
computeDailyTotals,
+ filterKnownAgentRows,
formatDuration,
mergeAgentDashboardRows,
type AgentDashboardRow,
@@ -98,6 +100,7 @@ const EMPTY_DAILY: import("@multica/core/types").DashboardUsageDaily[] = [];
const EMPTY_BY_AGENT: import("@multica/core/types").DashboardUsageByAgent[] = [];
const EMPTY_RUNTIME: import("@multica/core/types").DashboardAgentRunTime[] = [];
const EMPTY_RUNTIME_DAILY: import("@multica/core/types").DashboardRunTimeDaily[] = [];
+const EMPTY_AGENTS: Agent[] = [];
function fmtMoney(n: number): string {
if (n >= 100) return `$${n.toFixed(0)}`;
@@ -169,7 +172,8 @@ export function DashboardPage() {
useCustomPricingStore((s) => s.pricings);
const { data: projects = [] } = useQuery(projectListOptions(wsId));
- const { data: agents = [] } = useQuery(agentListOptions(wsId));
+ const agentsQuery = useQuery(agentListOptions(wsId));
+ const agents = agentsQuery.data ?? EMPTY_AGENTS;
// Validate the picked project against the current workspace's list. A
// stale UUID — left over from a project that's been deleted, or from the
@@ -310,6 +314,20 @@ export function DashboardPage() {
[agentTokenRows, runTimeRows],
);
+ // Hide rollup rows for agents that were hard-deleted from the workspace —
+ // they'd otherwise show up as a bare UUID on the leaderboard (MUL-3771).
+ // Archived agents stay (the agent list is fetched with archived included);
+ // only truly-removed agents drop out. Skip filtering until the agent list
+ // has loaded so a slow agents fetch doesn't transiently blank the list.
+ const knownAgentIds = useMemo(
+ () => (agentsQuery.isSuccess ? new Set(agents.map((a) => a.id)) : null),
+ [agentsQuery.isSuccess, agents],
+ );
+ const visibleAgentRows = useMemo(
+ () => filterKnownAgentRows(agentRows, knownAgentIds),
+ [agentRows, knownAgentIds],
+ );
+
return (
<div className="flex h-full flex-col">
{/* h-auto + min-h-12 + flex-wrap: the toolbar (project filter,
@@ -411,7 +429,7 @@ export function DashboardPage() {
{/* Per-agent leaderboard — user picks the ranking metric;
the progress bar and column emphasis follow the metric. */}
<Leaderboard
- rows={agentRows}
+ rows={visibleAgentRows}
agents={agents}
lessThanMinuteLabel={t(($) => $.duration.less_than_minute)}
/>
diff --git a/packages/views/dashboard/utils.test.ts b/packages/views/dashboard/utils.test.ts
index f9ca6b2afa..43032d5cb2 100644
--- a/packages/views/dashboard/utils.test.ts
+++ b/packages/views/dashboard/utils.test.ts
@@ -5,6 +5,7 @@ import {
aggregateWeeklyTasks,
aggregateWeeklyTime,
computeDailyTotals,
+ filterKnownAgentRows,
formatDuration,
mergeAgentDashboardRows,
} from "./utils";
@@ -201,6 +202,29 @@ describe("mergeAgentDashboardRows", () => {
});
});
+describe("filterKnownAgentRows", () => {
+ const rows = [
+ { agentId: "live", tokens: 100, cost: 1, seconds: 10, taskCount: 1 },
+ { agentId: "deleted", tokens: 50, cost: 0.5, seconds: 5, taskCount: 1 },
+ ];
+
+ it("drops rows whose agent is no longer in the workspace", () => {
+ // "deleted" is absent from the known set — it's a hard-deleted agent whose
+ // legacy rollup row would otherwise render as a bare UUID.
+ const out = filterKnownAgentRows(rows, new Set(["live"]));
+ expect(out.map((r) => r.agentId)).toEqual(["live"]);
+ });
+
+ it("keeps every row while the agent list is still loading (null set)", () => {
+ const out = filterKnownAgentRows(rows, null);
+ expect(out.map((r) => r.agentId)).toEqual(["live", "deleted"]);
+ });
+
+ it("drops every row when the known set is empty", () => {
+ expect(filterKnownAgentRows(rows, new Set())).toEqual([]);
+ });
+});
+
describe("formatDuration", () => {
it("formats seconds-only durations", () => {
expect(formatDuration(45, "<1m")).toBe("45s");
diff --git a/packages/views/dashboard/utils.ts b/packages/views/dashboard/utils.ts
index 411d57bc3e..bb92ff1d4b 100644
--- a/packages/views/dashboard/utils.ts
+++ b/packages/views/dashboard/utils.ts
@@ -227,6 +227,23 @@ export function mergeAgentDashboardRows(
});
}
+// Drop usage rows whose agent no longer exists in the workspace. The agent
+// list is fetched with `include_archived: true`, so archived agents keep
+// their names and stay on the leaderboard; only hard-deleted agents fall out
+// of `knownAgentIds`. Those are legacy rollup rows that would otherwise
+// render as a bare UUID (MUL-3771).
+//
+// `knownAgentIds` is empty while the agent list is still loading; callers
+// pass `null` in that case so the rows pass through untouched instead of the
+// whole leaderboard blanking on a slow fetch.
+export function filterKnownAgentRows(
+ rows: AgentDashboardRow[],
+ knownAgentIds: ReadonlySet<string> | null,
+): AgentDashboardRow[] {
+ if (!knownAgentIds) return rows;
+ return rows.filter((r) => knownAgentIds.has(r.agentId));
+}
+
// ---------------------------------------------------------------------------
// Weekly fold for run-time + tasks. Mirrors `aggregateByWeek` in
// `runtimes/utils.ts` which already covers cost / tokens — same calendar