memorix icon indicating copy to clipboard operation
memorix copied to clipboard

withTimeout does not abort in-flight LLM/embedding fetches

Open RaviTharuma opened this issue 3 months ago • 2 comments

Description

withTimeout (src/timeout.ts in 1.4.3) only races a timer against a Promise. It does not abort the underlying fetch / LLM / embedding work.

function withTimeout(promise, ms, label) {
  return new Promise((resolve, reject) => {
    const timer = setTimeout(() => reject(new Error(`${label} timed out after ${ms}ms`)), ms);
    promise.then(value => { clearTimeout(timer); resolve(value); }, error => { clearTimeout(timer); reject(error); });
  });
}

After the wrapper rejects, the HTTP request keeps running. Under formation = "active" plus embedding retries this leaks concurrent upstream calls and can stall the single-threaded control plane so MCP tool handlers never finish — which matches host-side 6000s memorix_store timeouts (see companion issue).

Steps to Reproduce

  1. Point LLM/embeddings at an endpoint that accepts the request and never sends a response body.
  2. Call memorix_store with formation = "active".
  3. Observe formation timeout log at 12s, but Node still has open sockets / the next store still hangs.

Expected Behavior

Timeouts should AbortController.abort() the fetch. Formation, embed, and store must have a single hard deadline that actually stops work.

Actual Behavior

The Promise rejects; the network call continues. Multiple overlapping stores (Grok fires parallel MCP tools) pile up.

Environment

  • Memorix 1.4.3 (confirmed in dist/cli/index.js)
  • HTTP control plane, several clients on one process

Additional Context

This is the likely root of unbounded memorix_store MCP hangs even though DEFAULT_FORMATION_TIMEOUT_MS = 12000.

RaviTharuma avatar Aug 14 '26 07:08 RaviTharuma

Likely root cause for #196. Also worsens #199 if retries are not aborted.

RaviTharuma avatar Aug 14 '26 07:08 RaviTharuma

1.6.1 发布前重新跑过取消链路。超时和取消会传到进行中的 provider fetch,hook 层也有独立的硬截止,避免请求虽然对客户端超时但后台仍继续占用资源。

AVIDS2 avatar Aug 17 '26 04:08 AVIDS2