Skip to content

docs(metrics): Add cache effects and interaction to the net saving - #107

Merged
boazdavid merged 1 commit into
mainfrom
docs/cache-effect-net-saving
Nov 22, 2026
Merged

boazdavid merged 1 commit into
mainfrom
docs/cache-effect-net-saving

Conversation

@boazdavid

Copy link
Copy Markdown
Contributor

Summary

The metrics doc called llm.savings.cache_effect.usd and llm.savings.interaction.usd "a breakdown" and said "never add it to saved or added". That is correct for tokens, because a cache effect nets zero tokens. It is wrong for money:

  • No operation contains a cache effect (design §4.4, §6.3). The sink books saved.usd and added.usd from op.Saved and op.Caused only.
  • Design §6.2 and check 6 (§6.5) define the bill difference as the operations plus the cache effects plus the interaction.
  • A keep-alive ping is a spend (design §4.2, rule 5), so it is in added.usd. A dashboard that followed the old text showed every ping as a cost and never its rescue.

What changed

  • docs/metrics/metrics.md: each counter is a separate part. It is not in saved or added. A new section, "The net saving", gives the full formula.
  • metrics/metrics.go: the two metric descriptions say the same.
  • metrics/metrics_test.go: two test comments.

No counter changes. The sink still books effects to their own counter.

How it was tested

  • go test ./... in the root module and in metrics/.
  • On the Cortex central stack (epoc001), the Cortex ledger and Prometheus agree within about 2% on the net only when the effects and the interaction are added.

Related: the Cortex dashboards use this formula in boazdavid/cortex PR 1958.

Assisted-By: Claude (Anthropic AI) [email protected]

The metrics doc called llm.savings.cache_effect.usd and
llm.savings.interaction.usd "a breakdown" and said "never add it to
saved or added". That is correct for tokens: a cache effect nets zero
tokens. It is wrong for money. No operation contains an effect, and
design §6.2 and check 6 define the bill difference as the operations
plus the effects plus the interaction.

A dashboard that followed the old text showed every keep-alive ping
as a cost (the ping is a spend in added.usd) and never its rescue.

- Say that each counter is a separate part, not in saved or added.
- Add a "The net saving" section with the full formula.
- Update the two metric descriptions and two test comments.

No counter changes. The sink still books effects to their own counter.

Assisted-By: Claude (Anthropic AI) <[email protected]>
Signed-off-by: DAVID BOAZ <[email protected]>
@boazdavid
boazdavid merged commit 360243d into main Nov 22, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant