Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(model-hub): one door for every token figure the usage tab states
cyh8ccb8c0a7eda
diff --git a/docs/plans/model-hub-usage-metering.md b/docs/plans/model-hub-usage-metering.mdindex 2b88628e5..f8dcdad43 100644--- a/docs/plans/model-hub-usage-metering.md+++ b/docs/plans/model-hub-usage-metering.md@@ -1383,3 +1383,84 @@ What proved it: `npm test -- UsageTab.test.tsx` now runs 1 file / 14 cases, andfails with the resolver's own message when `MEMORY-LIST-006`'s citation is rotted to anonexistent ID (reverted after checking). Full suite 231 files / 2943 tests, CLI gate 22citations across 22 rows, `tsc` clean, `eslint` clean, `npm run build` ✓.++### Stage 2, round 7 (head `f5991f2a6`) — breaker tripped: a token figure states a number without saying it was measured++One P2 finding, and it is a **class repeat on a second reviewed head** (`5957182` →+`f5991f2a6`), so the breaker trips mechanically. As the orchestrator in a user-started+session I recorded the scope decision and continued: the smallest complete action is clear,+reversible, and changes no contract.++The finding is about the copy round 2 introduced. `byDay.zero` claims 「这个区间的 token 用量+是 0」 for a window whose upstreams never reported anything, because `usageDayColumns`+carried `requests` and `tokens` and **dropped `token_reports`** — so no site in the day+series could ask the coverage question even if its copy wanted to.++**Why this is the same class, and why round 2's closure could not have held.** Round 2 named+the class *the day series asks tokens a question only requests can answer* and closed it with+`usageDayIsMetered`. That predicate is about activity, and it is still right about activity.+What round 2 missed is that a bucket carries **three independent facts, not two**:++| Counter | The question it alone answers |+| --- | --- |+| `requests` | did calls happen |+| `token_reports` | did an upstream say what they cost |+| `input_tokens + output_tokens` | how much |++A rendered `0` is therefore three different readings — a cost reported as nothing, a cost+nobody reported, and nothing having run at all — and round 2's projection could distinguish+only the third. Round 2 also explicitly ruled the stat cards *out* of the class, on the+evidence that they 「each state a token figure they really do own」. Ownership was the wrong+test: owning the figure says nothing about whether the figure is a measurement.++**The inventory, which is what makes this a class and not a line.** Every token figure the+tab states, found by grepping every token expression in `UsageTab.tsx` rather than by+recalling the panels — **8 members**, one of which round 2's ruling had cleared:++1. the tokens stat card's value+2. its input/output split note+3. the cached-input card's note — 「No input tokens in this window」, the same defect one card+ over: with nothing reported there were no input tokens *we know of*, and an absence of+ reports is not an absence of usage+4. the by-model row cell+5. the by-source row cell+6. the day bar's tooltip readout+7. the sr-only day table cell+8. the peak / no-peak sentence++**The fix is one door plus an enumerable marker.** `useTokenText(counters, value)` is the only+path from a token count to text, and coverage travels *with* the value rather than being+checked by the caller, so a new token figure cannot be written without naming the counters it+came from. `TokenFigure` wraps it in `<span data-usage-token="">`, which is not styling: it is+what lets a test enumerate every node-shaped token figure on screen and assert they all went+through the door — completeness by construction, which a per-site test cannot claim. Figures+interpolated into translated sentences have no element of their own and call `useTokenText`+directly; their sentence is then the asserted unit.++**Two predicates, deliberately not one.** The first draft was `token_reports > 0` alone, and+it would have shipped the mirror image of the defect it fixes: a day where nothing ran cost+nothing, and that zero is measured by *our own* request counter rather than promised by an+upstream. Blanking it reads an idle day as unknowable. So:++- `usageTokensAreReported` = `token_reports > 0` — an upstream costed something. Used by peak+ selection and by the claim about what the reports said.+- `usageTokensAreKnown` = `usageTokensAreReported(c) || c.requests === 0` — the number is a+ measurement, so printable. Used by the figure door.++Only a day whose tokens were reported can be the busiest one: a day with no report has no+measured cost to compare, so naming it the peak puts a superlative on a number the report+never carried. And the no-peak copy becomes four-way with **`reported` ordered before+`metered`** — a window with any report in it can state what its reports said, and the calls+that came back without one are the requests card's shortfall to name, not this sentence's.++**The backend premise, verified rather than assumed.** A reported zero really does exist on+the wire: `extract_protocol_usage` (`core/handlers/model_hub/stream_wire.py:533`) returns a+non-null report for an explicit all-zero usage block — `_usage_sum` returns `0`, not `None` —+and `usage.py:464` sets `token_reports = call.requests if usage is not None else 0`. So+MH-USAGE-025 draws a window that exists, not a hypothetical.++**What proved it, by breaking it.** Rotting `usageTokensAreKnown` to `return true` fails+MH-USAGE-021 and MH-USAGE-026 and nothing else; swapping the `reported`/`metered` branch order+fails MH-USAGE-025 and only it. Both restored. Full suite 231 files / 2950 tests, catalog gate+24 citations across 24 rows, model_hub catalog pytest ✓, `tsc` clean, `eslint` clean,+`npm run build` ✓.diff --git a/tests/scenarios/model_hub/catalog.yaml b/tests/scenarios/model_hub/catalog.yamlindex ecc00a2fb..167c8aafd 100644--- a/tests/scenarios/model_hub/catalog.yaml+++ b/tests/scenarios/model_hub/catalog.yaml@@ -276,6 +276,18 @@ scenarios:kind: observationlayer: unittest: ui/src/components/settings/models/UsageTab.test.tsx::MH-USAGE-024+ - id: MH-USAGE-025+ name: A window whose upstreams reported zero tokens reads as measured rather than unreported+ status: covered+ kind: observation+ layer: unit+ test: ui/src/components/settings/models/UsageTab.test.tsx::MH-USAGE-025+ - id: MH-USAGE-026+ name: Every token figure the usage report states names the coverage it was measured from+ status: covered+ kind: observation+ layer: unit+ test: ui/src/components/settings/models/UsageTab.test.tsx::MH-USAGE-026- id: MH-RES-LIVE-001name: Live turn retries an eligible backup before streaming startsstatus: covereddiff --git a/ui/src/components/settings/models/UsageTab.test.tsx b/ui/src/components/settings/models/UsageTab.test.tsxindex 1d9093e7a..fdea3cd81 100644--- a/ui/src/components/settings/models/UsageTab.test.tsx+++ b/ui/src/components/settings/models/UsageTab.test.tsx@@ -154,19 +154,93 @@ describe('UsageTab', () => {expect(container.textContent).toContain(en.settings.models.usage.byDay.unreported);expect(container.textContent).not.toContain(en.settings.models.usage.byDay.quiet);+ expect(container.textContent).not.toContain(en.settings.models.usage.byDay.zero);// Every column says what its day carried, so a bar the report could not// measure still reads as a day that ran rather than as an unexplained sliver.// (Whether it is floored to one is CSS the DOM cannot answer for; the decision// behind it is `usageDayIsMetered`, asserted over columns in// `usageProjection.test.ts`.)+ //+ // The two kinds of day in this window state their tokens differently, which is+ // the point: a day of uncosted calls has no number to print, while the day+ // between them ran nothing and so really did cost zero.const readouts = [...container.querySelectorAll('.model-hub-usage-track')].map((track) => track.getAttribute('title'));expect(readouts).toEqual([- 'Aug 16, 2026 · 0 tokens · 4 requests',+ 'Aug 16, 2026 · — tokens · 4 requests','Aug 17, 2026 · 0 tokens · 0 requests',- 'Aug 18, 2026 · 0 tokens · 4 requests',+ 'Aug 18, 2026 · — tokens · 4 requests',]);});+ it('MH-USAGE-025: reads a window whose reports all came back zero as measured, not as missing', () => {+ // The mirror of MH-USAGE-021, one question over. Every call here WAS costed and+ // the answer was nothing — an explicit all-zero usage block, which+ // `extract_protocol_usage` forwards as a report rather than as an absence, so+ // `token_reports` equals `requests` while every token count is 0. Reading that+ // as 「no day reported its tokens」 would call a valid upstream answer missing+ // evidence, and blanking the figures would hide a cost the report does state.+ const free = counters({ requests: 4, token_reports: 4, input_tokens: 0, cached_input_tokens: 0, output_tokens: 0 });+ const { container } = draw(readyRegion(summary({+ from_day: '2026-08-17',+ to_day: '2026-08-18',+ window_days: 2,+ totals: free,+ sources: [source({ ...free, models: [model(free)] })],+ days: [{ ...free, day: '2026-08-18' }],+ })));++ expect(container.textContent).toContain(en.settings.models.usage.byDay.zero);+ expect(container.textContent).not.toContain(en.settings.models.usage.byDay.unreported);+ expect(container.textContent).not.toContain(en.settings.models.usage.byDay.quiet);+ // A measured zero is a number, and the requests card has no shortfall to state+ // about it either — nothing went unreported.+ expect(container.textContent).toContain(en.settings.models.usage.requests.reported);+ expect(container.textContent).not.toContain(en.settings.models.usage.tokens.none);+ // And the cached card may say what MH-USAGE-026 forbids it to say, because here+ // it is true: these calls were costed, and the cost included no input.+ expect(container.textContent).toContain(en.settings.models.usage.cached.none);+ const tokenFigures = [...container.querySelectorAll('[data-usage-token]')];+ expect(tokenFigures.length).toBeGreaterThan(0);+ for (const figure of tokenFigures) expect(figure.textContent).toBe('0');+ });++ it('MH-USAGE-026: every token figure on screen states its own coverage, whatever states it', () => {+ // The class MH-USAGE-021 and MH-USAGE-025 are two members of: a token figure+ // printed without asking whether anything reported it. Asked of every figure the+ // tab renders rather than of a list of the seven known ones — the marker is+ // emitted by the single door they all go through, so a card, cell, or column+ // added later is covered by existing rather than by an edit here.+ const uncosted = counters({ requests: 6, token_reports: 0, input_tokens: 0, cached_input_tokens: 0, output_tokens: 0 });+ const { container } = draw(readyRegion(summary({+ from_day: '2026-08-17',+ to_day: '2026-08-18',+ window_days: 2,+ totals: uncosted,+ sources: [source({ ...uncosted, models: [model(uncosted)] })],+ // Both reported days carried calls nobody costed, so no day of this window+ // may print a token number at all.+ days: [{ ...uncosted, day: '2026-08-17' }, { ...uncosted, day: '2026-08-18' }],+ })));++ const tokenFigures = [...container.querySelectorAll('[data-usage-token]')];+ expect(tokenFigures.length).toBeGreaterThan(0);+ for (const figure of tokenFigures) expect(figure.textContent).toBe(en.settings.models.usage.blank);+ // …and the sentences that interpolate a figure instead of holding one say the+ // same thing, since a tooltip and a note have no element of their own to mark.+ const readouts = [...container.querySelectorAll('.model-hub-usage-track')].map((track) => track.getAttribute('title'));+ expect(readouts).toEqual([+ 'Aug 17, 2026 · — tokens · 6 requests',+ 'Aug 18, 2026 · — tokens · 6 requests',+ ]);+ // The notes go the same way. The tokens card replaces the input/output split+ // rather than blanking both halves of it — 「— in · — out」 states a breakdown of+ // a number nobody gave — and the cached card must not read an absence of reports+ // as an absence of input.+ expect(container.textContent).toContain(en.settings.models.usage.tokens.none);+ expect(container.textContent).not.toContain(' in · ');+ expect(container.textContent).not.toContain(en.settings.models.usage.cached.none);+ });+it('MH-USAGE-023: states every day of the window in text, not only in a pointer tooltip', () => {const { container } = draw(readyRegion(summary()));const tooltips = [...container.querySelectorAll('.model-hub-usage-track')].map((track) => track.getAttribute('title') ?? '');diff --git a/ui/src/components/settings/models/UsageTab.tsx b/ui/src/components/settings/models/UsageTab.tsxindex 34acb3cfe..bcd66497b 100644--- a/ui/src/components/settings/models/UsageTab.tsx+++ b/ui/src/components/settings/models/UsageTab.tsx@@ -24,7 +24,7 @@ import { useTranslation } from 'react-i18next';import { SegmentedRadio } from '@/components/ui/segmented';import { formatCount, formatDayTime, formatPercent } from './format';import { foldRegionRead, regionFailed, type RegionRead } from './regionRead';-import type { UsageByModel, UsageBySource, UsageSummary } from './types';+import type { UsageByModel, UsageBySource, UsageCounters, UsageSummary } from './types';import {USAGE_WINDOW_OPTIONS,formatLocalDay,@@ -35,6 +35,8 @@ import {usageDayIsMetered,usageIsEmpty,usageReportShortfall,+ usageTokensAreKnown,+ usageTokensAreReported,usageTotalTokens,type UsageDayColumn,type UsageIdentity,@@ -47,6 +49,44 @@ const useCount = () => {return (value: number) => formatCount(value, i18n.language);};+/** Anything a token figure is derived from: a totals bucket, a row, or a day. */+type TokenCoverage = Pick<UsageCounters, 'requests' | 'token_reports'>;++/**+ * The one way this tab turns a token count into text.+ *+ * A rendered `0` cannot say which of three things it means — a cost reported as+ * nothing, a cost nobody reported, or nothing having run at all — and every panel+ * this tab draws states token figures, so wording any single one of them correctly+ * leaves all the others to be found one review round at a time. The figure asks+ * its own bucket first: for calls that no upstream ever costed there is no+ * measurement to print, and the blank marker the cached share and the metering+ * timestamp already use says exactly that.+ *+ * Coverage travels with the value rather than being checked by the caller, so a+ * new token figure cannot be written without naming the counters it came from.+ */+const useTokenText = () => {+ const { t } = useTranslation();+ const count = useCount();+ return (counters: TokenCoverage, value: number) =>+ usageTokensAreKnown(counters) ? count(value) : (t('settings.models.usage.blank') as string);+};++/**+ * A token figure standing on its own, as a cell or a card value.+ *+ * `data-usage-token` is not styling: it is what lets a test enumerate every token+ * figure on screen and assert they all went through the door, which is a claim+ * about completeness that a per-site test cannot make. A figure interpolated into+ * a translated sentence has no element of its own and uses `useTokenText`+ * directly; its sentence is then the asserted unit.+ */+const TokenFigure: React.FC<{ counters: TokenCoverage; value: number }> = ({ counters, value }) => {+ const tokenText = useTokenText();+ return <span data-usage-token="">{tokenText(counters, value)}</span>;+};+/*** A row's own name, or the honest absence of one.*@@ -101,7 +141,7 @@ const Cell: React.FC<{ column: SourceColumn; children: React.ReactNode }> = ({ c);};-const StatCard: React.FC<{ label: string; value: string; note: string }> = ({ label, value, note }) => (+const StatCard: React.FC<{ label: string; value: React.ReactNode; note: string }> = ({ label, value, note }) => (<div className="model-hub-usage-stat flex flex-col rounded-xl border border-border bg-background"><span className="model-hub-usage-stat-label">{label}</span><span className="model-hub-usage-stat-value font-semibold text-foreground">{value}</span>@@ -119,8 +159,13 @@ const StatGrid: React.FC<{ summary: UsageSummary }> = ({ summary }) => {<div className="grid gap-4 sm:grid-cols-3"><StatCardlabel={t('settings.models.usage.tokens.label') as string}- value={count(usageTotalTokens(totals))}- note={t('settings.models.usage.tokens.detail', { input: count(totals.input_tokens), output: count(totals.output_tokens) }) as string}+ value={<TokenFigure counters={totals} value={usageTotalTokens(totals)} />}+ // The input/output split is a reading of the same unreported total, so it+ // cannot survive on its own once the total is blank: it says what nobody+ // reported instead.+ note={(usageTokensAreKnown(totals)+ ? t('settings.models.usage.tokens.detail', { input: count(totals.input_tokens), output: count(totals.output_tokens) })+ : t('settings.models.usage.tokens.none')) as string}/><StatCardlabel={t('settings.models.usage.requests.label') as string}@@ -134,9 +179,15 @@ const StatGrid: React.FC<{ summary: UsageSummary }> = ({ summary }) => {<StatCardlabel={t('settings.models.usage.cached.label') as string}value={cachedShare === null ? (t('settings.models.usage.blank') as string) : formatPercent(cachedShare, i18n.language)}- note={(cachedShare === null- ? t('settings.models.usage.cached.none')- : t('settings.models.usage.cached.detail', { cached: count(totals.cached_input_tokens), input: count(totals.input_tokens) })) as string}+ // 「No input tokens in this window」 is the same defect one card over: with+ // nothing reported there were no input tokens WE KNOW OF, and an absence of+ // reports is not an absence of usage. Coverage is asked before the share, so+ // the card states the missing reports rather than an empty input.+ note={(!usageTokensAreKnown(totals)+ ? t('settings.models.usage.tokens.none')+ : cachedShare === null+ ? t('settings.models.usage.cached.none')+ : t('settings.models.usage.cached.detail', { cached: count(totals.cached_input_tokens), input: count(totals.input_tokens) })) as string}/></div>);@@ -151,7 +202,7 @@ const ModelRow: React.FC<{ model: UsageByModel }> = ({ model }) => {<span role="rowheader" className="model-hub-usage-model flex min-w-0 items-baseline"><RowIdentity identity={modelIdentity(model)} goneKey="settings.models.usage.bySource.goneModel" /></span>- <Cell column="tokens">{count(usageTotalTokens(model))}</Cell>+ <Cell column="tokens"><TokenFigure counters={model} value={usageTotalTokens(model)} /></Cell><Cell column="requests">{count(model.requests)}</Cell><Cell column="cached">{share === null ? (t('settings.models.usage.blank') as string) : formatPercent(share, i18n.language)}@@ -176,7 +227,7 @@ const SourceRows: React.FC<{ source: UsageBySource }> = ({ source }) => {<span role="rowheader" className="model-hub-usage-source flex min-w-0 items-baseline font-semibold text-foreground"><RowIdentity identity={sourceIdentity(source)} goneKey="settings.models.usage.bySource.goneSource" /></span>- <Cell column="tokens">{count(usageTotalTokens(source))}</Cell>+ <Cell column="tokens"><TokenFigure counters={source} value={usageTotalTokens(source)} /></Cell><Cell column="requests">{count(source.requests)}</Cell><Cell column="cached">{share === null ? (t('settings.models.usage.blank') as string) : formatPercent(share, i18n.language)}@@ -227,14 +278,23 @@ const BySourcePanel: React.FC<{ summary: UsageSummary }> = ({ summary }) => {** Which day ran is `usageDayIsMetered`'s answer and never a token total: an* upstream can serve a call and report nothing about it, so a window of those has- * bars to draw and a peak it cannot name.+ * bars to draw and a peak it cannot name. Whether a day's cost is known at all is+ * `usageTokensAreReported`'s separate answer — asked of the very same zero.*/const ByDayPanel: React.FC<{ summary: UsageSummary }> = ({ summary }) => {const { t, i18n } = useTranslation();const count = useCount();+ const tokenText = useTokenText();const columns = React.useMemo(() => usageDayColumns(summary), [summary]);- const peak = columns.reduce<UsageDayColumn | null>((best, column) => (column.tokens > (best?.tokens ?? 0) ? column : best), null);+ // Only a day whose tokens were reported can be the busiest one. A day with no+ // report has no measured cost to compare, so naming it the peak would put a+ // superlative on a number the report never carried.+ const peak = columns.reduce<UsageDayColumn | null>(+ (best, column) => (usageTokensAreReported(column) && column.tokens > (best?.tokens ?? 0) ? column : best),+ null,+ );const metered = columns.some(usageDayIsMetered);+ const reported = columns.some(usageTokensAreReported);const day = (value: string) => formatLocalDay(value, i18n.language);// One day's figures as a hover readout. The table below states the same three// values in cells, and MH-USAGE-023 derives its expectation from this sentence@@ -242,7 +302,7 @@ const ByDayPanel: React.FC<{ summary: UsageSummary }> = ({ summary }) => {const readout = (column: UsageDayColumn) =>t('settings.models.usage.byDay.column', {day: day(column.day),- tokens: count(column.tokens),+ tokens: tokenText(column, column.tokens),requests: count(column.requests),}) as string;return (@@ -291,7 +351,7 @@ const ByDayPanel: React.FC<{ summary: UsageSummary }> = ({ summary }) => {{columns.map((column) => (<tr key={column.day}><th scope="row">{day(column.day)}</th>- <td>{count(column.tokens)}</td>+ <td><TokenFigure counters={column} value={column.tokens} /></td><td>{count(column.requests)}</td></tr>))}@@ -301,12 +361,19 @@ const ByDayPanel: React.FC<{ summary: UsageSummary }> = ({ summary }) => {<span className="truncate">{day(summary.from_day)}</span><span className="model-hub-usage-peak truncate">{peak !== null- ? t('settings.models.usage.byDay.peak', { tokens: count(peak.tokens), day: day(peak.day) })- // No peak is two different windows: one nobody used, and one whose- // upstreams never reported what they cost. Only the first is quiet.- : metered- ? t('settings.models.usage.byDay.unreported')- : t('settings.models.usage.byDay.quiet')}+ ? t('settings.models.usage.byDay.peak', { tokens: tokenText(peak, peak.tokens), day: day(peak.day) })+ // No peak is three different windows, and the tokens cannot tell them+ // apart: one nobody used, one whose upstreams never reported what the+ // calls cost, and one that was measured and really did cost nothing.+ // Coverage is asked before activity, because a window with any report+ // in it can state what its reports said — the calls that came back+ // without one are the requests card's shortfall to name, not this+ // sentence's.+ : reported+ ? t('settings.models.usage.byDay.zero')+ : metered+ ? t('settings.models.usage.byDay.unreported')+ : t('settings.models.usage.byDay.quiet')}</span><span className="truncate">{day(summary.to_day)}</span></div>diff --git a/ui/src/components/settings/models/usageProjection.test.ts b/ui/src/components/settings/models/usageProjection.test.tsindex 5bd035f29..fc6dedca0 100644--- a/ui/src/components/settings/models/usageProjection.test.ts+++ b/ui/src/components/settings/models/usageProjection.test.ts@@ -12,6 +12,8 @@ import {usageDayIsMetered,usageIsEmpty,usageReportShortfall,+ usageTokensAreKnown,+ usageTokensAreReported,usageTotalTokens,} from './usageProjection';@@ -86,6 +88,41 @@ describe('usageReportShortfall', () => {});});+describe('usageTokensAreReported', () => {+ // The same rendered zero, three payloads apart. Only `token_reports` says+ // whether it is a measurement, which is why no caller may read the total.+ it('separates a reported zero from calls nobody reported', () => {+ expect(usageTokensAreReported(counters({ requests: 4, token_reports: 4 }))).toBe(true);+ expect(usageTokensAreReported(counters({ requests: 4, token_reports: 0 }))).toBe(false);+ expect(usageTokensAreReported(counters())).toBe(false);+ });++ it('asks about coverage and never about size', () => {+ expect(usageTokensAreReported(counters({ requests: 1, token_reports: 1, input_tokens: 900_000 }))).toBe(true);+ expect(usageTokensAreReported(counters({ requests: 1, token_reports: 0, input_tokens: 900_000 }))).toBe(false);+ });+});++describe('usageTokensAreKnown', () => {+ // Wider than reported by exactly one case, and that case is the honest one:+ // nothing ran, so nothing was spent, and our own request counter is the evidence.+ // Refusing it would trade an unreported cost read as free for an idle window read+ // as unknowable.+ it('prints the zero nothing ran to earn, and refuses the one nobody costed', () => {+ expect(usageTokensAreKnown(counters({ requests: 0, token_reports: 0 }))).toBe(true);+ expect(usageTokensAreKnown(counters({ requests: 4, token_reports: 0 }))).toBe(false);+ expect(usageTokensAreKnown(counters({ requests: 4, token_reports: 4 }))).toBe(true);+ });++ // A partial report is a real measurement of the calls it covered; the calls it+ // did not cover are the shortfall's sentence to say, not this figure's.+ it('treats a partial report as a measurement and leaves the gap to the shortfall', () => {+ const partial = counters({ requests: 12, token_reports: 9, input_tokens: 400 });+ expect(usageTokensAreKnown(partial)).toBe(true);+ expect(usageReportShortfall(partial)).toBe(3);+ });+});+describe('usageCachedInputShare', () => {it('is the cached share of reported input', () => {expect(usageCachedInputShare(counters({ input_tokens: 200, cached_input_tokens: 50 }))).toBe(0.25);@@ -150,8 +187,13 @@ describe('formatLocalDay', () => {describe('usageDayColumns', () => {// A reported day exists because a call was metered on it, so it carries one- // unless the case is about a day that carried several.- const day = (value: string, tokens: number, requests = 1) => ({ ...counters({ requests, input_tokens: tokens }), day: value });+ // unless the case is about a day that carried several. Tokens imply the report+ // they were summed from — the server only totals what an upstream told it — so+ // the coverage counter follows the tokens unless a case sets it apart.+ const day = (value: string, tokens: number, requests = 1, token_reports = tokens > 0 ? requests : 0) => ({+ ...counters({ requests, token_reports, input_tokens: tokens }),+ day: value,+ });it('spans the whole window and zero-fills the days that carried no turn', () => {const columns = usageDayColumns(summary({ from_day: '2026-08-14', to_day: '2026-08-18', days: [day('2026-08-16', 40)] }));@@ -177,6 +219,25 @@ describe('usageDayColumns', () => {expect(columns.map((column) => column.requests)).toEqual([0, 3, 0]);});+ // And so does coverage, for the same reason one step further in: four calls that+ // were measured at nothing and four whose upstreams said nothing carry identical+ // tokens and identical requests. Only this counter tells the series apart, so a+ // column that lost it could not be drawn or described honestly at any zero.+ it('carries the token reports of every reported day through, and gives a filled-in day none', () => {+ const columns = usageDayColumns(summary({+ from_day: '2026-08-14',+ to_day: '2026-08-16',+ days: [day('2026-08-14', 0, 4, 4), day('2026-08-16', 0, 4, 0)],+ }));+ expect(columns.map((column) => column.tokens)).toEqual([0, 0, 0]);+ expect(columns.map((column) => column.requests)).toEqual([4, 0, 4]);+ expect(columns.map((column) => column.token_reports)).toEqual([4, 0, 0]);+ // Three identical zeroes, three different facts — a measured nothing, a day+ // nobody used, and a day nobody costed.+ expect(columns.map(usageTokensAreReported)).toEqual([true, false, false]);+ expect(columns.map(usageTokensAreKnown)).toEqual([true, true, false]);+ });+// The distinction the whole series exists to draw. A day whose upstreams never// reported their tokens still served the calls the user made, so it is a metered// day with nothing to scale — not an idle one.diff --git a/ui/src/components/settings/models/usageProjection.ts b/ui/src/components/settings/models/usageProjection.tsindex c8971d878..76deb90fa 100644--- a/ui/src/components/settings/models/usageProjection.ts+++ b/ui/src/components/settings/models/usageProjection.ts@@ -79,6 +79,36 @@ export function usageReportShortfall(counters: UsageCounters): number {return Math.max(0, counters.requests - counters.token_reports);}+/**+ * Whether an upstream said what anything in this bucket cost.+ *+ * Three independent facts share one payload, and only one counter answers each:+ * `requests` says calls happened, `token_reports` says an upstream told us what+ * they cost, and the token counts say how much. A total of zero is therefore+ * several different readings, and only this counter can find the one where a cost+ * was actually reported — which is the only reading allowed to speak for the+ * report, as a peak or as a claim about what the reports said.+ */+export function usageTokensAreReported(counters: Pick<UsageCounters, 'token_reports'>): boolean {+ return counters.token_reports > 0;+}++/**+ * Whether the token counts are a measurement, and so printable as a number.+ *+ * Wider than `usageTokensAreReported` by exactly one case, and it is not a+ * concession: a bucket where nothing ran cost nothing, and that zero is measured+ * by our own request counter rather than promised by an upstream. Blanking it+ * would trade the defect this answers — an unreported cost read as free — for its+ * mirror image, an idle day read as unknowable.+ *+ * So the two questions stay apart. Every token figure the tab prints asks this+ * one; whether the report itself has anything to say about tokens is the other.+ */+export function usageTokensAreKnown(counters: Pick<UsageCounters, 'requests' | 'token_reports'>): boolean {+ return usageTokensAreReported(counters) || counters.requests === 0;+}+/** Share of input tokens served from cache, or null when there is no input to* take a share of. Clamped to [0, 1] because the subset relation is the* server's promise, not something this view can verify. */@@ -97,6 +127,8 @@ export type UsageDayColumn = {day: string;/** Calls metered on this day, whether or not their tokens came back. */requests: number;+ /** Calls whose upstream said what they cost — what makes `tokens` a measurement. */+ token_reports: number;tokens: number;/** Height against the busiest rendered day, in [0, 1]. */ratio: number;@@ -136,11 +168,18 @@ export function usageDayColumns(summary: UsageSummary): UsageDayColumn[] {const reportedByDay = new Map(summary.days.map((day: UsageByDay) => [day.day, day]));const span = windowSpan(summary.from_day, summary.to_day);const days = span ?? summary.days.map((day) => day.day);- // Both counters travel, because tokens alone cannot tell a day nobody used- // from a day whose upstream never said what it cost.+ // All three counters travel, because tokens alone cannot tell a day nobody+ // used from a day whose upstream never said what it cost — nor either of those+ // from a day that really did cost nothing. Dropping `token_reports` here is+ // what made a rendered 0 ambiguous no matter how carefully the copy was worded.const counted = days.map((day) => {const reported = reportedByDay.get(day);- return { day, requests: reported?.requests ?? 0, tokens: reported ? usageTotalTokens(reported) : 0 };+ return {+ day,+ requests: reported?.requests ?? 0,+ token_reports: reported?.token_reports ?? 0,+ tokens: reported ? usageTotalTokens(reported) : 0,+ };});// Scaled against the days on screen, not every day reported: a stray row// outside the window would otherwise flatten every bar the user can see.diff --git a/ui/src/i18n/en.json b/ui/src/i18n/en.jsonindex 156e61882..1a085b7c2 100644--- a/ui/src/i18n/en.json+++ b/ui/src/i18n/en.json@@ -951,7 +951,8 @@"blank": "—","tokens": {"label": "Tokens",- "detail": "{{input}} in · {{output}} out"+ "detail": "{{input}} in · {{output}} out",+ "none": "No request in this window reported its tokens"},"requests": {"label": "Requests",@@ -984,7 +985,8 @@"column": "{{day}} · {{tokens}} tokens · {{requests}} requests","peak": "Peak {{tokens}} on {{day}}","quiet": "No day in this window carried a metered turn",- "unreported": "Requests ran, but no day reported its tokens"+ "unreported": "Requests ran, but no day reported its tokens",+ "zero": "Every day that reported its tokens reported zero"}},"supplyTooltip": {diff --git a/ui/src/i18n/zh.json b/ui/src/i18n/zh.jsonindex 44ad5ade4..5a53991bf 100644--- a/ui/src/i18n/zh.json+++ b/ui/src/i18n/zh.json@@ -951,7 +951,8 @@"blank": "—","tokens": {"label": "Tokens",- "detail": "输入 {{input}} · 输出 {{output}}"+ "detail": "输入 {{input}} · 输出 {{output}}",+ "none": "这个区间没有请求回报 token"},"requests": {"label": "请求数",@@ -984,7 +985,8 @@"column": "{{day}} · {{tokens}} tokens · {{requests}} 次请求","peak": "峰值 {{tokens}},出现在 {{day}}","quiet": "这个区间没有任何一天有计量数据",- "unreported": "有请求,但没有任何一天回报了 token"+ "unreported": "有请求,但没有任何一天回报了 token",+ "zero": "有回报 token 的日子,回报的都是 0"}},"supplyTooltip": {