From dff5a9891440eeaaff8091d3048a56bc004cf3bc Mon Sep 17 00:00:00 2001 From: Nam Rodriguez Date: Wed, 4 Nov 2026 18:56:24 -0500 Subject: [PATCH] Analytics: say whether tokens per day count every model call or only runs The analytics API now puts the per-call meter's daily totals on the page (every model call: runs, including work on runs started earlier, reviews, follow-ups, chat) instead of what the run records add up to. The chart's title says which one it shows, and the API types carry the metered cost, the run records' cost and what the metered cost was for. --- dashboard/e2e/analytics.spec.ts | 5 ++++- dashboard/src/app/analytics/page.tsx | 2 +- dashboard/src/lib/api.ts | 16 +++++++++++++++- 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/dashboard/e2e/analytics.spec.ts b/dashboard/e2e/analytics.spec.ts index cd3b5457..85a3f79d 100644 --- a/dashboard/e2e/analytics.spec.ts +++ b/dashboard/e2e/analytics.spec.ts @@ -18,7 +18,8 @@ function days(n: number) { const SUMMARY = { runs: 42, prs_opened: 30, prs_merged: 21, prs_closed: 3, prs_open: 6, merge_rate: 0.7, failed_runs: 4, failure_rate: 0.095, - cost_usd: 96.4, cost_per_run: 2.3, cost_per_merged_pr: 4.59, tokens_in: 12_000_000, tokens_out: 900_000, + cost_usd: 96.4, run_cost_usd: 41.2, cost_basis: "metered", cost_by_feature: [{ feature: "review", cost_usd: 50 }, { feature: "run", cost_usd: 41.2 }, { feature: "feedback", cost_usd: 5.2 }], + cost_per_run: 2.3, cost_per_merged_pr: 4.59, tokens_in: 12_000_000, tokens_out: 900_000, median_run_minutes: 11.5, median_hours_to_merge: 5.2, time_to_merge_known: 12, merged_untouched: 9, merged_with_edits: 3, edits_known: 12, reviews: 55, }; @@ -205,6 +206,8 @@ test("the scorecard answers whether it is worth it, against the previous period" await expect(page.getByTestId("tile-untouched")).toContainText("75%"); await expect(page.getByTestId("tile-ci")).toContainText("6 of 8 runs went green"); await expect(page.getByTestId("tile-findings")).toContainText("24 fixed in code, 8 settled by a person"); + // The tokens per day are the meter's (every model call), and say so. + await expect(page.getByText("Tokens per day, every model call")).toBeVisible(); const views = page.getByRole("navigation", { name: "Analytics views" }); await views.getByRole("link", { name: "Reliability" }).click(); await expect(page.getByRole("table", { name: "Failures by reason" })).toContainText("Timed out after #s"); diff --git a/dashboard/src/app/analytics/page.tsx b/dashboard/src/app/analytics/page.tsx index e0f889b4..3ccbffb1 100644 --- a/dashboard/src/app/analytics/page.tsx +++ b/dashboard/src/app/analytics/page.tsx @@ -276,7 +276,7 @@ function Body({ data, loading, stats, tab }: { data: Analytics; loading: boolean [shortDay(r.day), tokens(r.tokens ?? 0), r.runs])} empty="No days." />} > {data.daily.every((r) => !r.tokens) ? ( diff --git a/dashboard/src/lib/api.ts b/dashboard/src/lib/api.ts index 08f9f6fc..b54a3e6d 100644 --- a/dashboard/src/lib/api.ts +++ b/dashboard/src/lib/api.ts @@ -3222,8 +3222,21 @@ export interface AnalyticsSummary { failure_rate: number | null; /** Runs a person closed on purpose: not failures. Older backends leave it out. */ closed_runs?: number; + /** + * What the team spent on model calls in the period. With `cost_basis` + * "metered": every call the usage meter counted (runs, including work on + * runs started earlier, reviews, follow-ups, chat). With "runs" (one + * repository picked, or an older server): what the run records add up to. + */ cost_usd: number; + /** What the run records add up to (runs only, on the day each started). */ + run_cost_usd?: number; + cost_basis?: "metered" | "runs"; + /** The metered cost by what the calls were for, largest first. */ + cost_by_feature?: { feature: string; cost_usd: number }[]; + /** From the run records. */ cost_per_run: number | null; + /** From the run records. */ cost_per_merged_pr: number | null; /** Tokens in plus out. */ tokens?: number; @@ -3250,7 +3263,8 @@ export interface Analytics { previous_period: { start: string; end: string }; summary: AnalyticsSummary; previous: AnalyticsSummary; - daily: { day: string; runs: number; prs_opened: number; merged: number; failed: number; cost_usd: number; tokens?: number; reviews: number }[]; + /** `cost_usd` and `tokens` are metered when the summary's `cost_basis` is "metered"; `run_*` are the run records'. */ + daily: { day: string; runs: number; prs_opened: number; merged: number; failed: number; cost_usd: number; tokens?: number; run_cost_usd?: number; run_tokens?: number; reviews: number }[]; sources: { source: string; runs: number; prs: number; merged: number; merge_rate: number | null }[]; repos: { repo: string; runs: number; prs: number; merged: number; failed: number; cost_usd: number; tokens?: number; merge_rate: number | null; reviews: number }[]; /** One row per person (however Jira, GitHub or the dashboard named them), Coderhelm's own work, and runs that recorded nobody. */