Skip to content

Show per-model token counts alongside cost in desktop and menubar - #1315

Merged
iamtoruk merged 3 commits into
fix/dock-pace-followupsfrom
feat/per-model-cached-tokens
Sep 12, 2026
Merged

iamtoruk merged 3 commits into
fix/dock-pace-followupsfrom
feat/per-model-cached-tokens

Conversation

@iamtoruk

Copy link
Copy Markdown
Member

Supersedes #1265. Same feature, rebased off #1314 so the diff is only this change. Original work by @ozymandiashh.

#1265 contained #1267 as a merge commit, so it could not be read or landed on its own. This is its two commits replayed onto fix/dock-pace-followups, plus one test.

What it does

Per-model input, output and cache-read counts next to cost: a secondary line under each macOS menubar Models row, a Cache read column in the desktop Overview. The desktop Models tables keep token counts visible for unpriced models, where usage used to render as dashes.

Verified against real data

Built this branch and fix/dock-pace-followups, ran status --format menubar-json on both, structurally diffed the full payload.

  • Only differences are the four added current.topModels[].*Tokens fields. Every cost, call and session figure is identical to the digit, on both the durable-day and fresh-session paths.
  • Per-model rows sum exactly to the period headline for input, output, cache read, cache write and cost, on both paths.
  • Top models cross-checked against models --format json for the same window: calls, all four token counts and cost agree exactly.

