Skip to content

fix(metrics): Price the 1-hour write tier in the miss cost, and define the miss cost in the spec - #1271

Merged
amiddavid merged 2 commits into
mainfrom
fix/miss-cost-premium-1h
Nov 24, 2026
Merged

amiddavid merged 2 commits into
mainfrom
fix/miss-cost-premium-1h

Conversation

@boazdavid

Copy link
Copy Markdown
Collaborator

Behavior change: needs a human developer's yes before merge.

  • Who it affects: anyone who reads llm_cache_miss_cost_usd_total (the central "Miss cost by cause" panel).
  • Old: a miss with 1-hour cache writes was priced as if all writes were at the 5-minute rate.
  • New: the 1-hour part is priced at the 1-hour rate, so those misses book a larger, correct premium. Misses with no 1-hour writes do not change.
  • How to turn it off: there is no switch. Revert this commit.

Summary

Part of #1270.

  1. missCostUSD (proxy/inferencemetrics.go) now adds the 1-hour premium on the CacheWrite1h part of a write. It uses Price.CacheWrite1hPremium, which is the one place that premium is taken.
  2. docs/metrics/spec.md 5.4 now defines the miss cost exactly, so every proxy that pushes to the central stack books the same figure:
    • the formula: cache_write x (write_5m - read) + cache_write_1h x (write_1h - write_5m)
    • what counts as a miss
    • the order of causes (the order context-guru already uses)
    • a model with no rate books $0

The matching Cortex change is tracked in #1270. It is not in this PR.

What changed

File Change
proxy/inferencemetrics.go missCostUSD adds min(CacheWrite1h, CacheWrite) x CacheWrite1hPremium()
proxy/inferencemetrics_test.go New test TestMissCostPricesTheOneHourTierAtItsOwnRate
docs/metrics/spec.md 5.4: the miss rule, the order of causes and the miss cost formula

How it was tested

  1. I wrote the new test first. It failed: miss cost = 0.00345, want 0.00435.
  2. After the fix it passes.
  3. go test -count=1 ./proxy/... ./proxyapp/metricspush/... passes.
  4. go vet ./proxy/ and gofmt -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.

…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 boazdavid 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 @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

  1. 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 input but no cache_read. missCostUSD calls p.Resolved(e.Model) (proxy/inferencemetrics.go:261). Resolved fills CacheRead from CacheReadFor, which returns Input * CacheReadFracFor(model). That is the Anthropic 0.1x guess, and Resolved marks it CacheReadFallback (#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 (CacheReadFor falls through to CacheReadFracFor), internal/modelinfo/cachefrac.go:95-112 (returns AnthropicCacheReadFrac for any unmatched model). The write side falls back too: CacheWrite5mFor uses CacheWriteFracFor(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 modelinfo resolves it (#1248)." Or change the code to skip the money when p.CacheReadFallback is set. That second option is a behavior change and needs a human's yes.

Non-blocking

  • proxy/inferencemetrics_test.go:261: want calls p.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 names cache_write_1h_rate but does not say where it comes from. No gateway states it. context-guru derives it as 2.0x input, or the operator's Write1hFrac, 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 is other (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.md asks. 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-By are 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. CacheWrite1h is a subset of CacheWrite (dash/event.go:317-331), so the formula does not count a token twice.
  • Resolved keeps Write1hFrac, so CacheWrite1hPremium() after Resolved gives the same premium as Event.CostUSD (CostWithCacheWrite1h) and dash/spendexplain.go:386-390. The figures agree.
  • Test arithmetic: with Input 3e-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) and AttributeCache (dash/event.go:1229-1248): cold_start, then ttl_expiry, then the stored cause. They match. "First request of the thread" matches seenSession, which is per thread (dash/capture.go:683).
  • "Keep-alive pings are never misses": Observe returns after observePing (proxy/inferencemetrics.go:123-126).
  • Fail open: Observe recovers 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_total by name only. No query needs a change.
  • I did not run Go tests. Live tests are not approved.

@boazdavid boazdavid 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 @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 want with the helper it tests. want uses p.CacheWrite1hPremium(). A bug in that helper changes got and want the same way, so the test still passes. A literal value is stronger: want := 0.00345 + 0.0009 (400 x (6e-6 - 3.75e-6), from AnthropicCacheWrite1hFrac = 2.0). The PR body already states 0.00435.
  • proxy/inferencemetrics.go:267 — no test covers the min(CacheWrite1h, CacheWrite) clamp. A test with CacheWrite1h > CacheWrite would 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.CacheWrite is 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.
    • Resolved keeps Write1hFrac, so an operator's 1-hour rate still applies.
    • This agrees with dash/keepalive.go:1280-1284. There, MissUSD uses (5m - read) and miss1h uses (1h - read).
    • CacheWrite1h is a subset of CacheWrite (internal/providerusage/providerusage.go:15). The min guards a bad count. The token counter at proxy/inferencemetrics.go:149-150 uses the same split.
    • An unpriced model still returns 0 (!ok). CacheWrite <= 0 still returns 0. TestUnpricedMissBooksNoMoney still covers this.
    • A non-Claude model has no CacheWrite1h, so the new term adds nothing for it.
  • Fail open: Observe keeps its recover. 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": missCause returns no miss for hit and for an empty reason. Pings return before observeCacheMiss (proxy/inferencemetrics.go:123-126). The partial-read rule (#496) is in AttributeCache (dash/event.go:1227-1230).
    • Cause order: AttributeCache sets cold_start before ttl_expiry (dash/event.go:1233-1236). missCause then maps model_changed, compaction_after_rewrite, bypass_flip, then tools/system/effort to prefix_change, else other (proxy/inferencemetrics.go:276-295). The spec list has the same order.
    • "First request of the thread": ObserveThread keys on the thread (proxy/dashcapture.go:850-864), and CauseFirstOnModel maps to cold_start. This matches.
    • "Effort or thinking settings": CauseEffortChanged covers effort, thinking mode and thinking budget (dash/event.go:53).
    • concurrent maps to other, as the spec says.
  • 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]>
