Skip to content

feat(storage): bound memory storage with optional maxSize + LRU eviction - #38

Merged
pi0 merged 4 commits into
mainfrom
fix/mem-limit
Jul 7, 2026
Merged

pi0 merged 4 commits into
mainfrom
fix/mem-limit

Conversation

@pi0x

@pi0x pi0x commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Closes #35

Summary

createMemoryStorage() was backed by an unbounded Map — entries were only removed via TTL expiry or explicit deletion. High-cardinality keys (per-URL / per-user) and TTL-less entries could accumulate indefinitely, an unbounded memory leak that ends in OOM.

This adds an opt-in size ceiling with LRU eviction while keeping the zero-config path unchanged.

Changes

  • createMemoryStorage(opts?) now accepts { maxSize?: number } (entry count).
    • get() promotes a hit to most-recently-used (reinsert; Map preserves insertion order).
    • set() reinserts at the most-recent position, then evicts the oldest entries (clearing their TTL timers) until back under the ceiling.
  • Default unchanged: maxSize unset/0 → fully unbounded.
  • Exported new MemoryStorageOptions type.
  • Documented maxSize in the README Custom Storage section (automd API block regenerated).
  • Added tests: LRU eviction, get/re-set refreshing recency, unbounded-by-default.

Notes

  • maxSize bounds entry count, not approximate byte size — simpler and predictable; byte-size accounting can be a follow-up.
  • Kept unbounded as the default (issue's first suggested option) to avoid silently changing behavior for existing users.

Verification

  • Tests: 103 passed
  • tsgo --noEmit: clean
  • obuild: succeeds

🤖 Generated with Claude Code

pi0 and others added 2 commits July 7, 2026 15:02
…Storage

createMemoryStorage() was backed by an unbounded Map — entries were only
removed by TTL expiry or explicit deletion, so high-cardinality or
TTL-less keys could grow without limit and OOM.

Add an optional maxSize (entry count) to createMemoryStorage(opts). When
set, get() promotes hits to most-recently-used and set() evicts the
least-recently-used entries once over the ceiling. Default stays
unbounded so the zero-config path is unchanged.

Closes #35

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Apply a sensible default bound (DEFAULT_MEMORY_MAX_SIZE = 1000) so the
zero-config memory storage is safe out of the box. Pass maxSize to change
the ceiling or Infinity to opt back into unbounded growth.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@pi0x, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 449558cb-bc8d-4045-896a-250f00b182df

📥 Commits

Reviewing files that changed from the base of the PR and between 078b750 and 8e4eb90.

📒 Files selected for processing (4)
  • README.md
  • src/index.ts
  • src/storage.ts
  • test/index.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mem-limit

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

pi0 and others added 2 commits July 7, 2026 15:07
Per perf review, 1000 is low for a general/HTTP cache keyed per-URL and
could thrash. Raise DEFAULT_MEMORY_MAX_SIZE to 10 000 — still bounds
memory against unbounded high-cardinality growth while avoiding eviction
churn for typical workloads.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Not part of the public API — drop it from index exports and the generated
API docs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@pi0
pi0 merged commit 0266ada into main Jul 7, 2026
4 checks passed
@pi0
pi0 deleted the fix/mem-limit branch July 7, 2026 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

createMemoryStorage is unbounded — add maxSize / LRU eviction

2 participants