Concurrent disk-cache loads parse the embedding JSONL twice
Description
ensureDiskCacheLoaded() and startDiskCacheLoad() can race: two callers see !diskCacheLoaded && !diskCacheLoadPromise and both run loadDiskCache(). The 305MB JSONL is parsed twice on the HTTP thread. Logs show:
[memorix] Loaded 27320 cached API embeddings from disk
[memorix] Loaded 27320 cached API embeddings from disk
Steps to Reproduce
- Large JSONL cache, cold process.
- Two concurrent paths call
ensureDiskCacheLoaded()/ providercreate()(HTTP session + deferred attach, or two MCP sessions during OpenCodemcp list). - Count
Loaded N cached API embeddingslines in~/.memorix/background.log.
Expected Behavior
A single in-flight promise. One parse. Later callers await the same promise.
Actual Behavior
Two full streaming parses. Extra event-loop load during MCP initialize.
Environment
- Memorix 1.6.0
- Observed on macOS HTTP control plane while OpenCode listed 27 MCP servers
Additional Context
#214 single-flights ensureDiskCacheLoaded() through diskCacheLoadPromise before awaiting.
Related: #214.
Fix is in PR https://github.com/AVIDS2/memorix/pull/214 — not on main yet, so leaving this issue open until that PR merges.
Relevant work:
01763fa1ee— concurrent disk-cache loads are single-flighted so the JSONL is not parsed twice- Files:
src/embedding/api-provider.ts
Fixed by #214 and released in v1.6.2. Concurrent cache loads are single-flighted so the JSONL cache is not parsed twice. Closing as shipped.