Repository navigation
feat(prices): price the Bob tiers' 1-hour cache write at the input rate - #970
Conversation
Bob bills a 1-hour cache write at the input rate (measured on a real Bob account on 2026-11-04). The 6 Bob tier rows in the example price list now set cache_write_1h_frac: 1.0. Without it, the dashboard adds a 2.0x premium Bob does not charge. The pin test from #937 asserted that no shipped row sets the key. It now asserts that exactly the 6 Bob tiers do. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Vitaly Zabershinsky <[email protected]>
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @vz-ibm) | Claude Code 2.1.316 | offload-review skill, @vz-ibm's session | fresh | 1 of 2 | 1 of 2 | 1c75849e0807 |
approve |
Verdict: approve
Findings
None.
Non-blocking
- The PR's own measurement says Bob bills a cache read at the input rate too. The PR body says "2.0 Bobcoins per million tokens for every token type". The Bob rows still leave
cache_readunset, so a read is priced at 0.1xin(modelinfo.go:80-89,CacheReadFracFor). If the measurement is right, the 1h fix is only part of the truth. A 0.1x read rate under-prices keep-alive pings for Bob by 10x (dash/keepalive.go:1148,PingUSDEach = Prefix*CacheRead + Output). It also makes the 5m miss cost look larger than it is (MissUSD = Prefix*(CacheWrite-CacheRead)). This is out of scope for this PR. I propose a follow-up issue, and a human decision, because it changes keep-alive figures for Bob users. - The "Who it affects" line says "Nothing else", but the KV-cache suggest engine also moves. For a Bob tier,
Write1h - Write5mis now 0 (5m is 1.0x for a non-Claude id,cachefrac.go:54-59; 1h ismax(1.0*in, 5m)=in,modelinfo.go:107-108). Sosticky1hBreakeven(kvcache/sticky.go:96-103) returns 0, andHistoricalProbability.longHold(kvcache/strategy.go:589-595) pickswrite_1hunless pings are free. Suggest cells for Bob will now recommend 1h arms. This does not reach live traffic:headTTL1hHonoredModels(proxy/campaign.go:93) holds onlyaws/claude-haiku-4-5, so a campaign does not activate a 1h arm for a Bob tenant. Consider adding "the KV-cache suggestions for Bob now favor the 1-hour arms" to the behavior-change note. - Pre-existing stale doc, not caused by this PR.
docs/reference/reference.md:906shows{match: "premium*", ...}as an example. The example file droppedpremium*for enumerated tiers. A reader may copy the family form the YAML comment warns against.
What I checked
- Read the full diff (2 files, +24/-10) and the commit message.
deploy/service/prices.example.yaml: all 6 Bob rows setcache_write_1h_frac: 1.0.in/out/noteare unchanged. No other row gained the key.KnownFields(true)accepts the key (table.go:65).- Rate math for a Bob tier, by trace:
Price.CacheWrite = in(WriteFrac forced to 1.0 for a non-Claude match,table.go:138-141, thenResolved).CacheWrite1h() = max(in*1.0, in) = in.CostWithCacheWrite1hpremium = 0, so no 1h surcharge is added (modelinfo.go:140-148).kvcache.FromPricetakesp.Write1hFracwhen the user set no 1h multiple (kvcache/pricing.go:123-125) and getsWrite1h = in. ResolvedkeepsWrite1hFrac(modelinfo.go:116-120), soTable.Pricereturns the key on lookup.- All non-test callers of
CacheWrite1h()/CostWithCacheWrite1h(dash, keepalive, tooldefer, kvcache): each is a cost or savings figure. None gates a live request. Keep-alivespentUSDis a counter only. Fail-open is not touched. - The test: it walks every entry, wants 1.0 on exactly the 6 Bob matches and 0 elsewhere, and fails with
t.Fatalfif a Bob row is missing from the file. Match strings are lowercased and have no*, so the map lookup is exact. The test can fail in both directions (a missing key, or a key on a non-Bob row). - Data dependence: none. A price list holds rates. No
docs/data-dependence.mdrow is needed. - Behavior-change note is at the top of the PR body, with who, old, new and how to turn it off, as
CLAUDE.mdrequires. A human must still approve it. - Docs:
reference.md:921-924and the YAML header already document the key.docs/hosted.md:517tells operators to install this file, so this PR does reach hosted operators who copy it again. - I did not run Go tests (not approved, Go not installed).
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (claude, user of @vz-ibm) | Claude Code 2.1.316 | offload-review skill, @vz-ibm's session | fresh | 2 of 2 | 1 of 2 | 1c75849e0807 |
blocking |
Verdict: blocking
Findings
- deploy/harbor/kv_ttl_cost_model.py:531-556 — the Python price reader ignores
cache_write_1h_frac, so the shipped file now gives Go and Python different Bob 1-hour rates- What fails: an operator installs
prices.example.yamlas/etc/context-guru/prices.yaml. This is the default--pricespath ofkv_ttl_cost_model.py,kv_ttl_predictor_arms.pyandkv_ttl_keepalive_policy.py(DEFAULT_PRICES, line 697 andkv_ttl_predictor_arms.py:185). Forpremiumat $3.00/MTok:- Go (
Price.CacheWrite1hFor,modelinfo.go:107-108):max(3.00 × 1.0, 3.00)= $3.00/MTok. - Python (
_derive_write_1h, line 564-576):3.00 × write_1h_multiple (2.0)= $6.00/MTok.from_operator_filenever reads the key. - So the harbor cost model and predictor arms still add the 2.0x premium that this PR removes from the dashboard. The
write_1harms and thelongHoldport (kv_ttl_predictor_arms.py:123-128) price Bob rows at 2x the Go figure, and their pick betweenwrite_1handping_5mcan differ from the Go simulator.
- Go (
- Proof:
grep -n "1h_frac" deploy/harbor/*.pyreturns nothing. The module docstring (line 66) says the file is "parsed with the same rules as internal/modelinfo/table.go".TestPythonPriceReaderMatchesGoTable(deploy/harbor/kv_ttl_price_parity_test.go:17) comparesCacheWrite1h()but its fixture has no row with the key, so it cannot catch the gap. The gap came in with #937, but no shipped row set the key until this PR. This PR makes it reachable. - Fix: in
from_operator_file, readcache_write_1h_fracper entry (reject a negative value, astable.go:117does). When it is above 0, usemax(input × frac, write_5m)forwrite_1h. Add a row such as{match: "premium", in: 4.0, out: 20.0, cache_write_1h_frac: 1.0}to the parity test fixture.
- What fails: an operator installs
Non-blocking
- The cited measurement may also cover cache reads. The PR body says Bob billed "2.0 Bobcoins per million tokens for every token type". If "every token type" includes cache reads, the Bob rows still price a read at 0.1x input (
CacheReadFracFor("premium")). That would overstate the prefix-cache saving on Bob rows. Please say in the PR whether the measurement saw cache reads, and whether they cost 1.0x. - The KV-cache simulator's pick changes for Bob, not only its figures. With
Write1h == Write5m,longHold(kvcache/strategy.go:589-595) always pickswrite_1h, andsticky1hBreakeven(kvcache/sticky.go:102) becomes 0. SoStickySession1hcommits to 1h for any reuse above 0. This is the right result for a flat rate. The PR's behavior-change note says "1-hour figures"; it could also say the suggested strategy can change for Bob rows. docs/reference/reference.md:935-945describes the shipped Bob entries. It could say in one line that they setcache_write_1h_frac: 1.0, and why.
What I checked
- Read the full diff (2 files, +24/−10) and the commit message.
- YAML rows: all 6 Bob tiers set
cache_write_1h_frac: 1.0.openai/gpt-oss-20b(a Bob auxiliary model) does not. That matches the test and the PR text. - Go path:
table.go:117-126parses the key and rejects a negative value.Price.ResolvedkeepsWrite1hFrac(modelinfo.go:116-120).CacheWrite1hForclamps to the 5-minute rate. Bob matches are not Claude ids, so the 5-minute rate is 1.0x input and the 1-hour rate is exactly the input rate. kvcache.FromPrice(kvcache/pricing.go:116-156): an unset userWrite1hmultiplier lets the entry's 1.0 win. A user-set multiplier still overrides it. Consistent with the PR's "turn it off" note.- Readers of the 1-hour rate:
keepalive/keeper.go:1767,keepalive/substitute.go:256,310,tooldefer/ledger.go:57,dash/*,kvcache/sticky.go,kvcache/strategy.go. Keep-alive gates and the ping-cost ceiling (keeper.go:1083) use the read and output rates, not the 1-hour rate. So no live proxy decision changes; only reported costs and the dashboard simulator change. Proxy-side kvcache users (proxy/campaign*.go,proxy/predictive.go,proxy/adaptcache.go) do not readWrite1h. - The rewritten test: it fails when a Bob row loses the key, when a non-Bob row gains it, and when a Bob row is renamed (
seencheck). Its assertions are exact values. - Fail open and data dependence: a price list holds rates only. No component path, marker or store use changes.
docs/data-dependence.mdneeds no row. LoadTabletreats a malformed file as a startup error; the new key is valid YAML in the existing flow-map rows.- I did not run Go or Python tests (live tests not approved).
The Python cost model ignored an entry's cache_write_1h_frac, so for a Bob tier it priced the 1-hour write at 2.0x input while Go priced it at 1.0x. The reader now applies the entry's multiple with the Go rule, max(input x frac, 5-minute rate), and rejects a negative value. The parity test fixture now has a non-Claude row and a Claude row with the key. It failed on the 1-hour field before the fix. docs/reference/reference.md: the Bob tiers set the key, and why. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: Vitaly Zabershinsky <[email protected]>
Round 1: repliesR2-1: the Python price reader ignores
Non-blocking: Non-blocking: the KV-cache simulator's pick changes for Bob (R1, R2). Correct. With Non-blocking: the reference example Open: does Bob bill a cache read at the input rate too? (R1, R2). Both of you raise this, and you are right that the measurement says "every token type". This PR only changes the 1-hour write. I have asked the author whether the read rate should change here too. I will answer in round 2. |
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (claude, user of @vz-ibm) | Claude Code 2.1.316 | offload-review skill, @vz-ibm's session | resumed | 2 of 2 | 2 of 2 | 5f68125a28ad |
approve |
Verdict: approve
Findings
None.
Earlier findings
- R2-1 (Python price reader ignores
cache_write_1h_frac): fixed in5f68125a.from_operator_filereads the key per entry (kv_ttl_cost_model.py:540-541) and rejects a negative value (line 542)._derive_write_1hreturnsmax(input × frac, write_5m)when the entry sets the key (line 575-576). This is the same rule asPrice.CacheWrite1hFor(modelinfo.go:107-108).- Trace for the fixture row
premium(in 4.0, non-Claude):write_5m= 4.0 × 1.0. Pythonwrite_1h= max(4.0, 4.0) = 4.0. GoCacheWrite1h()= max(4.0, 4.0) = 4.0. Before the fix Python gave 8.0, as the author's reply says. - Trace for
claude-sonnet-4*(in 3.0, Claude) withcache_write_frac: 1.5:write_5m= 4.5 in both. Pythonwrite_1h= max(3.0, 4.5) = 4.5. Go:CacheWrite1h()callsCacheWrite5mFor(""), which returns the resolvedCacheWrite= 4.5. Same. So the test covers the 5-minute floor in all 4 header cases.
- R1 had no findings. Its non-blocking points:
- The KV-cache pick changes for Bob: the PR body now says so (checked the current body).
- The stale
premium*example inreference.md:906: the author left it for a later change. Accepted. It is older than this PR. - The cache-read rate for Bob: see "Non-blocking".
- My round-1 non-blocking points:
reference.mdnow notes the key on the Bob tiers (line 939-940). The behavior-change note now names the simulator pick change and the harbor change.
Non-blocking
- The cache-read question is still open. The author's reply says they asked whether Bob also bills a cache read at the input rate, and will answer in round 2. I found no answer yet in the reviews, comments or PR body. This PR changes only the 1-hour write, so it is not a blocker for this PR. Please record the answer, or a follow-up issue, before merge.
PriceBook.overridere-deriveswrite_1hwithout the entry's multiple (kv_ttl_cost_model.py:590-591). An override that changesinputbut notwrite_1hon a Bob row gets 2.0x again. Go'sOverride.Apply(kvcache/pricing.go:173-195) does not re-derive, so the two differ here. No harbor script callsoverridetoday (grep -n "\.override(" deploy/harbor/*.pyfinds only the definition), so nothing fails now.
What I checked
- Last review: round 1,
1c75849e080710a80d611c840c798d9fdc1a50b7, 2026-11-09T09:08:17Z - New commits read: 1 (
5f68125afix(harbor): read cache_write_1h_frac in the Python price reader) - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review:
- Comment by vz-ibm at 2026-11-09T09:28:29Z (round-1 replies). I checked each reply against the code: R2-1 fixed,
reference.mdnote added, simulator note added to the PR body,premium*example deferred (accepted), cache-read question still open (noted above). - The PR body change (behavior-change block). I read the current body. It now names the simulator pick change and the harbor change.
- Comment by vz-ibm at 2026-11-09T09:28:29Z (round-1 replies). I checked each reply against the code: R2-1 fixed,
- Read the full diff
1c75849e..5f68125a(3 files, +15/−5), and the code around it:from_operator_file,_derive_write_1h,override,for_model,_lookupinkv_ttl_cost_model.py, and the whole parity test. _lookupandhit()replace onlycache_readandmodel, so the entry'swrite_1hsurvives a lookup.- The parity test compares the 1-hour field (
p.write_1hagainstCacheWrite1h()), with a non-Claude row and a Claude row that set the key, and with 4 file headers. - Fail open and data dependence: no change. The commit touches an offline analysis script, a test and a doc.
- I did not run Go or Python tests (live tests not approved).
vz-ibm
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @vz-ibm) | Claude Code 2.1.316 | offload-review skill, @vz-ibm's session | resumed | 1 of 2 | 2 of 2 | 5f68125a28ad |
approve |
Verdict: approve
Findings
None.
Status of round-1 items
- Reviewer 2, finding 1 (Python reader ignores
cache_write_1h_frac): fixed in5f68125a. I checked it myself:kv_ttl_cost_model.py:541reads the key per entry. Line 542 rejects a negative value, astable.go:117does._derive_write_1h(line 575-576) returnsmax(input × frac, write_5m)when the frac is above 0. This is the same rule as Go'sCacheWrite1hFor(modelinfo.go:107-108). Trace forpremiumat $4.00: Pythonmax(4.00, 4.00)= 4.00. Gomax(4.00, 4.00)= 4.00. Before the fix, Python gave 8.00, as the author's quoted failure says.- Trace for the new Claude row
claude-sonnet-4*at $3.00, plain head: 5-minute rate is 1.25 × 3.00 = 3.75. Python and Go both givemax(3.00, 3.75)= 3.75. So the fixture also tests the clamp to the 5-minute rate. Good choice. - The parity test compares
CacheWrite1h()(field 4) for both new ids under all 4 file heads. It can fail in both directions. - All 3 Python callers of the file (
kv_ttl_cost_model.py:1766,kv_ttl_predictor_arms.py:503,kv_ttl_keepalive_policy.py:818) go throughfrom_operator_file, so all get the fix.
- Non-blocking, the KV-cache pick changes for Bob (R1, R2): fixed. The behavior-change block now says it.
- Non-blocking,
reference.mdBob note (R2): fixed atdocs/reference/reference.md:938-939. - Non-blocking, stale
premium*example (R1): rejected for this PR, left for a separate change. I accept this. It is old text, not caused by this PR. - Open, does Bob bill a cache read at the input rate too? (R1, R2): the author says it is out of scope and that they asked the author of the measurement. No answer is on the PR yet. This does not block: this PR does not change the read rate. Please record the answer, or open an issue, before or after merge.
Non-blocking
- The precedence between the entry's key and a caller's own 1-hour multiple differs between Python and Go. In Go,
kvcache.FromPricelets a caller-setMultipliers.Write1hwin over the entry (kvcache/pricing.go:122-125). In Python, the entry's frac wins overPriceBook(write_1h_multiple=...)(line 575). No Python caller setswrite_1h_multipletoday (only the default, line 1706), so no output differs now. If someone adds a CLI flag for it later, the two will disagree. One line in the docstring would warn them.
What I checked
- Last review: round 1,
1c75849e080710a80d611c840c798d9fdc1a50b7, 2026-11-09T09:07:48Z - New commits read: 1 (
5f68125afix(harbor): read cache_write_1h_frac in the Python price reader) - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review:
- Reviewer 2 round-1 review (09:08:17Z): read it. Its finding 1 is fixed, see above. Its non-blocking points match mine and are handled above.
- Author's "Round 1: replies" comment (09:28:29Z): checked each reply. I accept each one, see "Status of round-1 items".
- PR body: the behavior-change block now names the simulator pick change and the harbor change.
- Read the full diff
1c75849e..5f68125a(3 files, +15/-5) and the code around it:from_operator_file,_derive_write_1h,override, and the whole parity test. PriceBook.override(line 586-596) calls_derive_write_1h(p)with no entry frac. An override replaces the rates by hand, and Go'sOverride.Apply(kvcache/pricing.go:174-197) also ignores the entry's frac. No difference.- An entry with
in: 0and a frac: Python and Go both fall back to the 5-minute rate. - Fail open and data dependence: no change. The change is in an offline harbor script and a doc.
- I did not run Go or Python tests (live tests not approved, Go not installed).
The cache read questionNo change to the read rate in this PR.
|
Summary
Bob bills a 1-hour cache write at the input rate. This PR makes the example price list say so, with the per-entry key from #937.
What we found
On a real Bob account (2026-11-04), a 1-hour cache write cost the same as fresh input: 2.0 Bobcoins per million tokens for every token type. Bob's own
creditsfield matched that rate on 20 calls, and so did the account total.Without the key, the dashboard adds a 2.0x premium that Bob does not charge.
What changed
deploy/service/prices.example.yaml:cache_write_1h_frac: 1.0onpremium,premium-ide,standard,standard-ide,fastandfast-ide, with a one-line reason.internal/modelinfo/write1hfrac_test.go: the pin test from fix(modelinfo): keep the 1-hour cache-write rate; set it per model #937 said that no shipped row sets the key. That was the intent of fix(modelinfo): keep the 1-hour cache-write rate; set it per model #937 alone. It now says that exactly the 6 Bob tiers set it, and no other row does.The
inandoutrates do not change.Data dependence
None. A price list holds rates, not data.
How it was tested
TestShippedPriceListSetsTheOneHourRateOnTheBobTiersOnlypasses. I checked that it fails when one Bob row is missing the key (fast-ide: Write1hFrac = 0, want 1).go test ./kvcache/ ./dash/ ./keepalive/: OK.go test ./internal/modelinfo/: all pass exceptTestRateFillTableAndPrice. It fails the same way on cleanmain(test: TestRateFillTableAndPrice fails on main (exact float strings since #860) #969).