Repository navigation
refactor(modelinfo): one source for the cache price multiples - #849
Conversation
The read (0.1x), 5-minute write (1.25x) and 1-hour write (2.0x) multiples were written in about 8 places. They now live in internal/modelinfo, and kvcache, dash, components/offload, cheapmodel and proxy read them. Every value is unchanged. Refs #797 Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
When the price table left the cache-write rate blank, agentRates used 1.25x for every model. ParseTable and the price feed use 1.0x for a family with no write premium. agentRates now asks modelinfo.CacheWriteFracFor. Refs #797 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 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.316 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | fff1938fcdc6 |
blocking |
Verdict: blocking
Findings
- dash/spendexplain.go:229 — the 1-hour write rate stays the literal
2 * p.Inputin seven dash sites the refactor did not reach- What fails: someone tunes
AnthropicCacheWrite1hFracininternal/modelinfo/cachefrac.go(its comment says "This is the ONE place they are written").dash/cachestate.go,dash/adaptcompaction.go:1024,dash/keepalive.goandkvcachefollow the new value. The seven sites below keep 2.0x. The same 1-hour write then shows two different costs on two dashboard pages. - Proof: the literal remains at
dash/spendexplain.go:229,:388,:405and:479(the last one publishescache_write_1hto the page),dash/adapttools.go:481,dash/toolsuggest.go:236, anddash/adaptcompaction.go:1036— six lines below the line this PR did convert (adaptcompaction.go:1024).spendexplain.go:229also repeats the premium expression2*p.Input - p.CacheWritethat commit 1 just wrapped inPrice.CacheWrite1h()formodelinfo.go:93. All values match today, so no current figure is wrong; the defect is the false "ONE place" claim plus the split source. - Fix: replace each
2 * p.Inputwithp.CacheWrite1h()(and the premium withp.CacheWrite1h() - p.CacheWrite) in those seven dash sites, or narrow the comment incachefrac.goto the truth.
- What fails: someone tunes
Non-blocking
- The blank read tier in
agentRates(extract_econ.go:131) stays flat 0.1x for every family. Gemini bills a cached read near 0.25x of input. This is pre-existing and out of this PR's scope, but the family rule now covers only the write tier. Worth its own issue. - The behavior change (commit 2) is named at the top of the PR as the repo rules require. It still needs a human developer's yes before merge. I did not see that yes.
dash/kvcachesim.go:378-380tells the user "Defaults to 1.25x / 2.0x input" in UI strings. Those defaults now read the shared constants, so the strings stay true. No action.
What I checked
- Full diff of both commits (
67ad917e,fff1938f), plus the code around every change. - Commit 1 value equivalence, site by site:
agentCacheReadPerMTok= 3.00 x 0.1 = 0.30;agentCacheWritePerMTok= 3.75;HaikuPricing= 1.25 / 0.10;NextRequestUSD1h cold = Input x 2.0;adaptRatesmixed write =(1-f)*CacheWrite + f*Input*2.0;CostWithCacheWrite1hpremium =2*Input - CacheWrite;medianPingUSD= usd/1.25x0.1;kvcacheDefault multiples = 0.1 / 1.25 / 2.0;ParseTabledefaults = 0.1 / 1.25. All identical to the old literals. Commit 1 is behavior-neutral. - Commit 2:
CacheWriteFracFor(c.ModelName)gates onIsClaude(substring, handlesaws/prefixes) andGPT56OrLater(handles routing prefixes). Verified the three test models:claude-sonnet-5→ 1.25,azure/gpt-5.5→ minor 5 < 6 → 1.0,gemini-3-flash-preview→ 1.0.SelfRatesandModelNameboth come from the request's own model (proxy/modes.go:61,proxy/proxy.go:853), so fresh rate and family frac describe the same model. The PR body names the change, its effect, and the turn-off. - Consistency claim "the same answer ParseTable and the price feed give": confirmed at
table.go:118-128(family-gated fill) andlitellm/litellm.go:222-223. - New tests:
TestAgentRatesBlankWriteFollowsTheModelFamilyfails on the old code for the 1.0 cases;multiples_test.goandcachemultiples_test.gomatch the code (checkedCostWithCacheWrite1h(0,0,1000,0,1000)= 1000 x 6e-6 by hand). - Imports: no cycle —
modelinfoimports only stdlib and yaml;kvcache,cheapmodel,dash,components/offload,proxyimport it. - Scanned the repo for leftover rate literals: no 0.1 or 1.25 rate literals remain in code; the 1h 2.0x sites are finding 1.
dash/schema.go:150,166andkvcachesim.gohits are comments or UI strings. - Data dependence: no change (metadata only).
docs/data-dependence.mdneeds no row change.
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.316 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | fff1938fcdc6 |
approve |
Verdict: approve
Findings
None. I found no wrong behavior, no data loss, no broken fail-open path, and no missing test for the new behavior.
Non-blocking
- Merge gate, not a code defect: commit 2 changes what users get. A model family with no write premium (GPT before 5.6, Gemini, unknown) now gets a blank write tier of 1.0x fresh in
agentRates, not 1.25x. The PR names this at the top, with who, old, new, and the turn-off. PerRELEASING.md, a human developer must say yes before merge. Do not merge on this review alone. dash/adaptcompaction.go:1036still writes the 1h tail rate as2 * p.Input.p.CacheWrite1h()gives the same number. The literal is the drift risk this PR exists to remove.dash/spendexplain.go:229, 388, 479still compute the 1h premium as2*p.Input - p.CacheWriteand expose"cache_write_1h": 2 * p.Input. This duplicatesPrice.CacheWrite1h/CostWithCacheWrite1hwith bare literals. Same values today. A follow-up can route them through the method.TestAgentRatesBlankWriteFollowsTheModelFamilyhas no GPT-5.6+ case (expect 1.25).CacheWriteFracForcovers that family ininternal/modelinfo/cachefrac_test.go, so coverage exists elsewhere.- The blank read tier still applies the Anthropic 0.1x to every family (
extract_econ.go:131,table.go:92,litellm.go:220). Pre-existing and consistent across all three sources. Not this PR's scope.
What I checked
- Read
CLAUDE.mdand the diff of both commits in full, plus the code around every hunk. - Commit 1 is value-identical. I checked each rewrite against the old literal:
HaikuPricing(1.25/0.10), theagentRatesfallbacks,NextRequestUSD,adaptRates,medianPingUSD,write1hMultiple,ParseTabledefaults, thekvcachedefaults,CostWithCacheWrite1h's premium, andproxy'sagentCacheReadPerMTok.Price.CacheWrite1h()=2*p.Inputexactly, so every derived figure is unchanged. - Commit 2 behavior:
CacheWriteFracFordelegates toIsClaude/GPT56OrLater, which I read. The test's three cases are correct:claude-sonnet-5→ 1.25,azure/gpt-5.5→ 1.0 (minor 5 < 6),gemini-3-flash-preview→ 1.0. The new answer matches whatParseTable(table.go:118-128) and the LiteLLM feed (litellm.go:223) already give the same model, so the gate, the table and the feed now agree. - Reach of the change:
SelfRatescomes fromproxy.selfRatesthrough the price chain, and both chain sources fill a blank write tier when input is known. The blank-write path inagentRatesneeds aPricewith input but no write rate. An emptyModelNamereturns zeroSelfRates, so the family lookup always sees a real id. The fallback constants (noSelfRatesat all) are unchanged at 1.25x. - Float equality:
3.00 * 0.1differs from the old literal0.30by 1 ulp. I checked every test that pins these constants (extract_econ_test.go,extract_cold_test.go,extract_improve_test.go,TestBreakEvenSizesMatchTheDocumentedVerdict): all compare with tolerances or use explicitSelfRates, so none breaks. - New tests: read all three. They assert the shipped multiples,
CacheWrite1h, theParseTabledefaults,NextRequestUSD's two tiers, and the family-following write tier. The arithmetic in each is correct. - Imports and cycles:
cheapmodel,kvcache,dash,proxy,components/offloadnow importinternal/modelinfo;modelinfoimports none of them, so no cycle. - I did not run builds or tests. Live tests are not approved for this review, so the PR's "-race all pass" claim is unverified by me.
Seven dash sites still wrote `2 * p.Input` for the 1-hour rate. They now call Price.CacheWrite1h(). Values are unchanged. A test pins the old literal. Refs #797 Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
|
Fixed in 86e260c. All seven sites now use |
|
No source found, so 0.1x stays. I checked the repo code and docs, |
|
Added a GPT-5.6+ case ( |
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.316 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 86e260c31687 |
approve |
Verdict: approve
Findings
None. My round-1 finding is fixed, and the new commit introduces no defect.
Status of earlier findings
- Mine, round 1 — the 1h write rate stayed the literal
2 * p.Inputin seven dash sites. Fixed in86e260c3. I read the full diff: all seven sites now callp.CacheWrite1h(), and the three premium sites usep.CacheWrite1h() - p.CacheWrite.spendexplain.go:479now publishes"cache_write_1h": p.CacheWrite1h(). I grepped dash, kvcache, components, cheapmodel, proxy and internal for2 * p.Inputunder any receiver name: no hit outside tests. The "ONE place" comment incachefrac.gois now true. - Reviewer 2, round 1 — same literal sites (non-blocking). I checked them myself; fixed by the same commit. Agree with reviewer 2, and add only this: my grep also covered
2*x.Inputforms with other receiver names, and found none. - Reviewer 2, round 1 — no GPT-5.6+ case in the family test. Fixed:
86e260c3addsazure/gpt-5.6-lunaexpecting 1.25. I tracedGPT56OrLater: lastgpt-segment gives major 5, minor 6, so it returns true and the frac is 1.25. The case is correct. - Mine and reviewer 2, round 1 — blank read tier flat 0.1x for every family (non-blocking). Rejected by the author: no source holds a per-family read fraction (repo, docs,
prices.example.yaml, module cache, eval box). I checked the reason:table.go:92andlitellm.go:220apply the same flat 0.1x, so the three sources agree and no data exists to do better. I accept the rejection. The question stays open in the PR body.
Non-blocking
- The merge gate stands: commit
fff1938fchanges what users get (blank write tier 1.0x for families with no premium). The PR names it as required. A human developer must still say yes before merge. TestCacheWrite1hMatchesTheOldBareLiteralcompares the method against the same arithmetic (2*in - in*1.25), so it cannot fail on a pure refactor of the test's own expression. It still pins the method toInput x 2.0, which is the point. No action needed.
What I checked
- Last review: round 1,
fff1938fcdc69249811c8b2cb19cb41babbcd78f, 2026-11-02T10:28:31Z. - New commits read: 1 (
86e260c3"refactor(dash): read the 1-hour write rate from Price.CacheWrite1h"). - Read in full: 2 reviews, 3 comments, 0 inline comments (from the three files in my folder).
- New items since my last review:
- Reviewer 2's round-1 review (10:29:05Z, approve) — read in full; its literal-site notes are my finding 1, its other notes handled above.
- Author comment 10:56:49 (fix summary) — verified against the diff and a repo-wide grep.
- Author comment 10:56:51 (read tier stays 0.1x, no source) — reason checked and accepted.
- Author comment 10:56:53 (GPT-5.6+ test case added) — traced the case by hand.
- Commit
86e260c3— read the full diff and the code around each hunk. Every conversion is value-identical (CacheWrite1h()=Input x 2.0). Both test additions checked by hand. No import changes, no behavior change, no data-dependence change.
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.316 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 86e260c31687 |
approve |
Verdict: approve
Findings
None. The new commit is value-identical everywhere it touches, and it fixes every open item.
Status of earlier findings
- Reviewer 1, finding 1 (seven dash sites with the bare
2 * p.Input): fixed in86e260c3. I re-read all seven sites —spendexplain.go(4),adapttools.go,toolsuggest.go,adaptcompaction.go. Each now callsp.CacheWrite1h()(premium form:p.CacheWrite1h() - p.CacheWrite). I grepped the repo for any remaining bare2 * <something>.Input: none outside tests.adapttools.goandtoolsuggest.gohold amodelinfo.Price, so the method applies. Values are unchanged. - Reviewer 2 (me), non-blocking notes from round 1:
adaptcompaction.go:1036literal — fixed.spendexplain.goliterals — fixed.- Missing GPT-5.6+ test case — added (
azure/gpt-5.6-luna, expect 1.25). I tracedGPT56OrLater("azure/gpt-5.6-luna"): lastgpt-token, major 5, minor 6 → true, so 1.25. Correct. - Blank read tier flat 0.1x — the author rejected a change with a reason: no per-family read fraction exists in the repo,
prices.example.yaml, the module cache or the box. I accept the reason. All three price sources (extract_econ.go:131,table.go:92,litellm.go:220) apply 0.1x consistently, so no source disagrees. Gemini's real read rate is a separate issue, as reviewer 1 also noted.
Non-blocking
- Merge gate, still open: the behavior change in commit 2 (blank write tier 1.0x for non-premium families) is named at the top of the PR body. I found no human developer's yes in the PR body or the comments. Per
RELEASING.md, record that yes before merge. TestCacheWrite1hMatchesTheOldBareLiteral's second assertion (CacheWrite1h() - CacheWriteequals2*in - CacheWrite) restates the first. Harmless; it documents the premium form.
What I checked
- Last review: round 1,
fff1938fcdc69249811c8b2cb19cb41babbcd78f, 2026-11-02T10:29:05Z. - New commits read: 1 —
86e260c3"refactor(dash): read the 1-hour write rate from Price.CacheWrite1h". - Read in full: 2 reviews, 3 comments, 0 inline comments (from the three saved files).
- New items since my last review:
- Reviewer 1's round-1 review (posted 34 s before mine, so I read it only now): checked its finding against the code myself, see above.
- Author comment 10:56:49 (seven sites fixed): verified in the diff and by grep.
- Author comment 10:56:51 (read tier stays 0.1x): checked the reason against the three fill sites; accepted.
- Author comment 10:56:53 (GPT-5.6+ test case): verified in the diff and traced the family rule.
- New commit, site by site: every changed line replaces
2 * p.Inputwithp.CacheWrite1h()or the premium form.CacheWrite1h()isInput * AnthropicCacheWrite1hFracwith the constant at 2.0, so each value is bit-identical. The commit touches no logic beyond the rate expression. - New tests:
TestCacheWrite1hMatchesTheOldBareLiteral— arithmetic correct, including thein = 0case. Theazure/gpt-5.6-lunacase — correct perGPT56OrLater. - Imports: the test additions need no new imports; the dash files already import
modelinfo. - I did not run builds or tests. Live tests are not approved for this review.
Behavior change (needs a human developer's yes)
agentRates) priced that write at 1.25x the input rate.ParseTableand the price feed already give (CacheWriteFracFor).cache_writein the price table for the model. Or revert commit 2.Anthropic and GPT-5.6+ values do not change.
Summary
Closes #797. The cache multiples (read 0.1x, 5-minute write 1.25x, 1-hour write 2.0x) now live in
internal/modelinfo. Seven other places read them.What changed
Commit 1, pure refactor, every value the same:
internal/modelinfo/cachefrac.go:AnthropicCacheReadFrac,AnthropicCacheWrite5mFrac,AnthropicCacheWrite1hFrac.modelinfo.go: newPrice.CacheWrite1h().CostWithCacheWrite1huses it.2 * p.Inputsites indash/spendexplain.go(4),adapttools.go,toolsuggest.goandadaptcompaction.gonow callPrice.CacheWrite1h(). A repo-wide grep finds no other bare 2x or2*p.Inputin non-test code.table.go(ParseTable),kvcache/pricing.go(Default*Multiple),dash/cachestate.go,dash/adaptcompaction.go,dash/keepalive.go(two places),components/offload/extract_econ.go,cheapmodel/usage.go,proxy/proxy.goread the constants.Commit 2, behavior:
agentRatesblank write tier follows the model family.Decisions
proxy: stays separate. Its comment holds: the gate prices the traffic it sees, /stats the aggregate. It now reads the shared read multiple. The $3.00 fresh rate is still a local literal.CacheWriteFracFordocs say Gemini and pre-5.6 GPT charge no write premium. So 1.0 wins.Data dependence
No change. Metadata only (token counts and prices).
How it was tested
-raceon the box:./internal/...,./kvcache/...,./components/offload/...,./cheapmodel/...,./dash/...,./proxy/...all pass.gofmt -landgo vetare clean.internal/modelinfo/multiples_test.go(pins 0.1 / 1.25 / 2.0,CacheWrite1h,ParseTabledefaults),dash/cachemultiples_test.go, andTestAgentRatesBlankWriteFollowsTheModelFamily(now with a GPT-5.6+ case at 1.25; fails on the old code for gemini and gpt-5.5).Open questions
kvcache.Multipliersoverride is a per-request query parameter of the simulator page. It is not a deployment setting. So it cannot reach the dashboard or the gate without a new config key. I did not add one. Do we want it?agentRates,ParseTableand the price feed apply 0.1x to every family. I found no per-family read fraction in the repo, its docs, the Go module cache or on the box (no bifrost or LiteLLM price file). Gemini's read rate (about 0.25x per reviewer 1) has no source here. So I kept 0.1x. Which source do we trust for a family read fraction?$3.00 / $0.30agent rates stay as local literals inoffloadandproxy.