Skip to content

fix: reject unsafe in-memory cache bounds - #1779

Open
kang-heewon wants to merge 1 commit into
trunkfrom
fix/1707-cache-option-validation
Open

fix: reject unsafe in-memory cache bounds#1779
kang-heewon wants to merge 1 commit into
trunkfrom
fix/1707-cache-option-validation

Conversation

@kang-heewon

Copy link
Copy Markdown
Member

Outcome

InMemoryCacheStore now rejects unsafe maxEntries and cleanupIntervalMs values before allocating a cleanup timer or accepting entries. Capacity must be a positive safe integer, and cleanup intervals must be positive integer delays no greater than 2,147,483,647 milliseconds.

Invalid values produce the stable cache-core/invalid-configuration Problem with the offending option and value. Existing valid cleanup and LRU behavior remains unchanged.

Fixes #1707

Reviewer context

  • The new public Problem, option type, and numeric bounds are exported from @croco/cache-core and documented.
  • @croco/cache-core receives a minor changeset; generated Problem registry metadata requires a patch changeset for @croco/problems-core.
  • The full API-doc generator also synchronized existing deterministic drift in the Problem subclass list, tRPC option ordering, and HTTP pipe factory rendering; these files contain no runtime changes.

Verification

  • Pre-fix focused test: 14 invalid numeric cases failed by being accepted
  • pnpm --filter @croco/cache-core test — 107 passed
  • pnpm --filter @croco/cache-core typecheck — passed
  • pnpm --filter @croco/cache-core lint — passed with 0 warnings/errors
  • pnpm --filter @croco/cache-core... build — passed
  • pnpm docs:api:check — 116 build tasks and 4,529 pages passed; generated API docs match
  • pnpm check — 24/25 passed, 1 not applicable
  • pnpm public-api:check, problem-registry:check, docs:api-triggers:check, and package-manifests:check — passed
  • pnpm changeset-required:check -- --base origin/trunk --head HEAD — passed
  • Pre-push workspace gates — 234/234 test tasks and 233/233 typecheck tasks passed

Review gates

  • Correctness and regression — PASS. Tests cover zero, negative, null, NaN, both infinities, fractions, values above each maximum, both valid boundaries, no timer allocation on invalid input, and unchanged periodic cleanup behavior.
  • API, security, compatibility, and release — PASS. Public exports, API docs, Problem registry, recovery guidance, snapshots, manifests, and changesets are synchronized. Valid configurations keep their prior semantics; invalid configurations fail earlier with stable diagnostics.
  • Maintainability and minimality — PASS. One shared numeric validator enforces both resource bounds at construction, and runtime changes remain confined to cache-core. Other source packages are unchanged.
  • Independent adversarial review — PASS after fix. A runtime maxEntries: null defaulting gap was found, fixed with undefined-only defaulting, and covered for both options; re-review found no remaining actionable findings.

Residual risk

JavaScript consumers that previously relied on timer clamping or invalid capacities now fail at construction and must supply values within the documented bounds.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 24 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 756b17be-b645-41a6-bfd5-07ea842be394

📥 Commits

Reviewing files that changed from the base of the PR and between 6795b4d and 1059888.

⛔ Files ignored due to path filters (1)
  • packages/problems-core/src/generated/problem-code-registry.ts is excluded by !**/generated/**
📒 Files selected for processing (20)
  • .changeset/safe-cache-resource-bounds.md
  • docs/problem-code-registry.json
  • packages/cache-core/README.md
  • packages/cache-core/src/index.ts
  • packages/cache-core/src/libs/InMemoryCacheStore.ts
  • packages/cache-core/src/libs/numericValidation.ts
  • packages/cache-core/src/libs/problems/CacheStoreProblems.ts
  • packages/cache-core/src/tests/CacheExports.spec.ts
  • packages/cache-core/src/tests/InMemoryCacheStore.spec.ts
  • packages/docs/src/content/docs/api/cache-core/src/classes/InvalidCacheConfigurationProblem.md
  • packages/docs/src/content/docs/api/cache-core/src/type-aliases/CacheNumericOption.md
  • packages/docs/src/content/docs/api/cache-core/src/type-aliases/InMemoryCacheStoreOptions.md
  • packages/docs/src/content/docs/api/cache-core/src/variables/MAX_CACHE_ENTRIES.md
  • packages/docs/src/content/docs/api/cache-core/src/variables/MAX_CACHE_TIMER_DELAY_MS.md
  • packages/docs/src/content/docs/api/problems-core/src/classes/Problem.md
  • packages/docs/src/content/docs/api/problems-core/src/variables/CROCO_PROBLEM_CODE_REGISTRY.md
  • packages/docs/src/content/docs/api/protocols-trpc/src/type-aliases/TrpcRouterOptions.md
  • packages/docs/src/content/docs/api/transports-http/src/classes/ParamResolver.md
  • packages/docs/src/content/docs/en/reference/problem-recovery-cookbook.md
  • public-api-surface.snapshot.json

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.

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

📊 Benchmark Results

✅ All benchmarks passed

Benchmark p75 Threshold Baseline vs Baseline Status Notes
CrocoApp constructor 44.9μs 30.0ms 8.2μs +448.8% -
CrocoApp lambdaHandler (10 controllers) 2.2ms 50.0ms 258.4μs +741.0% -
Lambda cold-start simulation 1.8ms 80.0ms 418.1μs +324.1% -
Lambda cold-start with headers 1.6ms 80.0ms 369.7μs +340.4% -
Lambda cold-start with binary body 1.6ms 80.0ms 339.1μs +359.4% -
Lambda cold-start with query params 1.5ms 80.0ms 301.3μs +410.5% -
Lambda cold-start with authorizer context 1.6ms 80.0ms 299.8μs +418.1% -
Lambda cold-start realistic scenario 1.5ms 80.0ms 299.2μs +413.9% -
EventBusConfig.start (10 handlers) 1.7μs 10.0ms 1.4μs +20.2% -
EventPublisher.publishNow single event 1.9μs 2.0ms 1.7μs +14.9% -
DefaultHandlerResolver.resolve × 10 0.1μs 5.0ms 0.1μs -11.2% -
Container.get singleton (cold) 94.9μs 5.0ms 70.3μs +35.0% -
Container.register × 50 components 3.7ms 10.0ms 3.2ms +13.5% -
Container.validate (50 components) 4.0ms 20.0ms 3.4ms +19.2% -
Container.get singleton (warm) 1.7μs 500.0μs 1.6μs +4.3% -
TelemetryRuntime.init (lambda preset) 2.4μs 200.0ms 1.1ms -99.8% -
lambdaPreset config creation 1.6μs 2.0ms 1.4μs +10.6% -

Updated: 2026-08-08T08:07:11.300Z · Commit: 752fcb1

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.

[cache-core] Reject invalid capacity and cleanup intervals before creating timers

1 participant