(feat)cache hit rate#809
Merged
Merged
Conversation
Adds `cache_hit_rate: Option<f64>` to UsageTokenBreakdown and UsageModelBreakdown, computed in build_token_breakdown / build_model_breakdown via a shared helper that: - only counts records with `cached_tokens_available == true` in BOTH numerator (cached_tokens) and denominator (input_tokens), so a partially reporting provider does not get its hit rate artificially deflated by unreported input - returns None when no record reports cache, or when the filtered input sum is zero (avoids divide-by-zero on tool-only turns) Renderers (terminal + markdown) append a ` (NN%)` suffix to the "Cached" cell when hit rate is available. When coverage is Unavailable the existing "not reported" fallback is preserved regardless of hit_rate state. PartialEq-only on the affected breakdown structs (and their parent SessionUsageReport) because Option<f64> precludes total equality. Five compute-layer tests cover: all-reported normal case, no-record reports, partial coverage (the bug-prone case), input_sum=0 edge, per-model isolation. Two render tests lock the cell format and the "not reported" fallback.
Renders the new backend `cacheHitRate` field across the three UI surfaces that show cached tokens: - Session report card: appends ` (NN%)` inline to the "Cached" cell when coverage is available/partial, preserves the existing "Cache not reported" fallback when unavailable - Session detail panel: adds a dedicated "Hit rate" column to the per-model table; falls back to "-" when a model has no reported cache data - Markdown export builder (`buildSessionUsageExportMarkdown`): same inline ` (NN%)` suffix so the exported markdown matches the Rust-side terminal/markdown renderer output Two helpers in usageReportUtils: - formatHitRateSuffix(rate, t) - ` (NN%)` for inline append - formatHitRatePercent(rate, t) - bare `NN%` for table cells i18n adds `usage.table.hitRate` to en-US/zh-CN/zh-TW. Tests: 5 helper unit tests (round-trip / NaN / Infinity / rounding) and 2 card behaviour tests (inline rendering + unavailable fallback).
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.
No description provided.