Volatile fields were isolated first by bracketing with repeat baseline runs (generated, liveSessions, and today's row).

Grouping

buildTopModels merges token counts with the same getShortModelName call that merges cost, in the same loop, so aliased ids land in one row for both. Breaking that key fails 8 tests across 3 files.

Durable days already carried all four counts in ModelDayStats, and addSliceIntoDay / subtractModelStats / sanitizeModels handle them alongside cost, so the reconcile swap moves tokens and cost together.

Cache versions

STATUS_SNAPSHOT_RENDER_VERSION 7 to 8 only. Justified: a warm v7 snapshot would hide the new fields. Costs one recompute per query, then reuses.

DAILY_CACHE_VERSION stays at 32 and PROVIDER_PARSE_VERSIONS is untouched, which is correct here: the counts were already persisted, so no finalized history is discarded.

Added test

test: pin per-model output normalization in buildPeriodData. The per-model output path normalizes reasoning tokens the same way the headline does, but every fixture and my whole corpus report zero reasoning tokens, so replacing that expression with the raw counter passed all 3996 tests. Two assertions on the existing grok/codex fixture now pin it.

One thing to confirm before merging

The all-provider Overview models table now reads current.topModels instead of a union over each day's top-five history. That is more accurate but applies the payload's 20-row cap to that view for the first time. On my data the table goes from 47 rows to 20, dropping every local and free model.

The old rows were not trustworthy: Cursor (auto) showed 1691 calls and $3.31 against a true 25 calls and $0.01, and GPT-5.6 Luna showed 139 calls against a true 501. So this trades a long wrong tail for a short correct list, which I think is right, but it is a product call. Raising TOP_MODELS_LIMIT for the desktop payload would get both.

Tests

  • root: tsc --noEmit clean, 3996 passed, 5 skipped
  • app: typecheck clean, 894 passed (27 failures in usePolled/overviewSnapshot are pre-existing, identical on the baseline)
  • mac: swift build clean, 541 tests passed, swift build -c release clean

The Swift layout proof renders the real popover root at its actual 360pt width and asserts fittingSize.width == 360, including a 12.3 billion cache-read row, so the new line cannot widen the popover. Rendered it and checked both schemes: absent counts show a dash, a known zero shows 0, and a legacy row with no counts shows no second line.

Known nit, pre-existing: compactTokenCount has no billions rung, so 12.3 billion renders as 12345.7M. It is the same helper the Tokens line already used, so I left it alone.

ozymandiashh and others added 3 commits September 12, 2026 12:33
Review follow-ups on the per-model token counts, addressed on the merged
head.

buildPeriodData walked every assistant call in every session twice: once
through sessionBillableOutputTokens for the headline and again through
sessionModelBillableOutputTokens for the per-model split. Both derive from
the same traversal and the same sawUsage fallback decision, so fold them
into one sessionBillableOutput(session) returning { total, byModel }; the
two existing exports become thin wrappers, keeping their semantics for
other callers. A call whose model resolves to no breakdown bucket still
counts toward the session total and still lands in no row, exactly as
before, so no total moves.

The macOS accessibility text grouped a signed string, counting the minus
as a leading digit and emitting it twice: a -1,234,567 count read as
"--1,234,567", a different number to a screen reader. Group the magnitude
and re-apply the sign; magnitude is unsigned, so Int.min no longer traps
on negation either. Negative counts are not expected from the CLI, but the
payload field is a plain Int and a corrupt or hand-edited snapshot carries
whatever it carries.

Two findings are disclosed rather than changed:

* buildTopModels' unknown-vs-zero guard cannot fire on the durable path.
  ModelDayStats types the four counts as required numbers and daily-cache
  sanitizeModels runs each through num(), so a missing value becomes a
  known 0 and a carried day under-reports as exact instead of unknown.
  Making it reachable means widening ModelDayStats to optional counts and
  teaching every daily-cache arithmetic site (fold, subtract, reduce) plus
  buildPeriodDataFromDays to propagate absence — a durable-cache contract
  change, too broad to ride along here. The guard stays: PeriodData
  already types these counts optional, so fresh-session and plugin-sourced
  rows may legitimately omit them.

* The all-provider Overview models table now reads current.topModels and
  so inherits the payload's 20-row TOP_MODELS_LIMIT, which its previous
  uncapped daily-history union did not have. Kept, because that union was
  itself a per-day top-five truncation whose tail rows were already
  partial sums, but the PR body's "the cap is unchanged" claim was wrong
  for this view and the trade-off is now recorded at the call site.
@iamtoruk
iamtoruk merged commit ef97600 into fix/dock-pace-followups Sep 12, 2026
27 of 28 checks passed
iamtoruk added a commit that referenced this pull request Sep 12, 2026
Rebase resolution for #1289 onto main (#1306, #1313, #1314, #1315, #1328,
#1329). Conflicts kept both intents: main's second-row title composition,
glance-window accessibility actions, cache-read line, host field and merged
Notifications section keep their behaviour and now resolve through L(…).

Adds 14 keys to both tables, drops 4 that no longer have a call site, and
retranslates the two Copilot explanations main rewrote.
ozymandiashh added a commit to ozymandiashh/codeburn that referenced this pull request Sep 15, 2026
…localization catalog

The per-model token line arrived with the getagentseal#1315 re-land as a raw
interpolated Text(…), so the localization coverage scanner fails: a
zh-Hans user got an English fragment. The key joins both tables with
positional specifiers per the getagentseal#1331 rule, Chinese rebinding the word
order.
iamtoruk pushed a commit that referenced this pull request Sep 17, 2026
…lls dimming (#1443)

The period model list the Overview table reads is no longer cut at 20 rows, so
every model with usage in the period shows up instead of only the costliest
twenty - the rows that dropped out were exactly the $0 local and free models.

formatTokens gains a billions rung, so a codeburn models totals row reads 29.9B
instead of 29868.7M; the menubar row formatter gains the same rung, and compare
now reuses formatTokens instead of its own K/M copy.

The desktop Models tables stop dimming the calls column on unpriced rows. In the
shipped app those rows do not reach the table yet - codeburn models defaults to
minCost 0.01 and getModels passes no override - so the change takes effect once
that filter is addressed, tracked separately.

Also re-lands the three #1315 commits that never reached main: per-model token
counts beside per-model cost in the Overview and the macOS menubar Models rows.
Status snapshot revision goes to 9 so a warm snapshot cannot keep serving the
truncated list. Fixes #1318.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants