feat(usage): raise the management read entry cap from 200k to 500k - #1099
Conversation
The cap is a reader bound, not retention: it silently clipped what one management read could return for small-row logs inside the already-bounded 64 MiB byte window. Benchmarked at the cap-binding worst case (63.5 MiB / 629k tiny rows, unique request ids): read 1.4s + summarize 0.6s, ~0.9 GiB transient RSS, request-scoped — inside the recorded acceptance threshold. Devlog: devlog/_plan/260806_disposition_sweep/060_usage_cap_500k.md
|
✅ Deterministic PR hygiene checks passed. |
📝 WalkthroughWalkthroughThe management usage log retention limit increases from 200,000 to 500,000 entries. The truncation test and usage-cap disposition plan update the corresponding expectations, timing note, benchmark criteria, and results. ChangesUsage log retention cap
Estimated code review effort: 2 (Simple) | ~10 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ 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.
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 `@src/usage/log.ts`:
- Line 424: Validate production Bun memory headroom with a cap-binding read and
concurrent /api/usage requests, including the separate entries.slice() behavior
in readUsageSnapshotForManagement. If headroom is insufficient, update
parseUsageTextCooperatively or the aggregation path to retain only the newest
MANAGEMENT_USAGE_MAX_ENTRIES entries, or enforce an appropriate
deployment-specific lower limit.
🪄 Autofix
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: ASSERTIVE
Plan: Pro Plus
Run ID: 49ce273c-bbc2-4688-910e-fec7e42e28f3
📒 Files selected for processing (3)
devlog/_plan/260806_disposition_sweep/060_usage_cap_500k.mdsrc/usage/log.tstests/usage-log.test.ts
| const MANAGEMENT_USAGE_MAX_READ_BYTES = 64 * 1024 * 1024; | ||
| const MANAGEMENT_USAGE_READ_CHUNK_BYTES = 1024 * 1024; | ||
| const MANAGEMENT_USAGE_MAX_ENTRIES = 200_000; | ||
| const MANAGEMENT_USAGE_MAX_ENTRIES = 500_000; |
There was a problem hiding this comment.
🚀 Performance & Scalability | 🔵 Trivial
Verify production memory headroom before release.
parseUsageTextCooperatively parses the complete byte-window input before it applies MANAGEMENT_USAGE_MAX_ENTRIES. The higher cap therefore allows more entries to remain in the snapshot and flow into /api/usage aggregation. The devlog reports approximately 897 MiB transient RSS for the cap-binding case at devlog/_plan/260806_disposition_sweep/060_usage_cap_500k.md:49. Identical reads share parsing, but readUsageSnapshotForManagement still returns a separate entries.slice() to each caller.
Run one cap-binding read and concurrent /api/usage requests under the production Bun memory limit. If the process lacks sufficient headroom, bound parsing or aggregation to the newest 500,000 entries, or enforce a deployment-specific lower limit.
🤖 Prompt for 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.
In `@src/usage/log.ts` at line 424, Validate production Bun memory headroom with a
cap-binding read and concurrent /api/usage requests, including the separate
entries.slice() behavior in readUsageSnapshotForManagement. If headroom is
insufficient, update parseUsageTextCooperatively or the aggregation path to
retain only the newest MANAGEMENT_USAGE_MAX_ENTRIES entries, or enforce an
appropriate deployment-specific lower limit.
Summary
MANAGEMENT_USAGE_MAX_ENTRIESinsrc/usage/log.tsfrom 200,000 to 500,000. The cap is a reader bound, not retention: for small-row logs it silently clipped what one management read could return inside the already-bounded 64 MiB byte window, hiding history from/api/usagewithout deleting it.tests/usage-log.test.ts) to the 500,001-row shape and refreshes its timing comment.devlog/_plan/260806_disposition_sweep/060_usage_cap_500k.mdrecords the synthesis, the audit rounds, and the benchmarks (lands separately with the sweep unit's follow-up; the doc is committed on this branch).Verification
bun test tests/usage-log.test.ts tests/api-usage.test.ts tests/usage-rollup-merge.test.ts— 37 pass / 0 fail (cap test passes withinSTORE_BUDGET_MS).bun x tsc --noEmitclean.src/usage/log.tschanges.Checklist
Summary by CodeRabbit
New Features
Documentation