fix(grok): cache context breakdown like Codex/Claude - #382
Conversation
Grok context breakdown re-scanned all session logs on every provider tab switch because the result cache was brittle and files were never memoized. Add Codex-style per-file parse cache, in-flight request coalescing, and sticky UI state so revisiting Grok stays instant.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe PR adds versioned and memoized caching to Grok context aggregation, deduplicates concurrent computations, invalidates file parsing when session files change, and retains or clears dashboard breakdown data according to source-specific cache state during refreshes. ChangesContext breakdown caching
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant Dashboard
participant ContextBreakdownPanel
participant getUsageCategoryBreakdown
Dashboard->>ContextBreakdownPanel: Switch source or date range
ContextBreakdownPanel->>ContextBreakdownPanel: Restore cached response or clear data
ContextBreakdownPanel->>getUsageCategoryBreakdown: Fetch updated breakdown
getUsageCategoryBreakdown-->>ContextBreakdownPanel: Return response
ContextBreakdownPanel->>ContextBreakdownPanel: Cache and apply response
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 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.
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 `@dashboard/src/ui/dashboard/components/ContextBreakdownPanel.jsx`:
- Around line 702-706: Update the useEffect cache-miss path in
ContextBreakdownPanel so data is cleared before starting a fetch when
cacheRef.current[cacheKey] has no entry. Preserve cached-data rendering on cache
hits, and ensure the loading guard can show the skeleton instead of rendering
the previous source or date range payload.
🪄 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: a9a1480c-039c-4b44-8769-b79bf9ea5da5
📒 Files selected for processing (4)
dashboard/src/ui/dashboard/components/ContextBreakdownPanel.jsxdashboard/src/ui/dashboard/components/__tests__/ContextBreakdownPanel.test.jsxsrc/lib/grok-context-breakdown.jstest/grok-context-breakdown.test.js
…flash First visit to an uncached source kept the previous provider's payload in state, so it briefly rendered under the new source's display branch with mismatched totals. Reset data explicitly on cache miss so the loading skeleton shows instead (CodeRabbit review finding).
|
Pushed a follow-up commit addressing the CodeRabbit finding: on a cache miss the panel now resets |
|
CI green with the follow-up. Thanks for the caching work — the per-file parse cache plus in-flight coalescing is exactly the Codex/Claude pattern this needed. Merging. |
Summary
updates.jsonlwhenever the dashboard switched provider tabs (Claude ↔ Codex ↔ Grok), so users with large Grok histories saw repeated “Scanning session logs…”.FILE_PARSE_CACHE, size+mtime keyed) — same idea as CodexPARSED_GROUP_CACHEContextBreakdownPanelso revisiting a source keeps the last payload instead of flashing the skeleton (loading && !data)API surface
No API change. Still
GET /functions/tokentracker-usage-category-breakdown?source=grok|codex|claudewith the same response shape.Test plan
node --test test/grok-context-breakdown.test.js(includes result cache, in-flight, file invalidation)dashboardvitestContextBreakdownPanel.test.jsx(sticky source revisit)Summary by CodeRabbit