Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(dashboard): count reasoning inside output token totals

Rudy Celekli3c52283afa1e
diff --git a/cli/beacon/internal/endpoint/dashboard/static/app.js b/cli/beacon/internal/endpoint/dashboard/static/app.js
index de3e99e3..7d96e1dc 100644
--- a/cli/beacon/internal/endpoint/dashboard/static/app.js
+++ b/cli/beacon/internal/endpoint/dashboard/static/app.js
@@ -2377,8 +2377,7 @@ function usageTotal(usage = {}) {
return (usage.input_tokens || 0) +
(usage.output_tokens || 0) +
(usage.cache_read_input_tokens || 0) +
- (usage.cache_creation_input_tokens || 0) +
- (usage.reasoning_output_tokens || 0);
+ (usage.cache_creation_input_tokens || 0);
}
// The estimate is labeled wherever it appears: it is a list price from the embedded catalog
@@ -2405,7 +2404,7 @@ function renderTokenCards(totals, pricing) {
const cards = [
{ label: "Total Tokens", value: formatTokens(totalTokens), hint: "local captured usage" },
{ label: "Input Tokens", value: formatTokens((totals.input_tokens || 0) + (totals.cache_read_input_tokens || 0) + (totals.cache_creation_input_tokens || 0)), hint: "fresh + cached" },
- { label: "Output Tokens", value: formatTokens((totals.output_tokens || 0) + (totals.reasoning_output_tokens || 0)), hint: "completion + reasoning" },
+ { label: "Output Tokens", value: formatTokens(totals.output_tokens), hint: "includes reasoning" },
{ label: "Cached Tokens", value: formatTokens((totals.cache_read_input_tokens || 0) + (totals.cache_creation_input_tokens || 0)) },
{ label: "Reasoning", value: formatTokens(totals.reasoning_output_tokens) },
{ label: "Reported cost (USD)", value: totals.cost_usd ? totals.cost_usd.toFixed(4) : "-", hint: "runtime-reported only" },
@@ -2433,7 +2432,6 @@ function renderTokenSplit(totals) {
{ name: "Input (fresh)", value: freshInput, color: "#0f7498" },
{ name: "Cached input", value: cached, color: "#10b981" },
{ name: "Output", value: output, color: "#7dd3fc" },
- { name: "Reasoning", value: reasoning, color: "#f59e0b" },
].filter((segment) => segment.value > 0);
const total = segments.reduce((sum, segment) => sum + segment.value, 0);
if (!total) {
@@ -2462,6 +2460,7 @@ function renderTokenSplit(totals) {
</div>
`).join("")}
</div>
+ ${reasoning > 0 && output > 0 ? `<p class="muted token-reasoning-note">Reasoning: ${escapeHTML(formatTokens(reasoning))} tokens (included in output).</p>` : ""}
`;
}
@@ -2577,7 +2576,7 @@ function renderTokenThroughput(series) {
.map((bucket) => {
const usage = bucket.usage || {};
const input = (usage.input_tokens || 0) + (usage.cache_read_input_tokens || 0) + (usage.cache_creation_input_tokens || 0);
- const output = (usage.output_tokens || 0) + (usage.reasoning_output_tokens || 0);
+ const output = usage.output_tokens || 0;
const inputWidth = Math.max(0, Math.round((input / max) * 100));
const outputWidth = Math.max(0, Math.round((output / max) * 100));
return `
diff --git a/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/token-reasoning.spec.ts b/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/token-reasoning.spec.ts
new file mode 100644
index 00000000..5a487f56
--- /dev/null
+++ b/cli/beacon/internal/endpoint/dashboard/testdata/lens-e2e/tests/token-reasoning.spec.ts
@@ -0,0 +1,58 @@
+import { expect, test } from '@playwright/test';
+
+// These fixed expectations follow tokens.Usage.TotalTokens: reasoning is an
+// output breakdown, not another disjoint quantity to add to the API's output.
+const cases = [
+ { name: 'reasoning subset', usage: { input_tokens: 100, output_tokens: 50, reasoning_output_tokens: 20 }, total: '150', compact: '150', output: '50', reasoning: '20', width: '33%', note: true },
+ { name: 'existing Gemini aggregate', usage: { input_tokens: 9600, output_tokens: 870, cache_read_input_tokens: 8000, reasoning_output_tokens: 420 }, total: '18,470', compact: '18.5K', output: '870', reasoning: '420', width: '5%', note: true },
+ { name: 'zero reasoning', usage: { input_tokens: 100, output_tokens: 50, reasoning_output_tokens: 0 }, total: '150', compact: '150', output: '50', reasoning: '0', width: '33%', note: false },
+ { name: 'absent reasoning', usage: { input_tokens: 100, output_tokens: 50 }, total: '150', compact: '150', output: '50', reasoning: '0', width: '33%', note: false },
+ { name: 'null reasoning', usage: { input_tokens: 100, output_tokens: 50, reasoning_output_tokens: null }, total: '150', compact: '150', output: '50', reasoning: '0', width: '33%', note: false },
+ { name: 'all output is reasoning', usage: { output_tokens: 50, reasoning_output_tokens: 50 }, total: '50', compact: '50', output: '50', reasoning: '50', width: '100%', note: true },
+ { name: 'cached input remains disjoint', usage: { input_tokens: 100, output_tokens: 50, cache_read_input_tokens: 30, cache_creation_input_tokens: 20, reasoning_output_tokens: 20 }, total: '200', compact: '200', output: '50', reasoning: '20', width: '25%', note: true },
+ { name: 'partial reasoning without output does not invent totals', usage: { input_tokens: 100, reasoning_output_tokens: 7 }, total: '100', compact: '100', output: '0', reasoning: '7', width: '0%', note: false },
+ { name: 'empty usage', usage: {}, total: '0', compact: '0', output: '0', reasoning: '0', width: null, note: false },
+];
+
+for (const fixture of cases) {
+ test(`token totals: ${fixture.name}`, async ({ page }) => {
+ const usage = { ...fixture.usage, cost_usd: 0.1256, estimated_cost_usd: 0.2345, events: 1 };
+ const groups = [{ key: 'owned-model', usage }];
+ await page.route('**/api/status', (route) => route.fulfill({ json: { log_path: '/owned/runtime.jsonl' } }));
+ await page.route('**/api/tokens?*', (route) => route.fulfill({ json: {
+ totals: usage, total_events: 1, events_with_usage: 1,
+ series: [{ start: '2026-10-19T12:00:00Z', usage }],
+ by_model: groups, by_harness: groups, by_session: groups,
+ } }));
+ await page.goto('/tokens.html');
+ const cards = page.locator('#token-cards .card');
+ const card = (label: string) => cards.filter({ has: page.locator('.muted').filter({ hasText: new RegExp(`^${label}$`) }) }).locator('.value');
+ await expect(card('Total Tokens')).toHaveText(fixture.total);
+ await expect(card('Output Tokens')).toHaveText(fixture.output);
+ await expect(card('Reasoning')).toHaveText(fixture.reasoning);
+ await expect(card('Reported cost \\(USD\\)')).toHaveText('0.1256');
+ await expect(card('Est. cost \\(USD\\)')).toHaveText('~0.2345');
+ // All three breakdowns must agree with the API/CLI total, including zero
+ // token groups retained because they carry a runtime-reported cost.
+ await expect(page.locator('#token-breakdowns .panel-total')).toHaveText([fixture.compact, fixture.compact, fixture.compact]);
+ await expect(page.locator('#token-models tr td').nth(2)).toHaveText(fixture.output);
+ const note = page.locator('#token-split .token-reasoning-note');
+ if (fixture.note) {
+ await expect(note).toContainText(fixture.reasoning);
+ await expect(note).toContainText('included in output');
+ } else {
+ await expect(note).toHaveCount(0);
+ }
+ // The donut's segments are disjoint. Reasoning stays available as a
+ // separate annotation/card rather than occupying another slice.
+ if (fixture.width === null) {
+ await expect(page.locator('#token-split .token-donut')).toHaveCount(0);
+ await expect(page.locator('#token-throughput .throughput-row')).toHaveCount(0);
+ } else {
+ await expect(page.locator('#token-split .token-split-legend')).not.toContainText('Reasoning');
+ await expect(page.locator('#token-split .token-donut strong')).toHaveText(fixture.compact);
+ await expect(page.locator('#token-throughput .throughput-row strong')).toHaveText(fixture.total);
+ await expect(page.locator('#token-throughput .throughput-output')).toHaveAttribute('style', `width: ${fixture.width}`);
+ }
+ });
+}