Repository navigation
Fix: Bound the held first-request estimate and show it as a range (#915) - #1001
Conversation
…or (#915) The first request on an unseen warm cache cannot be priced exactly: the size of the warm prefix is not in the usage. Keep it held out of the totals, and store and show a floor (every removed token at the read rate) beside the existing write-rate ceiling, so the range brackets the true saving. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
The Overview note and the request detail row showed only the ceiling of a held estimate, which can be about 2x too high. Show the floor and the ceiling together, so a reader sees the bounds the true saving lies between. Totals are unchanged. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
ae3ff87 to
fd700c8
Compare
…nd add the missing insert placeholder (#915) The rebase onto main left a conflict marker in accountant_switch_test.go and one placeholder too few in the requests INSERT after this PR's new estimated_saved_low_usd column, so the dash package did not build or insert. 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 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 | d731a15f8c6e |
blocking |
Verdict: blocking
Findings
-
dash/accountant_price.go:478 — heldFloorUSD re-prices the deferral's tokens, which the held figure excludes
- What fails: a held request on which tool deferral acted stores a floor that is too low. The floor drops by the deferral's Saved tokens x (write rate - read rate), although the deferral's dollars are not in the held ceiling. With the new test's prices: a mask op that saves 15,976 w5m tokens plus a tooldefer op that saves 2,188 w5m tokens gives a held ceiling of 15976 x 2.5e-6 = $0.03994. The correct floor is 15976 x 0.2e-6 = $0.0031952. The code returns 0.0031952 - 2188 x (2.5e-6 - 0.2e-6) = -$0.0018. The UI then hides the range (
estRangeneedslow > 0) and falls back to the ceiling alone. The stored floor and both Overview sums are wrong for such rows. - Proof:
accOverridesetsEstimatedSavedUSD = fig.DeltaUSD - deferFig(line 452), wheredeferFig = fig.ByComponent["tooldefer"]. So the held figure excludes the deferral.heldFloorUSD(p, fig.DeltaUSD-deferFig)then loops over every op ine.accRes.Opswith no operator filter (lines 480-486) and subtractstierUSD(p, o.Saved) - readRate x o.Savedforcontext-guru.tooldeferops too. Those ops' Saved tokens are not part of the figure being floored.countedSavedTokens(line 519) shows the pattern this loop is missing: it filterstoolSectionOperators. The new test covers only a single mask op, so this case is untested. - Fix: skip
o.Operator == "context-guru.tooldefer"inheldFloorUSD's loop (or derive the floor fromfig's per-component tokens, which already exclude the deferral). Add a test with a tooldefer op on a held request.
- What fails: a held request on which tool deferral acted stores a floor that is too low. The floor drops by the deferral's Saved tokens x (write rate - read rate), although the deferral's dollars are not in the held ceiling. With the new test's prices: a mask op that saves 15,976 w5m tokens plus a tooldefer op that saves 2,188 w5m tokens gives a held ceiling of 15976 x 2.5e-6 = $0.03994. The correct floor is 15976 x 0.2e-6 = $0.0031952. The code returns 0.0031952 - 2188 x (2.5e-6 - 0.2e-6) = -$0.0018. The UI then hides the range (
-
dash/ui/app.js:1871 — the subscription Overview now shows a dollar estimate
- What fails: a Claude-subscription Overview shows the sentence "Estimated saving, not in any total: $x to $y" on the Preset card. The page's own contract says every saving is in tokens, not dollars: the hero, the cards and the info text all render tokens when
subis set. The base code suppressed this sentence on a subscription with(sub ? '' : ...). Commit fd700c8 drops that guard. A subscription user now sees a stray dollar figure on a token-denominated page. - Proof:
subis set inrenderSavedLedgerfromstate.sub(app.js around line 1741);subInfo[0]states "On a Claude subscription every saving is in tokens, not dollars." The base line was+ (sub ? '' : ' Estimated saving, not in any total: ' + estUsd(...) + '.'). The new line has nosubguard. The PR names no such change, and CLAUDE.md requires a behavior change that alters what is shown to be named and approved by a human developer. - Fix: restore the guard, or name this change in the PR and get the owner's yes.
- What fails: a Claude-subscription Overview shows the sentence "Estimated saving, not in any total: $x to $y" on the Preset card. The page's own contract says every saving is in tokens, not dollars: the hero, the cards and the info text all render tokens when
Non-blocking
- docs/data-dependence.md, the Dashboard row, still says "Two more flags and one number sit beside it" and names
estimated_saved_usd. The newestimated_saved_low_usdcolumn is missing from that sentence. The dependence is the same class (a number, no text), so the row's reason still holds. Update the enumeration. estRange(dash/ui/app.js:107) hides the floor wheneverlow <= 0and shows only "≈ ceiling". On a held request whose true saving is small, the reader gets no sign the figure can be far lower. Finding 1 makes this state reachable. Consider "up to $x" wording for that case.- The comment on
Event.EstimatedSavedLowUSDsays the true saving lies in [low, high] for every held row. On a negative held figure the UI shows only the ceiling as a cost. Cosmetic.
What I checked
- Read CLAUDE.md and docs/design.md. Read the full diff of 9d34f00..d731a15 and every file it touches.
- dash/accountant_price.go: traced
PriceMode,accOverride,AccountantFigureandheldFloorUSDtogether. Verified the ceiling/floor arithmetic of the new test by hand ($0.021569 hand figure and the bounds hold). - Counted the INSERT columns against its placeholders in dash/store.go (146 = 146, with 7 limitCols and 40 token columns),
requestColsagainstscanRequest(130 = 130), the full Overview SELECT against its Scan (last termestimated_saved_low_usdinto&o.EstimatedSavedLowUSD), and the lean window query against its dest list. All aligned. - dash/schema.go: the new column is in both the CREATE TABLE and
additiveColumns, same position. Old rows default to 0 and the UI falls back to the ceiling. PriceandPriceModeboth resetEstimatedSavedLowUSD; searched all writers ofEstimateHeld/EstimatedSaved*— no path sets held without the floor.- Golden test: the comparison decodes JSON and diffs key by key, so the three golden edits are consistent regardless of field order. All three stats goldens updated.
- dash/ui/app.js: read
renderSavedLedger,estRange,estUsdand both call sites, plus the request detail row. - No live tests were run (not approved).
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 | d731a15f8c6e |
blocking |
Verdict: blocking
Findings
-
dash/accountant_price.go:453 — the floor subtracts the tool deferral's read-rate adjustment, but the deferral's dollars are not in the ceiling
- What fails: A held request that also deferred tools stores a floor that is too low. It can be negative when the true floor is positive. The UI then drops the range and shows the ceiling alone, so the range feature disappears exactly on deferred threads. The Overview sums the same wrong floor.
- Proof: The ceiling passed in is
fig.DeltaUSD - deferFig(line 452), because the deferral's figure stays on the lever and out of the held estimate (comment at lines 442-445). ButheldFloorUSD(line 478) loops over every op ine.accRes.Opswith no operator filter, so it subtracts the read-rate adjustment of thecontext-guru.tooldeferop too. Those tokens' dollars were already removed from the base. Trace, withCacheWrite = 2.5e-6,CacheRead = 0.2e-6:- tooldefer op:
Saved.CacheWrite5m = 12000; mask op:Saved.CacheWrite5m = 4000. fig.DeltaUSD = 16000 x 2.5e-6 = 0.04;deferFig = 0.03; ceiling =0.01.heldFloorUSDsubtracts16000 x (2.5e-6 - 0.2e-6) = 0.0368, so the floor is0.01 - 0.0368 = -0.0268.- The correct floor is
4000 x 0.2e-6 = 0.0008. - The stored
estimated_saved_low_usdis-0.0268, not0.0008. InestRange(dash/ui/app.js:107)low > 0fails, so the request row and the Overview fall back to the ceiling alone. - The new tests cover only a request with no deferral op, so they cannot catch this.
- tooldefer op:
- Fix: In
heldFloorUSD, skip the deferral's op, the same wayaccOverrideremoves its dollars:if o.DryRun || o.Call != nil || o.Operator == "context-guru.tooldefer" { continue }. Add a test with a held request that carries a tooldefer op, and assert the floor is the non-defer removed tokens at the read rate.
-
dash/ui/app.js:1871 — the subscription Overview now shows the dollar estimate; before this PR it showed none
- What fails: A Claude subscription account with held requests sees a new dollar line on the Overview. The old code suppressed the estimate on the subscription view (
sub ? '' : ' Estimated saving...'). The new code always shows it. The rest of that view avoids dollars on purpose: its headline says every saving is in tokens, not dollars. - Proof:
git show fd700c81 -- dash/ui/app.jsremoves thesub ? '' :guard. The commit message names only the range display. It does not name this change. The repo rule (CLAUDE.md, "No behavior change for an edge case without a human developer's permission") needs the change named at the top of the PR, with the owner's yes. I did not read the PR description, so I cannot say it is missing there; the commit does not carry it. - Fix: Either restore the
subguard, or name the change at the top of the PR and get the owner's confirmation.
- What fails: A Claude subscription account with held requests sees a new dollar line on the Overview. The old code suppressed the estimate on the subscription view (
Non-blocking
heldFloorUSDcomment (dash/accountant_price.go:477) says the floor "equals it when nothing was priced as a write". This is not exact whenSavedholds Input-tier tokens: they bill atp.Input, not at the read rate, so the floor is below the ceiling even with no write. The bound itself stays valid.- The Overview floor sum mixes rows from before this column with new rows. A held row written between #915 and this PR has a ceiling but a 0 floor. On such a database the low end of the summed range counts only the new rows, so it understates. Each request row handles this correctly (it falls back to the ceiling alone). This ages out on its own.
- docs/data-dependence.md, "Dashboard database" row, names
estimate_heldandestimated_saved_usd. The newestimated_saved_low_usdis the same kind of number, so the dependence does not change. Add the column to that row, or state in the PR that the dependence is unchanged. - The golden files put the new key in different positions: before
estimated_saved_usdin stats.json and stats_lean.json, after it in stats_windowed.json. The test compares values, not key order, so this is cosmetic.
What I checked
- Read CLAUDE.md, docs/design.md, and the full diff of all three commits (fca1057, fd700c8, d731a15).
- Read dash/accountant_price.go in full. Traced
AccountantFigure,accOverride, andheldFloorUSDagainst each other. Checked which ops and effects enterDeltaUSD, whatdeferFigremoves, and what the floor loop adjusts. - Verified the SQL plumbing by count: the requests INSERT names 99 columns + 7 limitCols + 40 token columns = 146, and the VALUES lines hold 33 + 30 + 34 + 9 + 40 = 146 placeholders. The Exec args list adds
e.EstimatedSavedLowUSDin the same position as the column. - Checked
requestColsorder againstscanRequest, the full Overview SELECT against its Scan list, and the lean query terms against the lean Scan list. All align. - Checked the migration: the column is in
ddland inadditiveColumnswith the sameREAL NOT NULL DEFAULT 0, so a fresh and an upgraded database get the same shape.addColumnsis idempotent. NoSELECT *reads the requests table positionally. - Read both new tests and checked their arithmetic by hand: ceiling
15976 x 2.5e-6, floor15976 x 0.2e-6, and the issue's hand figure 0.021569 bracketed by the bounds. Confirmed the helpers (SetAccountant,accNear,insertReq) exist andinsertReqgoes throughinsertBatch. - Checked the golden test: it unmarshals both sides and diffs values, so the key-order difference is harmless.
- Grepped for other consumers of
EstimatedSavedUSD,estimate_held, andestimated_saved_usd(Go and UI). Both UI consumers were updated to the range;declFilterInBaselinein dash/toolsuggest.go is unaffected. - Checked the head commit's conflict-marker cleanup: no
<<<<<<<,=======, or>>>>>>>markers remain in dash/. - Checked the fail-open and booking rules: the floor is never booked, enters no total and no baseline, and
Priceresets it. No behavior of any total changed. - Live tests were not approved, so I did not build or run anything.
…bscription guard (#915) heldFloorUSD re-priced the tool deferral's tokens although the held ceiling excludes the deferral's figure, so a held request that also deferred tools stored a negative floor. The range line also lost its subscription guard in the merge with main, showing a dollar estimate on a token-only page. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
|
Round 1 replies. Both reviewers found the same two problems. Both are fixed in 803ddfc.
Non-blocking items:
Assisted-By: Claude (Anthropic AI) [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 | resumed | 1 of 2 | 2 of 2 | 803ddfc67f84 |
approve |
Verdict: approve
Findings
None.
Earlier findings
- My finding 1 and reviewer 2's finding 1 (the floor counted the deferral's tokens): fixed.
heldFloorUSDnow skipso.Operator == "context-guru."+DeferComponent(dash/accountant_price.go:482). I traced the new testTestPriceMode_HeldFloorLeavesTheDeferralOutby hand: a mask op of 4,000 write tokens and a tooldefer op of 12,000 givesfig.DeltaUSD = 0.04,deferFig = 0.03, ceiling0.01, floor4000 x 0.2e-6 = 0.0008. The loop skips only the tooldefer op, so the floor no longer drops by the deferral's adjustment. I also checked the skip is not too wide:toolfilter,toolschema,expandandadjudicatestay in the floor, and their dollars stay in the held ceiling, so the floor still matches the figure it bounds. The test passes the gates inaccOverride(its unpriced entry ispenalty_unknown, the plausibility bound excludes the tooldefer op throughtoolSectionOperators, andtooldeferis anenvelopeComponentsname). - My finding 2 and reviewer 2's finding 2 (the subscription Overview showed a dollar estimate): fixed. The
sub ? '' :guard is back in dash/ui/app.js:1871, in the base form. The range text still shows for non-subscription accounts. The author says the guard was lost in the merge with main. The restored line matches the base version. - My non-blocking items: the data-dependence.md row now names
estimated_saved_low_usd("two flags and two numbers"), fixed. The mixed-population floor sum, the Input-tier comment wording and the golden key order were left as is, with the reasons "ages out" and "no behavior change". I accept those reasons; none of the three changes what a number means.
Non-blocking
- None new. The items the author chose to leave are listed above and stay non-blocking.
What I checked
- Last review: round 1, d731a15, 2026-11-11T06:12:35Z
- New commits read: 1 (803ddfc, "fix(dash): Keep the deferral out of the held floor and restore the subscription guard (#915)")
- Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files in my folder)
- New items since my last review: the author's comment at 2026-11-11T06:15:48Z (round-1 replies, read and each claim checked against the code), and commit 803ddfc (diff read in full, all four files). Reviewer 2's round-1 review (06:12:23Z) I read now in full; it found the same two defects as my round 1, both now fixed.
- Read the fixed
heldFloorUSDand the new test in the file, not only the diff. Traced the test throughPriceModeandaccOverride: the unpriced-op rule, the plausibility bound, the row checks and the deferral lever. - Confirmed nothing else changed between d731a15 and 803ddfc: the commit touches only dash/accountant_price.go, dash/accountant_switch_test.go, dash/ui/app.js and docs/data-dependence.md.
- Re-checked that the floor still enters no total and no baseline, and that both
PriceandPriceModereset it. - Live tests were not approved, so I did not build or run anything.
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 | 803ddfc67f84 |
approve |
Verdict: approve
Findings
None. Both round-1 findings are fixed and the fixes are correct.
Round 1 findings
- heldFloorUSD re-priced the deferral's tokens — fixed in 803ddfc.
- The loop now skips
o.Operator == "context-guru."+DeferComponent(dash/accountant_price.go:481), which iscontext-guru.tooldefer, the exact operator whose dollarsdeferFigremoves from the held ceiling (line 452). The skipped set (DryRun, Call, tooldefer) is now exactly the set of ops whose nets are not infig.DeltaUSD - deferFig. Cache effects are never re-priced, so no other op or effect needs skipping. The floor and the ceiling now cover the same tokens. - The new test
TestPriceMode_HeldFloorLeavesTheDeferralOutcovers the case my round-1 review said was untested. I checked its arithmetic by hand: DeltaUSD = 16000 x 2.5e-6 = $0.04, deferFig = $0.03, ceiling = 4000 x 2.5e-6 = $0.01, floor = 4000 x 0.2e-6 = $0.0008. Both assertions match. The request passes the gates:countedSavedTokensskips the tooldefer op, so the bound sees 4000 against TokensBefore 20000.
- The loop now skips
- The subscription Overview showed a dollar estimate — fixed in 803ddfc.
- The
sub ? '' :guard is back (dash/ui/app.js:1870), in the same form as the base code, with the range text inside it. A subscription page shows no dollar estimate again. The author confirmed this was a merge error and not an intended change.
- The
Non-blocking
estRange(dash/ui/app.js:107) still hides the floor whenlow <= 0and shows "≈ ceiling" alone. After the fix this state means the true floor is genuinely at or below zero, so it is rarer. The reader still gets no sign the true saving can be far below the ceiling. My round-1 note; the author's reply did not address this one. Left for a later PR.- Reviewer 1's note on pre-column rows in the Overview floor sum: I agree with the author's reason to leave it. The sum ages out and each request row falls back to its own ceiling.
What I checked
- Last review: round 1, d731a15, 2026-11-11T06:12:23Z.
- New commits read: 1 (803ddfc "fix(dash): Keep the deferral out of the held floor and restore the subscription guard (#915)").
- Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files; .review-in-inline.txt is empty).
- New items since my last review, and what I did about each:
- Review by reviewer 1 at 2026-11-11T06:12:35Z: read in full. Both findings match mine. I checked the trace myself (16000/4000 token example, ceiling $0.01, wrong floor -$0.0268, correct floor $0.0008) and it is correct. No new findings in it.
- Comment by the author at 2026-11-11T06:15:48Z: read in full. It replies to both reviewers, states the merge error on the
subguard, and lists the non-blocking dispositions. Checked each claim against the code; all are accurate. - Commit 803ddfc: read the full diff and the code around each change.
- Verified the operator string:
DeferComponent = "tooldefer"(dash/accountant_price.go:228), so the skip matchescontext-guru.tooldefer, the nametoolSectionOperatorsand the library's operator both use. - Confirmed the fix touches nothing else: the commit changes only
heldFloorUSD's skip, the new test, the restoredsubguard, and the data-dependence row. No JSON output, golden file, column count or query changes, so the round-1 alignment checks still hold. - docs/data-dependence.md: the Dashboard row now names
estimated_saved_low_usd("the least it could be"). My round-1 non-blocking item is fixed. - No live tests were run (not approved).
|
Integrator note for v0.7.3. Two things are needed before this PR can merge:
The owner must still choose what to book for these rows: nothing (your recommendation), the floor, or the midpoint. I will ask the owner when CI is green. |
|
@amiddavid, both points are answered.
Booking for these rows stays the owner's decision. Assisted-By: Claude (Anthropic AI) [email protected] |
Resolve the dash/store.go conflict in the requests INSERT: main added restored_tokens and this branch adds estimated_saved_low_usd. Keep both columns and both placeholders (100 columns, 107 '?' incl. the dynamic limit/stored-token parts — the same 7-offset as the merge base). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
estRange fell back to the ceiling alone whenever the floor was not above zero, so a request whose true saving may be a cost read as "≈ $high". A floor below zero comes only from a new row, so show it; a floor of exactly 0 is what an older row holds and still shows the ceiling alone. Tests: a node test of the real estRange (fails before this change), and a Go test pinning that the floor keeps breaks and added tokens at their priced value and can go below zero. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
The go test time limit goes from 20m to 40m on the test and cover targets. On main's CI, the dash package took 1140 s of the 1200 s limit, so PRs that add dash tests (#1001, #1064, #1068) failed build-test with "test timed out after 20m0s". Behavior change: none (CI and local test limits only). Data dependence: none. Follow-up: speed up or split the dash tests. Reviews: 2 offload reviews (GLM), round 1, both approve at 0612436, which is the PR head. Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]>
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 | 3 of 3 | deb710388d4f |
blocking |
Verdict: blocking
Findings
- dash/estrange.test.mjs:1 — the new node test never runs: nothing wires it into
go testor CI- What fails:
deb71038changes what the UI shows (a held estimate whose floor is a cost now shows the range). Its only test for that change isdash/estrange.test.mjs. No Go wrapper runs it, no Makefile target runs it, and no CI step runs it.go test ./dash/...— what CI'sbuild-testruns — never executes the file. A later revert ofestRangetolow > 0passes CI. - Proof: every other
.mjstest indash/has a Go wrapper that runs it undergo test:navhash.test.mjs←dash/navhash_test.go:27,savings.test.mjs←dash/savingsparts_test.go:15,ui_smoke.mjs←dash/ui_smoke_test.go:61. A grep forestrangeover all*.go, the Makefile and.github/finds nothing. The commit message says "a node test of the real estRange (fails before this change)" — true only when run by hand. The PR description still says "The UI text has no test." - Fix: add a wrapper test in
dash/, the same 8 lines asTestSavingsPartsAddUp(look upnode, skip when absent, runnode --test estrange.test.mjs, fail on error).
- What fails:
Non-blocking
- The head does not contain #1082 (
3c876dcb, the 40-minute go-test limit). It landed at 09:38:36Z, two minutes after the head was pushed. The integrator asked at 09:38:57Z to mergeorigin/mainso CI runs with the new limit. CI on this head passed anyway (build-testsuccess at 10:03:58Z), so this is open housekeeping, not a red build: merge main before this PR merges. - The PR description's Tests section says "The UI text has no test".
deb71038added one. The line is stale. estRangestill falls back to the ceiling alone when the floor is exactly 0. On a new row this can happen when a model's cache-read price is 0. The base code did the same, so this is not a regression.
Earlier findings
- Round 1, finding 1 (both reviewers): the floor re-priced the deferral's tokens. Fixed in 803ddfc, still intact at HEAD.
heldFloorUSDskipso.Operator == "context-guru."+DeferComponent(dash/accountant_price.go:481). I re-read the function after the merge: the skip set (DryRun, Call, tooldefer) is unchanged. - Round 1, finding 2 (both reviewers): the subscription Overview showed a dollar estimate. Fixed in 803ddfc, still intact at HEAD. The
sub ? '' :guard is at dash/ui/app.js:1873. - My round-2 non-blocking note (
estRangehid a floor of 0 or below): addressed by deb7103. A negative floor now shows as a range. A floor of exactly 0 still falls back, by design: it is what a row from before the column holds (the column isREAL NOT NULL DEFAULT 0). I traced both call sites: each passesestimated_saved_low_usd || 0, so a missing key also falls back, and each is guarded (estimate_held/estimated_requests > 0). - Reviewer 1's non-blocking note (the Overview floor sum mixes rows from before the column): the author rejected it with "it ages out, and each row falls back to its ceiling". I checked the reason: only the summed low end understates, each request row renders its own fallback, and no booked total changes. I accept it.
What I checked
- Last review: round 2, 803ddfc, 2026-11-11T06:17:49Z
- New commits read: 2 (c88ece1 "Merge main into fix/915-unseen-warm-baseline", deb7103 "fix(dash): Show a held estimate's floor when it is a cost")
- Read in full: 4 reviews, 3 comments, 0 inline comments (from the three files; .review-in-inline.txt is empty)
- New items since my last review, and what I did about each:
- Comment by @amiddavid at 07:25:01Z (CI timeout in the dash package, data-dependence section wanted): checked both points. The author answered at 07:53:42Z; the data-dependence section is now in the PR description and names the column and each storage level. The CI claim I could not rerun (live tests not approved), but
build-teston the final head is green. - Comment by @amiddavid at 09:38:57Z (merge
origin/mainfor #1082's 40-minute limit): checked. The merge c88ece1 predates #1082 by 19 minutes, and the head predates it by 2 minutes, so the request is not yet satisfied. Noted under Non-blocking. - Commit c88ece1 (the merge): read the full diff against both parents. Main brought in 10 already-reviewed PRs; my job was the resolution. Nine files were changed by both sides since the merge base 9d34f00. I verified each keeps both sides:
- dash/store.go (the hand-resolved conflict): counted the requests INSERT by script — 100 static columns, 107 static placeholders, 107 static args (97 in the first list + 7
limitArgs+auth_subscription,sweep_false_expands_warm,restored_tokens), and the order matches (main'srestored_tokensand this branch'sestimated_saved_low_usdeach sit at the same position in columns, placeholders and args). - dash/query.go: aligned
requestColswithscanRequestposition by position, all 100 plus the dynamic token tail:estimated_saved_low_usd→&e.EstimatedSavedLowUSD,restored_tokens→&e.RestoredTokens. - dash/overview.go: the SELECT tail (
restored_tokens,estimate_held,estimated_saved_usd,estimated_saved_low_usd) matches the Scan tail (&restoredTok,&o.EstimatedRequests,&o.EstimatedSavedUSD,&o.EstimatedSavedLowUSD). - dash/schema.go: both columns are in the CREATE TABLE and in
additiveColumns, same definition. - dash/event.go, dash/accountant_price.go, dash/ui/app.js, docs/dashboard.md, docs/data-dependence.md: both sides' changes present; nothing of this branch's was dropped (the dash/ deletions in the merge are main rewriting main's own keepalive and table code).
- Interaction check: main's #1067 adds a
context-guru.expand_restoreop. I read its construction (apply/restore.go:146-170): it is insert-only (SizeBefore0,MessageSplice.Inserted1), so it carries Caused tokens and no Saved tokens.heldFloorUSDre-prices only Saved tokens, so the restore's cost stays at its priced value in both the floor and the ceiling. No defect.
- dash/store.go (the hand-resolved conflict): counted the requests INSERT by script — 100 static columns, 107 static placeholders, 107 static args (97 in the first list + 7
- Commit deb7103: read the full diff and the code around each change.
estRange(low > 0→low !== 0): traced both call sites (app.js:1873 and app.js:3891). Both coerce|| 0and are guarded, solowis never null or undefined. Old rows hold 0 and fall back to the ceiling; a negative floor shows-$x to $y;-0falls back (-0 !== 0is false). Thehigh > lowguard and thelow > deltaclamp inheldFloorUSDkeep the range well-ordered.- The new Go test
TestPriceMode_HeldFloorKeepsBreaksAndAddedTokensAndCanBeACost: traced the arithmetic by hand againstheldFloorUSD. Floor = delta − 4000×(2.5e-6 − 0.2e-6) = 4000×0.2e-6 − 1000×2.5e-6 + brk, with brk = 500×0.2e-6 − 500×2.5e-6. That is −$0.00285, below zero as asserted. The test's expectations match the implementation. - The new
dash/estrange.test.mjs: traced the regex extraction by hand.cut('usd')andcut('estRange')stop at their own closing braces;cut('estUsd')'s lazy first pattern spans throughestRange's closing brace, so the concatenation definesestRangetwice with identical text — the eval is still correct. The assertions pass on the new code and fail on the old (estUsd(0.0075)contains no-$0.0017). Then I looked for what runs it — finding 1.
- Comment by @amiddavid at 07:25:01Z (CI timeout in the dash package, data-dependence section wanted): checked both points. The author answered at 07:53:42Z; the data-dependence section is now in the PR description and names the column and each storage level. The CI claim I could not rerun (live tests not approved), but
- CI on the head deb7103: all checks green (
build-test,purego,build,analyze,trivy,DCO, CodeQL). - No live tests were run (not approved).
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 | 3 of 3 | deb710388d4f |
approve |
Verdict: approve
Findings
None.
Earlier findings
- My finding 1 and reviewer 2's finding 1 (the floor counted the deferral's tokens): fixed in 803ddfc, and still fixed at HEAD after the merge with main.
heldFloorUSDstill skipso.Operator == "context-guru."+DeferComponent(dash/accountant_price.go:481). The merge changed nothing in that function. - My finding 2 and reviewer 2's finding 2 (the subscription Overview showed a dollar estimate): fixed in 803ddfc, and still fixed at HEAD. The
sub ? '' :guard is intact at both display call sites (dash/ui/app.js:1873 and the request row). - Reviewer 2's round-2 non-blocking item (
estRangehid a floor at or below zero): fixed by deb7103.estRangenow shows a negative floor (low !== 0in place oflow > 0). I checked the semantics: an old row (floor exactly 0) still falls back to the ceiling alone; the|| 0guards at both call sites keep null and undefined at 0; a negative floor renders throughusdas "-$x". The range display is this PR's own new feature — base main has noestRange— so no owner permission is needed for the negative case.
Non-blocking
- The head does not contain #1082 (3c876dc, the Makefile's 20m → 40m test timeout). The integrator's last comment (2026-11-11T09:38:57Z) asked for a merge of
origin/mainso CI runs with the new limit. The head predates 3c876dc by about 2 minutes (deb7103 at 09:36:33Z, 3c876dc at 09:38:36Z), so the author could not have merged it. CI is green on this head (build-test passed, 25m16s), but it ran under the old 20m limit, and the same suite failed on a slow runner before. Main now also carries #1087 (df5110d): when a ready PR waits only for a merge of main, the integrator does that merge. So this is the integrator's step now — but the merge of main must happen before this PR merges, or the next slow runner can time build-test out again. dash/estrange.test.mjsand main'sdash/savings.test.mjsrun in no CI workflow (onlyopencode-plugin/test/*.test.mjsdoes). The new test follows the existing precedent, so this is not this PR's defect — but a UI helper with a test CI never runs can rot silently.- In
dash/estrange.test.mjs,cut('estUsd')'s first regex spans pastestUsd's one-line body and capturesestRangetoo (its body closes with}\n, not\n}). Harmless today — the duplicated declaration is identical text — but a helper inserted betweenestUsdandestRangein app.js would be swallowed into the extraction.
What I checked
- Last review: round 2, 803ddfc, 2026-11-11T06:17:41Z
- New commits read: 2 on the branch — c88ece1 "Merge main into fix/915-unseen-warm-baseline" and deb7103 "fix(dash): Show a held estimate's floor when it is a cost". The merge carries 11 main commits (43802c5 and below), each reviewed on its own PR; I read the merge result on every file this PR owns.
- Read in full: 4 reviews, 4 comments, 0 inline comments (from the three files in my folder).
- New items since my last review, and what I did about each:
- Comment by @amiddavid at 07:25:01Z (integrator note: CI timeout, data-dependence section). Checked both points below.
- Comment by @boazdavid at 07:53:42Z (author's reply: slow runner, Overview timings 106-177 ms branch vs 106-151 ms main, description updated). Verified the description and the query alignment myself.
- Comment by @amiddavid at 09:38:57Z (merge origin/main for the 40m limit): checked — the head does not contain 3c876dc; see Non-blocking. CI is green on the head regardless.
- Commit c88ece1: verified the dash/store.go conflict resolution by count — 97 static columns before
limitCols= 97 static args,limitCols(7) =limitArgs(7), thenauth_subscription, sweep_false_expands_warm, restored_tokens= 3 args, plus the N stored-token columns; 107 static?+ N dynamic, all aligned. Counted the merged Overview SELECT against its Scan: 59 top-level terms = 59 destinations (deferNetSumis one parenthesized expression, no extra comma). ConfirmedrequestCols/scanRequestcarryrestored_tokensat the same position, and thatestimated_saved_low_usdsurvived everywhere (schema, INSERT, requestCols, both Overview paths, data-dependence row). Checked main's newexpand_restoreop againstheldFloorUSDandcountedSavedTokens: it saves nothing, so it enters ceiling and floor consistently and adds nothing to the plausibility bound. - Commit deb7103: traced the new Go test by hand through
AccountantFigureandheldFloorUSD— mask op net 4000×2.5e-6 − 1000×2.5e-6, break value 500×0.2e-6 − 500×2.5e-6, ceiling 0.00635, floor −0.00285; both match the test's formulas and the floor is below zero as asserted. Verified the test passes theaccOverridegates (unpriced reason is penalty_unknown, counted tokens 4000 ≤ 20000, mask row exists). Traced the node test's regex extraction against the real app.js and both assertions (-$0.0017 to $0.0075;$0.0008 to $0.01); the oldlow > 0gate fails the first assertion, so the "fails before this change" claim holds. - PR description: read in full. The Data dependence section the integrator asked for is present and correct (metadata only, one dollar number, no text).
- CI on the head: build-test, purego, record, build, analyze, CodeQL, DCO all pass (checked via
gh pr checks). This also confirms the merge compiles and the golden files agree with the merged code. - Live tests were not approved, so I ran nothing myself.
|
Integrator note on GLM round 3 at deb7103: reviewer 1 approves, reviewer 2 blocks on one small point.
After the fix, round 4 (pre-approved by the owner) runs on the new head. The owner still has to decide what to book for these rows. |
Signed-off-by: DAVID AMID <[email protected]>
estrange.test.mjs had no Go wrapper, so no CI step ran it. A revert of estRange would have passed CI. The wrapper has the same shape as TestSavingsPartsAddUp: it skips when node is absent, else it runs the node test. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
|
Fixed the finding that
Assisted-By: Claude Opus 5.5 |
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 | 4 of 4 | 4f652fdb31a0 |
approve |
Verdict: approve
Findings
None.
Earlier findings
- Round 3, my finding 1 (
dash/estrange.test.mjsnever ran in CI): fixed in 4f652fd.TestEstRangeShowsANegativeFloor(dash/savingsparts_test.go:185) has the exact shape I proposed and the same shape asTestSavingsPartsAddUp: it looks upnode, skips when absent, runsnode --test estrange.test.mjs, fails on error.os/execis already imported in the file. The node test readsapp.jsthroughimport.meta.url, so the working directory of thego testbinary does not matter. A revert ofestRangetolow > 0now failsgo test ./dash. The author's mutation check (old gate: 1 fail; new code: 2 pass) matches my own hand trace from round 3. - Round 1, both findings (the floor re-priced the deferral; the subscription Overview showed a dollar estimate): fixed in 803ddfc, still intact at HEAD. The
heldFloorUSDskip (dash/accountant_price.go:481) and thesub ? '' :guard (dash/ui/app.js:1874) are unchanged after the second merge of main. - My round-2 non-blocking note (
estRangehid a floor at or below zero): addressed by deb7103, unchanged at HEAD (low !== 0, both call sites coerce|| 0). - Round-3 non-blocking (the head lacked #1082): resolved. The merge 33d1353 brings
3c876dcbin; the Makefile test and cover targets now say-timeout 40m. - Round-3 non-blocking (the PR text said "The UI text has no test"): fixed. The Tests section now says the range logic has a test that CI runs through a Go wrapper, and only the text around it has none. Accurate.
Non-blocking
- At review time,
build-testandpuregowere still running on the head; DCO, build, trivy, analyze and CodeQL are green. The change since the last green head is a 12-line test wrapper plus a byte-clean merge of main, so I expect them to pass, but the run was not finished when I posted. - Reviewer 1's round-3 note on
cut('estUsd')'s regex spanning intoestRange: I agree it is harmless today (I traced the same duplication in round 3; the extracted text definesestRangetwice, identically). A helper inserted between the two in app.js would be swallowed; a later PR can tighten the regex.
What I checked
- Last review: round 3, deb7103, 2026-11-11T13:24:32Z
- New commits read: 2 on the branch (33d1353 "Merge origin/main into fix/915-unseen-warm-baseline", 4f652fd "test(dash): run estrange.test.mjs in CI (#1001)"). The merge carries 8 main commits (3c876dc #1082, e86d897 #1073, df5110d #1087, b125d4b #334, d501cdb #1064, 9dda47d #1068, f123d52 #1083, 202087d #1074), each already reviewed and merged on main.
- Read in full: 6 reviews, 5 comments, 0 inline comments (from the three files; .review-in-inline.txt is empty)
- New items since my last review, and what I did about each:
- Review by reviewer 1 at 13:26:39Z (round 3, approve): read in full. No findings; its non-blocking notes are answered above.
- Comment by @amiddavid at 13:27:30Z (integrator relay of round 3; round 4 pre-approved by the owner): the fix it asks for is the wrapper, done.
- Comment by the author at 18:09:15Z (fix note with a mutation check): each claim checked against the code — wrapper present, main merged, PR text corrected. All accurate.
- Commit 33d1353 (the merge): verified clean by tree identity.
git merge-tree --write-tree deb71038 202087dereturns tree018b3319…, and33d1353c^{tree}is the same tree, so the merge is the automatic result with no hand resolution and nothing of either side dropped. - Commit 4f652fd: read the full diff; it is the wrapper only.
- Re-verified the branch's plumbing at HEAD after main's #1064 touched the same dash files:
- dash/store.go requests INSERT: recounted by script — 100 static columns, 107 static placeholders, 97 args in the first list + 7
limitArgs+auth_subscription,sweep_false_expands_warm,restored_tokens, order matched. - dash/query.go:
requestColsandscanRequestare byte-identical to the blocks I aligned in round 3 (estimated_saved_low_usd→&e.EstimatedSavedLowUSD;restored_tokens→&e.RestoredTokens). - dash/overview.go: the SELECT tail and Scan tail still end
estimated_saved_low_usd→&o.EstimatedSavedLowUSD; overview_lean.go unchanged. - dash/schema.go:
estimated_saved_low_usdis in the CREATE TABLE andadditiveColumns. - dash/ui/app.js after main's #1068:
usd(97),estUsd(106),estRange(112) sit unchanged, so the node test's regex extraction still cuts the right functions; both call sites keep|| 0and thesubguard.
- dash/store.go requests INSERT: recounted by script — 100 static columns, 107 static placeholders, 97 args in the first list + 7
- Checked the one interaction the previous green CI had not seen: main's #1073 moved the accountant onto a background goroutine and landed after the last green run on this branch. At HEAD,
finishcallsc.accWait()(proxy/dashcapture.go:824) beforeSetAccountant(844) andPriceMode(857), so the floor is still computed from the complete accountant result.heldFloorUSDreads onlye.accRes, whichSetAccountantfills first. heldFloorUSD's deferral skip re-read at HEAD: unchanged.- CI on the head: DCO, build, trivy, analyze, CodeQL green; build-test and purego in flight at posting time.
- No live tests were run (not approved).
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 | 4 of 4 | 4f652fdb31a0 |
approve |
Verdict: approve
Findings
None.
Earlier findings
- Reviewer 2's round-3 finding 1 (
dash/estrange.test.mjsnever ran in CI): fixed by 4f652fd.TestEstRangeShowsANegativeFloor(dash/savingsparts_test.go:185) has exactly the shape the integrator asked for and the same shape asTestSavingsPartsAddUp:exec.LookPath("node"), skip with a hint when absent, elsenode --test estrange.test.mjs, fail on error.go testruns a package from its own directory, so the bare filename resolves; the.mjsreadsui/app.jsthroughimport.meta.url, not the working directory, so the run does not depend on where it starts. A revert ofestRangetolow > 0now failsgo test ./dash. - My round-3 non-blocking item (the head lacked #1082, the 40-minute test limit): fixed by the merge 33d1353.
3c876dcbis an ancestor of HEAD, and the Makefile at HEAD passes-timeout 40mon both thetestandcovertargets. - Reviewer 2's round-3 non-blocking item (the PR text still said "The UI text has no test"): fixed. The description's Tests section now says the range logic has a test that CI runs through a Go wrapper, and only the UI text around it has none.
- Round-1 findings 1 and 2 (the deferral's tokens in the floor; the lost
subguard): still fixed at HEAD after the second merge of main.heldFloorUSDstill skipscontext-guru.tooldefer(dash/accountant_price.go:481), and thesub ? '' :guard is intact at dash/ui/app.js:1874. - My round-3 non-blocking note on
cut('estUsd')'s regex spanning intoestRange: left as is, harmless (the duplicated declaration is identical text). Main's #1068 did not touch theusd/estUsd/estRangeregion, so the extraction works unchanged.
Non-blocking
- CI on this head was still running when I posted.
build,analyze,purego,trivy,DCOand CodeQL pass;build-testandrecordwere pending.puregodoes not run./dash, so the new wrapper has no green CI run yet —build-testis the job that exercises it. Nothing in my reading suggests it will fail: the wrapper copies a pattern that passes in CI on main, and the.mjsitself passed my round-3 hand trace against the sameapp.jstext. - The owner's booking decision for held rows (book nothing, the floor, or the midpoint) is still open per the integrator. The PR books nothing, which is the reviewer-backed recommendation. Not a code matter.
What I checked
- Last review: round 3, deb7103, 2026-11-11T13:26:39Z
- New commits read: 2 on the branch — 33d1353 "Merge origin/main into fix/915-unseen-warm-baseline" and 4f652fd "test(dash): run estrange.test.mjs in CI (#1001)". The merge carries 8 main commits (#1082, #1073, #1087, #334, #1064, #1068, #1083, #1074), each reviewed on its own PR; I read the merge result on every file this PR owns.
- Read in full: 6 reviews, 6 comments, 0 inline comments (from the three files in my folder).
- New items since my last review, and what I did about each:
- Review by reviewer 2 at 13:24:32Z (round 3, blocking on the estrange test never running in CI): read in full. The finding matched my round-3 non-blocking item, raised with stronger proof (the other
.mjstests all have Go wrappers). Checked the fix myself — see Earlier findings 1. - Comment by @amiddavid at 13:27:30Z (integrator note relaying that finding, plus the stale PR-text line): both requests done — wrapper added, PR text corrected (verified in the current description).
- Comment by @boazdavid at 18:09:15Z (the author's fix note): each claim checked — the wrapper exists as described, the mutation claim matches my round-3 trace (the old
low > 0gate fails the first assertion), the merge is in the history, the PR text is corrected. - Commit 33d1353 (the merge, clean, no hand resolution): verified it disturbs nothing of this branch's.
dash/accountant_price.go,dash/accountant_switch_test.go,dash/estrange.test.mjs,dash/event.goanddash/overview_lean.goare byte-identical to deb7103.dash/store.gochanges only inDropOldestSessions(main's #1064); I re-counted the requests INSERT at HEAD — 97 static columns beforelimitCols= 97 static args (a script's 98 was a trailing comma after the last arg), 7limitCols= 7limitArgs, 3 columns after = 3 args, 107 static?+ N dynamic, all aligned. Re-counted the merged Overview SELECT against its Scan: 59 top-level terms = 59 destinations (deferNetSumstill one parenthesized expression). AlignedrequestColswithscanRequestposition by position, includingestimated_saved_low_usd→&e.EstimatedSavedLowUSDandrestored_tokens→&e.RestoredTokens.docs/dashboard.mdkeeps both sides: this branch's floor paragraph (lines 179-180) and main's #1068 sections.dash/ui/app.js: theusd/estUsd/estRangeregion is unchanged, so the node test's regex extraction still works. - Commit 4f652fd (the wrapper): read the diff and the file around it. Compared it line by line with
TestSavingsPartsAddUp; same imports (os/execalready in the file), same skip, same run. The commit touches nothing else.
- Review by reviewer 2 at 13:24:32Z (round 3, blocking on the estrange test never running in CI): read in full. The finding matched my round-3 non-blocking item, raised with stronger proof (the other
- PR description: re-read in full. The Tests correction is in; the Data dependence section is unchanged from round 3.
- CI on the head at posting time:
build,analyze,purego,trivy,DCO, CodeQL pass;build-testandrecordpending (see Non-blocking). - Live tests were not approved, so I ran nothing myself.
…aseline Move the data-dependence row change for estimated_saved_low_usd into docs/data-dependence/features/dashboard-database.md. The generated page docs/data-dependence.md comes from go run ./cmd/gen-datadep. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Refs #915. This does not close it: the exact price is still unknown.
Problem
The first request on a warm provider cache that the proxy has never seen (restart with missing state, or a session begun before the proxy) is priced as if every removed token was a cold write. The response usage does not give the size of the unseen warm prefix, so the saving cannot be computed exactly. On main (#930) the row is held out of every total and books 0, where the hand figure in the issue is about $0.0216.
Change
requests.estimated_saved_low_usd: a floor. It prices each removed token at the cache-read rate, because a client token never costs less than a read. The true saving lies between this floor andestimated_saved_usd.TestPriceMode_HeldEstimateIsBoundedByReadAndWriteandTestOverviewSumsTheHeldFloor.docs/dashboard.md.Not in this PR
Decision for the owner
Whether to book anything for these rows: the floor, the midpoint, or a prefix size from
--restart-graceor the observedcache_read. Booking a number changes totals, so it needs a human yes. Recommendation: keep $0 in the totals and show the range.Data dependence
requests.estimated_saved_low_usd. It is computed from the count of tokens removed and the model's cache-read price, because the held estimate needs a floor beside its ceiling. It reads no text.docs/data-dependence.mdnames the new column in the Dashboard database row.What it does at each level (see docs/data-dependence.md):
Tests
go test ./dash ./proxy -count=1passes.go vetandgofmt -lare clean.estRange) has a test,dash/estrange.test.mjs, which CI runs through a Go wrapper. The UI text around it has no test.node --check dash/ui/app.jspasses. I did not look at the page in a browser.run_m5.pywas not on disk. The floor was not checked against a real warm-prefix session.Assisted-By: Claude (Anthropic AI) [email protected]