Skip to content

Commit b97a72b

Browse files
committed
Revert "feat(usage): show the cached subset beside every token total"
This reverts 7b3c4e9. The reported defect was Devin-only and had nothing to do with the display layer. The logs table has always rendered a total with its cached value; Devin rows showed a bare total because the cloud-direct adapter decoded GetChatMessageResponse field 28 (response_dimension_groups, the rows the IDE draws) instead of field 7 (ModelUsageStats), so cache read and cache write never reached the log row in the first place. #4419 fixes that at the source, which is the whole fix. Changing the Usage page, the dashboard tile and the CLI tables rewrote surfaces that were already correct for every other provider, so the revert restores them.
1 parent 1e28e62 commit b97a72b

11 files changed

Lines changed: 10 additions & 152 deletions

File tree

-18.5 KB
Binary file not shown.

‎gui/src/format-tokens.ts‎

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,3 @@ export function formatTokens(n: number, locale: string): string {
3232
if (n < 1_000_000_000_000) return `${trim((n / 1_000_000_000).toFixed(1))}B`;
3333
return `${trim((n / 1_000_000_000_000).toFixed(1))}T`;
3434
}
35-
36-
/**
37-
* A token total with its cached subset beside it: `5.8만 c5.7만`, `58K c57K`.
38-
*
39-
* A cached request's total is mostly cache. Printing the total alone makes a
40-
* 58,000-token prompt that is 57,000 cache read and 1,000 fresh look like an
41-
* ordinary 58,000-token prompt, and it reads as a different, smaller request
42-
* than the log row directly below it, which already shows the companion. The
43-
* `c` marker matches the `logs.tokens.cacheRead` label, which reads
44-
* "cache read (c)".
45-
*
46-
* The companion is omitted only when there is no cache to report. It is NOT
47-
* omitted when the cached subset equals the total: a turn served entirely from
48-
* cache is the most interesting row on the page, and hiding its marker there
49-
* would blank exactly the case this exists for.
50-
*/
51-
export function formatTokensWithCache(total: number, cached: number | undefined, locale: string): string {
52-
const base = formatTokens(total, locale);
53-
if (cached === undefined || !Number.isFinite(cached) || cached <= 0) return base;
54-
return `${base} c${formatTokens(cached, locale)}`;
55-
}

