memorix icon indicating copy to clipboard operation
memorix copied to clipboard

Startup should not block MCP availability on full embedding rebuild

Open RaviTharuma opened this issue 8 months ago • 3 comments

Summary

Starting the MCP server currently does a full reindexObservations() during startup and hot reload. On larger projects with API embeddings enabled, that couples MCP availability to corpus-wide embedding throughput.

In practice this can block the entire Memorix MCP from becoming available to clients like OpenCode, even though lexical/fulltext search could be ready immediately.

Why this matters

For large corpora, startup currently does all of the following before the MCP is usable:

  • resets the Orama DB
  • reloads all observations
  • batch-generates embeddings for the full corpus
  • waits on provider retries / rate limits before tool availability finishes

That is the wrong coupling. MCP startup should only need a usable search index, not a complete vector rebuild.

Observed impact

In an OpenCode session that depended on Memorix MCP, the session would stall during tool resolution until Memorix finished startup work. After switching startup to lexical hydration only, the same session recovered immediately:

  • 2026-03-27T214400.log:274 service=session.prompt status=started resolveTools
  • 2026-03-27T214400.log:907 [memorix] Prepared search index for 8024 observations in project: RaviTharuma/opencode
  • 2026-03-27T214400.log:921 service=mcp key=mcpm_memorix toolCount=34 create() successfully created client
  • 2026-03-27T214400.log:929 service=session.prompt status=completed duration=9825 resolveTools

Before the patch, startup followed the heavy rebuild path and became sensitive to embedding-provider delays / rate limits on a roughly 8k to 10k observation corpus.

Root cause

createMemorixServer() currently uses the heavy rebuild path on startup and hot reload.

That path is appropriate for explicit rebuilds, but not for startup:

  • startup only needs lexical/fulltext search to be available immediately
  • vector enrichment can happen asynchronously afterward

Proposed fix

Introduce a lighter startup path that:

  • resets the in-memory DB
  • hydrates the lexical/BM25 index from persisted observations
  • does not call batch embedding generation during startup
  • queues active observations for existing background vector backfill when embeddings are enabled

Keep the current heavy full rebuild path for explicit reindex operations.

Verification from the patch branch

  • tests/memory/prepare-search-index.test.ts
  • npx vitest run tests/integration/release-blockers.test.ts
  • bunx tsc --noEmit
  • npm run build

I already have a patch prepared on my fork and will open a PR linked to this issue.

RaviTharuma avatar Mar 27 '26 22:03 RaviTharuma

Thanks for surfacing this. We agree startup should not block MCP availability during a full embedding rebuild, and we plan to address this in an upcoming release. We’ll treat this as an availability / startup-behavior issue rather than a purely search-quality issue, so the MCP control plane becomes usable before long-running embedding work finishes.

AVIDS2 avatar Apr 08 '26 03:04 AVIDS2

Thanks for confirming. Happy to help test or provide feedback on the implementation when it lands.

RaviTharuma avatar Apr 08 '26 17:04 RaviTharuma

Reproduced again on Memorix 1.6.0 (2026-08-17) in HTTP control-plane mode, not only the old full embedding rebuild.

/health and MCP initialize time out on ~40k–64k observation hosts while the process hydrates the corpus and parses a ~305MB embedding cache on the HTTP thread. New write-up: #215. Related: #223 (attach starves initialize after health is already green). Proposed fix: #214.

RaviTharuma avatar Aug 17 '26 13:08 RaviTharuma