Repository navigation
Description
What happened
Changing only the Usage activity search text or status rebuilds the complete screen statistics even when the resolved time range and Usage revision have not changed. Headline accounting, provider/model/tool breakdowns, pricing and provenance do not depend on those activity filters.
At 0117d76c5688475e7467ee6db83057bf65edbabd, the public readUsageScreen facade repeats four range aggregation/grouping queries and the unreadable-checkpoint SUM for each such request. A deterministic regression with 62 model records plus one tool observes 5 aggregation statements instead of 0 after changing the search text, while the expected range statistics remain identical.
Expected: reuse a bounded complete statistics projection for the same reader/database lifecycle, Usage revision and exact from/to boundaries. Read the revision, activity count and page in the same transaction. Keep all existing accounting, capacity and revision-fencing behavior.
How to reproduce
- Build Core and Storage from the baseline above.
- Populate an interactive root with model/tool Usage history.
- Read a screen with
{ range: { from, to }, search: '', status: 'all' }. - Without changing the data or range, request another screen with search
gptor a different activity status. - Observe that
usage-screen.tsrecomputes the model aggregate, provider/model/tool groups, pricing and provenance before reading the filtered activity, despite returning the same statistics.
Implementation and regression coverage: #5517. Its PR description includes the reproducible A/B commands, Node/Electron measurements and validation limits. Measurements must distinguish same-revision filter changes from range/revision changes, where recomputation is expected.
Environment
- Maka baseline:
0117d76c5688475e7467ee6db83057bf65edbabd - Surface: Storage
readUsageScreen, consumed by Runtime Host / Desktop Usage - macOS / arm64; Node 24.14.0 / SQLite 3.51.2
- Also verify the shipped Electron SQLite runtime
Logs, screenshots, or additional context
Acceptance:
- Reuse complete range statistics across search/status changes at the same revision and resolved time boundaries, with a fixed cache size owned by the existing reader lifecycle.
- Publish cached values only after the outermost transaction commits; a rollback and subsequent reuse of the revision counter cannot expose rolled-back statistics.
- Returned results remain independent: Host projection/mutation and deep freezing cannot corrupt or freeze the cached values.
- Data, pricing, repair, range, root and reader-lifecycle changes cannot return stale statistics. Cache hits preserve a coherent snapshot under external WAL writes and the existing capacity failure contract.
- Include regression coverage and same-process before/after measurements, including cache misses. Record performance evidence in the PR description.
Parent tracker: #5038. This is the statistics-reuse follow-up to #5515 / #5514. Pagination SQL and count improvements remain in #5514; frontend debounce and navigation remain in #5410. Continuous writes may invalidate the cache frequently. First-range aggregation, exact filtered counts and sparse substring searches remain range-sized work.
AI assistance: Codex inspected the source, reproduced the repeated work and drafted this issue under contributor direction.
Implementation submitted in #5517 (independent branch from the main baseline above). Acceptance is pending maintainer review and merge.
Activity
perf(storage): reuse Usage range statistics across filter changes (ap…