Skip to content

feat(prices): price the Bob tiers' 1-hour cache write at the input rate - #970

Merged
amiddavid merged 2 commits into
mainfrom
feat/bob-price-1h-rate
Nov 9, 2026
Merged

amiddavid merged 2 commits into
mainfrom
feat/bob-price-1h-rate

Conversation

@vz-ibm

@vz-ibm vz-ibm commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Behavior change, for operators who install the example price list (deploy/service/prices.example.yaml) and see Bob traffic.

  • Old: Bob's 1-hour cache writes were priced at 2.0x the input rate (the default).
  • New: the 6 Bob tier rows set cache_write_1h_frac: 1.0, so a Bob 1-hour write is priced at the input rate.
  • Who it affects: a Bob row's cost_usd, and the 1-hour figures on the keep-alive and KV-cache pages. The key is on the Bob rows only.
  • The KV-cache simulator's pick changes for Bob too. A 1-hour write now costs the same as a 5-minute one, so it picks write_1h for long holds, and the sticky break-even is 0.
  • The harbor cost model (deploy/harbor) now reads the key too, so its Bob 1-hour rate matches Go.
  • To turn it off: remove cache_write_1h_frac: 1.0 from those rows in your copy of the file.

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 credits field 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

The in and out rates do not change.

Data dependence

None. A price list holds rates, not data.

