memorix icon indicating copy to clipboard operation
memorix copied to clipboard

Formation timeout fires far past its budget (43-90s after 12s) — event-loop starvation during startup reindex / cache restore

Open chenshuangci opened this issue 3 weeks ago • 2 comments

Symptom

The formation timeout budget is enforced far too late. Repeated journal lines like:

[memorix] Formation timed out in memorix_store after 61778ms/12000ms at stage resolve | completed: extract=1ms
[memorix] Formation timed out in memorix_store after 68340ms/12000ms at stage resolve | completed: extract=0ms
[memorix] Formation timed out in memorix_store after 87263ms/12000ms at stage resolve

withTimeoutSignal rejects via setTimeout(..., 12000), but the rejection surfaces 43–90s after the budget expired (elapsed measured by the code in its own catch block). If the elapsed value is trustworthy, the timer callback itself ran tens of seconds late — i.e. the event loop was blocked for that long.

Clusters of 6–8 such lines in a row; every cluster is preceded within seconds by:

Startup reindex: restored cached API embeddings; uncached vectors stay in background recovery

Environment

  • memorix 1.10.3, serve-http (control-plane), team layout, Linux, Node 22
  • embedding via local llama-server (OpenAI-compatible, qwen3-embedding-8b, 4096d) — idle and responsive at every failure timestamp (±40s window, no slot activity)
  • embedding API cache jsonl ~400MB / ~6.9k entries; sqlite db ~227MB
  • systemd reports a ~7.1G memory peak for the endpoint process

Suspects

  1. Synchronous work in the startup reindex / embedding-cache restore path starving the loop (the log line above correlates with every cluster).
  2. Long major-GC pauses given the heap peak.

A budget enforced by a setTimeout cannot defend callers while the loop is blocked, so this is worth instrumenting regardless of which suspect wins:

  • perf_hooks.monitorEventLoopDelay around startup reindex / cache restore to pin the blocker
  • periodic yielding during cache restore / hydration loops
  • the whole-file worker parse already runs off-thread; the streaming row path may still run on the main thread

Happy to share journal excerpts and timing data.

chenshuangci avatar Nov 11 '26 21:11 chenshuangci

Resolved in PR #399 (merged to main as 521933c). Cache restoration now yields through the timer phase in bounded batches and starts after provider initialization, preventing startup reindex work from delaying formation deadlines. Local full suite: 3329 passed, 5 skipped.

AVIDS2 avatar Nov 18 '26 10:11 AVIDS2

Closing after the fix shipped in PR #399.

AVIDS2 avatar Nov 18 '26 10:11 AVIDS2