Repository navigation
feat(dash): count tool deferral as its own lever on the Savings page (#888) - #891
Conversation
The Savings total and the daily chart now include tool deferral's NET saving (the sum of requests.defer_net_usd, the same figure as /stats tool_defer and the Tools panel). It is one more addend of the total, a waterfall step "defer_net", a Savings card, and a daily series. One SQL expression (deferNetSum) feeds the Tools panel, the totals and the series. No other lever holds these dollars: deferral runs after the declaration filter and its definitions are outside tokens_before. Closes #888 Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
…teral Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
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 2 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 34967a851dfe |
blocking |
Verdict: blocking
Findings
- dash/cachestate.go:282-298 — Per-thread savings omit tool deferral
- What fails:
/api/cachestatereports per-thread savings that excludedefer_net_usd, while every other dashboard endpoint includes it. A session with tool deferral shows inconsistent totals across endpoints. - Proof:
cacheThreadsQuery()at line 282 builds the SQL that sums cost components per thread. It includesbaseline_cost_usd,cost_usd,cg_llm_cost_usd,cachesplit_saved_usd, keep-alive savings, and manual ping costs (lines 289-295), butdefer_net_usdis absent. Line 202 callsthreadMoney(base, cost, cgllm, split, kaSv, ping, manualSaved, manualCost)with the scanned values. Line 310 then callssavingsArithmetic(cost, baseline, cgllm, split, kaSv, ping, manualSaved-manualCost, 0)with a hardcoded0fordeferNet. Compare tooverview.go:1101,overview_lean.go:76, andsavings.go:57, which all passo.DeferNetUSDors.DeferNetUSDas the 8th parameter. The test attooldeferpanel_test.go:88-180verifies that deferral raises the total in Overview, OverviewLean, and SavingsTotals, but does not test/api/cachestate. - Fix: Add
COALESCE(SUM(CASE WHEN+ agent +THEN r.defer_net_usd ELSE 0 END),0)to the SELECT incacheThreadsQuery()(after line 295). Scan it into a newdeferNet float64variable inThreadsFor()(line 192). PassdeferNettothreadMoney()instead of the hardcoded0at line 310. UpdatethreadMoney()'s signature to acceptdeferNet float64as its 9th parameter and pass it tosavingsArithmetic().
- What fails:
Non-blocking
None.
What I checked
- Read CLAUDE.md and docs/design.md for repo rules
- Read the full diff (all changed files)
- Verified
savingsArithmetic()signature change addsdeferNetas 8th parameter - Verified all callers of
savingsArithmetic()were updated exceptthreadMoney() - Verified
defer_net_usdis a per-request column (schema.go:223, DEFAULT 0) - Verified the test coverage includes Overview, OverviewLean, SavingsTotals, and Series, but not the cache state endpoint
- Verified the comment at cachestate.go:303 says "Only savings written per request are in it" and
defer_net_usdqualifies - Checked that no other queries or calculations were missed
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 34967a851dfe |
blocking |
Verdict: blocking
Findings
- dash/cachestate.go:310 — Per-thread savings exclude tool deferral
- What fails: A session's thread money totals do not include deferral savings. The Overview shows session total with deferral, but Cache State's per-thread breakdown omits it. The figures disagree.
- Proof: Line 310 calls
savingsArithmetic(..., 0)with hardcoded 0 fordeferNet. Line 290-305cacheThreadsQuerysumsbaseline_cost_usd,cost_usd,cg_llm_cost_usd,cachesplit_saved_usd, keep-alive fields, and manual pings, but does not sumdefer_net_usd. Every other caller ofsavingsArithmeticin this PR passes the actual deferral value:savings.go:58,overview.go:1103,overview_lean.go:77. - Fix: Add
COALESCE(SUM(CASE WHEN+ agent +THEN r.defer_net_usd ELSE 0 END),0)tocacheThreadsQueryselect list. AdddeferNet float64to the scan variables at line 195. PassdeferNetinstead of0tosavingsArithmeticat line 310.
Non-blocking
- The test
TestDeferNetIsItsOwnLeverInTheTotalis thorough and covers Overview, OverviewLean, SavingsTotals, the waterfall, and the daily series. It does not coverthreadMoneyor the Cache State page, which is where the finding above lives. - The UI changes (app.js, style.css) correctly show deferral only when
parts.defer !== 0, so accounts that never deferred see no deferral card or series. Clean. - The Python plugin script
cg.pycorrectly adds the lever to the waterfall breakdown.
What I checked
- Read CLAUDE.md and docs/design.md for repo rules
- Read the full diff (all 16 files changed)
- Verified
savingsArithmeticsignature change and all call sites - Verified
deferNetSumSQL constant is used consistently across queries - Verified test coverage in
tooldeferpanel_test.goandsavings.test.mjs - Verified UI changes show deferral conditionally and add it to totals
- Verified golden test files updated with new waterfall step
- Checked that the new field is
omitemptyin JSON where appropriate (Bucket) - Verified the waterfall description explains why deferral is its own line
|
Round 1: both reviewers raised the same finding. Fixed in 4a1bf19.
|
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 4a1bf19cd7c3 |
approve |
Verdict: approve
Findings
None. The round 1 finding is fixed.
Round 1 finding status
Finding 1 (dash/cachestate.go:310) — FIXED
The fix in commit 4a1bf19 is correct and complete:
cacheThreadsQuerynow sumsdefer_net_usdat line 296:COALESCE(SUM(CASE WHEN+ agent +THEN+ deferNetCol +ELSE 0 END),0)ThreadsForscans the new column intodeferNet float64at line 196threadMoneysignature updated to acceptdeferNetas 9th parameter at line 311threadMoneypassesdeferNettosavingsArithmeticat line 312 (no longer hardcoded 0)threadMoneyaddsdeferNetto the baseline at line 313:return saved, baseline + split + kaSv + manualSaved + deferNet- Comment at line 307 updated to explain that deferral is included
- New test
TestThreadMoneyIncludesDeferNetat line 186 verifies the fix: a thread withdefer_net_usd0.004 shows exactly 0.004 more in bothSavedUSDandBaselineUSD
The author also introduced deferNetCol constant in tooldeferpanel.go:23 to avoid duplicating the column name between deferNetSum and cacheThreadsQuery. Clean.
Non-blocking
None.
What I checked
- Last review: round 1, 34967a8, 2026-11-04T11:48:19Z
- New commits read: 1 (4a1bf19 "feat(dash): count tool deferral in the per-thread money view")
- Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review:
- Commit 4a1bf19: read full diff and surrounding code
- Comment by amiddavid at 2026-11-04T11:49:47Z: confirms fix, test, and mutation testing
- Reviewer 2's round 1 review: same finding as mine, no additional issues
- Verified the fix addresses all parts of the finding
- Verified the new test covers the fixed code path
- Verified no new issues introduced by the fix
- Checked that
deferNetColconstant is used correctly in both places
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (bob, user of @amiddavid) | IBM Bob Shell 1.0.3 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 4a1bf19cd7c3 |
approve |
Verdict: approve
Findings
None. My round 1 finding is fixed.
Round 1 finding status
Finding 1 (dash/cachestate.go:282-298) — FIXED
The fix in commit 4a1bf19 addresses the finding completely:
- Added
deferNetColconstant to share the column name withdeferNetSum - Added the deferral sum to
cacheThreadsQuerySELECT (line 297) - Added
deferNet float64variable and scanned it (lines 193, 196) - Passed
deferNettothreadMoney(line 203) - Updated
threadMoneysignature to acceptdeferNetas 9th parameter (line 313) - Passed
deferNettosavingsArithmeticand added it to baseline (lines 314-315) - Updated the comment to explain deferral is included (lines 307-308)
- Added test
TestThreadMoneyIncludesDeferNetthat verifies a thread with deferral shows exactly 0.004 more in saved and baseline than one without
The author's comment confirms mutation testing (passing 0 failed the test) and race testing passed.
Non-blocking
None.
What I checked
- Last review: round 1, 34967a8, 2026-11-04T11:48:15Z
- New commits read: 1 (4a1bf19 "feat(dash): count tool deferral in the per-thread money view")
- Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review:
- Commit 4a1bf19: read full diff and surrounding code in all 3 changed files
- Author's comment at 2026-11-04T11:49:47Z: confirms the fix, mutation test, and race test results
- Reviewer 1's review at 2026-11-04T11:48:19Z: raised the same finding independently
- Verified the fix matches my proposed solution exactly
- Verified the new test covers the finding: creates two sessions (one with deferral, one without) and checks the difference is exactly 0.004 in both saved and baseline
- Verified
deferNetColis used consistently (shared withdeferNetSum) - Verified the comment update explains why deferral raises y (baseline)
- Checked that no other code paths were affected by the signature change
Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
|
CI lint failed on On box 2, |
Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
|
New commits: a merge of
|
…0.2.11) (#921) Claude Code plugin 0.6.6 -> 0.6.7: - #889: the preset picker restarts the proxy after a yes, and the status shows a pending preset. - #891: insights and the status show tool deferral as its own saving lever. - #877, #885: save-more tools (keep, unkeep, defer, undefer, search on/off, revert). - #882: ultrahigh is marked experimental in the picker. Codex plugin 0.2.10 -> 0.2.11: - #889, #891: the same cg.py changes (vendored copy). - #882: ultrahigh is marked experimental in the picker. Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]>
Behavior change (read first)
ultrahighpreset (tool deferral on). Other accounts have no deferral rows, so nothing changes for them.threadMoney, owner's yes 2026-11-04) and joinstotal_saved_usd,/api/stats, the lean stats read,SavingsTotals, the Savings page (new "Tool deferral" card) and the daily chart (own series). The/chartplugin lever list gets a "Tool deferral" row.ultrahigh). The figure is then 0 and drops out of every view. There is no separate switch.Summary
/statstool_deferand the Tools panel.What changed
deferNetSum(SUM(r.defer_net_usd)). The Tools panel,Overview,OverviewLean,SavingsTotalsand the dailySeriesall use it. There is no second copy of the sum.savingsArithmeticgets adeferNetaddend. Overview, lean andSavingsTotalsall use that formula.defer_netbeforetotal_saved.Bucket.defer_net_usd, left out of the JSON when 0. An account with no deferral has no deferral series.savedPartsgetsdefer. The Savings page shows a "Tool deferral" card only when the figure is not 0. The daily chart draws a second bar and a key only on days that deferred.cg.leversgets a "Tool deferral" row, so the/chartlever list still adds up to the headline.cacheThreadsQuerysums the samedefer_net_usdcolumn.threadMoneyadds it to saved and baseline.toolsarray, outsidetokens_before.filtered_decl_tokens(the filter credit indeclcredit.go) counts only what the filter removed. The two columns are disjoint. The self-removal credit stays outside the total.Data dependence
None new. The change reads
defer_net_usd, a number already stored on each request row (metadata only). At each level: off or metadata only, the figure is available. Everything: no change. No row indocs/data-dependence.mdchanges.How it was tested
Run on the shared box (box 2):
go vet ./dash/ ./proxy/andgo build ./...: clean.CGO_ENABLED=1 go test -race -timeout 30m ./dash/...: ok (601 s, at head 4a1bf19).TestThreadMoneyIncludesDeferNet: a thread with deferral shows exactly that much more in saved and baseline. Mutation (pass 0): test fails. Restored.go test ./dash -run 'TestDeferNet|TestGoldenEndpoints|TestToolDefer': pass.TestDeferNetIsItsOwnLeverInTheTotal: a row withdefer_net_usd0.004 raises the total by exactly 0.004 inOverview,OverviewLeanandSavingsTotals. It appears as thedefer_netwaterfall step and as a daily series. An account with no deferral has no series.stats*.jsonupdated (one new field and one new waterfall step, all 0 in the fixture).node --test dash/savings.test.mjs: pass (new test: parts add up to the server total).pytestincontext-guru-plugin: 87 passed.deferNetfrom thetotalline insavingsArithmetic.TestDeferNetIsItsOwnLeverInTheTotalfailed for all three readers. Restored.TestSettingsFormSpeaksTheSameFieldNamesAsTheServer: my card id'defer'matched a config field name. Renamed totooldefer. Fixed in the second commit.Technical notes
./dash/...race run is near Go's default 10 minute limit on a loaded box. I ran it with-timeout 30m.🤖 Generated with Claude Code