@boazdavid

Copy link
Copy Markdown
Collaborator Author

Replies to round 1. All fixes are in 8f6d9bc8.

Reviewer 1

  1. Blocking: "It does not use a fallback rate" is false. Fixed. I changed the spec, not the code, so there is no new behavior change. The spec now says: a rate the price states is used as it is; a blank tier rate is the model's standard multiple of its input rate (Price.Resolved, fix(metrics): Inference dashboard fallback-rate share and output-per-request panels compute the wrong figure #1248); a model with no price books no money.
  2. Non-blocking: the test uses CacheWrite1hPremium() for want. Fixed. want is now a literal: 600*(3.75e-6-0.3e-6) + 400*(6e-6-0.3e-6).
  3. Non-blocking: the spec does not say where the 1-hour rate comes from. Fixed. The spec now states the Price.CacheWrite1hFor rule: Write1hFrac times input, never below the 5-minute rate, when the operator sets it; else 2.0x input.
  4. Non-blocking: rules 3 to 6 need a write. Fixed. The spec now says that rules 3 to 6 apply only when the request wrote cache tokens, else the cause is other.

Reviewer 2

  1. Non-blocking: want uses the helper it tests. Fixed, as in reviewer 1 item 2.
  2. Non-blocking: no test for the min(CacheWrite1h, CacheWrite) clamp. Fixed. New test TestMissCostClampsTheOneHourPartToTheWrite.
  3. Non-blocking: "each term is never below zero" is not the same as "the premium is never below zero". Fixed in the code. A 1-hour token now pays (1h - read), and a 5-minute token pays (5m - read), each clamped at zero. This is the split dash/keepalive.go uses for a lapse. The spec formula changed to match. For real feeds the figure is the same as before.

Tests: go test -count=1 ./proxy/... ./proxyapp/metricspush/... passes. go vet ./proxy/ and gofmt -l proxy/ are clean.

@boazdavid boazdavid 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 @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:374 now states the Price.Resolved rule (#1248). It matches CacheReadFor and CacheWrite5mFor. 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. want is a literal at proxy/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): Write1hFrac x 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:362 matches AttributeCache (dash/event.go:1243-1247). There, a cause is stored only in the default branch, after the CacheWrite <= 0 case.
  • Reviewer 2, non-blocking 1 (helper in want): fixed, the same change as above.
  • Reviewer 2, non-blocking 2 (no clamp test): fixed. TestMissCostClampsTheOneHourPartToTheWrite sets 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 as dash/keepalive.go:1280-1283 (MissUSD, miss1h). For a feed with 1h >= 5m >= read, the figure is the same as at 296d68a5: (5m - read) + (1h - 5m) = (1h - read).

Non-blocking

  • proxy/inferencemetrics.go:268: suppose a price states cache rates but no input rate, and the operator sets no Write1hFrac. Then CacheWrite1h() is 0, and 1-hour tokens book no miss cost. At 296d68a5 they 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 state input.
  • dash/spendexplain.go:386-390 still 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 (8f6d9bc8 fix(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): w1h is clamped to [0, CacheWrite]. The 5-minute part is CacheWrite - w1h, so no token is priced twice. Each part is clamped at 0. An unpriced model and a zero write still return 0.
  • Resolved keeps Write1hFrac and sets CacheWrite to the 5-minute rate. So CacheWrite1h() = 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. Observe keeps its recover.
  • 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 boazdavid 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 @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

  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 matches CacheReadFor and CacheWrite5mFor (internal/modelinfo/modelinfo.go:98-118). The author changed the spec, not the code, so this fix adds no behavior change.
  2. Non-blocking, want uses the helper: fixed. See my item 1.
  3. Non-blocking, the source of the 1-hour rate: fixed. The spec text matches CacheWrite1hFor (modelinfo.go:124-129): Write1hFrac x input, never below the 5-minute rate, else AnthropicCacheWrite1hFrac (2.0, cachefrac.go:78) x input.
  4. Non-blocking, rules 3 to 6 need a write: fixed. AttributeCache sets CacheUnknown with no stored cause when CacheWrite <= 0 (dash/event.go:1241-1244). missCause then returns other. concurrent is stored before that check, but it maps to other (rule 7), so the new sentence is exact.

Reviewer 2 (mine)

  1. want uses the helper it tests: fixed. want is now a literal: 600 x 3.45e-6 + 400 x 5.7e-6 = 0.00435. This is the same figure as before.
  2. No test for the clamp: fixed. TestMissCostClampsTheOneHourPartToTheWrite sets CacheWrite1h = 5000 on 1000 written tokens. The code clamps w1h to 1000, so the 5-minute part is 0 and want = 1000 x 5.7e-6. This is correct.
  3. "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() is Input x 2.0 when Write1hFrac is 0. If Input is 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, use max(p.CacheWrite1h(), p.CacheWrite).

What I checked

  • Last review: round 1, 296d68a, 2026-11-22T13:25:17Z
  • New commits read: 1
    • 8f6d9bc8 fix(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 - w1h is never below 0, so no token is priced twice and no token is lost.
    • After Resolved, p.CacheWrite is the 5-minute rate. Resolved keeps Write1hFrac, so CacheWrite1h() gets the operator's 1-hour rate.
    • An unpriced model and CacheWrite <= 0 still return 0.
  • Fail open: Observe keeps its recover. 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.

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]>
@amiddavid
amiddavid merged commit 46e94e5 into main Nov 24, 2026
9 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization 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]>
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]>
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