Repository navigation
perf(server): warm the usage scan cache after startup - #29731
juliusmarminge wants to merge 2 commits into
Conversation
ApprovabilityVerdict: Approved at Macroscope's review found this PR approvable — Warms the existing usage cache after server activation and shares that work with concurrent summaries. The change reuses existing parsing and persistence paths without changing usage defaults or source transcripts. No code changes detected at You can add or adjust custom eligibility rules. Learn more. |
Thread transfer impact✅ Thread transfer remains within every enforced ceiling.
Baseline: unavailable · PR result: Scenario and decoded snapshot size10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed. |
57bea92 to
b7aa3ff
Compare
Dismissing prior approval to re-evaluate b7aa3ff
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Cache scanning and coordination apps/server/src/usage/UsageService.ts |
UsageService adds a 31-day cache warm-up scan and shared completion state. Summary scans wait for active warm-up, while rate loading can proceed during that wait. Warm-up loads the scan cache and settings, scans transcript directories, schedules persistence, and logs failures. |
Activation and server wiring apps/server/src/usage/UsageService.ts, apps/server/src/server.ts, apps/server/src/usage/UsageService.test.ts |
The server application includes the warm-up layer. The layer starts warm-up after activation without blocking its launch. Tests cover activation gating, shared parsing, and scanning an older transcript omitted by a one-day summary. |
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Other
Sequence Diagram(s)
sequenceDiagram
participant ServerActivation
participant layerWarmup
participant UsageService
participant scanSummary
ServerActivation->>layerWarmup: releases activation
layerWarmup->>UsageService: starts warmScanCache
scanSummary->>UsageService: waits while warm-up is active
UsageService->>scanSummary: signals warm-up completion
Possibly related issues
- [Bug]: OpenCode usage scan takes ~5 min on a large OpenCode 2 database, repeats on every refresh and stalls the server #28430 — The change adds scan-cache warm-up, which relates to the report of repeated, slow usage scans. The retrieved issue summary notes that OpenCode account-based readers may remain outside this warm-up path.
Possibly related PRs
- pingdotgg/t3code#21776 — This PR adds the warm-up layer to the startup activation wiring introduced there.
- pingdotgg/t3code#28111 — This PR warms the scan cache using the 31-day window and settings used by the retention behavior changed there.
- pingdotgg/t3code#29724 — This PR starts cache warm-up through UsageService and exercises the parser-backed scan implementation added there.
Suggested reviewers: maria-rcks, t3dotgg, pixpmusic
Merge Risk: 
Minimal · up to b581f
-
The startup cache warm-up remains active, and the previously reported delays have been addressed. No actionable merge-blocking risk remains after normal checks.
Pre-merge checks: 
4
-
Full details: Description check
-
Explanation
The description explains the problem, implementation, scope approval, performance impact, and focused tests. It uses a "Tests" heading instead of the required "Verification" heading, but the required verification details are present.
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
CodeRabbit Verify
- Run CodeRabbit Verify to test the changes in this pull request.
Dismissing prior approval to re-evaluate 6806f5b
The first usage summary after a restart on a fresh or stale cache paid for parsing every changed transcript. After activation the server now parses the default 30-day window into the persisted scan cache in the background; a summary arriving meanwhile waits for that warm-up instead of parsing the same files again. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ces while waiting A summary in flight at activation used to make the warm-up skip for the server's lifetime, even when it covered only an hour or a day. The warm-up now waits for in-flight summaries and then warms the rest of the window from cache. A summary that waits on the warm-up now fetches prices in the meantime instead of afterwards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6806f5b to
b581f66
Compare
Stacked on https://git.cafe/pingdotgg/t3code/pulls/29724.
After a restart with a cold or stale scan cache, the first
server.getUsageSummarypaid for parsing every changed transcript while the user waited: p50 8.6s and p95 34s on a fresh install. The per-file scan cache is persisted, so this work only has to happen once per new or changed file, and it can happen before anyone opens the usage page.Change
UsageService.warmScanCacheresolves the transcript directories and parses the default 30-day window (31 days, to cover the client's local-midnight start) into the scan cache, then persists it. It only covers transcript directories; account-based scan readers (Cursor, etc.) still run on request because they make network calls.UsageService.layerWarmupforks it withforkParked, so it starts only after server activation and never delays readiness. It is wired in next to the other post-activation background layers inserver.ts. Parsing runs in the layer-1 child processes, so the server's main thread stays mostly idle.UsageService.awaitWarmupspan) and then reads the warmed cache, instead of parsing the same files a second time. The warm-up skips itself if a summary is already in flight, because that summary warms the cache anyway. Later restarts only parse files that are new or grew.Before / after
On cups, against the real
~/.claude+~/.codexdata (3,779 files, 292k records, 30-day window):Tests
A new
UsageService.test.tscase:Deferred.No sleeps or polling.
Scope and approval: maintainer-approved direction from the 2026-11-02 fleet trace audit
🤖 Generated with Claude Code