fix(usage): bound startup hydration tail reads - #1256
Conversation
📝 WalkthroughWalkthrough
ChangesRecent usage read bounding
Estimated code review effort: 2 (Simple) | ~10 minutes 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 |
|
✅ Deterministic PR hygiene checks passed. |
5011789 to
86f8160
Compare
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Ingwannu
left a comment
There was a problem hiding this comment.
Reviewed exact head 86f81604. Startup hydration is now capped to a 64 MiB tail instead of expanding to an unbounded whole-file read, while preserving newest-valid-row parsing within that window. Focused coverage passed locally (30 tests), git diff --check passed, and typecheck passed. Core Linux/macOS/keyring/storage shards are green; the remaining npm-global/gates jobs are still queued, so do not merge until the exact head is fully green.
86f8160 to
f2ce1ea
Compare
Ingwannu
left a comment
There was a problem hiding this comment.
Re-reviewed rebased exact head f2ce1ea5. The PR diff is unchanged in scope from the approved bounded-tail patch. Exact-head focused tests passed 30/30 and typecheck passed. Do not merge until the newly triggered exact-head CI is green.
f2ce1ea to
7c40ac6
Compare
⏳ DRAFT
What to do
Review readiness checklist
0/4 boxes ticked. This PR stays in draft until every box above is ticked. |
|
Rebased exact head Focused verification on the rebased state:
The branch is now exactly one commit ahead and zero behind |
Summary
readRecentUsageEntries()startup hydration at a 64 MiB tail window;Why
readRecentUsageEntries()starts with a small tail window and multiplies it until enough valid rows are found. Before this change, the upper bound was the fullusage.jsonlsize. A large or malformed persisted row could therefore make every startup allocate and parse the complete ledger even though the caller only requests a small recent set.The management/history paths already use separately bounded readers. Startup hydration should have the same finite-memory property.
Behavior
The reader still returns the newest valid entries that fit inside the retained window and still expands for trace-sized rows. It now stops at 64 MiB. If that bounded tail contains no newline, the function returns an empty recent set rather than attempting a whole-file read. The append-only ledger itself is not modified.
Verification
tests/usage-log.test.ts30/30 passed.b22e0e6d0): the same suite 30/30 passed.bun x tsc --noEmit: passed.bun scripts/privacy-scan.ts: passed.git diff --check: passed.Checklist
Ready for review; upstream CI and maintainer review remain pending.
Summary by CodeRabbit
Bug Fixes
Tests
Review readiness checklist
This PR stays in draft until every box below is ticked. Tick all four boxes once the requirements are met:
All CI tests are green on my local testing.
I pushed my PR to the latest dev commit.
I resolved all correct Codex and CodeRabbit findings.
My PR is ready for review.