Skip to content

Write Node persistent caches without node-persist's write queue - #346

Merged
InventivetalentDev merged 4 commits into
mainfrom
fix/node-cache-write-queue
Oct 21, 2026
Merged

InventivetalentDev merged 4 commits into
mainfrom
fix/node-cache-write-queue

Conversation

@InventivetalentDev

@InventivetalentDev InventivetalentDev commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

What

NodeEnv.openCache creates node-persist stores with writeQueue: false, so a persistent put resolves as soon as its file is written. NodeCache serializes writes to the same key while allowing different keys to write concurrently. put returns the supplied value, matching its Promise<T> contract, instead of node-persist's stored record.

Why

With node-persist's default write queue, a setItem that starts while another write is in progress resolves from a one-second setInterval that node-persist unrefs. PersistentCache.getOrLoad awaits that write, so a load can stall for up to a second. In a short-lived Node process, nothing else keeps the event loop alive, and Node exits with the load still pending (exit code 13 for an unsettled top-level await).

Risk

Low. Only Node persistent caches change. Same-key writes must remain ordered to prevent corrupt JSON; a failed write must reject its caller without preventing later writes to that key.

Testing

  • yarn workspace minerender typecheck and yarn build:lib: pass.
  • Three focused native cache tests pass: prompt writes and returned values, overlapping same-key writes followed by reopening, and deterministic write ordering and failure recovery while other keys remain independent.
  • The same-key overlap probe produced corrupt JSON with the unguarded writeQueue: false change; it passes with the per-key queue.

Note

AI-assisted.

…ite queue

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added library Public minerender package (packages/minerender) fix Bug fix (fix/ branches) labels Oct 21, 2026
@InventivetalentDev
InventivetalentDev marked this pull request as ready for review October 21, 2026 19:11
@InventivetalentDev
InventivetalentDev merged commit 4951e0f into main Oct 21, 2026
3 checks passed
@InventivetalentDev
InventivetalentDev deleted the fix/node-cache-write-queue branch October 21, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix (fix/ branches) library Public minerender package (packages/minerender)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant