Repository navigation
Fix: Cap the replay credit in the status line, series and breakdown - #1037
Conversation
…down (#586) The headline, /api/components and the episode view cap the summarizer and offloader replay credit through the ledgers. The status line, /api/series, /api/breakdown and the metrics export summed the stored credit, so they could read far above the headline for the same rows. - SavingsTotalsCapped applies the ledger correction. /stats uses it for the current and live scopes. The all scope stays uncapped, because a lifetime read would stream every row on each refresh (#502), and says so with cap_not_applied. - /api/series and /api/breakdown return cap_correction_usd and cap_not_applied beside their rows. The ledgers do not say which bucket a correction belongs to, so it is not spread over them. - The Prometheus help text of the baseline series says they are uncapped. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | fresh | 1 of 2 | 1 of 2 | eb0f89bfc531 |
blocking |
Verdict: blocking
Findings
-
dash/savings.go:103-116 — CapCorrectionUSD is all-or-nothing, but the headline applies each ledger on its own, so a one-ledger failure makes the readers disagree with the headline
- What fails: the summarize ledger scan fails and the replay ledger scan succeeds (or the reverse), on a session with real cap credit. The headline then applies the one correction that worked (
dash/api.go:1407and1413in the lean path,1506-1507in the full path — eachApply*runs when its own ledger succeeded).CapCorrectionUSDreturns an error when either ledger fails (dash/savings.go:107-114), so/api/series,/api/breakdownand the/statscurrent/live scopes reportcap_correction_usd: 0,cap_not_applied: trueand keep the stored figure. The headline shows the partially corrected figure. The two views show different money for the same rows — exactly the disagreement this PR exists to remove (#586). - Proof: lean path,
dash/api.go:1404-1416:if l, lerr := db.SummarizeLedgerFor(...); lerr == nil { o.ApplySummarizeLedger(l) }— a summarize failure does not stopo.ApplyReplayLedger(repLedger)at 1413, andReplayCapNotAppliedstays false.dash/savings.go:129-133:SavingsTotalsCappedsetsCapNotAppliedand drops the whole correction whenCapCorrectionUSDerrors, which happens if either of the two ledgers errors. The same holds fora.capCorrection(dash/api.go:1561-1572). - Fix: in
CapCorrectionUSD, apply whichever ledger succeeded and return the sum of the successful ones, mirroring the headline. Only report not-applied when neither ran (no pricer, no windows).
- What fails: the summarize ledger scan fails and the replay ledger scan succeeds (or the reverse), on a session with real cap credit. The headline then applies the one correction that worked (
-
dash/capreaders_test.go:37 — the agreement test compares the combined correction against a replay-only field, and the summarize half of the new arithmetic is never exercised nonzero
- What fails:
capped.CapCorrectionUSDissummarize delta + replay delta(dash/savings.go:115). The test compares it with the headline'sreplay_cap_correction_usd, which is the replay delta alone (dash/replaycap.go:622-623). The fixture (replayCapAPI,dash/replaycap_test.go:547-582) writes onlyextract_llmcomponent rows.SummarizerComponentsissummarizeandcache_aware_summarizer(dash/event.go:976), so the summarize ledger is empty and its delta is 0. The two numbers agree only by fixture luck. - Proof: if the summarize half of
CapCorrectionUSDhad a wrong sign or double count, every assertion inTestSavingsTotalsCappedAgreesWithTheHeadlineandTestSeriesAndBreakdownCarryTheCapCorrection(line 92 makes the same replay-only comparison) would still pass. No test in this PR givesSavingsTotalsCappedorCapCorrectionUSDa nonzero summarize correction. That is the new behavior this PR adds, untested. - Fix: add a summarize row (a
summarizecomponent row on a session that crosses the compaction ceiling) to the fixture, or a second fixture, and assert the combined correction plus the baseline/total agreement there. Compare against the headline totals, not againstreplay_cap_correction_usd.
- What fails:
-
proxy/savings.go:97,104 — /stats now runs two full ledger walks on every status-line refresh, with no cache
- What fails: the status line reads
/statsoften (the PR's own behavior-change section names it).savingsStatsis synchronous and uncached (proxy/proxy.go:3037, the/statshandler has no cache). Each refresh now runs, for the current session and again for every live session:ReplayLedgerFor(streams every row of each session's full history) plusSummarizeLedgerFor, which runscompactEpisodeDatasetonce per summarizer component — two queries — and materializes every selected row in memory (dash/compactepisode.go:1269-1284,dash/summarizeattr.go:93-110). Before this PR the refresh cost two indexed aggregates. The cost now grows with the session's full history and with the live-session count (up tomaxKeepAliveSessions), on every refresh. The PR rejects the same scan for theallscope for this exact reason (#502, quoted inSavingsScope.CapNotApplied's comment); the dashboard's own equivalent read,/api/stats?lean=1, runs the same ledgers but behind a 30 s cache with one refresh in flight (dash/api.go:123,serveJSON). - Proof:
dash/savings.go:124-139—SavingsTotalsCappedcallsSavingsTotalsthenCapCorrectionUSD, which calls bothSummarizeLedgerForandReplayLedgerFor(dash/savings.go:107-113).proxy/savings.go:97and:104call it for the live and current scopes inside the/statshandler. - Fix: cache the correction — per session, with a short TTL, or recompute only when the session has new rows since the last computation. The dashboard's
jsonCacheshape is the model.
- What fails: the status line reads
Non-blocking
SavingsTotalsCapped'stotal_saved_usdstill omitsDeclFilterSavingsandCachesplitHistoricalUSD, which the lean headline adds for a session (dash/overview_lean.go:44-53). So "agrees with the headline" holds fornet_saved_usdandbaseline_cost_usd, not fortotal_saved_usd, when those credits are nonzero. Pre-existing forSavingsTotals; the new test's fixture has neither, so its total assertion is also fixture luck. Worth a sentence in the PR.- The UI offers "All time" (
dash/ui/app.jsQUICK_RANGES,[0, 'All time']). With it,/api/seriesand/api/breakdownrun both ledgers over the whole table, whichCapCorrectionUSD's own doc warns against (#502). Mitigated: both routes sit behindrouteCache(30 s TTL, one refresh in flight, 2-minute detached compute bound). The full/api/statsalready does the same scan for a lifetime read, so this is consistent — but the doc and the route disagree. a.capCorrectioncallsdb.CapCorrectionUSDdirectly and bypasses thea.replayLedgertest hook (dash/api.go:595-600). A test cannot inject a replay-ledger failure into series or breakdown. The failure paths of finding 1 are for that reason also hard to test as written.- The PR body has no data-dependence statement. The change adds none — it reads the same stored per-request credit the headline cap already reads. Say so in the PR to satisfy the CLAUDE.md rule.
What I checked
- The full diff of
eb0f89bfagainst base77a910b0:dash/api.go,dash/savings.go,dash/capreaders_test.go, the four golden files,proxy/promexport.go,proxy/savings.go. - The headline's cap application on both paths: the lean branch (
dash/api.go:1382-1416) and the full branch (dash/api.go:1423-1520),ApplyReplayLedger(dash/replaycap.go:617-630) andApplySummarizeLedger(dash/summarizeattr.go:152-162), againstSavingsTotalsCapped's arithmetic (dash/savings.go:124-139). The three-field correction (baseline, net, total) matches the headline when both ledgers run. - That the two ledgers do not double count:
ReplayLedgerForexcludes summarizer components (notSummarizerSQL,dash/replaycap.go:477-484). - The fixture
replayCapAPI(dash/replaycap_test.go:546-580): components areextract_llmonly, so the summarize ledger is empty — the basis of finding 2. - The cost claims:
ReplayLedgerFor's streaming and memory bound (dash/replaycap.go:486-498),SummarizeLedgerFor's twocompactEpisodeDatasetruns and full materialization (dash/summarizeattr.go:93-113,dash/compactepisode.go:1251-1286), the/statshandler's lack of a cache (proxy/proxy.go:2842-3037), and the dashboard'sjsonCacheTTL and single-flight (dash/api.go:108-125,358-400). - Route wiring: series and breakdown are cached routes with the default 10 s handler bound (
dash/api.go:824-852,854-880);cachedRouteruns the handler under a detached read context, soa.db(r)insidecapCorrectionis safe. - The golden-file diffs: each is the two new fields only, with
cap_not_applied: truefor a test setup with no pricer. Consistent withcapCorrection's nil-pricer branch. proxy/promexport.go: help-text changes only, no behavior.- The PR body: it names the behavior change, who it affects, the old and new behavior, and how to turn it off, as CLAUDE.md requires.
- Live tests were not run. Go is not installed on this machine and the review brief forbids builds.
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | fresh | 2 of 2 | 1 of 2 | eb0f89bfc531 |
blocking |
Verdict: blocking
Findings
-
proxy/savings_test.go:128 — the status line's new capping has no test where the cap runs, and the existing agreement test now pins the wrong reference
- What fails:
/stats' Current and Live scopes now returnSavingsTotalsCapped(proxy/savings.go:97,104). The only test that covers these scopes,TestStatsSavingsThreeScopesAgreeWithOverview, compares them against plainSavingsTotals(proxy/savings_test.go:128,139). It passes only because the fixture setsPrices: fixedPricer{}but noOptions.Windows, soCapCorrectionUSDreturnserrCapUnavailableand the capped call degenerates to the uncapped figure. No proxy test assertscap_correction_usd,cap_not_applied, the "all" scope'sCapNotApplied = truelabel, or that Current/Live equalSavingsTotalsCappedwhen a resolver is present. The PR's headline change (issue #586 names SavingsTotals as a status-line reader) ships untested at the layer it ships in. The dash-level tests (capreaders_test.go) cover onlydb.SavingsTotalsCapped, not the proxy wiring. - Proof:
savingsTestHandler(proxy/savings_test.go:55-62) buildsOptionswithPricesand noWindows.SavingsTotalsCapped→CapCorrectionUSD(dash/savings.go:104) returnserrCapUnavailablewhenwindows == nil, so lines 144-155 compare uncapped against uncapped.grep SavingsTotalsCapped proxy/*_test.goreturns nothing. Production setsWindows(cmd/context-guru-proxy/main.go:717), so the applied path is the one users get. - Fix: give the proxy fixture a window resolver (and traffic past the cap, as in dash's
replayCapAPI), then assert Current and Live equaldb.SavingsTotalsCappedfor the same filters and carrycap_correction_usd/cap_not_applied = false; keep a case that asserts All stays labelledcap_not_applied = truewith the stored figure.
- What fails:
-
dash/savings.go:103 — the correction is all-or-nothing, the headline applies each ledger on its own, so a partial failure breaks the agreement this PR exists to guarantee
- What fails:
CapCorrectionUSDreturns an error if either ledger fails, soSavingsTotalsCappedand the series/breakdowncap_correction_usdfall back to the stored figure withcap_not_applied = true. The headline does not work that way:/api/statsappliesApplySummarizeLedgerandApplyReplayLedgerindependently (dash/api.go:1506-1507; lean path 1406-1416) andReplayCapNotAppliedtracks only the replay ledger (dash/api.go:1508). When the summarize ledger fails and the replay ledger succeeds, the headline totals carry the replay delta and are labelled capped, while series/breakdown report correction 0 and the status line reports the stored figure. A client that sums the buckets and addscap_correction_usdthen does not land on the headline — the exact disagreement #586 reports — precisely in the state where one scan timed out, which is when scans do time out. - Proof: dash/savings.go:107-114 returns on the first ledger error. dash/api.go:1491-1499 logs a summarize failure and still applies the replay ledger at 1507;
ReplayCapNotAppliedstays false becauserepFailedis false. The two readers then disagree byrep.DeltaUSD(). - Fix: make both sides match. Either fold each ledger's delta in separately (return the per-ledger deltas and a per-ledger "not applied"), or make the headline skip the whole correction when either ledger fails, so one rule governs both.
- What fails:
Non-blocking
- Proxy
/statscost class changed.savingsStatsnow runs two row-streaming ledger scans per call (the current session's full history plus every live session's, up tomaxKeepAliveSessions), with no cache, while the dash-side equivalent (/api/stats?lean=1) sits behindstatsCache. TheSavingsStatsdoc comment still says the query is "cheap enough to run synchronously" (proxy/savings.go:47-48). The scans are session-bounded, which is the cost class the lean path already accepts, and/statsreaders look low-frequency (cg.py, monitoring). Consider a short TTL or updating the comment. - No consumer in this repo reads the new series/breakdown fields.
dash/uinever readscap_correction_usdorcap_not_appliedfrom/api/seriesor/api/breakdown, so the dashboard's own charts still sum uncapped buckets and can read above the headline tile until a consumer (UI or the downstream plugin) adds the correction. The API surface alone may be the intent; if the dashboard page was the target, that half is still open. SavingsTotalsCapped's "agrees with the headline" holds for the lean read, not the full one. The full/api/statsalso addsCachesplitHistoricalUSDand the decl-filter credit tototal_saved_usd(dash/api.go:1518, 1523-1525);SavingsTotalsnever did. Pre-existing lean/full gap, but the new doc comment (dash/savings.go:118-120) states the agreement without that limit.- capreaders_test.go:103 re-checks only
/api/seriesafterpricer = nil; the breakdown route's not-applied answer is not re-checked (its cache key was already used earlier in the test).
What I checked
- The full diff of
eb0f89bfagainst base77a910b0, and the code around every change:dash/api.go(series, breakdown, stats lean and full,capCorrection,serveJSON/cachedRoute/routeBounds),dash/savings.go,dash/replaycap.go(ReplayLedgerFor,ApplyReplayLedger),dash/summarizeattr.go(SummarizeLedgerFor,ApplySummarizeLedger),proxy/savings.go,proxy/promexport.go. - That the new fields' arithmetic matches the headline:
CapCorrectionUSD= summarize delta + replay delta; bothApplySummarizeLedgerandApplyReplayLedgeradd their delta to baseline, net and total, and the two ledgers cover disjoint components (notSummarizerSQL). - Route cost and bounding: series and breakdown are
cachedRoute-wrapped withdashHeavyTimeout; the ledger scans run under the compute context, so they are bounded. The UI's default range is all-time (state.from = 0), so the default series/breakdown views scan the whole table per cold cache key — the same class the full stats read already accepts, and the handler comment says so. - The golden files: key order and values match
encoding/json's sorted-map output for the new fields. - The new tests in capreaders_test.go: helpers exist (
replayCapAPI,nearEq,replayCapHarness.get), the fixture has real capped credit, and the cache-bypass trick (different bucket) is valid becausecachedRoutekeys on the query string. docs/data-dependence.md: the new reads use only dashboard metadata the headline already reads; no dependence change, so no row update needed.- Issue #586: the four readers it names (status line, metrics export, series buckets, per-group totals) are each addressed, by capping or by labelling.
- I did not run builds or tests (not approved, Go not installed on this machine).
…rrection (#586) Round 1 review of #1037. - CapCorrection runs the summarize and replay ledgers on their own, as the headline does. A ledger that fails keeps the other's correction and sets cap_not_applied, so series, breakdown and the status line land where the headline lands. Before, either failure dropped both. - API.capCorrection goes through the replayLedger test hook, so a replay failure reaches series and breakdown the way it reaches the headline. - /stats reuses the correction of a scope for 15 seconds. The totals under it stay live. Before, each refresh streamed the rows of the current session and of every live session through two ledgers. - Tests: the summarize half of the correction, a fixture with both kinds of credit for the partial failure, the proxy wiring (capped session scope, labelled lifetime scope, no resolver), and the cache. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
#586) Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
|
Round 1 replies. Fixes are in Reviewer 1, finding 1, and Reviewer 2, finding 2 (the correction was all-or-nothing): fixed.
Reviewer 1, finding 2 (summarize half never tested): fixed.
Reviewer 1, finding 3 (two ledger scans on each
Reviewer 2, finding 1 (no proxy test where the cap runs): fixed.
Non-blocking items
Tests: |
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | resumed | 1 of 2 | 2 of 2 | b2843a9f9e |
approve |
Verdict: approve
Findings
None. My three round-1 findings are fixed. I verified each fix in the code. Reviewer 2's two findings are fixed too.
Round-1 findings, resolved
-
All-or-nothing cap correction — fixed (
d577af74).DB.capCorrection(dash/savings.go:107-121) now runs each ledger on its own: one that fails leaves the other's delta inCorrectionUSDand setsNotApplied. The numbers now land where the headline lands in every partial-failure case:- Summarize fails, replay runs: headline applies the replay delta (
dash/api.go:1413,1507); reader returns the replay delta. Agree. - Replay fails, summarize runs: headline applies the summarize delta and sets
replay_cap_not_applied(dash/api.go:1415,1508); reader returns the summarize delta withcap_not_applied. Agree. - Neither runs (no pricer or resolver): both sides keep the stored figure and label it. Agree.
TestCapCorrectionKeepsTheLedgerThatRancovers all three with a fixture that holds both kinds of credit, so each failure leaves a non-zero part. The author also mutation-tested it (removed the summarize delta; both tests failed).- The label semantics differ from the headline's in one case: a summarize-only failure leaves the headline's
replay_cap_not_appliedfalse while the reader'scap_not_appliedis true. The numbers agree, andCapNotApplied's comment now says "in whole or in part". Accept.
- Summarize fails, replay runs: headline applies the replay delta (
-
Summarize half untested — fixed (
d577af74).TestSavingsTotalsCappedCountsTheSummarizeLedgerusessummarizeEventrows with credit past the span, asserts the summarize delta is negative and the replay delta is zero, and comparesSavingsTotalsCapped's baseline, net and total against anOverviewthatApplySummarizeLedgerandApplyReplayLedgercorrected — the headline's own arithmetic, not the replay-only JSON field. The replay-only comparison in the older test is now explained in the file comment. Helpers exist (dash/summarizeattr_test.go:50-70,handPriceindash/accounting_test.go:16). -
Uncached ledger scans on each /stats refresh — fixed (
d577af74).capCorrectionCache(proxy/savings.go:56-100) keeps each scope's correction for 15 s. The base totals stay live on every read (savingsCappedrunsSavingsTotalsoutside the cache). One scan per key at a time — the lock is held across compute on purpose.capKeysorts the live sessions on a copy, so the keeper's map order cannot split the cache. Tests:TestStatsSavingsReusesTheCorrectionButNotTheTotals(totals move, correction cached, recomputed past the TTL) andTestCapKeyIgnoresTheOrderOfLiveSessions(same set, same key, caller's slice untouched). The staleness is disclosed in the code comment and in the author's reply.
Reviewer 2's findings, resolved
- No proxy test where the cap runs — fixed.
proxy/savings_cap_test.gogives the handler a 1M window resolver and a session past the cap. It asserts thecurrentscope carries the correction and equalsSavingsTotalsCapped, theallscope keeps the stored figure withcap_not_applied: true, and a proxy with no resolver labels the session scope. I checked the wiring:Options.Windowsflows toh.opts.Windows(proxy/savings.go:99-100),/statsembeds the block underjson:"savings"(metrics/metrics.go:1096,proxy/proxy.go:3037), and the helpers used (New,Mux,setLastSession,InsertEvents,fixedPricer) all exist. - All-or-nothing correction — same as my finding 1. Fixed.
Non-blocking
DB.capCorrection(dash/savings.go:110-121) swallows both ledger errors with no log line. Round 1 logged "replay cap unavailable" in this path; the headline still logs its failures (dash/api.go:1495,1694). The reader gets the label, but an operator gets no log to find out why the cap did not run. Add oneslog.Warnper failed ledger.capCorrectionCache.getholds one mutex acrosscompute(), so a slow live-scope scan blocks a concurrent read of the current scope's key too. With one status-line reader this is the intended single-flight; a per-key lock would not serialize unrelated scopes. Fine as is.- A cached
NotAppliedresult from a transient scan failure holds for the full 15 s. Labelled, so acceptable.
What I checked
- Last review: round 1, eb0f89b, 2026-11-10T11:43:40Z.
- New commits read: 2 —
d577af74"fix(dash): Apply each cap ledger on its own, cache the status-line correction (#586)" andb2843a9f"docs(dash): Say where SavingsTotalsCapped and the full headline differ (#586)". - Read in full: 2 reviews, 1 comment, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt). - New items since my last review, and what I did about each:
- Reviewer 2's round-1 review (posted 11:46:12Z, after my 11:43:40Z): read in full. Its finding 2 matches my finding 1; its finding 1 (missing proxy test) I verified as fixed.
- The author's round-1 reply (11:54:37Z): read in full. Every claim in it checks out against the code, including the mutation test and the sorted-live-sessions rationale.
- Commit
d577af74: read the full diff and the code around each change —dash/api.go(capCorrection through the replayLedger hook),dash/savings.go(CapResult, CapCorrection, ApplyCap, SavingsTotalsCapped),dash/capreaders_test.go(four new tests),proxy/proxy.go(capCache field),proxy/savings.go(cache, savingsCapped, savingsStats),proxy/savings_cap_test.go. - Commit
b2843a9f: the doc line on SavingsTotalsCapped, which answers my round-1 non-blocking note about the full headline's extra total addends.
- The partial-failure agreement against both headline paths: lean (
dash/api.go:1404-1416) and full (dash/api.go:1506-1508), withApplySummarizeLedger(dash/summarizeattr.go:152-162) andApplyReplayLedger(dash/replaycap.go:617-630). - No leftovers of the removed API:
grep CapCorrectionUSD errCapUnavailableover non-test Go files finds only the struct fields and their setters. - The new tests' helpers and wiring:
summarizeEvent/testWindows/handPriceindash,New/Mux/setLastSession/InsertEvents/fixedPricer/metrics.Snapshot.Savings'sjson:"savings"tag inproxy. - Live tests were not run. Go is not installed on this machine and the review brief forbids builds. The author reports
go test ./dash ./proxypasses, with two unrelated timing tests flaky in the parallel run and passing alone on both this branch and the base.
boazdavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @boazdavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.241 | offload-review skill, @boazdavid's session | resumed | 2 of 2 | 2 of 2 | b2843a9f9e90 |
approve |
Verdict: approve
Findings
None. Both round-1 findings are fixed and verified. No new defect in the two new commits.
Earlier findings
- My finding 1 (no proxy test where the cap runs): fixed.
proxy/savings_cap_test.gogives the proxy a 1M window resolver and a session past the cap.TestStatsSavingsCapsTheSessionScopeAndLabelsTheLifetimeScopeasserts the Current scope equalsSavingsTotalsCappedfor the same rows, with a negative correction, and that All keeps the stored figure labelledcap_not_applied: true.TestStatsSavingsLabelsTheSessionScopeWithoutAWindowResolvercovers the no-resolver labelling. This is the fix I asked for. - My finding 2 (all-or-nothing correction vs the per-ledger headline): fixed.
CapCorrection(dash/savings.go:116-132) now runs each ledger on its own: a failed ledger keeps the other's delta and setsNotApplied. I traced every state against both headline paths: no pricer or windows (lean dash/api.go:1404, full :1508), both ledgers running, summarize failing while replay runs (full :1491-1507), and replay failing while summarize runs (lean :1412-1416). In every state the reader's buckets pluscap_correction_usdnow land on the headline's totals.TestCapCorrectionKeepsTheLedgerThatRancovers the partial failures with a fixture where both halves are non-zero, andTestSeriesAndBreakdownSayWhenTheReplayLedgerFailedreaches series and breakdown through thereplayLedgerhook. - Reviewer 1, finding 1 (same as my finding 2): fixed, verified above on my own reading.
- Reviewer 1, finding 2 (summarize half never exercised non-zero): fixed.
TestSavingsTotalsCappedCountsTheSummarizeLedgeruses realsummarizeEventrows with credit past the span and comparesSavingsTotalsCappedagainst an Overview thatApplySummarizeLedgerandApplyReplayLedgercorrected — not against the replay-only field. The fixture gate (sl.DeltaUSD() >= 0→ fatal) makes it self-checking. - Reviewer 1, finding 3 (two ledger scans per
/statsrefresh): fixed. The 15-secondcapCorrectionCache(proxy/savings.go:63-101) reuses each scope's correction, keeps the totals live, holds one scan per key at a time, and sorts the live-session set on a copy so the same set hits the same entry.TestStatsSavingsReusesTheCorrectionButNotTheTotalspins both halves of that contract, andTestCapKeyIgnoresTheOrderOfLiveSessionsthe key. - Non-blocking items: each accepted with a reason that checks out. The lean-vs-full doc sentence is in
b2843a9f(dash/savings.go:145-147); thea.capCorrectionhook bypass is gone (dash/api.go:1564-1568); the breakdown not-applied answer is now covered through the sharedcapCorrectionpath by the new failure test; the data-dependence statement is in the reply and adds no dependence.
Non-blocking
- The headline's
replay_cap_not_appliedstill tracks only the replay ledger. When the summarize ledger fails, the headline is labelled "capped" while it missed that half. The readers'cap_not_appliedis now the honest label. The figures agree in every state, so this is a label gap in the pre-existing headline code, not a defect of this PR. - The proxy cache's mutex is global across scopes, so one scope's scan makes a concurrent
/statscall for another scope wait, and/statshas no timeout wrapper (only/metricsdoes, proxy/proxy.go:614). Bounded by one scan; the steady state under the 15-second TTL is cheap. Worth remembering if/statsgrows more scopes. - The Live scope's capped fields are not asserted directly in the proxy tests (no fixture puts sessions in the keeper's live set). The path is shared with Current through
savingsCapped, andcapKey's set handling has its own test, so I accept this.
What I checked
- Last review: round 1, eb0f89b, 2026-11-10T11:46:12Z
- New commits read: 2 —
d577af74fix(dash): Apply each cap ledger on its own, cache the status-line correction;b2843a9fdocs(dash): Say where SavingsTotalsCapped and the full headline differ - Read in full: 2 reviews, 1 comment, 0 inline comments (from
.review-in-reviews.txt,.review-in-comments.txt,.review-in-inline.txt) - New items since my last review: the author's round-1 reply at 2026-11-10T11:54:37Z (each claim checked against the code, as listed under Earlier findings); commits
d577af74andb2843a9f(full diff read, plus the code around each change) - The new
CapCorrection/capCorrectionsplit,CapResult,ApplyCapandSavingsTotalsCapped: no remaining caller of the removedCapCorrectionUSDmethod orerrCapUnavailable(grepped); the fieldCapCorrectionUSDkeeps its JSON name, so the wire format is unchanged and the golden files need no update (none were made, correctly). - That the reader and the headline agree per state, by tracing the lean path (dash/api.go:1396-1418) and the full path (dash/api.go:1477-1508) against
capCorrection's four outcomes. - The proxy cache: lock discipline (no re-entry, compute does not call back), the nil-map and over-64 reset, the 15-second TTL, the copy-then-sort in
capKey, and that a failed scan's partial result is cached but labelled. - Compile-level facts for the new tests:
summarizeEvent(dash/summarizeattr_test.go:57),InsertEvents(dash/store.go:546),handPrice,testWindows,offload.EventFreshSummary,fixedPricer,oneMillionWindowsatisfyingmodelinfo.Resolver(internal/modelinfo/modelinfo.go:27), anda.replayLedger's hook (dash/api.go:596-601). All exist with matching signatures. - The author's test-run claim (
go test ./dash ./proxypassing, two flaky timing tests passing alone on base too) is not verifiable here: Go is not installed and live tests are not approved. The new tests' fixtures are self-gating (they fatal when the fixture stops proving the claim), which is the right shape.
Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
|
Merged
|
…ur share as an estimate (#988) On a Claude subscription, the dashboard Overview now shows saved tokens, not dollars. The total and each card read the accountant's tier tokens in /api/stats: tokens.saved, tokens.caused and tokens.by_feature. Tiers show in the order wr, wr1h, rd, in, then cost. Below the total, a dim line gives the 5-hour limit share as an estimate (used% x saved_usd / cost_usd, capped at 100 - used%). Behavior change: users on a Claude subscription who open the dashboard Overview. Old: every saving shows in dollars. New: every saving shows in tokens by kind, with a dim estimate of the 5-hour share below the total, and no dollars. How to turn it off: nothing to turn off. API-key, Bedrock, Vertex, manager and hosted users see no change. Owner's yes, 2026-11-10, in the integrator session: "1021 and 988 in this order are also ready" and "988 is ready". Data dependence: metadata only (token counts by tier, the auth kind and the rate-limit numbers). The same at each storage level. docs/data-dependence.md has the row. Reviews: 2 offload reviews (GLM), round 5, both approve at 6da7583 (the merge of main that resolved the dash/ui/app.js conflict by hand). After it: one merge of main (#1037, #1021) with no hand resolution (remerge-diff 0). The 6da7583 hand resolution kept both sides of one line in the Tool deferral card: main's "Not counted in Your preset." text, and #988's saving() wrapper. Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]>
Behavior change (needs a human's yes)
Who it affects: anyone who reads the status line (
/statssavings.currentandsavings.live).Old: the status line summed the stored credit. It could read far above the dashboard headline.
New: the status line applies the same cap as the headline. For a capped session it now shows the lower number.
How to turn it off: no switch. Use
SavingsTotalsin place ofSavingsTotalsCappedinproxy/savings.go.Problem
Fixes #586.
#546 and #573 cap the summarizer and offloader replay credit in the headline,
/api/componentsand the episode view. Other readers still summedrequest_components.saved_usdand so disagreed with the headline.I ran 150 turns of one session through a built
origin/main. The transcript passed the compaction ceiling./api/stats(headline)/statscurrent (status line)/api/seriesChanges
SavingsTotalsCappedapplies the summarize and replay ledger correction.CapCorrectionUSDadds the two ledgers in one place./statsuses it for thecurrentandlivescopes.allscope stays uncapped and returnscap_not_applied: true. A lifetime read would stream every row through the ledgers on each refresh. dash: #498's tests guard 2 of 4 queries and no numbers; the session query still grows with the square of its size #502 forbids that./api/seriesand/api/breakdownreturncap_correction_usdandcap_not_appliedbeside their rows. The ledgers do not say which bucket a correction belongs to, so I did not spread it over the buckets. Rows plus the correction equal the headline.Result
Same 150-turn session, built from this branch:
/api/stats(headline)/statscurrent/api/seriesbuckets +cap_correction_usd/api/breakdowngroups +cap_correction_usd/statsallcap_not_applied: trueNot done
Tests
dash/capreaders_test.go: the capped totals match the headline, the label shows when the cap cannot run, and series and breakdown carry the correction.series_day,series_hour,breakdown_agent,breakdown_model. Each diff is the two new fields only.go test ./dash ./proxy,go vetandgofmtpass.TestPreflightResolvesToolsOnTheServicePATHincmd/context-guru-proxyfails. It fails the same way on the base without this change.Assisted-By: Claude (Anthropic AI) [email protected]