How it was tested

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 vz-ibm left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_read unset, so a read is priced at 0.1x in (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 - Write5m is now 0 (5m is 1.0x for a non-Claude id, cachefrac.go:54-59; 1h is max(1.0*in, 5m) = in, modelinfo.go:107-108). So sticky1hBreakeven (kvcache/sticky.go:96-103) returns 0, and HistoricalProbability.longHold (kvcache/strategy.go:589-595) picks write_1h unless pings are free. Suggest cells for Bob will now recommend 1h arms. This does not reach live traffic: headTTL1hHonoredModels (proxy/campaign.go:93) holds only aws/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:906 shows {match: "premium*", ...} as an example. The example file dropped premium* 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 set cache_write_1h_frac: 1.0. in/out/note are 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, then Resolved). CacheWrite1h() = max(in*1.0, in) = in. CostWithCacheWrite1h premium = 0, so no 1h surcharge is added (modelinfo.go:140-148). kvcache.FromPrice takes p.Write1hFrac when the user set no 1h multiple (kvcache/pricing.go:123-125) and gets Write1h = in.
  • Resolved keeps Write1hFrac (modelinfo.go:116-120), so Table.Price returns 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-alive spentUSD is 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.Fatalf if 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.md row 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.md requires. A human must still approve it.
  • Docs: reference.md:921-924 and the YAML header already document the key. docs/hosted.md:517 tells 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 vz-ibm left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. 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.yaml as /etc/context-guru/prices.yaml. This is the default --prices path of kv_ttl_cost_model.py, kv_ttl_predictor_arms.py and kv_ttl_keepalive_policy.py (DEFAULT_PRICES, line 697 and kv_ttl_predictor_arms.py:185). For premium at $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_file never 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_1h arms and the longHold port (kv_ttl_predictor_arms.py:123-128) price Bob rows at 2x the Go figure, and their pick between write_1h and ping_5m can differ from the Go simulator.
    • Proof: grep -n "1h_frac" deploy/harbor/*.py returns 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) compares CacheWrite1h() 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, read cache_write_1h_frac per entry (reject a negative value, as table.go:117 does). When it is above 0, use max(input × frac, write_5m) for write_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.

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 picks write_1h, and sticky1hBreakeven (kvcache/sticky.go:102) becomes 0. So StickySession1h commits 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-945 describes the shipped Bob entries. It could say in one line that they set cache_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-126 parses the key and rejects a negative value. Price.Resolved keeps Write1hFrac (modelinfo.go:116-120). CacheWrite1hFor clamps 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 user Write1h multiplier 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 read Write1h.
  • 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 (seen check). 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.md needs no row.
  • LoadTable treats 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]>
@vz-ibm

vz-ibm commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

Round 1: replies

R2-1: the Python price reader ignores cache_write_1h_frac. Fixed in 5f68125a.

  • from_operator_file reads the per-entry key. _derive_write_1h uses max(input × frac, write_5m), the same rule as Go's Price.CacheWrite1hFor. A negative value is rejected, as in table.go.
  • The parity test fixture now has premium (non-Claude) and claude-sonnet-4* (Claude) with the key. Before the fix it failed on the 1-hour field in every case, for example plain "premium" field 4: python 8, go 4. Now it passes.
  • The harbor Python tests and go test ./deploy/harbor/ pass.

Non-blocking: reference.md (R2). Fixed: the Bob tier note says that the tiers set cache_write_1h_frac: 1.0, and why.

Non-blocking: the KV-cache simulator's pick changes for Bob (R1, R2). Correct. With Write1h == Write5m, longHold picks write_1h and the sticky break-even is 0. That is the right answer for a price where a 1-hour write costs the same as a 5-minute one. I will add it to the behavior-change block at the top.

Non-blocking: the reference example premium* (R1). A stale doc from before this PR. Left for a separate change.

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 vz-ibm left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in 5f68125a.
    • from_operator_file reads the key per entry (kv_ttl_cost_model.py:540-541) and rejects a negative value (line 542).
    • _derive_write_1h returns max(input × frac, write_5m) when the entry sets the key (line 575-576). This is the same rule as Price.CacheWrite1hFor (modelinfo.go:107-108).
    • Trace for the fixture row premium (in 4.0, non-Claude): write_5m = 4.0 × 1.0. Python write_1h = max(4.0, 4.0) = 4.0. Go CacheWrite1h() = 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) with cache_write_frac: 1.5: write_5m = 4.5 in both. Python write_1h = max(3.0, 4.5) = 4.5. Go: CacheWrite1h() calls CacheWrite5mFor(""), which returns the resolved CacheWrite = 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 in reference.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.md now 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.override re-derives write_1h without the entry's multiple (kv_ttl_cost_model.py:590-591). An override that changes input but not write_1h on a Bob row gets 2.0x again. Go's Override.Apply (kvcache/pricing.go:173-195) does not re-derive, so the two differ here. No harbor script calls override today (grep -n "\.override(" deploy/harbor/*.py finds only the definition), so nothing fails now.

What I checked

  • Last review: round 1, 1c75849e080710a80d611c840c798d9fdc1a50b7, 2026-11-09T09:08:17Z
  • New commits read: 1 (5f68125a fix(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.md note 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.
  • Read the full diff 1c75849e..5f68125a (3 files, +15/−5), and the code around it: from_operator_file, _derive_write_1h, override, for_model, _lookup in kv_ttl_cost_model.py, and the whole parity test.
  • _lookup and hit() replace only cache_read and model, so the entry's write_1h survives a lookup.
  • The parity test compares the 1-hour field (p.write_1h against CacheWrite1h()), 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 vz-ibm left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in 5f68125a. I checked it myself:
    • kv_ttl_cost_model.py:541 reads the key per entry. Line 542 rejects a negative value, as table.go:117 does.
    • _derive_write_1h (line 575-576) returns max(input × frac, write_5m) when the frac is above 0. This is the same rule as Go's CacheWrite1hFor (modelinfo.go:107-108). Trace for premium at $4.00: Python max(4.00, 4.00) = 4.00. Go max(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 give max(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 through from_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.md Bob note (R2): fixed at docs/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.FromPrice lets a caller-set Multipliers.Write1h win over the entry (kvcache/pricing.go:122-125). In Python, the entry's frac wins over PriceBook(write_1h_multiple=...) (line 575). No Python caller sets write_1h_multiple today (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 (5f68125a fix(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's Override.Apply (kvcache/pricing.go:174-197) also ignores the entry's frac. No difference.
  • An entry with in: 0 and 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).

@vz-ibm

vz-ibm commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator Author

The cache read question

No change to the read rate in this PR.

  • The only price we measured for Bob is in Bobcoins: 2.0 per million tokens, for every token type.
  • We have no measured dollar price for Bob. The in/out dollar rates in the file are estimates, as the file says.
  • The author asked for proof of real prices before any rate changes. So the read rate stays as it is, and this PR keeps only the 1-hour write change.

@amiddavid
amiddavid merged commit f5f6e35 into main Nov 9, 2026
9 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants