From 6cd2845edbb7ed48c3b15eba0af65a1623254131 Mon Sep 17 00:00:00 2001 From: Paul Holstein <44263169+holstein13@users.noreply.github.com> Date: Sun, 22 Feb 2026 15:13:53 -0500 Subject: [PATCH] fix(report): recompute token totals after subagent row, fix import order - Recompute totalInputTokens, totalOutputTokens, totalCacheCreation, totalCacheRead, and grandTotal after injecting the "Subagents (combined)" row so tokenUsage.totals stays consistent with byModel rows - Fix CostSection import order: external packages before path aliases, merge duplicate import type statements Co-Authored-By: Claude Opus 4.6 --- .../components/report/sections/CostSection.tsx | 7 +++++-- src/renderer/utils/sessionAnalyzer.ts | 10 +++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/renderer/components/report/sections/CostSection.tsx b/src/renderer/components/report/sections/CostSection.tsx index 55b4ae5d..1a5408ba 100644 --- a/src/renderer/components/report/sections/CostSection.tsx +++ b/src/renderer/components/report/sections/CostSection.tsx @@ -6,8 +6,11 @@ import { DollarSign } from 'lucide-react'; import { AssessmentBadge } from '../AssessmentBadge'; import { ReportSection, sectionId } from '../ReportSection'; -import type { ModelTokenStats, ReportCostAnalysis } from '@renderer/types/sessionReport'; -import type { ModelPricing } from '@renderer/types/sessionReport'; +import type { + ModelPricing, + ModelTokenStats, + ReportCostAnalysis, +} from '@renderer/types/sessionReport'; const fmt = (v: number) => `$${v.toFixed(4)}`; const fmtK = (v: number) => (v >= 1000 ? `${(v / 1000).toFixed(1)}k` : String(v)); diff --git a/src/renderer/utils/sessionAnalyzer.ts b/src/renderer/utils/sessionAnalyzer.ts index 82da65ff..201acc47 100644 --- a/src/renderer/utils/sessionAnalyzer.ts +++ b/src/renderer/utils/sessionAnalyzer.ts @@ -882,7 +882,7 @@ export function analyzeSession(detail: SessionDetail): SessionReport { totalCacheReadTokens += stats.cacheRead; } - const grandTotal = + let grandTotal = totalInputTokens + totalOutputTokens + totalCacheCreationTokens + totalCacheReadTokens; // --- Cost analysis --- @@ -1150,6 +1150,14 @@ export function analyzeSession(detail: SessionDetail): SessionReport { const subagentLabel = 'Subagents (combined)'; byModel[subagentLabel] = subagentTokenStats; modelStats.set(subagentLabel, subagentTokenStats); + + // Update totals to include subagent tokens so the footer row stays consistent + totalInputTokens += subagentTokenStats.inputTokens; + totalOutputTokens += subagentTokenStats.outputTokens; + totalCacheCreationTokens += subagentTokenStats.cacheCreation; + totalCacheReadTokens += subagentTokenStats.cacheRead; + grandTotal = + totalInputTokens + totalOutputTokens + totalCacheCreationTokens + totalCacheReadTokens; } // --- Assessment computations ---