Repository navigation
feat(pricing): price each known request at the tier of its prompt size - #1407
Conversation
Step 2 of prompt-size price tiers (refs #1343). Callers that price a request with a known prompt size now use Price.At(PromptTokens(...)). - dispatcher price adapter passes promptTokens through (keep-alive per-ping guard, summary and sweep projections) - Event cost_usd, keep-alive ping and substitute cost - accountant savings: removed tokens at the size without context-guru, added tokens at the size with it - tool deferral ledger, campaign replay, cache state, keep-alive views, miss cost metric - docs/dashboard.md describes the tier rule Behavior change: long requests of GPT-5.4+ (over 272K) and Haiku 5.5 (over 100K) now show 2x or 5x cost. flat: true turns it off per entry. Assisted-By: Claude Opus 5.5 <[email protected]> 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 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 9f5eea7073e8 |
approve |
Verdict: approve
Findings
None. I could not prove a wrong behavior, a data loss, or a broken fail-open path.
Non-blocking
- Ping projections price the prefix alone, not the prompt the ping sends. A ping carries 1 fresh input token beyond the prefix (
kvcache.DefaultPingInputTokens). So a prefix exactly at a tier line (272,000 for GPT-5.4+, 100,000 for Haiku 5.5) bills one tier up, whileprojectedPingUSD,dash/keepalive.go(live view, calculator) andNextRequestUSDprice it at base. The window is one token wide, and recorded costs (billedPrompt,priceCost) use the real usage, so only the guard and the views can under-price at that exact size. Same shape intooldefer/ledger.go:144:int64(billed(...))truncates the without-size by a fraction of a token. - The
cg_*savings counters andPriceCGstay at base rates. The dashboard's savings and the metrics module's counters can now disagree for a tiered model. The PR names both in Open questions 1, so this is tracked, not missed. accPrices's size without context-guru is an estimate (billed size + saved − caused of the counted ops). The PR says so in Open question 4. The estimate only picks a rate tier, so a small size error changes nothing unless it crosses a line.- The replay prices a row's pings at the row's own prompt size (
campaign/replay.go:188). A replayed ping readsCachedContext, which can sit below the line while the row's prompt sits above. The replay engine is calibrated in its own units, so I rate this an approximation, not a defect.
What I checked
- The full diff
b8f4d92b..HEAD, and the code around every hunk:dash/accountant_price.go,dash/event.go,dash/cachestate.go,dash/keepalive.go,keepalive/keeper.go,keepalive/substitute.go,proxy/keepalive.go,proxy/keepalivectl.go,proxy/campaignauto.go,proxy/adaptcache.go,proxy/inferencemetrics.go,proxy/tooldefer.go,tooldefer/flow.go,tooldefer/ledger.go,campaign/replay.go. - The base commit's
modelinforules this PR builds on:Price.At,PromptTokens,WithTiers,BuiltinTier,tierRate, and the orderResolvedbeforeWithTiersat every price source (table.go:345,litellm.go:223). EveryPricerreturns resolved, tiered rates, soAtalways multiplies filled base rates. - The per-side pricing in
AccountantFigureandheldFloorUSD: Saved tokens at the size without, Caused at the size with; cache effects priced per side instead of onNet()(needed, because the two sides can carry different rates); spend and DryRun ops excluded from both the dollars and the without-size; nilaccRes, missing usage and flat prices all fall back to base, exactly as before. - That flat-priced models keep their old numbers:
Aton a price with no tiers returns the same rates;accPricesreturns base for both sides when!p.HasTiers(). So the behavior change touches only tiered models, as the PR claims. - Every
k.pricecall site inkeepalive(projected ping, summary, sweep, refresh,pingCost, substitute,sweepAnswerUSD): each passes either the billed usage size or the planned prefix. Fail-open paths (no model, no rate, zero price) unchanged. - The dispatcher adapter contract (
dispatch/dispatch.go:90) and the test fake now matching it; no other host in this repo setsdispatch.price. priceCost's localp = p.At(...): the caller'spis untouched, soPriceMode→accOverride→heldFloorUSDstill receive the tiered price;CacheReadFallbackandUnitsurviveAt.tooldefer.Price: gross at the size without the deferral (prompt + deferred − list, tokenizer factor applied), cost and search at the size sent; unknown size prices both sides at base.- The new tests' arithmetic, line by line (272,000 at the line is base, 272,001 is 2x/1.5x; Haiku 100,000/100,001 at 5x; both sides of a saving; unknown size). Test helpers (
accNear,testKeeper,setPrices,fixedPrice,pingOutputBudget,SetAccountant) all exist with matching signatures. - The PR body: the behavior change is named at the top (who, old, new, how to turn it off), data dependence is stated as metadata only, and every call site I found in the sweep of
dash/proxypricing paths appears in its decision table (including the ones left at base:readvalue,cachehistory,insightsapi/ToolReportFor, metricsink,PriceCG). - Commit message: DCO sign-off and
Assisted-Bypresent.
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.332 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 9f5eea7073e8 |
approve |
Verdict: approve
Findings
None. I found no wrong behavior, no data loss, no broken fail-open path and no security problem.
Non-blocking
- keepalive/fake_test.go:158 — stale comment. The
proxyPricercomment still says the adapter ignores "the endpoint and the prompt size". The newPriceapplies the prompt size. Fix the comment to say "the endpoint" only. - dash/accountant_price.go:22-24 — the comment overstates one case. It says a cache effect "only moves tokens between tiers, so it does not change the size". A mark effect (
markPremium) adds the host's mark tokens to the request sent. Those tokens are in the billed sizewbut not in the client sizen, sonover-counts the client size by the mark's tokens. The effect is a few dozen tokens and the direction is conservative (the client size reads larger, its tier can only rise). No fix needed; say "except the mark" in the comment. - dash/toolsuggest.go:230 — decl-filter savings stay at base rates. The query has each row's
cache_read,cache_writeandcache_write_1h; onlyfresh_inputis missing. The PR body's reason ("no per-request size is in the query") is partly wrong: a partial size is there. On a tiered model this figure under-states by up to 5x. Documented as a base-rate figure in the PR table, so this is a note, not a defect. - Two new tiered paths have no test.
heldFloorUSD's per-side price (dash/accountant_price.go:522) andmissCostUSD's tier (proxy/inferencemetrics.go:262) are new behavior. The PR's own mutation list covers neither. Low risk: both reuseaccPrices/At, which are tested. - Host-package placement.
accPricesis savings math and lives indash, a host package. CLAUDE.md says cost and savings math is business logic and a PR that adds logic to a host package states why it cannot live in a library package. The PR table does not say. I accept it because the wholeAccountantFiguredomain already lives there and the function readsEventfields plusaccountant.Result; moving it is a wider refactor than this PR. - Process, not code. The behavior change is named at the top of the PR and says "the owner decides before merge". Do not merge before the owner's yes on the
MaxUSDPerPingrefusal above the line.
What I checked
- Read the full diff (
git diff b8f4d92b..HEAD), one commit, and the code around every hunk:dash/accountant_price.go,dash/event.go,dash/cachestate.go,dash/keepalive.go,keepalive/keeper.go,keepalive/substitute.go,tooldefer/flow.go,tooldefer/ledger.go,proxy/keepalive.go,proxy/keepalivectl.go,proxy/campaignauto.go,proxy/adaptcache.go,proxy/inferencemetrics.go,proxy/tooldefer.go,campaign/replay.go. - Read the base machinery from #1343:
internal/modelinfo/pricetier.go(At,PromptTokens,WithTiers, built-in tiers),modelinfo.go(Resolved,Cost,CacheWrite1h),table.goandlitellm.go(both resolve a price beforeWithTiers, soAtsees stated rates). - Traced each side of the savings model.
accPricesbuilds the client size as billed size plusSavedminusCausedof the counted ops. Cache effects keep the size (a break, rescue, split or TTL move moves tokens between tiers; only the mark adds size — noted above).Savedprices at the client tier,Causedat the sent tier. This matches the whole-request tier rule the providers state, andBaselineCostUSD = CostUSD + DeltaUSDholds by construction. - Checked
priceCost: the reassignmentp = p.At(...)is local to the function;PriceModestill passes the tiered price toaccOverride, which re-derives per side.CacheReadFallbacksurvivesAt, soFallbackRateCostUSDstays consistent. - Checked loop scoping in
dash/keepalive.go: bothp = p.At(...)sites use a fresh per-row or per-call variable, so no row prices at another row's tier.KeepAliveCalcreassigns after its last use of the base price. - Checked the keeper:
billedPromptprefers the billed usage and falls back to the planned prefix. The projected guards (projectedPingUSD, summary, sweep, refresh) use the prefix, which is the ping's prompt size. Projection and actual cost now use the same tier, so theMaxUSDPerPingguard is consistent before and after the ping. - Checked the tooldefer ledger: gross at the client size (sent size plus deferred minus list, both scaled by the billed factor), cost at the sent size, unknown size at base. The one production caller (
proxy/tooldefer.go:413) passesFreshInput;proxy.Usagehas the field. - Checked the signature change of the price callback (
func(string, int64)): all production callers updated (campaign.Rows,rowsWith,autoRowsFor,adaptReport, tests). The dispatcher adapter inproxy/keepalive.gois the only setter ofdispatch.price; no other host implements it. - Checked the left-at-base callers the PR names (
PriceCG, lifecycle rates, read-time legacy passes, metrics module,toolsuggest): they read base fields of a tiered price, which is the unchanged behavior, and the docs list them. - Checked the docs against the code: tier lines (272,000 at 2x/1.5x; 100,000 at 5x),
flat: true, the feed winning over built-in tiers, and the base-rate totals list all matchpricetier.go,table.goand the call sites. - Checked the new tests' arithmetic by hand (at the line is base, one token above is the tier, per-side pricing, unknown size,
NextRequestUSD); the expected values matchAt's strict>comparison. Test helpers (accNear,near,testKeeper,SetAccountant,pingOutputBudget) exist, and no package gets a duplicate helper name. - Did not run builds or tests: live tests are not approved for this review.
Review round 1 of #1407. - price a projected ping and the replay ping at prefix + ping input - round the tool deferral size without the deferral up - test heldFloorUSD, missCostUSD and the replay ping - fix two comments Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Replies to round 1 (both reviewers)Both reviewers approved. Commit Reviewer 2
Reviewer 1
Not changed: the refresh-saving projection still prices the bare prefix. It is the rewrite that a ping saves, and that rewrite has the prefix's size. Tests (macOS, Go 1.27.4):
|
Owner decisions (David Amid, 2026-11-25)
|
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.332 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | b13e68329213 |
approve |
Verdict: approve
Findings
None. The new commit fixes the round-1 notes correctly, and I found no new wrong behavior.
Round-1 findings: status
Mine (all were non-blocking):
- Ping projections priced the prefix alone. Fixed.
pingPrompt(keeper.go:2082) addskvcache.DefaultPingInputTokens;projectedPingUSD,projectedSummaryUSD,projectedSweepBatchesUSD, thedash/keepalive.golive view and calculator,keepalivectlandNextRequestUSDall use it. New boundary tests check a prefix of exactly 272,000 (keepalive,NextRequestUSD). - The ledger truncated the without-size. Fixed.
math.Ceilon the net (ledger.go:147); a negative net rounds to 0, still the dearer side. The Haiku test crosses 99,999 → 100,001;BilledDeltaFactorfor the haiku family is 1.3686 (billedfactor.go:63), soceil(1.3686) = 2holds. - The replay priced pings at the row's size. Fixed. A second lookup at
CachedContext + 1(replay.go:193), after the row filter, with a fallback to the row's rates when the lookup fails. The test's arithmetic matchesPingCost = prefix*PRead + 7*PIn + 1*POut(pingFresh = 7, predictive/features.go:24). cg_*counters,PriceCG, the estimated without-size. Unchanged, kept as the owner's open questions 1 and 4. Accepted.
Reviewer 1's (all were non-blocking; I checked each myself):
- Stale
proxyPricercomment. Fixed; it now names the endpoint only. accPricescomment and the mark effect. Fixed as asked: the comment names themarkPremiumexception. See Non-blocking for the direction claim.toolsuggeststays at base. Kept, with the PR table corrected. I verified:declFilterSavingsQuery(toolsuggest.go:218) selectscache_read,cache_write,cache_write_1hbut nofresh_input. Without fresh input the size is understated, so a tier picked from it could read too cheap. Base is the safe choice. Accept.- No test for
heldFloorUSDandmissCostUSD. Fixed.TestHeldFloorUsesTheSavedSidePrice: ceiling 50,000 at 10e-6, floor 50,000 at the 2x read rate 1e-6 — matchesheldFloorUSDwithpbfromaccPrices.TestMissCostUsesTheTierOfThePrompt: 300,000 above the line at (10e-6 − 1e-6), 272,000 at the line at (5e-6 − 0.5e-6) — matchesAt's strict>. accPriceslives indash. The Technical notes now state the reason (theAccountantFiguredomain lives there) and propose a move as a follow-up. Accept, as I did in round 1.- The owner's yes before merge. Still stands. The behavior-change block at the top of the PR is unchanged in substance.
The author's one rejection-with-reason: expectedRefreshSavingUSD still prices the bare prefix (keeper.go:1323). The reason is right: the figure prices the rewrite a ping saves, that rewrite has at least the prefix's size, and the function is a deliberate lower bound (issue #415), so a cheaper tier can only under-state a saving. Accept.
Non-blocking
- The summary and sweep projections price the tier at
prefix + 1, but the real call's prompt is larger. A substitute summary is built from the forwarded body and carries the summarizer's own instruction; a sweep question carries its question text. Whenprefix + 1sits below a line and the real prompt crosses it, the guard under-projects by the tier multiple on the read dollars. This is the same estimate class as the 2000-token output guess (summaryOutputBudgetGuess, "unmeasured"), the window is the instruction's size, and the recorded cost uses the real usage. Not a defect; worth a line in the PR's Technical notes if the author wants it exact. - The new
accPricescomment asserts a direction I could not prove. It says the without-size "errs low" and so is conservative; reviewer 1's round-1 derivation said the opposite (nover-counts by the mark's tokens). From this repo alone I cannot settle which holds — it depends on the accountant library's mark-effect semantics. No code depends on the claim: the size adjustment is the same either way, and the error is a few dozen tokens at a tier line. Suggest the author cites the accountant semantics for the direction, or restores the old "moves tokens between tiers" wording, in a later docs pass.
What I checked
- Last review: round 1, 9f5eea7, 2026-11-25T14:19:49Z.
- New commits read: 1 —
b13e6832"fix(pricing): price a ping at its own size, round up, test more sites". - Read in full: 2 reviews, 1 issue comment, 0 inline comments (from the three saved files), plus the current PR body (the author edited it; body edits appear in no comment list).
- New items since my last review, and what I did: reviewer 1's round-1 review (checked each of its six notes against the code myself); the author's reply comment (verified every fixed/kept claim against the diff); the new commit (full diff plus the code around each hunk); the PR body edits (the corrected
toolsuggestrow and the new Technical notes). - The new commit's code:
pingPromptand its three call sites; the+DefaultPingInputTokenstier shift indash/cachestate.go, bothdash/keepalive.gosites andproxy/keepalivectl.go(rate selection only — the dollar formulas still price the prefix and one output token, the pre-PR shape); the replay's second price lookup (placed after the row filter, so dropped rows cost no extra lookup; thepingOKfallback is dead in practice but harmless);math.Ceilon the deferral without-size. - The new tests' arithmetic by hand: the replay ping (272,001 above the line,
272,000*2 + 7*2 + 2), the held floor, the miss cost, the Haiku round-up (factor 1.3686,ceilgives 100,001), and the two updated boundary tests (271,999 base, 272,000 tier). Constants verified at their sources:pingFresh = 7,DefaultPingInputTokens = 1,BilledDeltaFactor(haiku) = 1.3686. - That nothing else moved:
git diff 9f5eea70..HEADtouches only the files listed above;AccountantFigure,accPriceslogic,priceCost, the dispatcher adapter and the tooldefer cost side are unchanged from the head I approved in round 1. - Commit message: DCO sign-off and
Assisted-Bypresent. Tests were not run: live tests are not approved for this review; the author reports them green with five new mutations.
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.332 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | b13e68329213 |
approve |
Verdict: approve
Findings
None. The fixes behave as the reply claims. I verified each one by hand. My round-1 note that started the accPrices comment change was itself wrong; see Non-blocking 1.
Non-blocking
- dash/accountant_price.go:23-26 — the new comment states a direction that does not follow, and the PR Technical note repeats it. The comment says the mark effect's tokens are "already in the billed size" and that "not counting them leaves the size without a little low, so the without side is never priced dearer than it should be". Two facts contradict it:
markPremiummoves the tail content between tiers: our request writes it, the client's request bills it as input. The same content is in both bodies. The size does not change. The round-1 wording ("a cache effect only moves tokens between tiers") was right for the mark too.- The marker's own bytes (the only real asymmetry) are counted:
apply/ops.gotailOpreports the tail mark as a rewrite of the last message (SizeAfter>SizeBefore), the library prices that growth as the op'sCaused, andaccPricessubtracts every counted op'sCausedfrom the size without. So the size without is exact for the marker.
My round-1 note claimed the marker bytes were never subtracted. That was wrong, and the new comment inherits the error with the direction flipped. Fix: drop the exception and restore "a cache effect only moves tokens between tiers, so it does not change the size". Also fix the PR Technical note ("the size without errs low. That is the conservative direction"). Comment only; the code is unchanged and right.
- keepalive/keeper.go:2083 —
pingPromptadds 1 token; the measured law is about 7.kvcache.DefaultPingInputTokensis 1, butpredictivepingFreshis 7 ("the measured law of a keep-alive's own cost"), and a ping resends the caller's body, so the real fresh input is the last turn's, not 1. The tier picked for a projection can sit one tier low when the true prompt crosses a line. The projections already omit the fresh-input cost altogether (pre-existing), so this is second-order. The new campaign test shows both constants side by side (+1for the tier, 7 inPingCost). Consider one constant for the ping's own input. - dash/toolsuggest.go — the corrected PR reason overstates. The table now says the query has no
fresh_input, so "a partial size cannot pick a tier safely". Therequeststable hasfresh_input(dash/cachestate.go:422 reads it); adding one column to the query would give the exact size. Keeping the figure at base rates is a fair scope decision, but the reason should say "not done here", not "cannot".
What I checked
- Last review: round 1,
9f5eea7073e8, 2026-11-25T14:23:39Z. - New commits read: 1 —
b13e6832"fix(pricing): price a ping at its own size, round up, test more sites". - Read in full: 2 reviews, 1 comment, 0 inline comments (the inline file is empty), from the three saved files.
- New items since my last review: reviewer 2's round-1 review (4 notes, all dispositioned below), the author's reply comment, commit
b13e6832(full diff plus the code around each hunk).
Earlier findings, disposition:
- Mine 1, stale
proxyPricercomment. Fixed: "the endpoint" only. - Mine 2,
accPricescomment. Rewritten, but the new direction claim is wrong. See Non-blocking 1. My round-1 note was the error's source. - Mine 3, toolsuggest at base rates. Rejected with a reason. The reason overstates ("cannot"); the figure's staying at base is acceptable. See Non-blocking 3.
- Mine 4, no tests for
heldFloorUSDandmissCostUSD. Fixed. I checked both tests' arithmetic: the floor re-prices 50,000 saved input at the dear tier's read rate (10e-6 → 1e-6); the miss cost prices 300,000 written tokens at the 2x write-read premium and 272,000 at the base premium. - Mine 5, placement of
accPricesindash. Addressed: the PR Technical notes now give the reason and propose a move as a follow-up. - Mine 6, the owner's yes. Still pending. The PR's behavior-change block still says "the owner decides before merge". Do not merge before it.
- Reviewer 2, ping projections at the bare prefix. Agree, and fixed:
pingPrompt(prefix + ping input) now feedsprojectedPingUSD,projectedSummaryUSD,projectedSweepBatchesUSD;NextRequestUSD, thedashlive view and calculator, andkeepalivectladd the same token. I checked everyk.priceandp.Atcall site again; onlyexpectedRefreshSavingUSDkeeps the bare prefix, and the author's reason holds (the rewrite it prices has at least the prefix's size; under-stating the saving makes the refresh fire less, the cheap direction). - Reviewer 2, ledger truncation. Agree, and fixed:
math.Ceilon the deferred-minus-list difference. The new test crosses 99,999 → 100,001 on Haiku with the 1.3686 billed factor; the arithmetic is right. - Reviewer 2, replay ping at the row's size. Agree, and fixed: the ping prices at
CachedContext + ping inputwith a fail-open fallback to the row's rates when the lookup fails; the stake keeps the row's rates, a fair proxy. - Reviewer 2,
cg_*counters andPriceCGat base rates. Agree: tracked as the PR's open questions.
The new commit, checked hunk by hunk:
campaign/replay.go: the extra price lookup per row is memoized behindautoPrice; the fallback on!pingOKfails open. The test's numbers check out (row at 271,010 → base; ping at 272,001 → dear;PingCost= 272,000×2 + 7×2 + 2).dash/cachestate.go,dash/keepalive.go,proxy/keepalivectl.go: only the tier lookup adds the ping input; the dollar formulas still multiply the bare prefix, so no figure double-counts the extra token.NextRequestUSD's two callers (manual ping, cachestate) describe a ping-shaped next request, which matches.keepalive/keeper.go:pingPromptis applied at all three projection sites;pingCost, the substitute andsweepAnswerUSDstill price by the billed usage (billedPrompt), which is the measured size.tooldefer/ledger.go:Ceilof the difference, not of each term; a negative difference still rounds toward zero, as before.- Test hygiene: imports added (
math,kvcache,dash) are used; no duplicate helper names in any package;tokens.BilledDeltaFactorreturns 1.3686 for the Haiku family, as the new test assumes. - Docs: no doc change was needed for the +1;
docs/dashboard.md's rule ("the tier of the request they describe") still matches the code.
Did not run builds or tests: live tests are not approved for this review.
A cache effect, the mark included, only moves tokens between tiers. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Round 2 notes
The approvals at Local tests: waived (owner rule) |
…rice line The saving is the bill without context-guru minus the bill as sent, each at its own prompt size. The tokens that stay, and all output, change rate when the two sizes sit on different sides of a line. That re-rate is split over the components in proportion to their net saved tokens. With no such component it books to the ended-change figure. Owner decision, 2026-11-25. Same rule as accountant#112. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
The tokens that stay exclude the Caused tokens of each cache effect that AccountantFigure books. A break the client body has too is booked nowhere, so its tokens stay. Found in review of accountant#112. Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
New since round 2: the owner's decision on savingsOwner decision (David Amid, 2026-11-25): the dashboard savings count the full bill difference. The saving is the bill without context-guru minus the bill as sent, each priced at its own prompt size. This matches rossoctl/accountant#112. The owner granted round 3 for this change.
Tests (macOS, Go 1.27.4):
Local tests: waived (owner rule) |
Assisted-By: Claude Opus 5.5 <[email protected]> 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 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 3 of 3 | c540077e060e |
approve |
Verdict: approve
Findings
None. The re-rate is a real behavior change with the owner's decision recorded, and I could not break its arithmetic.
Round-2 notes: status
Mine:
- Summary and sweep projections price the tier at
prefix + 1. Kept as an estimate, now recorded in the PR Technical notes ("the same estimate class assummaryOutputBudgetGuess", follow-up). Accept. - The
accPricescomment asserted a direction I could not prove. Fixed ind8963449: the comment says again "a cache effect only moves tokens between tiers". Reviewer 1 supplied the proof I lacked: the marker's own bytes are a rewrite op (apply/ops.go:286tailOp,SizeAfter>SizeBefore), priced as the op'sCaused, whichaccPricessubtracts. I spot-checkedtailOp; the claim holds. Resolved.
Reviewer 1's round-2 notes (checked myself):
accPricescomment direction. Fixed ind8963449, as above.pingPromptadds 1, the measured law is 7. Kept as a follow-up, recorded in the Technical notes. Accept: the+1fixes the tier line for the minimal ping shape;pingFresh = 7is the measured average insidePingCost; one shared constant is a fair later cleanup.toolsuggestreason overstated. The PR table now says "Not done here" and the Technical notes name the follow-up (therequeststable hasfresh_input,dash/cachestate.go:422). Accept.
The new commits
d8963449— comment only, and now correct.c6e96d6b— the re-rate. I verified the model by hand: the booked total (ops + booked effects + re-rate) equals the bill without minus the bill as sent, each at its own prompt size. I recomputed all nine test scenarios independently and each matches, including the two-component 3:1 split, the negative re-rate (mask at −1.15, delta −1.65), the no-line and no-tier cases, and the owner's 290K → 250K example with output (1.68 both ways).c540077e— the double-count fix.bookedCausedmirrors the booking switch inAccountantFigurecase by case; I walked every branch (InBaseline break, owned break, ended break with empty ChangeID, unowned break, rescue/split/ttl/mark, unknown kind) and each matches. The identity test's numbers check out by hand: booked 1.004 = bill difference 1.004, with the rescue's 1,000 read and the break's 20,000 write removed from the stay exactly once.
Points I probed and accept:
- The stay subtraction. Every token of the with-bill is either an op's
Caused, a booked effect'sCaused, or stay — so no token is priced twice, and the clampmax(stay.X, 0)only guards drift. The unowned break stays in the re-rate by the author's stated choice; I checked when that case can occur with the figure applied (dropped ops and observe mode both gate the figure away,accOverridereturns early), and a dry-run change's counterfactual break carries no tokens in the bill, so leaving it in stay is harmless. bookReRaterow safety. Shares come only from counted ops, so every share's component already has aByComponentkey — the re-rate cannot create a figure-without-row fallback. Thetotal == 0path books toEndedBreakUSD, andaccOverrideadds theended_changerow when it is non-zero, so the rows still sum toDeltaUSD.- The gates around the figure.
countedSavedTokensuses tokens, not dollars, so the re-rate cannot trip the plausibility bound. The held estimate keeps the re-rate in both its ceiling and its floor, so the floor stays under the ceiling. - Process. The re-rate is named in the behavior-change block at the top of the PR with the owner decision (David Amid, 2026-11-25), the owner granted round 3, and
docs/dashboard.mdstates the split rule, theended_changefallback and the negative case, matching the code.
Non-blocking
- The re-rate books into
ByComponentFirst(the first-removal column). That column's old reading was "the write and input tiers of the saved tokens"; it now also carries rate-change dollars with no tokens behind them. The PR table names the choice and no token figure changes, so I accept it — but a reader of the components table can no longer derive that column from the token columns. - A cost-causing component absorbs no share of a negative re-rate (shares need net saved tokens above 0), so a saving component can go below 0, as the test shows. This is the owner's rule and
docs/dashboard.mdstates it. Noted only so the choice is visible in the review trail.
What I checked
- Last review: round 2, b13e683, 2026-11-25T14:37:59Z.
- New commits read: 3 —
d8963449"docs(pricing): fix the accPrices comment",c6e96d6b"feat(dash): count the full bill difference when a request crosses a price line",c540077e"fix(dash): do not re-rate the tokens of a booked cache effect twice". - Read in full: 4 reviews, 4 comments, 0 inline comments (from the three saved files), plus the current PR body.
- New items since my last review, and what I did: reviewer 1's round-2 review (its three notes checked against the code and dispositioned above); the owner-decisions comment at 14:36 (counters → accountant#111, no global switch, estimate accepted, merge yes at hand-off); the author's round-2 reply at 14:41 (each claim verified, including the comments-only approval note for
b13e6832..d8963449); the round-3 announcement at 15:29 with the owner's savings decision; the three new commits (full diff, plusdash/accountant_price.goin full around the new functions); the updated PR body anddocs/dashboard.md. - The re-rate arithmetic: recomputed every new and updated test in
dash/pricetier_callers_test.goby hand fromaccPrices,tierUSD,bookedCausedandbookReRate— all nine scenarios match their expected values, and the two identity tests (booked total = bill difference) hold in my independent computation. bookedCausedagainst the booking switch branch by branch; the stay computation (billed tiers minus ops'Causedminus booked effects'Caused, clamped); thepw == pbearly return (Price stays comparable, so==is sound); the output term (OutputTokens× the output-rate difference, output not counted in the prompt size).- That nothing else moved:
git diff b13e6832..HEADtouches onlydash/accountant_price.go,dash/pricetier_callers_test.goanddocs/dashboard.md; the keepalive, tooldefer, campaign and proxy sides are unchanged from the head I approved in round 2. - Commit messages: DCO sign-off and
Assisted-Bypresent on all three. Tests were not run: live tests are not approved; the author reports plaingo test ./dash ./proxyand-race -run TestFiguregreen, with four re-rate mutations each failing a test.
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.332 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 3 of 3 | c540077e060e |
approve |
Verdict: approve
Findings
None. The re-rate is a large change to the savings figures, and I could not break it. The decomposition is exact, the double-count fix is right, and the owner's decision is recorded.
Non-blocking
- dash/accountant_price.go:273 — the re-rate books into the first-removal column.
bookReRateadds its share toByComponentFirst, including the re-rate of read-tier stay tokens, which the column's own doc calls replay content. The invariant holds (ByComponentminus both columns still equals the costs), and the code comment says the choice.docs/dashboard.mdsays which row an unowned re-rate books to, but not which column carries it. One line in the docs would close it. - The tool-deferral saving now has two methods. The accountant's
deferFigcan include a re-rate share (a deferral with net saved tokens owns one), while the lever's ownPriceintooldefer/ledger.goprices gross and cost per side with no re-rate. The two figures already differed in scope; the re-rate widens the gap. A note on the lever, or a later alignment, would do.
What I checked
- Last review: round 2,
b13e68329213, 2026-11-25T14:39:38Z. - New commits read: 3 —
d8963449"docs(pricing): fix the accPrices comment",c6e96d6b"feat(dash): count the full bill difference when a request crosses a price line",c540077e"fix(dash): do not re-rate the tokens of a booked cache effect twice". - Read in full: 4 reviews, 4 comments, 0 inline comments (the inline file is empty), from the three saved files.
- New items since my last review, and what I did: the author's owner-decisions comment (14:36, posted as my round-2 review landed), the author's round-2 reply (14:41), reviewer 2's round-2 review (14:37, posted after my round-2 fetch; read in full now), the author's round-3 comment (15:29), the three commits, and the PR body edits (behavior-change block, toolsuggest row, Technical notes).
Earlier findings, disposition:
- Round-2 note 1, the
accPricescomment direction. Fixed ind8963449: the old wording is back ("a cache effect only moves tokens between tiers, so it does not change the size"). Verified against the code: the marker bytes leave the size without as the tail-breakpoint op'sCaused. - Round-2 note 2, the ping input constant (1 vs 7). Kept as a follow-up, recorded in the Technical notes. Accept.
- Round-2 note 3, toolsuggest "cannot". Fixed: the PR row and Technical notes now say "not done here" and name the follow-up. Accept.
- My process note, the owner's yes. Resolved: the owner's decisions of 2026-11-25 are on the PR (counters to accountant#111, no global switch, the estimated size accepted, the merge yes at hand-off), and the re-rate itself carries "Owner decision, 2026-11-25" in its commit message and in the PR's behavior-change block.
- Reviewer 2's round-2 notes (the direction comment, the summary and sweep projection estimate): fixed and recorded the same way. Agree with both dispositions.
The new commits, checked in depth:
- The decomposition is exact. I proved the identity: the booked total (
DeltaUSD + KeepAliveSavedUSD + SplitUSD + TTLUSD) equals the bill without minus the bill as sent, each at its own prompt size. It rests on three facts, each true under the library's semantics: the ops' and the booked effects'Saved/Causedare tier moves of content present in both bodies; the unbooked effects'Caused(anInBaselinebreak, an unowned break) stays instay, where it re-rates once, which is right because the client body has those tokens too; andstayis the billed tokens minus what the counted ops and the booked effects caused.BaselineCostUSD = CostUSD + DeltaUSDnow equals the client's bill exactly. - Every new test's arithmetic, by hand. The owner's example (290K→250K with 2,000 output: 1.68); the 3:1 split that sums to the delta; the negative re-rate (−1.65, the mask share goes below 0); the Haiku opposite sides (0.046); both-above and no-tiers (no re-rate); the mixed cache-effect case (booked 1.004 = bill difference 1.004 — this is the test that pins the
c540077efix); theInBaselinebreak kept in the re-rate (2.4). bookedCausedmirrors the booking switch case by case.InBaseline, an unowned break and an unknown kind return zero (their tokens stay); the owner case, the ended-change case, rescue, split, both TTL legs and both mark legs returnCaused(their value is booked, so their tokens must not re-rate twice). The share list is built after the unpriced-op skip, so a skipped op cannot own a re-rate.- Guards and clamps.
pw == pbreturns 0, so no line crossed, a flat price or an unknown size keeps the old figures (the no-tiers test covers it). Negativestaytiers clamp to 0, so a library over-attribution under-counts the re-rate instead of exploding it. The re-rate adds dollars only; noaddTokcall, so no token figure changes, as the PR claims. - The held path. The re-rate stays whole inside both the ceiling and the floor of a held estimate (the line crossing does not depend on the warm or cold hypothesis), and the estimated branch zeroes the first-removal column with the rest.
- The agree and shadow tests.
priceOfAccbuilds prices with no tiers, so the re-rate is zero on every shared accountant case and those comparisons are unaffected. - The docs. The
docs/dashboard.mdexample matches the code and the test (290K×2x − 250K×1x on input, plus the output re-rate), and the split rule, theended_changefallback, the negative re-rate and the no-line case are all stated. d8963449changes comment lines only; the code is unchanged under it.
Did not run builds or tests: live tests are not approved for this review. The author reports ./dash and ./proxy green and four mutations failing tests.
Owner decision: merge yes (David Amid, 2026-11-25)The owner said yes to merging this PR with its behavior change:
The owner also granted round 4. It re-checks the docs and comments delta after |
Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Round 4: re-check the delta after
|
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.332 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 4 of 4 | cb595cd2b500 |
approve --> |
Verdict: approve
Findings
None. The delta since round 3 changes docs and comments only, and every statement in it matches the code.
Round-3 notes: status
Mine:
- The re-rate books into
ByComponentFirst, which no longer follows the token columns. Fixed in the docs (cb595cd2):docs/dashboard.mdnow names the column (saved_first_usd), says it carries the re-rate of staying cache-read tokens too, and says it can no longer be derived from the token columns. I verified the column name against the json tag (dash/event.go:728). - A cost-causing component absorbs no share of a negative re-rate. Now stated in
docs/dashboard.md: "a component that only causes cost (no net saved tokens) gets no share". MatchesbookReRate's share rule (net saved tokens above 0).
Reviewer 1's round-3 notes (checked myself):
- The docs did not say which column carries the re-rate. Fixed, same docs change as my note 1.
- The tool-deferral saving has two methods (the lever's
Pricevs the accountant'sdeferFig). Fixed incb595cd2: thePricedoc comment intooldefer/ledger.gonow says the lever prices gross and cost per side with no re-rate, and thatdeferFigcan include a re-rate share, so the two differ in scope. I verified both halves against the code:tooldefer.Pricehas no re-rate term, and a tooldefer op with net saved tokens does receive a share inbookReRate.
The new commits
31dbc96d— one line indocs/dashboard.md: theended_changerow's name is approximate when it holds an unowned re-rate. Matches thetotal == 0path inbookReRateand the rowaccOverrideadds.cb595cd2— the docs naming above, plus thetooldeferledger comment. The.gochange touches comment lines only;Price's body is unchanged from the head I approved in round 3.
No code changed since c540077e, so my round-3 verification of the re-rate arithmetic, the bookedCaused switch, the stay computation and the gates still stands at this head.
Non-blocking
- Nothing new. The two round-3 notes are now documented, and the owner's merge yes (David Amid, 2026-11-25, 15:58) is on the PR with the behavior change named.
What I checked
- Last review: round 3, c540077, 2026-11-25T15:34:54Z.
- New commits read: 2 —
31dbc96d"docs(dashboard): say the ended_change row can hold an unowned re-rate",cb595cd2"docs(pricing): name the re-rate column and the ledger scope". - Read in full: 6 reviews, 6 comments, 0 inline comments (from the three saved files), plus the current PR body.
- New items since my last review, and what I did: reviewer 1's round-3 review (read in full; its two notes dispositioned above); the owner's merge-yes comment at 15:58 (the behavior change, the per-ping limit and
flat: trueare all named in it); the author's round-4 announcement at 15:59; the two new commits (full diff, and the changed files around the changes). - Every claim in the new docs and comments against the code: the
saved_first_usdjson tag (dash/event.go:728); the share rule and theended_changefallback inbookReRate; the absence of a re-rate term intooldefer.Price; the presence of re-rate shares indeferFig's path. - That nothing else moved:
git diff c540077e..HEADtouches onlydocs/dashboard.md(+9/−3) and the comment block abovetooldefer.Price(+4/−1); the full diff from baseb8f4d92botherwise matches the heads I approved in rounds 1 to 3. - Commit messages: DCO sign-off and
Assisted-Bypresent on both. Tests were not run: live tests are not approved; the delta changes no executable line.
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.332 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 4 of 4 | cb595cd2b500 |
approve |
Verdict: approve
Findings
None. The delta after c540077e changes documentation and comments only, and every statement in it matches the code.
Non-blocking
None new. Both my round-3 notes are fixed, and I have nothing further to raise.
What I checked
- Last review: round 3,
c540077e060e, 2026-11-25T15:36:44Z. - New commits read: 2 —
31dbc96d"docs(dashboard): say the ended_change row can hold an unowned re-rate",cb595cd2"docs(pricing): name the re-rate column and the ledger scope". - Read in full: 6 reviews, 6 comments, 0 inline comments (the inline file is empty), from the three saved files.
- New items since my last review, and what I did: reviewer 2's round-3 review (15:34, posted just before mine; read in full now — its two notes match mine or the owner's rule, and both are now in the docs); the owner's merge yes (15:58); the author's round-4 announcement (15:59); the two commits; the final
docs/dashboard.mdtext.
Earlier findings, disposition:
- Round-3 note 1, the docs did not say which column carries the re-rate. Fixed in
cb595cd2: the docs now name the first-removal column (saved_first_usd), say it also carries the re-rate of cache-read tokens that stay, and say it can no longer be derived from the token columns. I verified the column name against the code:ByComponentFirst→CompRow.SavedFirstUSD→ jsonsaved_first_usd(dash/event.go:728). All three statements matchbookReRate. - Round-3 note 2, the tool-deferral saving has two methods. Addressed in
cb595cd2: thePricedoc comment intooldefer/ledger.gonow says the lever prices gross and cost per side with no re-rate, and that the accountant figure (deferFig) can include a re-rate share, so the two differ in scope. I checked the comment's claims against the code:Pricehas no stay term, and a deferral op with net saved tokens above 0 does become a re-rate share inAccountantFigure. Accurate. - Reviewer 2's round-3 notes. Note 1 is my note 1 (fixed the same way). Note 2 (a cost-causing component gets no share of a negative re-rate) is the owner's rule and is now stated in the docs: "A component that only causes cost (no net saved tokens) gets no share." That matches the share rule (
tierTotal(Saved) - tierTotal(Caused) > 0), which applies to both signs of the re-rate.
The two commits, checked claim by claim:
31dbc96d+cb595cd2touch onlydocs/dashboard.mdand the doc comment abovetooldefer.Price. No code line changes; the head I approved at round 3 is unchanged under them.- Every new docs statement against the code: the share rule (net saved tokens, only above 0); the
ended_changefallback with its name approximate and no tokens (bookReRateadds dollars only, noaddTok); the column name and its json tag; the negative re-rate taking a net-saving component below 0 (matchesTestFigureNegativeReRateCanTakeAComponentBelowZero); no line crossed or no tiers gives the old figures. - Commit messages: DCO sign-off and
Assisted-Bypresent on both.
Process: the owner's merge yes for the behavior change is on the PR (15:58, David Amid, 2026-11-25), and round 4 was granted for this docs delta. From my side the PR is ready for hand-off.
Did not run builds or tests: live tests are not approved for this review. No code changed since the author's last green run.
…ent test (#1426) test(proxy): pass the prompt-size price callback in the predictive agent test #1407 changed campaign.Rows to take a price callback with a prompt size. #1410 added predictive_agent_test.go with the old callback. Both merged close together, so main did not compile for the proxy tests. The test price function now takes (model, promptTokens) and ignores the size. The rates stay the same. No production code changes. Refs #1407, #1410 test(proxy): gofmt the price callback, with blank parameter names lint-build failed with "gofmt needed". gofmt wraps a function literal that is too long for one line. The callback ignores its parameters, so it now names them "_", as the other tests do (campaign/campaign_test.go, proxy/campaignauto_test.go). The line is shorter, and gofmt keeps it on one line. Fixes the main build after #1407 and #1410 merged close together. Test only. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
The flat $0.50 per-ping cap blocked GPT-5.5 pings above about 500K tokens after #1407. Such a ping saves 9x to 11x its cost. - Value rule: allow the planned pings of one idle span when they cost less than one miss (prefix x (write rate - read rate)), both priced at the tier of the prompt size. Live keeper and replay call one function, Policy.PingVerdict. - keepalive_max_usd_per_ping is now an opt-in flat cap on top. The loader no longer fills 0.50 and no strategy sets it. - Summary and sweep calls keep their $0.50 default cap. - New reason "not worth it". "over budget" now means the operator cap. - keepalive.PingPrompt replaces the proxy's own prefix + 1 sum. Fixes #1420 Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
feat(metrics): price the cg_* savings counters by prompt size Bump rossoctl/accountant to 05cd0f84 (#112). The host pricer now has PriceAt, which reads the rate of the tier for the prompt size, with the same rule as the dashboard (modelinfo.Price.At). The host also fills Observation.Output, so the sink re-rates the output tokens. The counters now book the full bill difference at each prompt size. They did book base rates. Set flat: true on a price-file entry to turn the tiers off. Refs #1407, rossoctl/accountant#112. docs(metrics): name the llm_savings counters, fix 3 comments build(deps): pin accountant and accountant/metrics to v0.8.0 No pseudo-version is left in go.mod. v0.8.0 is 05cd0f84 plus #113 (an in-place change ends when a later change deletes its item). Behavior change (sized llm_savings counters; accountant #113 in v0.8.0) approved by the owner in the integrator session, 2026-11-25: "1424 yes". Both accountant modules pinned to the v0.8.0 tags. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
…) (#1428) feat(keepalive): weigh a ping chain against the miss it protects (#1420) The flat $0.50 per-ping cap blocked GPT-5.5 pings above about 500K tokens after #1407. Such a ping saves 9x to 11x its cost. - Value rule: allow the planned pings of one idle span when they cost less than one miss (prefix x (write rate - read rate)), both priced at the tier of the prompt size. Live keeper and replay call one function, Policy.PingVerdict. - keepalive_max_usd_per_ping is now an opt-in flat cap on top. The loader no longer fills 0.50 and no strategy sets it. - Summary and sweep calls keep their $0.50 default cap. - New reason "not worth it". "over budget" now means the operator cap. - keepalive.PingPrompt replaces the proxy's own prefix + 1 sum. Fixes #1420 fix(keepalive): round 1 review fixes for the ping value rule (#1420) - A manager strategy's flat cap of 0 now leaves the account's own cap in place. Only a value other than 0 replaces it. - The strategy form says 0 = no flat cap. - A miss is priced at the 1-hour write rate when the policy writes at 1 hour (HeadTTL1h, OneHourAlways) or plans the 1-hour ping. - Replay weighs the miss at the ping's tier and the live wait-plan count (never more than live). The replay-versus-live test now goes through a real keeper. - The arm answer reports the effective cap after the manager strategy. - Fix stale comments and the OpenAI write-rate sentence. fix(keepalive): round 2 review fixes for the ping value rule (#1420) - The arm answer resolves the policy with the provider of the session's own last request, so the manager strategy cap is reported only where it is enforced (not on an OpenAI session). - A subagent keeps the 5-minute cache under OneHourAlways, so its miss is priced at the 5-minute rate. - Replace the replay chain test that restated its own definition with a pin on the K=8 tool wait and the OpenAI base count. Behavior change (value rule replaces the flat per-ping cap; flat cap opt-in) approved by the owner in the integrator session, 2026-11-25: "1428 yes". Approvals at 40a3473 carried over (SAME CHANGE: only sign-offs added). Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
) fix(dash): price the declaration-filter saving at its prompt size The declaration-filter query did not read fresh_input, so each row priced at base rates. Read it, size the prompt with modelinfo.PromptTokens, and price with Price.At, as #1407 does elsewhere. Both DeclFilterSavings and DeclFilterSavingsByTenant use it. Fixes #1438 fix(dash): price a filter saving at the size without the filter Review round 1. A removed declaration prices at the size the request would have had without the filter: sent plus removed tokens. Apply that to the declaration-filter saving. Price carriedCost at the request's prompt size too, so the items and the total on /api/adapt/tools agree. test(dash): correct the sent size in a tiered-price test comment mkEvent sets FreshInput to 10, so the one-hour request is 5,010 tokens sent, not 5,000. The 5,050 line holds either way. Only the comment changes. style(dash): gofmt the test case struct in toolsuggest_test.go CI lint-build failed with "gofmt needed". gofmt aligns one struct field. The change is whitespace only (git diff -w is empty). Behavior change (declaration-filter saving priced at the size without the filter) approved by the owner in the integrator session: "1442 yes". Approvals at eb64543 carried over: after them only a comment and a gofmt space change in a test. Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID AMID <[email protected]>
Behavior change (the owner decides before merge)
cost_usd, the savings figures and the keep-alive per-ping dollar guard price every request at the flat base rate.MaxUSDPerPing) now refuses some pings in long sessions above the line, which it let through before. Savings now include the tier re-rate: a saving is the bill without context-guru minus the bill as sent, each at its own prompt size, so when a request crosses a line the tokens that stay and all output change rate too. Example: gpt-5.6, a trim takes 290K to 250K, saving = 290K x 2x - 250K x 1x on input, plus the output re-rate. Savings change in both directions, and a component can show a saving below 0. Owner decision: David Amid, 2026-11-25.flat: trueon a price-file entry. There is no global switch. I added none (see Open questions).Data dependence: metadata only (token counts, model id, price table). No change to
docs/data-dependence.mdis needed: the Accountant row and the Dashboard database row already say these figures need counts and prices only.Refs #1343. Local tests: waived (owner rule)
Summary
Price.AtandPromptTokens. Nothing called them.p.At(PromptTokens(fresh, cacheRead, cacheWrite)).What changed
proxy/keepalive.godispatcher price adapterpromptTokensthrough: model price, then.At(promptTokens). FixesprojectedPingUSDvsMaxUSDPerPing, the summary, sweep and refresh projections.keepalive/keeper.gopingCost,substitute.gosubstitute cost andsweepAnswerUSDbilledPrompt); the planned prefix when usage has no input. A projected ping (projectedPingUSD, summary, sweep) is priced at prefix +DefaultPingInputTokens(pingPrompt), so a prefix of exactly 272,000 prices at the tier.dash/event.gopriceCost(cost_usd, cache-saved, fallback cost; alsoEvent.Price,PriceMode, the reprice pass, the ping row)dash/accountant_price.goAccountantFigure,heldFloorUSDstay x (rate without - rate billed). All output re-rates byoutput x (rate without - rate billed). The re-rate is split over the counted components in proportion to each one's net saved tokens (saved - caused, only above 0), so rows add up to the total. With no such component it books toEndedBreakUSD(theended_changerow): it is counted, owned by no component, and keeps the rows equal toDeltaUSD. It is a request-level re-rate, not an ended break, so the row name is approximate:docs/dashboard.mddefinesended_changeas the break a change left, and in this case the figure is the re-rate (no tokens). No new figure was added. It books in the first-removal column. No tokens move, so no token figure changes. A negative re-rate uses the same split. No line crossed, no tiers or an unknown size: the figures of before. Same rule as accountant#112 (which re-rates input tiers only).tooldeferledger (Book,Price)ResponsegainsFreshInput. Unknown size: base.campaign.Rows,autoPrice,adaptcacheCachedContextpluskvcache.DefaultPingInputTokens. The price callback gains apromptTokensargument.dash.NextRequestUSD(cache state, manual ping)DefaultPingInputTokens.dash/keepalive.golive view and calculator,proxy/keepalivectl.goDefaultPingInputTokens.proxy/inferencemetrics.gomiss costEvent.PriceCG(compaction calls)proxy selfRates/ratesFor(lifecycle/rates.go),proxy/predictive.go,proxy/campaignbuild.goprice map,cheapmodeldash/readvalue.go(tier cost split, legacy estimators),sweepattr,summarizeattr/replaycaplegacy rows,cachehistory,adaptcompaction,adapttools,toolapi,spendexplain,fivehourfitdash/toolsuggest.gocache_read,cache_writeandcache_write_1hper row, but the query does not selectfresh_input. Not done here (see Technical notes).proxy/metricsink.go(accountant metrics module)Pricerhas no prompt-size argument. See Open questions.docs/dashboard.mddocs/referencealready documentsflat: true(step 1). No other "flat rate" text found indocs/how-toordocs/reference.How it was tested
macOS, Go 1.27.4. No whole-package
-racerun (interim rule).go build ./...andgo vet ./...: clean.go test(no race):./dash,./proxy,./proxyapp,./keepalive,./tooldefer,./campaign,./internal/modelinfo/...,./dispatch/...: all pass.TestNoHooksKeepsTheBinaryDefaultspassed here too.go test -race -run <new tests>on./keepalive ./tooldefer ./dash ./proxy: pass.NextRequestUSD.heldFloorUSDper-side price,missCostUSDtier, ledger round-up. Each has a mutation that fails it..At(promptTokens)to base; event.Atremoved; accountantwith=At(w), without=At(w); accountantAt(n), At(n); tool deferral cost.At(0); ping cost by prefix instead of usage; campaign.At(0);NextRequestUSD.Atremoved.Open questions
github.com/rossoctl/accountant/metricsprices its savings counters throughPrice(model, time, tier), with no prompt size. This repo's glue cannot give it one. Thecg_*savings counters stay at base rates. To fix it, that module needs apromptTokensargument (or a per-side price function). I did not touch that repo.dash/accountant_price.go.flat: trueis per entry. Do you want one? I did not add one.Technical notes
Why
accPricesis indash: the wholeAccountantFiguredomain lives there. Moving it out is a wider refactor. Proposed as a follow-up.Re-rate and cache effects. The tokens that stay exclude the Caused tokens of each cache effect that is booked (a break the client body has too, an unowned break and an unknown kind are not booked, so their tokens stay). Without this a booked effect would be re-rated twice. The interaction is not priced in dash (
Result.Interactionis ignored on purpose), so the interaction-size bug of accountant#112 does not apply here.The tool deferral size without the deferral is rounded up (
math.Ceil), so a fractional billed size cannot fall below a tier line.Cache effects, the mark included, only move tokens between tiers. The marker's own bytes are a rewrite op (
apply/ops.gotailOp) that the library prices asCaused, andaccPricessubtracts them. The size without is exact for the marker.dash/toolsuggest.gois not done here. Therequeststable hasfresh_input(dash/cachestate.go:422), so adding the column to the query would give the exact size. This is a follow-up.The summary and sweep projections pick the tier at
prefix + 1. The real call is larger (instruction or question text), so near a line the guard can project one tier low. The recorded cost uses real usage. This is the same estimate class assummaryOutputBudgetGuess.pingPromptaddskvcache.DefaultPingInputTokens(1), whilepredictivepingFreshis 7. One shared constant is a follow-up.Event.accPrices(p)returns thewithandwithoutprices. With no billed usage, no tiers or no accountant result, both arep.At(0), the base price, so the old results stay unchanged.modelinfo.Priceis passed with itsTiersintoPriceModeandAccountantFigure. Callers need no change.keepalive.billedPrompt(u, prefix)prefers the billed usage size and falls back to the planned prefix.The
keepalivetest fakeproxyPricernow applies.At, as the real adapter does.