feat(app): show context cache hit rate#910
Conversation
📝 WalkthroughWalkthroughThis PR implements cache hit rate observability in the session context tab. It extends the test LLM server to report cached tokens, adds a computed ChangesCache Hit Rate Feature
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Suggested priority: P2 (includes user-path files (packages/app/src/components/session/session-context-metrics.test.ts, packages/app/src/components/session/session-context-metrics.ts, packages/app/src/components/session/session-context-tab.tsx, packages/app/src/i18n/en.ts, packages/app/src/i18n/zh.ts)).
P1/P0 are reserved for maintainer confirmation. Please relabel manually if this is a release blocker, security issue, data-loss risk, or updater/runtime failure.
There was a problem hiding this comment.
Code Review
This pull request introduces a "Cache Hit Rate" metric to the session context view, updating the metrics calculation, UI tab display (with color-coded values), localization dictionaries, and the mock LLM server for testing. The review feedback correctly identifies a calculation bug in the cacheHitRate formula: the denominator double-counts tokens because the input tokens count already includes the cached read and write tokens. The reviewer suggests simplifying the formula to read / input and provides corresponding updates for the call site and unit tests.
Perf delta summaryComparator: pass
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/opencode/test/lib/llm-server.ts`:
- Line 164: The responseCompleted event sets input_tokens_details.cached_tokens
from input.usage?.cacheRead but flowParts (the code that reconstructs usage when
converting chat chunks into response events for responses(...)) currently only
builds { input, output } and thus drops cacheRead; update flowParts to propagate
input.usage?.cacheRead into the reconstructed usage (e.g., include cached_tokens
or preserve input.usage as part of the usage object) so that responses(...)
receives and emits cached_tokens the same way responseCompleted does; update any
code paths that map chunk.usage -> usage in flowParts/responses to copy
input.usage?.cacheRead into input_tokens_details.cached_tokens (and similarly
preserve any existing token detail fields) so cached_tokens is not lost.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 134708f7-35f0-49ad-8044-b6953e1e6136
📒 Files selected for processing (7)
packages/app/e2e/snap/session-context-cache.snap.tspackages/app/src/components/session/session-context-metrics.test.tspackages/app/src/components/session/session-context-metrics.tspackages/app/src/components/session/session-context-tab.tsxpackages/app/src/i18n/en.tspackages/app/src/i18n/zh.tspackages/opencode/test/lib/llm-server.ts
Summary
Why
Issue #884 asks for cache hit rate visibility in the Context tab. The raw cache token row made users do the math manually and made cache behavior harder to observe during cache-first work.
Related Issue
Fixes #884
Human Review Status
Pending
Review Focus
Risk Notes
How To Verify
Screenshots or Recordings
docs/design/preview/screenshots/session-context-cache.pngfrombun run snap session-context-cache.Checklist
bug,enhancement,task,documentation. Type labels are author-added; the labeler bot does NOT assign them. Add the label in the GitHub UI, then tick this.app,ui,platform,harness,ci. The labeler bot assigns these on PR open based on changed paths. Confirm the bot's choice (or override if wrong), then tick this.P0,P1,P2,P3. The priority-triage bot suggests one on PR open. Confirm or override, then tick this.Pending,Approved by @<reviewer>, orNot required: <reason>(default isPending; "not required" is restricted to bot-authored low-risk PRs).dev, and my PR title and commit messages use Conventional Commits in English.Summary by CodeRabbit
New Features
Localization