fix(history): calculate utilisation in budget cost units - #14
Merged
Conversation
`settle_head` is the last resort, and it counted the admission without the weight: `forwarded`, `admitted` and `commits` went up, `cost` did not. The batch path in `stage_and_commit` records both. That was a skew in `avg_cost` until this branch, which is why it survived. This branch makes `cost_est` the numerator of utilisation, and the roll-up is written from the same atomic — so a stage that falls back to `settle_head` under contention reports a utilisation far below the true one, and `/api/flow` reads "safe" at the moment the counter is at its ceiling. The SQL fallback does not cover it either: `NULLIF(SUM(cost_est), 0)` only fires when the whole minute is zero, so a minute mixing both paths under-reports with nothing to catch it. Same weight, same source, same saturating add as the batch path. Claude-Session: https://claude.ai/code/session_012K8u7BEJyd6nDNMCQAgH3z
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.
Problem
Historical charts divided admitted item count by ceilings expressed in cost units. A message costing 7 appeared to consume 1 unit, understating utilisation by 7x. Target rollups also cannot attribute aggregate traffic to a
whenOporscopeBybudget, yet the UI drew a precise-looking percentage anyway.Fix
cost_estimatedrather thanadmitted;whenOpin graph detail so the UI can identify non-attributable histories;Review notes for Alice
No enforcement changes here. The live counter remains authoritative. This PR only prevents mixing two currencies and refuses to manufacture a historical percentage when the schema lacks the required operation/scope dimension.
The flow response adds
costbut preservesadmitted,total_admitted,ceiling, andutilisationfor compatibility.Verification
cargo test -p gate-servercargo clippy -p gate-server --all-targets -- -D warningsnpm run buildinui/