From 6765b8455131a52dc773365a1a5e22fd19378f75 Mon Sep 17 00:00:00 2001 From: "itarun.p" Date: Mon, 6 Apr 2026 21:08:39 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20model=20donut=20uses=20JSONL=20session?= =?UTF-8?q?=20tokens=20=E2=80=94=20excludes=20retired=20models?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit stats-cache modelUsage includes retired models (Haiku 4.5 at 57%, Opus 4.5 at 34%) with zero active sessions. Now computes model I/O tokens from JSONL sessions array — only shows currently active models. ADR-002 pattern: JSONL for windowed/current, stats-cache for all-time. Closes #140 --- app/overview-client.tsx | 17 ++++++++++++++++- components/overview/model-breakdown-donut.tsx | 3 +-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/app/overview-client.tsx b/app/overview-client.tsx index 4c06b30..a533f3f 100644 --- a/app/overview-client.tsx +++ b/app/overview-client.tsx @@ -138,6 +138,21 @@ export function OverviewClient() { const projects = projectsData?.projects ?? []; const projectCount = projects.length; + // Compute model usage from JSONL sessions (not stats-cache) to exclude retired models + const sessionModelUsage = useMemo(() => { + const usage: Record = + {}; + for (const s of sessions) { + if (!s.model) continue; + const existing = usage[s.model] ?? { inputTokens: 0, outputTokens: 0 }; + usage[s.model] = { + inputTokens: existing.inputTokens + (s.input_tokens ?? 0), + outputTokens: existing.outputTokens + (s.output_tokens ?? 0), + }; + } + return usage; + }, [sessions]); + const chartDays = useMemo(() => { if (!dateFrom || !dateTo) return 90; try { @@ -283,7 +298,7 @@ export function OverviewClient() { icon={} title="Model distribution" > - + diff --git a/components/overview/model-breakdown-donut.tsx b/components/overview/model-breakdown-donut.tsx index 671928c..fb03f5a 100644 --- a/components/overview/model-breakdown-donut.tsx +++ b/components/overview/model-breakdown-donut.tsx @@ -8,11 +8,10 @@ import { ResponsiveContainer, Legend, } from "recharts"; -import type { ModelUsage } from "@/types/claude"; import { formatTokens } from "@/lib/decode"; interface Props { - modelUsage: Record; + modelUsage: Record; } const MODEL_COLORS = [