Repository navigation
fix(metrics): Price the 1-hour write tier in the miss cost, and define the miss cost in the spec - #1271
Merged
Conversation
…e the miss cost in the spec llm.cache.miss_cost.usd priced every written token at the 5-minute write rate. A token billed at the 1-hour tier costs more, so the premium of a miss with 1-hour writes was too low. missCostUSD now adds the 1-hour premium (Price.CacheWrite1hPremium) on the CacheWrite1h part of the write. docs/metrics/spec.md 5.4 now states the miss cost formula, what counts as a miss, the order of causes, and the rule for a model with no rate, so every proxy that pushes to the central stack books the same figure. Refs #1270 Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
commented
Nov 22, 2026
boazdavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @boazdavid) | Claude Code 2.1.241 | offload-review skill, @boazdavid's session | fresh | 1 of 2 | 1 of 2 | 296d68a50c3f |
blocking |
Verdict: blocking
The code change is correct. The new spec text has one false rule, and other proxies will copy it.
Findings
- docs/metrics/spec.md:371 — "It does not use a fallback rate" is false for a non-Claude model with no stated read rate
- What fails: Take a non-Claude model whose price states
inputbut nocache_read.missCostUSDcallsp.Resolved(e.Model)(proxy/inferencemetrics.go:261).ResolvedfillsCacheReadfromCacheReadFor, which returnsInput * CacheReadFracFor(model). That is the Anthropic 0.1x guess, andResolvedmarks itCacheReadFallback(#1248). So context-guru books a miss cost that uses a fallback read rate. A second proxy (Cortex, #1270) that follows the spec books a different figure, or no figure. The PR's stated goal, "every proxy books the same figure", then fails for this case. - Proof:
internal/modelinfo/modelinfo.go:137-142(Resolved),:97-105(CacheReadForfalls through toCacheReadFracFor),internal/modelinfo/cachefrac.go:95-112(returnsAnthropicCacheReadFracfor any unmatched model). The write side falls back too:CacheWrite5mForusesCacheWriteFracFor(model)when no rate is stated (modelinfo.go:110-118). - Fix: Make the spec say what the code does. For example: "A model with no price counts the miss and books no money. A tier rate that the price leaves blank comes from the model's standard multiple of the input rate, as
modelinforesolves it (#1248)." Or change the code to skip the money whenp.CacheReadFallbackis set. That second option is a behavior change and needs a human's yes.
- What fails: Take a non-Claude model whose price states
Non-blocking
proxy/inferencemetrics_test.go:261:wantcallsp.CacheWrite1hPremium(), the same function the code calls. If that function regresses to 0, the test still passes, because both sides lose the term. Write the number:400 * (6e-6 - 3.75e-6).docs/metrics/spec.md:367-368: the spec namescache_write_1h_ratebut does not say where it comes from. No gateway states it. context-guru derives it as 2.0x input, or the operator'sWrite1hFrac, and never below the 5-minute rate (CacheWrite1hFor). Another proxy needs this rule to book the same figure.docs/metrics/spec.md:359: rule 6 (prefix_change) applies in code only when the request wrote tokens. A changed prefix with no write isother(dash/event.go:1243-1246). The same holds for causes 3-5. Rule 7 covers it as "anything else", but one clause would make it exact.- The PR names the behavior change at the top, as
CLAUDE.mdasks. A human developer must still give the yes before merge.
What I checked
- Read the full diff (3 files, one commit) and the commit message. Sign-off and
Assisted-Byare present. missCostUSD(proxy/inferencemetrics.go:253-270): the 5-minute term and the 1-hour term are each clamped at 0.min(CacheWrite1h, CacheWrite)guards a bad row.CacheWrite1his a subset ofCacheWrite(dash/event.go:317-331), so the formula does not count a token twice.ResolvedkeepsWrite1hFrac, soCacheWrite1hPremium()afterResolvedgives the same premium asEvent.CostUSD(CostWithCacheWrite1h) anddash/spendexplain.go:386-390. The figures agree.- Test arithmetic: with
Input3e-6, the 1-hour rate is 6e-6 and the premium is 2.25e-6. Old code gives 0.00345, new code 0.00435. This matches the failure the PR body quotes. - Spec order of causes against
missCause(proxy/inferencemetrics.go:275-297) andAttributeCache(dash/event.go:1229-1248): cold_start, then ttl_expiry, then the stored cause. They match. "First request of the thread" matchesseenSession, which is per thread (dash/capture.go:683). - "Keep-alive pings are never misses":
Observereturns afterobservePing(proxy/inferencemetrics.go:123-126). - Fail open:
Observerecovers from a panic. The change adds no new error path. - Data dependence: the change uses token counts and rates only. No component or feature row changes, so no row file or generated page is needed.
- Dashboards and recording rules read
llm_cache_miss_cost_usd_totalby name only. No query needs a change. - I did not run Go tests. Live tests are not approved.
boazdavid
commented
Nov 22, 2026
boazdavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (claude, user of @boazdavid) | Claude Code 2.1.241 | offload-review skill, @boazdavid's session | fresh | 2 of 2 | 1 of 2 | 296d68a50c3f |
approve |
Verdict: approve
Findings
None.
Non-blocking
- proxy/inferencemetrics_test.go:261 — the test computes
wantwith the helper it tests.wantusesp.CacheWrite1hPremium(). A bug in that helper changesgotandwantthe same way, so the test still passes. A literal value is stronger:want := 0.00345 + 0.0009(400 x (6e-6 - 3.75e-6), fromAnthropicCacheWrite1hFrac= 2.0). The PR body already states 0.00435. - proxy/inferencemetrics.go:267 — no test covers the
min(CacheWrite1h, CacheWrite)clamp. A test withCacheWrite1h>CacheWritewould pin the clamp. The clamp is correct as written. - docs/metrics/spec.md:370 — "Each term is never below zero" is not the same as "the premium is never below zero". If a price feed states a read rate above the 5-minute write rate, the first term is 0. The second term then books (1h - 5m) on the 1-hour tokens, which is more than (1h - read). Real feeds do not do this. If you want the formula to be exact for that case, clamp the sum for the 1-hour part at (1h - read). This is a note only.
What I checked
- I read the full diff (3 files, 1 commit) and the commit message.
missCostUSD(proxy/inferencemetrics.go:253-270):- After
Resolved,p.CacheWriteis the 5-minute rate (CacheWrite5mFor).CacheWrite1hPremium=CacheWrite1hFor("")-CacheWrite, clamped at 0 (internal/modelinfo/modelinfo.go:124-193). - So a 1-hour token pays (5m - read) + (1h - 5m) = (1h - read). A 5-minute token pays (5m - read). This is the write premium over a read, as the spec says.
ResolvedkeepsWrite1hFrac, so an operator's 1-hour rate still applies.- This agrees with dash/keepalive.go:1280-1284. There,
MissUSDuses (5m - read) andmiss1huses (1h - read). CacheWrite1his a subset ofCacheWrite(internal/providerusage/providerusage.go:15). Theminguards a bad count. The token counter at proxy/inferencemetrics.go:149-150 uses the same split.- An unpriced model still returns 0 (
!ok).CacheWrite <= 0still returns 0.TestUnpricedMissBooksNoMoneystill covers this. - A non-Claude model has no
CacheWrite1h, so the new term adds nothing for it.
- After
- Fail open:
Observekeeps itsrecover. The new code makes no call that can fail. It does not touch the request path. - Spec 5.4 against the code:
- "What counts as a miss":
missCausereturns no miss forhitand for an empty reason. Pings return beforeobserveCacheMiss(proxy/inferencemetrics.go:123-126). The partial-read rule (#496) is inAttributeCache(dash/event.go:1227-1230). - Cause order:
AttributeCachesetscold_startbeforettl_expiry(dash/event.go:1233-1236).missCausethen mapsmodel_changed,compaction_after_rewrite,bypass_flip, then tools/system/effort toprefix_change, elseother(proxy/inferencemetrics.go:276-295). The spec list has the same order. - "First request of the thread":
ObserveThreadkeys on the thread (proxy/dashcapture.go:850-864), andCauseFirstOnModelmaps tocold_start. This matches. - "Effort or thinking settings":
CauseEffortChangedcovers effort, thinking mode and thinking budget (dash/event.go:53). concurrentmaps toother, as the spec says.
- "What counts as a miss":
- The new test value: 1000 x 3.45e-6 + 400 x 2.25e-6 = 0.00435. This matches the PR body.
- Other readers of the metric: deploy/central/grafana/dashboards/cache.json:177 sums it by cause. The panel needs no change.
- Behavior change: the PR names it at the top (who, old, new, how to turn it off), as CLAUDE.md asks. A human developer must still say yes before merge.
- Data dependence: the cost uses token counts and rates only. The PR changes no component or feature data dependence, so no row file is needed.
- I did not run Go builds or tests. Live tests are not approved for this review.
…he rate rules in the spec Review round 1 of #1271: - The spec said the miss cost uses no fallback rate. That is false: Price.Resolved fills a blank tier rate from the model's standard multiple of its input rate (#1248). The spec now states this rule, and where the 1-hour rate comes from. - A 1-hour token now pays (1-hour rate - read rate), the same split dash/keepalive.go uses for a lapse. Before, it paid (5m - read) plus (1h - 5m), which is wrong when a feed states a read rate above the 5-minute write rate. - The spec says rules 3 to 6 of the cause order apply only when the request wrote cache tokens. - The test uses a literal expected value, and a new test covers the clamp of CacheWrite1h to CacheWrite. Refs #1270 Assisted-By: Claude Opus 5.5 Signed-off-by: DAVID BOAZ <[email protected]>
Collaborator
Author
|
Replies to round 1. All fixes are in Reviewer 1
Reviewer 2
Tests: |
boazdavid
commented
Nov 22, 2026
boazdavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (claude, user of @boazdavid) | Claude Code 2.1.241 | offload-review skill, @boazdavid's session | resumed | 1 of 2 | 2 of 2 | 8f6d9bc804bc |
approve |
Verdict: approve
All round-1 findings are fixed. The new commit is correct.
Findings
None.
Earlier findings
- Reviewer 1, finding 1 (spec says "no fallback rate"): fixed.
docs/metrics/spec.md:374now states thePrice.Resolvedrule (#1248). It matchesCacheReadForandCacheWrite5mFor. The fix is in the spec only, so the code behavior for this case does not change. - Reviewer 1, non-blocking 1 (test uses the helper for
want): fixed.wantis a literal atproxy/inferencemetrics_test.go:262. - Reviewer 1, non-blocking 2 (source of the 1-hour rate): fixed. The spec text matches
CacheWrite1hFor(internal/modelinfo/modelinfo.go:124-129):Write1hFracx input, never below the 5-minute rate, else 2.0x input. - Reviewer 1, non-blocking 3 (rules 3-6 need a write): fixed.
docs/metrics/spec.md:362matchesAttributeCache(dash/event.go:1243-1247). There, a cause is stored only in thedefaultbranch, after theCacheWrite <= 0case. - Reviewer 2, non-blocking 1 (helper in
want): fixed, the same change as above. - Reviewer 2, non-blocking 2 (no clamp test): fixed.
TestMissCostClampsTheOneHourPartToTheWritesets 5000 of 1000. The expected value is 1000 x (6e-6 - 0.3e-6) = 0.0057. Code trace:w1h= 1000, the 5-minute term = 0 x ... = 0, and the 1-hour term = 1000 x 5.7e-6. That matches. - Reviewer 2, non-blocking 3 (clamp of each term): fixed in code. A 1-hour token now pays
CacheWrite1h() - CacheRead, clamped at 0 (proxy/inferencemetrics.go:268). This is the same split asdash/keepalive.go:1280-1283(MissUSD,miss1h). For a feed with 1h >= 5m >= read, the figure is the same as at296d68a5: (5m - read) + (1h - 5m) = (1h - read).
Non-blocking
proxy/inferencemetrics.go:268: suppose a price states cache rates but noinputrate, and the operator sets noWrite1hFrac. ThenCacheWrite1h()is 0, and 1-hour tokens book no miss cost. At296d68a5they booked (5m - read). The spec text says the same thing as the code ("2.0x the input rate"), so this is not a defect. Real Claude prices stateinput.dash/spendexplain.go:386-390still uses the old split,write x (5m - read) + write1h x (1h - 5m), and it clamps only the sum. It gives the same figure for real feeds. It is not in this PR.
What I checked
- Last review: round 1, 296d68a, 2026-11-22T13:24:36Z
- New commits read: 1 (
8f6d9bc8fix(metrics): Price each 1-hour write token above a read, and state the rate rules in the spec) - 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 (13:25:17Z): I checked each of its 3 non-blocking points against the new commit. All are fixed. See "Earlier findings".
- Author reply comment (13:29:55Z): I checked each of its 7 replies against the diff. Each claim is true.
- Commit
8f6d9bc8: I read the full diff of all 3 files and the code around it.
missCostUSD(proxy/inferencemetrics.go:254-272):w1his clamped to [0,CacheWrite]. The 5-minute part isCacheWrite - w1h, so no token is priced twice. Each part is clamped at 0. An unpriced model and a zero write still return 0.ResolvedkeepsWrite1hFracand setsCacheWriteto the 5-minute rate. SoCacheWrite1h()=CacheWrite1hFor("")gives the rate that the spec states.- Test arithmetic: 600 x 3.45e-6 + 400 x 5.7e-6 = 0.00207 + 0.00228 = 0.00435. This is the same figure as at
296d68a5. - Spec 5.4 formula and bullets against the code: they match.
- Commit has DCO sign-off and
Assisted-By. - Fail open: no new error path.
Observekeeps itsrecover. - Data dependence: token counts and rates only. No row change is needed.
- Behavior change: the PR body names it at the top. A human developer must still say yes before merge.
- I did not run Go tests. Live tests are not approved.
boazdavid
commented
Nov 22, 2026
boazdavid
left a comment
Collaborator
Author
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (claude, user of @boazdavid) | Claude Code 2.1.241 | offload-review skill, @boazdavid's session | resumed | 2 of 2 | 2 of 2 | 8f6d9bc804bc |
approve |
Verdict: approve
Findings
None.
Status of earlier findings
Reviewer 1
- Blocking, "It does not use a fallback rate" is false: fixed. The spec now says that a blank tier rate is the model's standard multiple of its input rate (
Price.Resolved, #1248). This matchesCacheReadForandCacheWrite5mFor(internal/modelinfo/modelinfo.go:98-118). The author changed the spec, not the code, so this fix adds no behavior change. - Non-blocking,
wantuses the helper: fixed. See my item 1. - Non-blocking, the source of the 1-hour rate: fixed. The spec text matches
CacheWrite1hFor(modelinfo.go:124-129):Write1hFracx input, never below the 5-minute rate, elseAnthropicCacheWrite1hFrac(2.0, cachefrac.go:78) x input. - Non-blocking, rules 3 to 6 need a write: fixed.
AttributeCachesetsCacheUnknownwith no stored cause whenCacheWrite <= 0(dash/event.go:1241-1244).missCausethen returnsother.concurrentis stored before that check, but it maps toother(rule 7), so the new sentence is exact.
Reviewer 2 (mine)
wantuses the helper it tests: fixed.wantis now a literal: 600 x 3.45e-6 + 400 x 5.7e-6 = 0.00435. This is the same figure as before.- No test for the clamp: fixed.
TestMissCostClampsTheOneHourPartToTheWritesetsCacheWrite1h= 5000 on 1000 written tokens. The code clampsw1hto 1000, so the 5-minute part is 0 andwant= 1000 x 5.7e-6. This is correct. - "Each term is never below zero": fixed. A 1-hour token now pays (1h - read) and a 5-minute token pays (5m - read). Each is clamped at 0. The formula in the spec matches the code, and it matches
dash/keepalive.go:1280-1284.
Non-blocking
- proxy/inferencemetrics.go:268 — a price with no input rate now books $0 for 1-hour tokens.
CacheWrite1h()isInput x 2.0whenWrite1hFracis 0. IfInputis 0, then (1h - read) is below 0, so the 1-hour part books nothing. The round-1 code booked (5m - read) for those tokens. Real gateway prices always state an input rate, and the spec rule as written gives the same 0. So this is a note only. If you want a floor, usemax(p.CacheWrite1h(), p.CacheWrite).
What I checked
- Last review: round 1, 296d68a, 2026-11-22T13:25:17Z
- New commits read: 1
8f6d9bc8fix(metrics): Price each 1-hour write token above a read, and state the rate rules in the spec
- Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files)
- New items since my last review:
- Reviewer 1's round-1 review (13:24:36Z). I had not read it before. I checked each of its 4 items against the new commit. All 4 are fixed (see above).
- The author's reply comment (13:29:55Z). I checked each reply against the diff and the code. Each claim is true.
- Commit
8f6d9bc8. I read the full diff of the 3 files and the code around it.
missCostUSD(proxy/inferencemetrics.go:254-272):w1h = min(max(CacheWrite1h, 0), CacheWrite)guards a negative count and a count above the write.CacheWrite - w1his never below 0, so no token is priced twice and no token is lost.- After
Resolved,p.CacheWriteis the 5-minute rate.ResolvedkeepsWrite1hFrac, soCacheWrite1h()gets the operator's 1-hour rate. - An unpriced model and
CacheWrite <= 0still return 0.
- Fail open:
Observekeeps itsrecover. The change adds no new error path and does not touch the request path. - Behavior change: the PR body names it at the top. For real feeds, the figure is the same as in round 1. A human developer must still say yes before merge.
- Data dependence: the cost uses token counts and rates only. No row file is needed.
- I did not run Go builds or tests. Live tests are not approved for this review.
This was referenced Nov 22, 2026
Merged
boazdavid
added a commit
to rossoctl/cortex
that referenced
this pull request
Nov 23, 2026
Add the metrics push. core/accounting/push posts the llm.savings, llm.proxy.info, llm.inference, llm.keepalive and llm.cache counters over OTLP/HTTP, priced by the same accounting.USD the ledger uses. metrics.go holds the Sink and its counters; labels.go names the label values, with cortex pings labelled by outcome and cache misses by cause. core/config carries the metrics_push block (metricspush), validated and reload-guarded. cmd/cortex and cmd/cortex-envoy start the push with the accountant host and flush it on shutdown. The host options are shared through accounting.OptionsFrom so both binaries wire the sink the same way. .github/workflows/build.yaml passes the VERSION build-arg so the push can send service.version. The push has no default URL: nothing leaves the machine until a user sets one. A bad URL warns and turns the push off; accounting fails open. llm.cache.miss_cost_usd books the write premium of a cache miss, not its whole price, as the shared contract defines it (context-guru docs/metrics/spec.md 5.4, rossoctl/context-guru#1271): (CacheWrite - CacheWrite1h) x (write_5m - read) + CacheWrite1h x (write_1h - read). The miss cause follows the spec's order: cold_start, ttl_expiry, model_changed (only when the request wrote cache tokens), other. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
added a commit
to boazdavid/cortex
that referenced
this pull request
Nov 23, 2026
Add the metrics push. core/accounting/push posts the llm.savings, llm.proxy.info, llm.inference, llm.keepalive and llm.cache counters over OTLP/HTTP, priced by the same accounting.USD the ledger uses. metrics.go holds the Sink and its counters; labels.go names the label values, with cortex pings labelled by outcome and cache misses by cause. core/config carries the metrics_push block (metricspush), validated and reload-guarded. cmd/cortex and cmd/cortex-envoy start the push with the accountant host and flush it on shutdown. The host options are shared through accounting.OptionsFrom so both binaries wire the sink the same way. .github/workflows/build.yaml passes the VERSION build-arg so the push can send service.version. The push has no default URL: nothing leaves the machine until a user sets one. A bad URL warns and turns the push off; accounting fails open. llm.cache.miss_cost_usd books the write premium of a cache miss, not its whole price, as the shared contract defines it (context-guru docs/metrics/spec.md 5.4, rossoctl/context-guru#1271): (CacheWrite - CacheWrite1h) x (write_5m - read) + CacheWrite1h x (write_1h - read). The miss cause follows the spec's order: cold_start, ttl_expiry, model_changed (only when the request wrote cache tokens), other. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
added a commit
to boazdavid/cortex
that referenced
this pull request
Nov 23, 2026
Add the metrics push. core/accounting/push posts the llm.savings, llm.proxy.info, llm.inference, llm.keepalive and llm.cache counters over OTLP/HTTP, priced by the same accounting.USD the ledger uses. metrics.go holds the Sink and its counters; labels.go names the label values, with cortex pings labelled by outcome and cache misses by cause. core/config carries the metrics_push block (metricspush), validated and reload-guarded. cmd/cortex and cmd/cortex-envoy start the push with the accountant host and flush it on shutdown. The host options are shared through accounting.OptionsFrom so both binaries wire the sink the same way. .github/workflows/build.yaml passes the VERSION build-arg so the push can send service.version. The push has no default URL: nothing leaves the machine until a user sets one. A bad URL warns and turns the push off; accounting fails open. llm.cache.miss_cost_usd books the write premium of a cache miss, not its whole price, as the shared contract defines it (context-guru docs/metrics/spec.md 5.4, rossoctl/context-guru#1271): (CacheWrite - CacheWrite1h) x (write_5m - read) + CacheWrite1h x (write_1h - read). The miss cause follows the spec's order: cold_start, ttl_expiry, model_changed (only when the request wrote cache tokens), other. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
added a commit
to boazdavid/cortex
that referenced
this pull request
Nov 24, 2026
Add the metrics push. core/accounting/push posts the llm.savings, llm.proxy.info, llm.inference, llm.keepalive and llm.cache counters over OTLP/HTTP, priced by the same accounting.USD the ledger uses. metrics.go holds the Sink and its counters; labels.go names the label values, with cortex pings labelled by outcome and cache misses by cause. core/config carries the metrics_push block (metricspush), validated and reload-guarded. cmd/cortex and cmd/cortex-envoy start the push with the accountant host and flush it on shutdown. The host options are shared through accounting.OptionsFrom so both binaries wire the sink the same way. .github/workflows/build.yaml passes the VERSION build-arg so the push can send service.version. The push has no default URL: nothing leaves the machine until a user sets one. A bad URL warns and turns the push off; accounting fails open. llm.cache.miss_cost_usd books the write premium of a cache miss, not its whole price, as the shared contract defines it (context-guru docs/metrics/spec.md 5.4, rossoctl/context-guru#1271): (CacheWrite - CacheWrite1h) x (write_5m - read) + CacheWrite1h x (write_1h - read). The miss cause follows the spec's order: cold_start, ttl_expiry, model_changed (only when the request wrote cache tokens), other. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
added a commit
to boazdavid/cortex
that referenced
this pull request
Nov 24, 2026
Add the metrics push. core/accounting/push posts the llm.savings, llm.proxy.info, llm.inference, llm.keepalive and llm.cache counters over OTLP/HTTP, priced by the same accounting.USD the ledger uses. metrics.go holds the Sink and its counters; labels.go names the label values, with cortex pings labelled by outcome and cache misses by cause. core/config carries the metrics_push block (metricspush), validated and reload-guarded. cmd/cortex and cmd/cortex-envoy start the push with the accountant host and flush it on shutdown. The host options are shared through accounting.OptionsFrom so both binaries wire the sink the same way. .github/workflows/build.yaml passes the VERSION build-arg so the push can send service.version. The push has no default URL: nothing leaves the machine until a user sets one. A bad URL warns and turns the push off; accounting fails open. llm.cache.miss_cost_usd books the write premium of a cache miss, not its whole price, as the shared contract defines it (context-guru docs/metrics/spec.md 5.4, rossoctl/context-guru#1271): (CacheWrite - CacheWrite1h) x (write_5m - read) + CacheWrite1h x (write_1h - read). The miss cause follows the spec's order: cold_start, ttl_expiry, model_changed (only when the request wrote cache tokens), other. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
This was referenced Nov 24, 2026
boazdavid
added a commit
to boazdavid/cortex
that referenced
this pull request
Nov 24, 2026
Add the metrics push. core/accounting/push posts the llm.savings, llm.proxy.info, llm.inference, llm.keepalive and llm.cache counters over OTLP/HTTP, priced by the same accounting.USD the ledger uses. metrics.go holds the Sink and its counters; labels.go names the label values, with cortex pings labelled by outcome and cache misses by cause. core/config carries the metrics_push block (metricspush), validated and reload-guarded. cmd/cortex and cmd/cortex-envoy start the push with the accountant host and flush it on shutdown. The host options are shared through accounting.OptionsFrom so both binaries wire the sink the same way. .github/workflows/build.yaml passes the VERSION build-arg so the push can send service.version. The push has no default URL: nothing leaves the machine until a user sets one. A bad URL warns and turns the push off; accounting fails open. llm.cache.miss_cost_usd books the write premium of a cache miss, not its whole price, as the shared contract defines it (context-guru docs/metrics/spec.md 5.4, rossoctl/context-guru#1271): (CacheWrite - CacheWrite1h) x (write_5m - read) + CacheWrite1h x (write_1h - read). The miss cause follows the spec's order: cold_start, ttl_expiry, model_changed (only when the request wrote cache tokens), other. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
added a commit
to boazdavid/cortex
that referenced
this pull request
Nov 24, 2026
Add the metrics push. core/accounting/push posts the llm.savings, llm.proxy.info, llm.inference, llm.keepalive and llm.cache counters over OTLP/HTTP, priced by the same accounting.USD the ledger uses. metrics.go holds the Sink and its counters; labels.go names the label values, with cortex pings labelled by outcome and cache misses by cause. core/config carries the metrics_push block (metricspush), validated and reload-guarded. cmd/cortex and cmd/cortex-envoy start the push with the accountant host and flush it on shutdown. The host options are shared through accounting.OptionsFrom so both binaries wire the sink the same way. .github/workflows/build.yaml passes the VERSION build-arg so the push can send service.version. The push has no default URL: nothing leaves the machine until a user sets one. A bad URL warns and turns the push off; accounting fails open. llm.cache.miss_cost_usd books the write premium of a cache miss, not its whole price, as the shared contract defines it (context-guru docs/metrics/spec.md 5.4, rossoctl/context-guru#1271): (CacheWrite - CacheWrite1h) x (write_5m - read) + CacheWrite1h x (write_1h - read). The miss cause follows the spec's order: cold_start, ttl_expiry, model_changed (only when the request wrote cache tokens), other. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
boazdavid
added a commit
to boazdavid/cortex
that referenced
this pull request
Nov 24, 2026
Add the metrics push. core/accounting/push posts the llm.savings, llm.proxy.info, llm.inference, llm.keepalive and llm.cache counters over OTLP/HTTP, priced by the same accounting.USD the ledger uses. metrics.go holds the Sink and its counters; labels.go names the label values, with cortex pings labelled by outcome and cache misses by cause. core/config carries the metrics_push block (metricspush), validated and reload-guarded. cmd/cortex and cmd/cortex-envoy start the push with the accountant host and flush it on shutdown. The host options are shared through accounting.OptionsFrom so both binaries wire the sink the same way. .github/workflows/build.yaml passes the VERSION build-arg so the push can send service.version. The push has no default URL: nothing leaves the machine until a user sets one. A bad URL warns and turns the push off; accounting fails open. llm.cache.miss_cost_usd books the write premium of a cache miss, not its whole price, as the shared contract defines it (context-guru docs/metrics/spec.md 5.4, rossoctl/context-guru#1271): (CacheWrite - CacheWrite1h) x (write_5m - read) + CacheWrite1h x (write_1h - read). The miss cause follows the spec's order: cold_start, ttl_expiry, model_changed (only when the request wrote cache tokens), other. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID BOAZ <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part of #1270.
missCostUSD(proxy/inferencemetrics.go) now adds the 1-hour premium on theCacheWrite1hpart of a write. It usesPrice.CacheWrite1hPremium, which is the one place that premium is taken.docs/metrics/spec.md5.4 now defines the miss cost exactly, so every proxy that pushes to the central stack books the same figure:cache_write x (write_5m - read) + cache_write_1h x (write_1h - write_5m)The matching Cortex change is tracked in #1270. It is not in this PR.
What changed
proxy/inferencemetrics.gomissCostUSDaddsmin(CacheWrite1h, CacheWrite) x CacheWrite1hPremium()proxy/inferencemetrics_test.goTestMissCostPricesTheOneHourTierAtItsOwnRatedocs/metrics/spec.mdHow it was tested
miss cost = 0.00345, want 0.00435.go test -count=1 ./proxy/... ./proxyapp/metricspush/...passes.go vet ./proxy/andgofmt -l proxy/are clean.Data dependence
No change. The miss cost uses token counts and rates only (metadata).
Open questions
See #1270: the order of causes, and whether each proxy can keep its own rule for what counts as a miss.