From 79fe373bcdfafd7d73ac53bdeceda7ea1ac2e55c Mon Sep 17 00:00:00 2001 From: aiongg <67543387+aiongg@users.noreply.github.com> Date: Mon, 2 Nov 2026 19:01:52 +0000 Subject: [PATCH] Classifiers and Cost: unknown runs, phone layout, distinct items, unpriced models Classifiers says when ?run= names no run, scrolls a long By repo list and stacks both answers under the title on phones. Cost counts distinct classified items, lists items and price per model, says "price not reported" for models without USD, and leaves out the spend chart below three buckets. --- src/dash/api/insight.ts | 1 + test/insight.test.ts | 1 + web/src/api/mock/insightFixtures.ts | 2 +- web/src/api/types.ts | 2 ++ web/src/modules/classifiers/index.tsx | 34 ++++++++++++++---- web/src/modules/cost/index.tsx | 50 +++++++++++++++++++++++---- 6 files changed, 75 insertions(+), 15 deletions(-) diff --git a/src/dash/api/insight.ts b/src/dash/api/insight.ts index c41c790f..a634dd06 100644 --- a/src/dash/api/insight.ts +++ b/src/dash/api/insight.ts @@ -148,6 +148,7 @@ export function cost(db: DatabaseSync, req: Req): CostReport { runs: db.prepare(`SELECT run_id AS id, MIN(started_at) AS "from", MAX(COALESCE(ended_at, started_at)) AS "to" FROM token_usage GROUP BY run_id ORDER BY MAX(COALESCE(ended_at, started_at)) DESC`).all() as CostReport["runs"], run, total: { ...(total as object) } as UsageTotals, + itemsClassified: (db.prepare(`SELECT COUNT(*) AS n FROM (SELECT DISTINCT repo, number FROM classifications WHERE ${flt})`).get(p) as { n: number }).n, stages: q(`SELECT COALESCE(stage, '') AS stage, COALESCE(model, '') AS model, ${TOTALS} FROM token_usage WHERE ${flt} GROUP BY stage, model ORDER BY stage, model`), repos: q(`SELECT repo, ${TOTALS} FROM token_usage WHERE ${flt} AND repo IS NOT NULL GROUP BY repo ORDER BY COALESCE(SUM(COALESCE(input_tokens, 0) + COALESCE(output_tokens, 0) + COALESCE(cache_read_tokens, 0) + COALESCE(cache_write_tokens, 0)), 0) DESC`), series: q(`SELECT substr(COALESCE(ended_at, started_at), 1, ${len}) AS bucket, diff --git a/test/insight.test.ts b/test/insight.test.ts index f4e25303..c6287985 100644 --- a/test/insight.test.ts +++ b/test/insight.test.ts @@ -65,6 +65,7 @@ describe("insight", () => { test("cost totals, wall time and series", () => { const c = cost(db, rq("run=r1")); assert.deepEqual(c.total, { calls: 2, items: 6, input: 150, output: 30, cacheRead: 10, cacheWrite: 0, usd: 0.25, wallSeconds: 180 }); + assert.equal(c.itemsClassified, 6); assert.equal(c.stages.length, 1); assert.deepEqual(c.series, [{ bucket: "2026-11-01T10", tokens: 190, usd: 0.25 }]); }); diff --git a/web/src/api/mock/insightFixtures.ts b/web/src/api/mock/insightFixtures.ts index f4514a09..abe20047 100644 --- a/web/src/api/mock/insightFixtures.ts +++ b/web/src/api/mock/insightFixtures.ts @@ -122,5 +122,5 @@ export function costReport(run = ""): CostReport { tokens: Math.round((900_000 + r() * 6_000_000) * k), usd: Math.round((0.4 + r() * 4.5) * k * 100) / 100, })); - return { runs: [{ id: RUN, from: "2026-10-27T08:00:00Z", to: "2026-11-02T10:30:00Z" }, { id: "pilot-1029", from: "2026-10-29T14:00:00Z", to: "2026-10-29T15:10:00Z" }], run, total, stages, repos, series, bucketSize: "hour" }; + return { runs: [{ id: RUN, from: "2026-10-27T08:00:00Z", to: "2026-11-02T10:30:00Z" }, { id: "pilot-1029", from: "2026-10-29T14:00:00Z", to: "2026-10-29T15:10:00Z" }], run, total, itemsClassified: Math.round(21000 * k), stages, repos, series, bucketSize: "hour" }; } diff --git a/web/src/api/types.ts b/web/src/api/types.ts index 9d20d5ae..8b42a12f 100644 --- a/web/src/api/types.ts +++ b/web/src/api/types.ts @@ -489,6 +489,8 @@ export interface CostReport { /** A run id, or "" for all runs. */ run: string; total: UsageTotals; + /** Distinct items with a classification in the run (or all runs); `total.items` counts an item once per model. */ + itemsClassified: number; stages: ({ stage: string; model: string } & UsageTotals)[]; repos: ({ repo: string } & UsageTotals)[]; /** Spend per time bucket; `bucket` is an ISO hour or day. */ diff --git a/web/src/modules/classifiers/index.tsx b/web/src/modules/classifiers/index.tsx index 2995400c..4a230632 100644 --- a/web/src/modules/classifiers/index.tsx +++ b/web/src/modules/classifiers/index.tsx @@ -93,8 +93,8 @@ function Disagreements({ r, label, band, setFilter }: { r: ClassifierReport; lab Item Title - {r.a} - {r.b} + {r.a} + {r.b} @@ -103,11 +103,24 @@ function Disagreements({ r, label, band, setFilter }: { r: ClassifierReport; lab - {d.title} - + + {d.title} + {/* Phones: the two answers under the title instead of in their own columns. */} +
+
{r.a}
+
+ {d.a.label} {prob(d.a.prob)} +
+
{r.b}
+
+ {d.b.label} {prob(d.b.prob)} +
+
+ + {d.a.label} {prob(d.a.prob)} - + {d.b.label} {prob(d.b.prob)} @@ -168,6 +181,11 @@ function Classifiers(_: ViewProps) { options={cur.pairs.map((p) => ({ value: `${p.a}|${p.b}`, label: `${p.a} vs ${p.b} (${num(p.items)})` }))} /> + {run && run !== r.run && ( +

+ There is no run {run}. Showing the latest run, {r.run}. +

+ )}

Agreement on the type label, per run. Rows are grouped by {r.a}'s answer.

@@ -181,8 +199,10 @@ function Classifiers(_: ViewProps) { ({ key: x.label, n: x.n, agree: x.agree }))} picked={label} onPick={(k) => set({ label: label === k ? "" : k })} /> - - ({ key: x.repo, n: x.n, agree: x.agree }))} /> + +
+ ({ key: x.repo, n: x.n, agree: x.agree }))} /> +
diff --git a/web/src/modules/cost/index.tsx b/web/src/modules/cost/index.tsx index 1396d770..6c90dce5 100644 --- a/web/src/modules/cost/index.tsx +++ b/web/src/modules/cost/index.tsx @@ -4,6 +4,7 @@ import { useQuery } from "../../api/client"; import type { CostReport, UsageTotals } from "../../api/types"; import type { FeatureModule, ViewProps } from "../../registry/types"; import { num } from "../../lib/format"; +import { cn } from "../../ui/cn"; import { Block, Select, Stat, Th } from "../insight/parts"; const tokens = (u: UsageTotals) => u.input + u.output + u.cacheRead + u.cacheWrite; @@ -44,7 +45,7 @@ function UsageTable({ rows, name, subName }: { rows: Row[]; name: string; subNam {num(u.output)} {num(u.cacheRead)} {num(u.cacheWrite)} - {usd(u.usd)} + {u.usd === null ? "price not reported" : usd(u.usd)} {per(tokens(u), u.items)} {perUsd(u.usd, u.items)} {wall(u.wallSeconds)} @@ -86,12 +87,45 @@ function SpendChart({ r }: { r: CostReport }) { ); } +type ModelTotals = { model: string; items: number; usd: number | null }; + +// Totals per model across stages. USD stays null for a model that never reported a price. +function byModel(r: CostReport): ModelTotals[] { + const m = new Map(); + for (const s of r.stages) { + const cur = m.get(s.model) ?? { model: s.model || "unknown model", items: 0, usd: null }; + cur.items += s.items; + if (s.usd !== null) cur.usd = (cur.usd ?? 0) + s.usd; + m.set(s.model, cur); + } + return [...m.values()].sort((a, b) => b.items - a.items); +} + +// Spend per item counts only the items of models that report a price. +function SpendSub({ models }: { models: ModelTotals[] }) { + const priced = models.filter((m) => m.usd !== null); + const unpriced = models.filter((m) => m.usd === null); + return ( + <> + {priced.map((m) => ( +
+ {m.model}: {perUsd(m.usd, m.items)} per item +
+ ))} + {unpriced.length > 0 &&
{unpriced.map((m) => m.model).join(", ")}: price not reported
} + + ); +} + function Cost(_: ViewProps) { const [sp, setSp] = useSearchParams(); const run = sp.get("run") ?? ""; const { data: r } = useQuery(`cost:${run}`, (api) => api.cost(run)); if (!r) return
Loading…
; const t = r.total; + const models = byModel(r); + // Each model's calls count the same item again, so the headline uses distinct classified items. + const items = r.itemsClassified || Math.max(0, ...models.map((m) => m.items)); return (
@@ -107,15 +141,17 @@ function Cost(_: ViewProps) {

Token use per agent call. USD appears where the agent reported a cost.

- - - + `${m.model} ${num(m.items)}`).join(" · ")} /> + + } />
- - - + {r.series.length >= 3 && ( + + + + )} ({ key: s.stage, sub: s.model, u: s }))} />