Repository navigation
feat(dash): on a subscription the Cache strategy tables show tokens (#1048) - #1065
Conversation
…1048) On a Claude subscription, the Cache strategy tab's tables show tokens, not dollars: the session table, the live table and the behaviour panel. The calculator is a price what-if, so it keeps dollars with the label "at API-price weights". Managers and API-key users keep dollars. - /api/keepalive/sessions and /api/keepalive/live add each session's keepalive_tokens, keepalive_ping_tokens and tokens_unmeasured_requests. They come from sessionTokens, the Sessions tab's query (#1041), so the two tabs cannot disagree. - /api/keepalive/sessions adds expiry_tokens; /api/keepalive/behaviour adds tokens to each day and band. Both are the billed input tokens of the expiries, by tier: the token form of expiry_usd and usd. - The pings keep a column or a line of their own, never in a total. - Overview, Tool deferral card: on the token view the text says "Net of the names list." The searches have no token figure (#988 review). Behavior change: on a subscription, the Cache strategy tab tables show tokens in place of dollars. Managers and API-key users see no change. Data dependence: metadata only (token counts by tier). No change at any storage level. Fixes #1048 Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 0271a6e6e22d |
blocking |
Verdict: blocking
Findings
- dash/ui/app.js:9585 — the live table's token hint says "(measured)" even when the rescue is not measured
- What fails: a subscription user opens the Cache strategy tab. The ledger has no token figure for the window (rows from before #999, or requests the accountant could not price, so
tokens_unmeasured_requests > 0).kaTokenLinesthen answersmeasured: falseandrescuesText: 'The rescues are not measured in tokens.'(dash/ui/savings.js:262). The hint renders: "So far in this window (measured): The rescues are not measured in tokens. …". The label "(measured)" contradicts the sentence it sits on. This is the zero-versus-absence defect class this dashboard guards against (#1042 addedmeasuredTextfor the same reason on the tiles). - Proof:
kaTokenLines(savings.js:255-264) returnsmeasuredfalse exactly whentokenFigurereads "not measured"; renderKALive's subscription branch (app.js:9583-9590) prints the prefix "(measured)" unconditionally and does not branch ontk.measured. The dollar branch it replaces put "(measured)" after real figures only. - Fix: print the word only when it is true, for example
`So far in this window${tk.measured ? ' (measured)' : ''}: ${tk.rescuesText} …`. Add a case to savings.test.mjs if the sentence moves into savings.js.
- What fails: a subscription user opens the Cache strategy tab. The ledger has no token figure for the window (rows from before #999, or requests the accountant could not price, so
Non-blocking
- docs/data-dependence.md is not updated. The "Subscription headline" row mentions the Sessions tab (#1023) but not the Cache strategy tab (#1042, #1048). The PR body argues no row changes because storage does not change. #1041 extended the row for the same kind of change. Consider one sentence, so the row names every tab that shows tokens.
- The owner's yes is not recorded. The commit and the PR name the behavior change, who it keeps dollars, and that there is no switch. The sibling commits (#1041, #1042) also quote the owner's yes. Issue #1048 asks for this change; record the yes before merge, as RELEASING.md asks.
- Error path shows mixed units. If
loadKASessionsfails,renderKASessionsnever runs, sosubLabels($('#ka-downside-panel'), sub)never runs. The panel's headers and hint keep dollar labels while the split bar above shows token lines. The table itself shows an error, so no wrong number appears. renderKADownsideruns before the sessions fetch lands. It draws token lines fromkaState.sub; the panel's headers convert only whenrenderKASessionsruns later. For a moment the panel mixes token figures with dollar headers. Same non-blocking class as the point above.
What I checked
- Read CLAUDE.md, docs/design.md, and the full diff of all 10 changed files, with the code around each change.
- Server: the
addressableCTE change and the three new scan sites (dash/keepalive.go). Column order inexpiryTierCols,expiryTierTermsandtierDestmatches at every scan.MAX(cache_write - cache_write_1h, 0)insideSUMis SQLite's two-argument scalar max, the same patternaccTokenTailTermsalready uses. Everyaddressableconsumer names its columns; none scans positionally, so the three added CTE columns break nothing. keepAliveSessionTokensreusessessionTokens(#1023) under the same filter, so the two tabs read the same figures. BothKeepAliveSessionsandKeepAliveLivereturn early on an empty row list, so the token query never runs with an emptySessionIn(which would drop theINcondition and scan the whole window).- JSON: no name collisions from the new embedded
KeepAliveSessionTokens;Band.Tokensis a pointer withomitempty, and the KV-cache panel does not set it, sokvcache.jsonis unchanged (verified: the golden is not in the diff). - Every expiry has a token figure: the addressability gate requires
cache_write > 0, so at least one write tier is non-zero.tierSeriestherefore returns an empty list only whendailyis empty, the same state where the dollar chart showed no data. - UI:
subLabelscaches the dollar nodes on first call and restores clones, so repeated renders andsubflips are idempotent; it also fixes the oldtitle = undefinedcasesessionHeadershad.kaSessionTokenCells,bandTokens,tierSeriesagainst their mjs tests, and the wiring strings inTestKeepAliveTablesSubscriptionTokensAreWiredagainst app.js and index.html. Panel label counts (5, 4, 2) verified against index.html by hand. - Ran
node --test dash/*.test.mjs: 36 pass, 0 fail, the count the PR claims. No Go tests were run (not approved; Go is not on this machine). - Goldens:
ka_sessions.jsonandka_behaviour.jsoncarry the new fields; spot-checked arithmetic (5 expiries x 40 fresh input = 200input; ping rows carry their own usage ascache_read). - Docs: docs/dashboard.md matches the code (which figures stay dollars and why). Fail-open does not apply: the change touches the dashboard only, no proxy or library path.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 0271a6e6e22d |
approve |
Verdict: approve
Findings
None. I found no wrong behavior, no data loss, no broken fail-open path and no missing test.
Non-blocking
- dash/ui/app.js:9584 — the live table's token hint can contradict itself. On a subscription, the hint starts
So far in this window (measured): …and then insertstk.rescuesText. When the ledger's rescue is not measured (all-zero rescue and unpriced requests in the window), the sentence reads "So far in this window (measured): The rescues are not measured in tokens." Branch the prefix ontk.measured, asrenderKADownsidedoes (it usestk.rescuesTextwith no "(measured)" prefix). - dash/ui/app.js:9714 — the daily cost chart has no "not measured" state.
bandTokensandkaSessionTokenCellslabel a missingtokensfield "not measured" (a server from before #1048). The chart does not:tierSeriesreturns no series andlineChartshows its generic "No data in this window" empty state, while the misses chart beside it shows expiries. On a same-version server this cannot happen (every addressable row hascache_write > 0, so some tier is non-zero every day), so this is only the old-server case the rest of the PR defends against. - docs/data-dependence.md:232 — the "Subscription headline" row names #1023 but not #1048. This PR makes the Cache strategy tables read the same stored token counts and keeps nothing new, so the data dependence does not change. One clause ("since #1048 the Cache strategy tables show them too") would keep the row complete. #1042 also skipped this, so the precedent is mixed.
What I checked
- The full diff of all 10 files (
dash/keepalive.go,dash/ui/app.js,dash/ui/index.html,dash/ui/savings.js,dash/katabletokens_test.go,dash/savingsparts_test.go,dash/savings.test.mjs, both golden files,docs/dashboard.md), plus the code around each change. - The SQL.
addressableCTEnow carriesfresh_input,cache_read,cache_write_1h; the columns areINTEGER NOT NULL DEFAULT 0(dash/schema.go:150,188), so the per-row scans intoint64cannot hit NULL.MAX(a, b)with two arguments is SQLite's scalar max, soSUM(MAX(cache_write - cache_write_1h, 0))is per-row inside the GROUP BY, and the same clamped split is the onesessionTokensQueryalready uses (dash/query.go:651).tierDestmatches the column order of bothexpiryTierColsandexpiryTierTerms.ORDER BY 4inKeepAliveSessionsstill sorts bycost_usd(the token terms are appended after column 4). - The band sums. Each addressable row lands in exactly one gap band, one prefix band and one hour bin (
strftime('%H')is always 0–23), so the newgapTok/preTok/hourTokarrays and the daily sum each total the expiries' tokens. The new Go test asserts exactly that. - The empty-ids path.
KeepAliveSessionsreturns early when there are no rows (keepalive.go:1044) andKeepAliveLivedoes the same (keepalive.go:1293), sokeepAliveSessionTokensis never called with an emptyidslist — the unbounded no-IN scan thatinsightsapi.go:58andtoolapi.go:1348guard against cannot happen here. - The session-figure reuse.
keepAliveSessionTokensreads throughsessionTokens(withKeepAlive,session_id IN (…)), the same query the Sessions tab uses, so the two tabs report the same rescue, ping tokens and unmeasured count for a session; the Go test compares them row by row againstdb.Sessions. - The JS cell logic. I traced
kaSessionTokenCells,bandTokensandtierSeriesby hand againsttokenFigure,tokenLine,tierText,TOKEN_TIERSandpingLine, including the zero, unmeasured, pre-#1048 and did-not-run cases; each matches the mjs test's expectations and the shared zero rule.tierSeriesreturns at most 4 series andSERIEShas 4 colors;lineChartsupports multiple series with a legend. - The label swap.
subLabelsgeneralizes the oldsessionHeaders(same cache-and-restore of the dollar nodes, and it fixes the oldtitle = "undefined"case for an element with nodata-sub-title). Alldata-sub-labelelements also carrydata-sub-title. The three KA panels are disjoint from the sessions table, so no node is swapped twice.kaState.subis set before any KA panel renders (app.js:9061-9063). - The wiring tests. I checked every wanted string in
TestKeepAliveTablesSubscriptionTokensAreWiredagainst app.js, and the three panel label counts (5, 4, 2) against index.html (hint + 4 th; 4 th; h3 + hint). TheTestSessionsSubscriptionTokensAreWiredscoping to the sessions table is needed and correct (3 labels there). - The golden files. Both diffs are pure additions — no existing number changed — and the new
tokensobjects match the new query terms. - Rules. No proxy or library behavior changes (dashboard display only, additive JSON fields), so the behavior-change and fail-open rules are not engaged. Data dependence stays metadata-only. Tests cover the new behavior at all three layers (Go query, JS cells, UI wiring) plus the golden endpoints.
- The live table's token hint said "So far in this window (measured):" also when the rescue was not measured. It now adds "(measured)" only when kaTokenLines says the figure is measured. - renderKADownside sets the downside panel's headers to the units it draws. Before, only renderKASessions did, so the headers kept dollar labels until the sessions fetch landed, or for good when it failed. - docs/data-dependence.md: the Subscription headline row names the Cache strategy tab and its tables (#1042, #1048). No change in data use. - Pin both fixes in TestKeepAliveTablesSubscriptionTokensAreWired. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
|
Round 1 replies. Fixes are in 0a43489. Reviewer 1, blocking: "(measured)" on a rescue that is not measured. Fixed. The hint adds "(measured)" only when Non-blocking:
Tests: |
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 0a43489be378 |
approve |
Verdict: approve
Findings
None. The fix commit changes 6 lines and each one is right.
Earlier findings
- Reviewer 1, round 1, blocking: "(measured)" on a rescue that is not measured. Fixed. app.js:9586 now prints
(measured)only whentk.measuredis true. When the rescue is not measured, the hint reads "So far in this window: The rescues are not measured in tokens." No contradiction remains. The wiring test pins the branch (So far in this window${tk.measured ? ' (measured)' : ''}). - Reviewer 1, non-blocking: docs/data-dependence.md not extended. Fixed. The Subscription headline row now says "Since #1042 and #1048 the Cache strategy tab and its tables show them too." The data use does not change, so no other row moves.
- Reviewer 1, non-blocking: mixed units on the downside panel (error path and load order). Fixed.
renderKADownsidecallssubLabels(panel, kaState.sub)at its top, before its early return, so the panel's headers follow the units it draws even when the sessions fetch lands late or fails. I checked the call order:loadKeepAlivesetskaState.subat app.js:9061 and callsrenderKADownsideat 9069, so the flag is never stale. The second call fromrenderKASessionsis safe;subLabelscaches the dollar nodes on first use. - Reviewer 1, non-blocking: the owner's yes not recorded. Addressed. The author states the owner asked for #1048 on 2026-11-11, and the main session asks the owner to confirm before merge. Not a code defect; nothing to change here.
- Reviewer 2, round 1, non-blocking: the daily chart has no "not measured" state. Rejected by the author, and the reason is right. I verified in round 1 that a same-version server always fills at least one write tier on any day that has expiries: the addressability gate requires
cache_write > 0. The page and the server ship in one binary, so the "not measured" chart case needs a version mix that cannot occur. The chart then shows its empty state, and no wrong number appears. I accept the rejection. - Reviewer 2's other two non-blocking notes (the "(measured)" hint, data-dependence.md) are the same items as mine above. Both fixed.
Non-blocking
- None new.
What I checked
- Last review: round 1, 0271a6e, 2026-11-11T06:57:13Z
- New commits read: 1 —
0a43489bfix(dash): say "(measured)" only on a measured rescue (#1065 review 1) - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files)
- New items since my last review:
- Commit
0a43489b: read the full diff (dash/ui/app.js, dash/savingsparts_test.go, docs/data-dependence.md) and the code around each change. Verified both fixes in the file at the new head. - Reviewer 2's round-1 review (approve, three non-blocking notes): checked each note myself. Two match my round-1 items; the third (the chart's "not measured" state) I traced and agree with the author's rejection.
- The author's reply comment (2026-11-11T07:09:44Z): checked every claim it makes against the code. All hold.
- Commit
- The wiring test's two new pinned strings appear in app.js exactly as written, and the comment line above
subLabels(panel, kaState.sub)is stripped bystripComments, so the pin works. - Ran
node --test dash/*.test.mjsat the new head: 36 pass, 0 fail. No Go tests were run (not approved; Go is not on this machine). - Working tree under
dash/anddocs/is clean at0a43489b; no change outside the named files.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 0a43489be378 |
approve |
Verdict: approve
Findings
None. The fix commit changes three files by eight lines, and I found no defect in it.
Earlier findings
- Reviewer 1, blocking ("(measured)" on a rescue that is not measured) — fixed. Same defect as my non-blocking note 1.
app.js:9587now reads`So far in this window${tk.measured ? ' (measured)' : ''}: …`, exactly the proposed branch. The wiring test pins the string. - My non-blocking 1 (the same "(measured)" contradiction) — fixed by the same line.
- My non-blocking 2 (the daily chart has no "not measured" state) — rejected by the author, and the reason is right. The page and the server ship in one binary (
go:embed), so a #1048 UI cannot run against a pre-#1048 server. I verified in round 1 that on a same-version server every daily row has a non-zero write tier (the addressability gate requirescache_write > 0), sotierSeriesis empty only whendailyis empty — the same state where the dollar chart showed no data. No wrong number is shown either way. I withdraw it. - My non-blocking 3 / reviewer 1's note (data-dependence.md row incomplete) — fixed. The row now says "Since #1042 and #1048 the Cache strategy tab and its tables show them too." Accurate: the PR reads stored token counts and keeps nothing new, so no dependence change and no new "Decided by" entry is needed.
- Reviewer 1's two mixed-units notes on the downside panel — fixed.
renderKADownsidenow callssubLabels(panel, kaState.sub)(app.js:9266), before its early return, so the headers follow the units the split bar draws even when the sessions fetch lands late or fails. I checked: the only caller isloadKeepAliveat app.js:9069, which runs afterkaState.subis set (app.js:9061); the secondsubLabelscall inrenderKASessionsis idempotent, because the dollar nodes are cached on first call. Pinned in the wiring test. - Reviewer 1's note (the owner's yes not recorded) — answered. The author records that the owner asked for #1048 on 2026-11-11, and that the main session asks the owner to confirm before merge. That satisfies RELEASING.md's process; it is outside this diff.
What I checked
- Last review: round 1, 0271a6e, 2026-11-11T06:58:53Z.
- New commits read: 1 —
0a43489b"fix(dash): say “(measured)” only on a measured rescue (#1065 review 1)". Read the full diff (git diff 0271a6e6..HEAD) and the code around each change. - Read in full: 2 reviews, 1 comment, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt; the inline file is empty). - New items since my last review: commit
0a43489b(reviewed above, line by line) and the author's round-1 reply at 2026-11-11T07:09:44Z (each reply checked against the code; outcomes above). Reviewer 1's review at 06:57:13Z predates my posting time; I read it now in full as this round requires — its finding and notes are covered above. - The fix commit itself. The hint branch matches
kaTokenLines'smeasuredfield (savings.js:255-264).subLabels(panel, kaState.sub)sits beforerenderKADownside's early return, andpanelis the function's existing$('#ka-downside-panel'). Both new wiring strings exist verbatim inapp.js(subLabels(panel, kaState.sub);at 9266, thetk.measuredtemplate at 9587). The data-dependence row's change is text only. The commit carries DCO sign-off andAssisted-By:per repo convention. - Nothing else changed: the new diff touches no Go query, no JSON field and no golden file, so my round-1 verification of those stands.
Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Two conflicts, both additions side by side; keep both: - dash/ui/savings.js: the export list names this branch's fiveHourLearnedPct, weightsLabel, forecastView and #1065's kaSessionTokenCells, bandTokens, tierSeries. - dash/savings.test.mjs: this branch's three tests, then #1065's two. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Behavior change. On a Claude subscription, the Cache strategy tab tables show tokens in place of dollars. Managers and API-key users (also Bedrock, Vertex and hosted mode) see no change. There is no switch: the tab uses the same subscription test as #1042 (
kaState.sub).Fixes #1048
Summary
What changed
Server (
dash/keepalive.go)/api/keepalive/sessionsand/api/keepalive/liveadd 3 fields to each row:keepalive_tokens(the rescue),keepalive_ping_tokens(what the pings paid) andtokens_unmeasured_requests. A new wrapper callssessionTokens, the Sessions tab's query from feat(dash): on a subscription the Sessions tab shows tokens (#1023) #1041. There is no second copy of the query, so the two tabs cannot disagree about a session./api/keepalive/sessionsaddsexpiry_tokens: the billed input tokens of the session's expiries, by tier. It is the token form ofexpiry_usd./api/keepalive/behaviouraddstokensto each day ofdailyand to each gap, prefix and hour band. It is the token form ofusd. The KV-cache panel shares theBandtype; it does not set the field, so its JSON does not change.addressableread carries 3 more usage columns (fresh_input,cache_read,cache_write_1h).Dashboard (
dash/ui/app.js,savings.js,index.html)expiry_tokens. Their tokens: the pings, in their own column. Avoided (upper bound): the rescue, with thetokenFigurezero rule. Ahead or behind: a word, not a net (token kinds do not add). The note under the table counts expiries, not dollars.Keep-alive pings (not in the total): cost …on its own line. The hint shows the ledger's rescue and pings lines.count · tokens.savings.js:kaSessionTokenCells,bandTokens,tierSeries. They reusetokenFigure,tierText,pingLineandPING_LABEL.subLabelsswaps a header or note to itsdata-sub-labeltext, and back.sessionHeadersnow uses it.Figures kept in dollars, labelled "at API-price weights"
Each is a forecast or a price what-if. They get tokens with #1047.
How it was tested
node --test dash/*.test.mjs: 36 pass, 0 fail. New: the session row in tokens (rescue, pings apart, zero rule, old server, did not run) and the bands and the daily chart in tokens.TestKeepAliveTables_TokensMatchTheSessionsTab: the session and live rows equal the Sessions tab's figures;expiry_tokensequals the expiry row; the gap bands, prefix bands, hour bins and daily points each add up to it, tier by tier.TestKeepAliveTablesSubscriptionTokensAreWired.TestSessionsSubscriptionTokensAreWirednow counts token labels in the Sessions table only.ka_sessions.jsonandka_behaviour.jsonupdated.kvcache.jsonis unchanged.gofmt -lclean,go vet ./dash/clean,go test -race ./dash/...in two halves:^Test[A-H]ok (374 s),^Test[^A-H]ok (487 s). 0 failures.Data dependence
Metadata only: token counts by tier, from the usage columns and the accountant's token columns that #999 already stores. No change at any storage level, so
docs/data-dependence.mddoes not change.🤖 Generated with Claude Code