‎gui/src/pages/Logs.tsx‎

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useVirtualizer } from "@tanstack/react-virtual";
33
import { useI18n, LOCALES, type TFn } from "../i18n/shared";
44
import { formatProviderDisplayName } from "../provider-icons";
55
import { formatTokens } from "../format-tokens";
6-
import { formatTokensWithCache } from "../format-tokens";
76
import { hashLogConversationQuery } from "../log-conversation-id";
87
import { statusCodeInfo } from "../status-codes";
98
import { IconX } from "../icons";
@@ -364,27 +363,19 @@ function formatLogDateTime(ts: number, localeTag?: string, timeZone?: string): s
364363
function summarizeFilteredLogs(entries: LogEntry[]): {
365364
requests: number;
366365
totalTokens: number;
367-
cachedInputTokens: number;
368366
estimatedCostUsd: number;
369367
priorityLowerBound: boolean;
370368
unpricedRequests: number;
371369
unmeteredRequests: number;
372370
} {
373371
let totalTokens = 0;
374-
let cachedInputTokens = 0;
375372
for (const entry of entries) {
376373
const tokens = displayTokenTotal(entry);
377374
if (tokens !== undefined) totalTokens += tokens;
378-
// The banner sits directly above rows that already print `c <read>`, so a
379-
// total with no companion read as a different, smaller figure than the rows
380-
// it summarizes.
381-
const read = cacheSplit(entry).read;
382-
if (read !== undefined && read > 0) cachedInputTokens += read;
383375
}
384376
return {
385377
requests: entries.length,
386378
totalTokens,
387-
cachedInputTokens,
388379
...summarizeEstimatedCosts(entries),
389380
};
390381
}
@@ -696,11 +687,7 @@ export default function Logs({ apiBase }: { apiBase: string }) {
696687
<Notice tone="ok">
697688
{t("logs.conversation.totals", {
698689
requests: conversationTotals.requests,
699-
tokens: formatTokensWithCache(
700-
conversationTotals.totalTokens,
701-
conversationTotals.cachedInputTokens,
702-
localeTag ?? locale,
703-
),
690+
tokens: formatTokens(conversationTotals.totalTokens, localeTag ?? locale),
704691
cost: formatEstimatedUsdValue(
705692
conversationTotals.estimatedCostUsd,
706693
t,

‎gui/src/pages/Usage.tsx‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from "react";
22
import { useI18n, type TFn, type Locale } from "../i18n/shared";
33
import { formatProviderDisplayName } from "../provider-icons";
4-
import { formatTokens, formatTokensWithCache } from "../format-tokens";
4+
import { formatTokens } from "../format-tokens";
55
import { formatEstimatedUsdValue as formatUsdEstimate } from "../intl-formatters";
66
import { readSessionListCache, writeSessionListCache } from "../session-list-cache";
77
import { EmptyState, Notice } from "../ui";
@@ -64,10 +64,6 @@ interface UsageModel {
6464
totalTokens: number;
6565
inputTokens: number;
6666
outputTokens: number;
67-
// /api/usage has carried these all along; dropping them from the row type is
68-
// what left the token column without its cached companion.
69-
cachedInputTokens?: number;
70-
cacheReadInputTokens?: number;
7167
shareRatio: number;
7268
}
7369

@@ -78,8 +74,6 @@ interface UsageProvider {
7874
reportedRequests: number;
7975
estimatedRequests: number;
8076
totalTokens: number;
81-
cachedInputTokens?: number;
82-
cacheReadInputTokens?: number;
8377
shareRatio: number;
8478
}
8579

@@ -567,7 +561,7 @@ function UsageModelsTable({
567561
<td className="muted">{formatProviderDisplayName(model.provider, t)}</td>
568562
<td className="num">{model.requests}</td>
569563
<td className="num">{model.measuredRequests}</td>
570-
<td className="num mono">{formatTokensWithCache(model.totalTokens, model.cacheReadInputTokens ?? model.cachedInputTokens, locale)}</td>
564+
<td className="num mono">{formatTokens(model.totalTokens, locale)}</td>
571565
<td><div className="usage-bar"><div className="usage-bar-fill" style={{ width: `${Math.round(model.shareRatio * 100)}%` }} /></div></td>
572566
</tr>
573567
))}
@@ -627,7 +621,7 @@ function UsageProvidersTable({
627621
<td className="mono">{formatProviderDisplayName(provider.provider, t)}</td>
628622
<td className="num">{provider.requests}</td>
629623
<td className="num">{provider.measuredRequests}</td>
630-
<td className="num mono">{formatTokensWithCache(provider.totalTokens, provider.cacheReadInputTokens ?? provider.cachedInputTokens, locale)}</td>
624+
<td className="num mono">{formatTokens(provider.totalTokens, locale)}</td>
631625
<td><div className="usage-bar"><div className="usage-bar-fill" style={{ width: `${Math.round(provider.shareRatio * 100)}%` }} /></div></td>
632626
</tr>
633627
))}

‎gui/src/pages/dashboard-overview-head.tsx‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { IconAlert, IconInfo } from "../icons";
22
import { type TKey, useT } from "../i18n/shared";
3-
import { formatTokensWithCache } from "../format-tokens";
3+
import { formatTokens } from "../format-tokens";
44
import { formatUptime } from "../formatUptime";
55
import { navigateHash } from "../hash-routing";
66
import type { useDashboardData } from "./use-dashboard-data";
@@ -81,13 +81,7 @@ export function DashboardOverviewHead({
8181
<div className="stat" aria-busy={healthLoading || undefined}><div className="label">{t("dash.providers")}</div><div className="value">{providers.length}</div></div>
8282
<div className="stat" aria-busy={usageLoading || undefined}>
8383
<div className="label">{t("dash.tokens30d")}</div>
84-
<div className="value mono">{usage30d && usage30d.summary.requests > 0
85-
? formatTokensWithCache(
86-
usage30d.summary.totalTokens,
87-
usage30d.summary.cacheReadInputTokens ?? usage30d.summary.cachedInputTokens,
88-
locale,
89-
)
90-
: "—"}</div>
84+
<div className="value mono">{usage30d && usage30d.summary.requests > 0 ? formatTokens(usage30d.summary.totalTokens, locale) : "—"}</div>
9185
<div className="muted text-label dash-stat-coverage">
9286
{usage30d && usage30d.summary.requests > 0
9387
? t("dash.coverage").replace("{pct}", `${Math.round(usage30d.summary.coverageRatio * 100)}%`)

‎gui/src/pages/dashboard-shared.ts‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,17 +123,7 @@ export interface SidecarPatch {
123123
};
124124
}
125125
export interface ShadowCallData { enabled: boolean; model: string; sourceModels?: string[] }
126-
export interface UsageSummary30d {
127-
summary: {
128-
requests: number;
129-
totalTokens: number;
130-
coverageRatio: number;
131-
// Already on /api/usage; the tile showed a bare total only because this
132-
// type dropped them.
133-
cachedInputTokens?: number;
134-
cacheReadInputTokens?: number;
135-
};
136-
}
126+
export interface UsageSummary30d { summary: { requests: number; totalTokens: number; coverageRatio: number } }
137127
export type UpdateChannel = "latest" | "preview";
138128
export type Installer = "npm" | "bun" | "source";
139129
export type UpdateJobStatus = "running" | "restarting" | "succeeded" | "failed";

‎scripts/test-layout/layout.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,6 @@
718718
"grok-sync.test.ts": "providers/xai",
719719
"grok-writer-boundary.test.ts": "providers/xai",
720720
"gui-api-error.test.ts": "gui",
721-
"gui-format-tokens-cache.test.ts": "gui",
722721
"gui-management-session.test.ts": "gui",
723722
"gui-pair-capability.test.ts": "gui",
724723
"gui-pair-client.test.ts": "gui",

‎src/cli/usage-report.ts‎

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ interface CostRow {
1717
model?: string;
1818
requests: number;
1919
totalTokens: number;
20-
/**
21-
* Cache-read subset of the row's tokens. The API sends it; the CLI dropped it,
22-
* so a mostly-cached provider's TOKENS column read as an ordinary total while
23-
* the summary line two rows above already said `cached N`.
24-
*/
25-
cachedInputTokens?: number;
26-
cacheReadInputTokens?: number;
2720
estimatedCostUsd?: number;
2821
}
2922

@@ -60,8 +53,6 @@ interface UsageReportInput {
6053
ambiguous?: boolean;
6154
requests: number;
6255
totalTokens: number;
63-
cachedInputTokens?: number;
64-
cacheReadInputTokens?: number;
6556
estimatedCostUsd?: number;
6657
}[];
6758
}
@@ -85,16 +76,6 @@ function count(value: number | undefined): string {
8576
return typeof value === "number" && Number.isFinite(value) ? value.toLocaleString("en-US") : "—";
8677
}
8778

88-
/**
89-
* A row's token total with its cache-read subset, matching the summary line's
90-
* `cached N` wording rather than inventing a second vocabulary for the tables.
91-
*/
92-
function countWithCache(total: number | undefined, cached: number | undefined): string {
93-
const base = count(total);
94-
if (typeof cached !== "number" || !Number.isFinite(cached) || cached <= 0) return base;
95-
return `${base} (cached ${count(cached)})`;
96-
}
97-
9879
/**
9980
* Matches the dashboard's `~$` with four fraction digits. Estimates below a
10081
* hundredth of a cent still read as a number rather than collapsing to $0.00,
@@ -160,12 +141,7 @@ export function formatUsageReport(data: UsageReportInput): string[] {
160141
lines.push("");
161142
lines.push(...table(
162143
["PROVIDER", "REQUESTS", "TOKENS", "EST. COST"],
163-
providers.map(row => [
164-
row.provider,
165-
count(row.requests),
166-
countWithCache(row.totalTokens, row.cacheReadInputTokens ?? row.cachedInputTokens),
167-
usd(row.estimatedCostUsd),
168-
]),
144+
providers.map(row => [row.provider, count(row.requests), count(row.totalTokens), usd(row.estimatedCostUsd)]),
169145
));
170146
}
171147

@@ -187,7 +163,7 @@ export function formatUsageReport(data: UsageReportInput): string[] {
187163
// wrong conclusion. Mark it rather than presenting it as a single identity.
188164
row.ambiguous ? `${terminalText(row.accountLogLabel)} (ambiguous)` : terminalText(row.accountLogLabel),
189165
count(row.requests),
190-
countWithCache(row.totalTokens, row.cacheReadInputTokens ?? row.cachedInputTokens),
166+
count(row.totalTokens),
191167
usd(row.estimatedCostUsd),
192168
]),
193169
));
@@ -199,13 +175,7 @@ export function formatUsageReport(data: UsageReportInput): string[] {
199175
const shown = models.slice(0, MAX_MODEL_ROWS);
200176
lines.push(...table(
201177
["MODEL", "PROVIDER", "REQUESTS", "TOKENS", "EST. COST"],
202-
shown.map(row => [
203-
row.model ?? "-",
204-
row.provider,
205-
count(row.requests),
206-
countWithCache(row.totalTokens, row.cacheReadInputTokens ?? row.cachedInputTokens),
207-
usd(row.estimatedCostUsd),
208-
]),
178+
shown.map(row => [row.model ?? "-", row.provider, count(row.requests), count(row.totalTokens), usd(row.estimatedCostUsd)]),
209179
));
210180
if (models.length > shown.length) {
211181
lines.push(`... ${models.length - shown.length} more (use --json)`);

‎tests/cli/cli-usage-report.test.ts‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -404,28 +404,3 @@ describe("ocx logs --follow output contract", () => {
404404
}
405405
});
406406
});
407-
408-
describe("cached tokens in the per-row tables", () => {
409-
test("a provider and model row name their cache-read subset", () => {
410-
// The summary line has always said "cached N". The tables below it printed a
411-
// bare total, so a mostly-cached provider looked like an ordinary one.
412-
const lines = formatUsageReport({
413-
range: "today",
414-
summary: { requests: 1, totalTokens: 58_000, cachedInputTokens: 57_000 },
415-
providers: [{ provider: "devin-cli", requests: 1, totalTokens: 58_000, cacheReadInputTokens: 57_000 }],
416-
models: [{ provider: "devin-cli", model: "swe-2", requests: 1, totalTokens: 58_000, cachedInputTokens: 57_000 }],
417-
}).join("\n");
418-
expect(lines).toContain("58,000 (cached 57,000)");
419-
expect(lines.match(/cached 57,000/g)?.length).toBeGreaterThanOrEqual(2);
420-
});
421-
422-
test("a provider that reports no cache keeps a bare total", () => {
423-
const lines = formatUsageReport({
424-
range: "today",
425-
summary: { requests: 1, totalTokens: 58_000 },
426-
providers: [{ provider: "xai", requests: 1, totalTokens: 58_000 }],
427-
}).join("\n");
428-
expect(lines).toContain("58,000");
429-
expect(lines).not.toContain("cached");
430-
});
431-
});

‎tests/fixtures/test-layout-expected.json‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,6 @@
549549
"grok-sync.test.ts": "providers/xai",
550550
"grok-writer-boundary.test.ts": "providers/xai",
551551
"gui-api-error.test.ts": "gui",
552-
"gui-format-tokens-cache.test.ts": "gui",
553552
"gui-management-session.test.ts": "gui",
554553
"gui-pair-capability.test.ts": "gui",
555554
"gui-pair-client.test.ts": "gui",

0 commit comments

Comments
 (0)