fix: correct cost intelligence accuracy and add overhead breakdown#272
Merged
Conversation
- Fix double-counting of warmup + TTL savings: the same cacheReadTokens were counted in both buckets when a user returned after >5min following a warmup. Now mutually exclusive — warmup hits take priority. - Fix shadow context undercount for avoided compactions: replaced the snapshot approach (which tracked compressed token counts) with additive growth tracking using output tokens (always uncompressed) as the reliable per-turn growth signal. - Add per-worker-bucket breakdown (distill, curate, compact, warmup, recall) to the Lore overhead line on the main /ui/costs page, matching the per-session Cost Intelligence card format.
1ded983 to
0268437
Compare
This was referenced May 13, 2026
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.
Summary
Fix double-counting of warmup + TTL savings — the same
cacheReadTokenswere counted in bothwarmupSavingsandttlSavingswhen a user returned after >5min following a warmup ping. Since warmups exist for longer gaps, this was the common case, inflating savings by ~2x. Now mutually exclusive: warmup hits take priority, TTL savings only fire for non-warmup turns.Fix shadow context undercount for avoided compactions —
updateShadowContext()was snapshotting the compressed API token count, which underestimates the "without Lore" counterfactual because Lore's gradient manager already trimmed context. Replaced with additive growth tracking using output tokens (always uncompressed) as the reliable per-turn growth signal.Add Lore overhead breakdown to main costs page — the
/ui/costsaggregated view now shows per-worker-bucket breakdown (distill, curate, compact, warmup, recall) on the Lore overhead line, matching the per-session Cost Intelligence card format.Files Changed
packages/gateway/src/pipeline.tsoutputTokenstoupdateShadowContextpackages/gateway/src/cost-tracker.ts_lastActualInput/_lastOutputTokensfieldspackages/gateway/src/ui.ts