fix(usage): count cached tokens in every total — Codebase/Today/Yesterday were ~99% short - #152
Conversation
…rday were ~99% short The CLI's per-message tokens.input EXCLUDES cache reads; the sums used for the rows and charts (input + output + reasoning) dropped cache.read entirely. DeepSeek V4 sessions routinely carry ~700K cached prompt tokens per message, so the displayed totals massively undercounted. HistoryRow now carries a computed tokensTotal (input + output + reasoning + cache.read), verified against the DB's authoritative tokens.total, and every counting site (sumDailyUsage / buildUsageSeries / codebaseUsage) uses it. The extension's own tracked entries already included cached tokens in promptTokens, so the two sources are now consistent. Requests (1 per assistant message) and costs (CLI's own per-message field; billable = prompt - cached) were already correct. New regression test with a cache-heavy row (277 tests).
|
Hey @ltmoerdani One thing to flag, I noticed you mention this in your every message that you run tests locally and run linters, etc. Let me explain that the linter that I were implemented never allows developer to commit until the husky runs all linters, tests, and formatters. |
|
You can simply test the actual changes and do not worry about linters and tests. |
|
Conflicts resolved — merged the latest |
|
This is a clean fix. I checked the diff, One small note: test fixtures now all need Conflict resolution is solid both CHANGELOG entries (token-counting + DeepSeek thinking) kept. Checks 2/2 green. |
What
The CLI's per-message
tokens.inputexcludes cache reads, and the sums used for the usage rows and charts (input + output + reasoning) droppedcache.readentirely. DeepSeek V4 sessions routinely carry ~700K cached prompt tokens per message, so the displayed totals massively undercounted (verified: codebase showed ~6M tokens vs the real ~954M).Fix
HistoryRownow carries a computedtokensTotal = input + output + reasoning + cache.read, verified against the DB's authoritativetokens.total(matches real rows exactly).sumDailyUsage(Today/Yesterday),buildUsageSeries(charts + Models tab),codebaseUsage(Codebase row).promptTokens, so the two sources are now consistent.Audited and left as-is (already correct)
Verification
New regression test with a cache-heavy DeepSeek row; 277 unit tests, strict ESLint + tsc + prettier + markdownlint green, VSIX packages and installs cleanly.