Skip to content

Net cache savings, and cost buckets split by model - #19

Merged
fylorn merged 1 commit into
mainfrom
feat/cache-rate-and-model-buckets
Sep 15, 2026
Merged

fylorn merged 1 commit into
mainfrom
feat/cache-rate-and-model-buckets

Conversation

@fylorn

@fylorn fylorn commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Two changes the desktop overview needs.

The cache saving was gross, not net

Prices::cache_saving counted what cache hits saved and never subtracted what cache writes cost extra. Writes are not free — a 5-minute cache write is 1.25× the input rate, against a read's 0.1×. So a workload that rebuilds its cache constantly and rarely hits it pays more than one with no caching at all, and the panel reported it as money saved. That is exactly the case a user needs to see, and the number was hiding it.

It can now go negative, and a negative is a conclusion rather than an edge case to clamp away. The break-even is low: the write premium is 0.25× and each read saves 0.9×, so reading back about 28% of what was written already pays for it. Three tests pin the arithmetic, including the loss case.

Note this changes the sign and magnitude of cache_saved_micros in Summary and on stored rows for future writes; existing rows keep whatever they were written with.

Cost buckets split by model or provider

A trend chart and a composition chart answer two questions that belong together — when the money went, and what it went on. Read separately the viewer has to line up time across two pictures; stacked into one chart it is a single glance.

cost_buckets_by groups by (bucket, model) using the same bucket arithmetic as cost_buckets, exposed at GET /summary/buckets/by?dim=model. A test asserts the two line up: the caller fills empty buckets from a shared origin, so being one grid off would paint real data into an empty slot.

Gates

cargo fmt --all -- --check, cargo clippy --workspace --all-targets -- -D warnings, cargo test --workspace (61 binaries green), ./scripts/smoke.sh (46 passed, 0 failed).

🤖 Generated with Claude Code

Two changes the desktop overview needs.

**The cache saving was gross, not net.** It counted what cache hits
saved and never subtracted what cache writes cost extra — and writes
are not free: a 5-minute cache write is 1.25x the input rate against a
read's 0.1x. A workload that rebuilds its cache constantly and rarely
hits it pays *more* than one with no caching at all, and the panel
reported it as money saved. That is precisely the case a user needs to
see, and the number was hiding it.

It can now go negative, and a negative is a conclusion: caching is
losing money on this workload. The break-even is low — the write
premium is 0.25x and each read saves 0.9x, so reading back about 28% of
what was written already pays for it. Three tests pin the arithmetic,
including the loss case.

**Cost buckets can be split by model or provider.** A trend chart and a
composition chart answer two questions that belong together: when the
money went, and what it went on. Read separately, the reader has to
line up time between two pictures; stacked into one chart, both are a
single glance. `cost_buckets_by` groups by (bucket, model) with the
same bucket arithmetic as `cost_buckets` — a test asserts the two line
up, because the caller fills empty buckets from a shared origin and
being one grid off would draw real data in an empty slot.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Thanks for the PR. One thing before review: this targets main, and it should target dev.

main is a release-only line — branch-protected, linear history, and every commit on it is a tagged release snapshot. Routine work lands on dev and reaches main with the next release. GitHub pre-filled main here because it is the default branch, so this is our defaults being unhelpful rather than anything you did wrong.

No need to close and reopen: click Edit next to the PR title and change the base branch to dev. The commits and the discussion carry over.

See CONTRIBUTING.md and CONTRIBUTING.md for the branch contract.

@fylorn
fylorn merged commit c3e1a33 into main Sep 15, 2026
2 checks passed
@fylorn
fylorn deleted the feat/cache-rate-and-model-buckets branch September 15, 2026 18:10
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