jcp: count the joules a cache hit did not spend, without ever calling it spend #75
Merged
dcharlot
merged 1 commit from 2026-09-03 15:11:51 -04:00
jcp/avoided-energy into main 2026-09-03
jcp: count the joules a cache hit did not spend, without ever calling it spend
All checks were successful
standards workspaces build + test / aac-rs (pull_request) Successful in 38s
standards workspaces build + test / joule-code-rs (pull_request) Successful in 44s
standards workspaces build + test / eoc-rs (pull_request) Successful in 1m51s
standards workspaces build + test / jcp-rs (pull_request) Successful in 1m13s
standards workspaces build + test / proof-rs (pull_request) Successful in 1m9s
standards workspaces build + test / sandbox-rs (pull_request) Successful in 2m1s
standards workspaces build + test / jouleclaw-rs (pull_request) Successful in 4m54s
standards workspaces build + test / joulecontract-rs (pull_request) Successful in 38s
standards workspaces build + test / map-rs (pull_request) Successful in 32s
standards workspaces build + test / mesh-rs (pull_request) Successful in 33s
standards workspaces build + test / smart-byte-rs (pull_request) Successful in 2m31s
standards workspaces build + test / openpay (pull_request) Successful in 1m47s
standards workspaces build + test / arl-rs (pull_request) Successful in 10m59s
standards workspaces build + test / joule-ui-rs (pull_request) Successful in 9m45s
standards workspaces build + test / jouledesk-rs (pull_request) Successful in 9m34s
standards workspaces build + test / joulehook-rs (pull_request) Successful in 9m40s
standards workspaces build + test / sense-rs (pull_request) Successful in 8m8s
MCP's 2026-07-28 revision added `CacheableResult` with `ttlMs`/`cacheScope`, so a served result can declare itself reusable. When it is reused, work that would have run did not — and for a family whose doctrine is that inference is the last resort, the cheapest joule is the one never spent. Nothing in the family bound a reused result to an energy figure. It is also the easiest quantity here to lie with, so it does not become another `Energy`. **It is a counterfactual, not a measurement.** Nothing measures a joule that was not spent; an avoided figure is a claim about what would have happened. The only thing making it checkable is a pointer to the execution it stands in for, so `AvoidedEnergy` cannot be constructed without naming the receipt whose measured cost it claims to have avoided. Without that, "this hit saved 10 mJ" is unfalsifiable — and unfalsifiable savings are how an efficiency programme reports progress it never made. **It must never be added to energy spent.** If avoided joules were summed with spent joules, or subtracted from them, a system could manufacture arbitrary efficiency and, with enough hits, report negative consumption. Physics has no negative-joule case; an accounting system that does has a bug that looks like a triumph. So this type produces no `Energy`, offers no arithmetic against a spend total, and `AvoidedSummary::saving_ppm_of` takes the spend as an argument rather than holding it — the two totals meet in exactly one place, expressed as a ratio *to* spend and never a deduction *from* it. A test drives five million-microjoule hits against a 200 µJ spend and shows no path to a negative spend figure. **A cache hit is not free.** The net subtracts what serving the hit cost, since claiming the full prior cost over-claims by exactly that amount. When a lookup costs more than recomputing would have, the saving is reported **negative rather than clamped**: a cache that does not pay for itself is a real outcome, and rounding it to "no saving" hides the one case an operator most needs to act on. `unprofitable_hits` is counted separately, so a cache that is net-positive overall while losing on most requests is visible rather than averaged away. The saving inherits the basis measurement's acquisition class, because a saving standing in for an `Estimator` figure is an estimated saving however precisely it prints. Ranked by the 2026-08-29 sweep as the one remaining item it called unclaimed territory rather than an adapter. Verified: 265 jcp-rs tests pass (5 new), conformance passes all classes, no clippy warnings in the new file. Co-Authored-By: Claude Opus 5 <[email protected]>