memorix icon indicating copy to clipboard operation
memorix copied to clipboard

Concurrent disk-cache loads parse the embedding JSONL twice

Open RaviTharuma opened this issue 3 months ago • 2 comments

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

  1. Large JSONL cache, cold process.
  2. Two concurrent paths call ensureDiskCacheLoaded() / provider create() (HTTP session + deferred attach, or two MCP sessions during OpenCode mcp list).
  3. Count Loaded N cached API embeddings lines 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.

RaviTharuma avatar Aug 17 '26 13:08 RaviTharuma

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

RaviTharuma avatar Aug 17 '26 16:08 RaviTharuma

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.

AVIDS2 avatar Aug 18 '26 10:08 AVIDS2