memorix icon indicating copy to clipboard operation
memorix copied to clipboard

memorix_store can hang until MCP client timeout (observed 6000s)

Open RaviTharuma opened this issue 3 months ago • 3 comments

Description

memorix_store can fail to return a tool result for the full lifetime of the MCP client timeout. In Grok this default is 6000 seconds. Two production sessions recorded:

  • 2026-08-10T21:40:08Z → 2026-08-10T23:20:08Z — memorix_store duration_ms=6000002 success=false — MCP tool 'memorix_store' timed out after 6000 seconds
  • 2026-08-12T12:01:00Z → 2026-08-12T13:41:00Z — same error, duration_ms=6000010

Successful stores in the same sessions typically complete in ~1.4–5.2s (p50 ≈ 5094ms). The hang is not “slow formation”; the MCP call never completes until the client gives up.

The control plane was memorix 1.4.3 over HTTP (http://127.0.0.1:3211/mcp), formation = "active", LLM + embeddings via an OpenAI-compatible proxy (mistral/mistral-small-latest, mistral/mistral-embed). Embedding logs at the same time show 402 and 10–15s timeouts.

1.4.3 already wraps runFormation in withTimeout(..., FORMATION_TIMEOUT_MS) (default 12s) and then falls back to storing a base observation. That path cannot explain a 100-minute hang by itself. Something after/around store (embeddings in storeObservation, streamable-HTTP session, or a withTimeout that rejects without aborting the in-flight fetch) is not bounded.

Steps to Reproduce

  1. Run HTTP control plane: memorix serve-http --port 3211 with formation = "active" and an OpenAI-compatible LLM/embedding endpoint that is slow, returns 402, or never closes the HTTP body.
  2. Connect an MCP client that fires memorix_store (Grok, Claude Code, etc.).
  3. Optionally fire overlapping memorix_store / memorix_search on the same streamable-HTTP session (Grok does this).
  4. Wait. Formation should time out at 12s; instead the client often waits until its tool timeout (here 6000s).

Expected Behavior

Every MCP tool, especially memorix_store, should return an error or a degraded success within a hard budget (formation + embed + SQLite). In-flight LLM/embedding fetches should be aborted. The client should never wait tens of minutes.

Actual Behavior

The tool call stays open until the client timeout. Host chats look frozen and then just stop. No useful error is shown in the chat UI.

Environment

  • OS: macOS (darwin arm64)
  • Memorix: 1.4.3 (npm), HTTP control plane
  • Client: Grok (tool_timeout_sec default 6000)
  • SQLite store: ~/.memorix/data/memorix.db (~318MB + ~111MB WAL), generation 7897, ~20k observations
  • LLM/embed: OpenAI-compatible upstream returning 402 / 10–15s timeouts

Screenshots/Logs

Grok events.jsonl:

mcp_tool_call_started  memorix_store  2026-08-10T21:40:08.589Z
mcp_tool_call_completed memorix_store 2026-08-10T23:20:08.633Z  duration_ms=6000002  success=false
  error: MCP tool 'memorix_store' timed out after 6000 seconds

Control plane around the same period:

[memorix] Embedding batch too large for provider, retrying in chunks of 6
... chunks of 3, 2, 1
[memorix] Embedding provider temporarily unavailable at runtime: Embedding API error (402): ...
[memorix] Embedding failed or timed out, falling back to fulltext search
[memorix] Session … timed out (idle 30min), closing

Additional Context

withTimeout in src/timeout.ts only rejects the wrapper promise; it does not abort the underlying fetch. Combined with sequential embed-batch shrink retries, a single store can keep the event loop / HTTP session busy far longer than FORMATION_TIMEOUT_MS.

Related: HTTP session idle close (30min) and embedding 402 retry storm — filing as separate issues.

RaviTharuma avatar Aug 14 '26 07:08 RaviTharuma

Companion issues from the same Grok/HTTP control-plane investigation:

  • #197 HTTP idle session close
  • #198 project bind to server cwd
  • #199 embedding 402 retry storm
  • #200 withTimeout does not abort fetch (likely root of this hang)

RaviTharuma avatar Aug 14 '26 07:08 RaviTharuma

1.6.1 已经发出。这条链路这次重新走过:请求取消和超时边界仍然生效,#206 也把 hook 的 stdin、进程时限和写入路径一起收住了,不会再把 agent 卡在一次很长的 store 调用里。三平台完整 CI 和发布前全量测试都过了。感谢你把这个问题追到可复现。

AVIDS2 avatar Aug 17 '26 04:08 AVIDS2

Related remaining latency on 1.6.0 after HTTP is already healthy: first memorix_session_start / CLI memory store still takes 15–28s on 40k+ stores (loadAll() + lexical hydrate). Not a 6000s hang, but enough to trip 10–15s MCP client timeouts.

New write-up: #224.

RaviTharuma avatar Aug 17 '26 13:08 RaviTharuma