Skip to content

cache-manager: add opt-in protection against stale wrap writes - #1764

Merged
jaredwray merged 1 commit into
mainfrom
fix/cache-manager-stale-wrap-writes
Nov 19, 2026
Merged

jaredwray merged 1 commit into
mainfrom
fix/cache-manager-stale-wrap-writes

Conversation

@jaredwray

Copy link
Copy Markdown
Owner

Fixes #1763.

wrap() can restore a deleted key or replace an explicit value when an older loader finishes. This change adds the preventStaleWrapWrites option to createCache(). The default is false.

With the option active, set() and del() take precedence over older cache fills for the same key in the same instance. The original caller still receives its result. A later wrap() can start a new loader. The same rule applies to background refreshes and copies from a lower tier.

The cache orders store writes per key and waits for every store before it starts the next write. Other keys can proceed independently. The option covers single-key operations. Bulk operations, clear(), and changes from other instances are outside its scope.

Verification

  • pnpm build and node scripts/test-build.mjs passed.
  • The TypeScript check passed for the package and its tests.
  • pnpm test passed all 1,406 tests on Node 24. All 99 tests in cache-manager passed. The package reached 100% line, branch, function, and statement coverage.
  • All eight new cases with protection active failed on d6b7d6f and passed on 093ca90. The default-behavior case passed on both commits.
  • The test audit below covers all nine cases. The tests use public cache and store methods. No existing test changed.

Test audit

  • Cold fill after deletion, two cases. The original caller receives its value. The option determines whether the old loader can restore the key. The default case protects compatibility.
  • New loader after deletion. Two later calls share one new loader while the old loader is active. The existing concurrency test covers calls without a deletion.
  • Background refresh after a set. The old refresh must preserve the new value. Only the new refresh emits a success event. The existing refresh tests do not overlap an explicit write.
  • Active store write, two modes. A newer set wins after the old fill enters the store. An unrelated key can proceed. The nonblocking case also checks early return.
  • Partial store failure. A failed tier must not release a queued deletion while another tier can still save the old value.
  • Copy from a lower tier, two modes. A slow tier can return an older snapshot. The original caller receives it, and the primary store keeps the newer explicit value.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T07:47:02.079303Z 093ca90 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@codecov

codecov Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (d6b7d6f) to head (093ca90).

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #1764   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           29        30    +1     
  Lines         3632      3702   +70     
  Branches       812       845   +33     
=========================================
+ Hits          3632      3702   +70     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jaredwray
jaredwray merged commit b7611eb into main Nov 19, 2026
16 checks passed
@jaredwray
jaredwray deleted the fix/cache-manager-stale-wrap-writes branch November 19, 2026 07:50
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-manager] Stale wrap() loader or background refresh can overwrite newer del() / set()

1 participant