Skip to content

remember blocks on synchronous embedding → times out on MCP clients with a bounded tool timeout #79

Closed

Description

@RobertSigmundsson

Context: We run surreal-memory as the production memory engine for our agent swarm (Uruboros), via both the stdio MCP server and the CLI. Full open cards.

Problem: smem_remember over the MCP interface reliably times out at the client's 30s tool-call cap (Claude Code / Claude Desktop) because the embedding is computed synchronously inside the write path (our embedding provider is a proxied Gemini endpoint). The identical write via the CLI (smem remember --stdin) succeeds — no 30s cap. Reproduced repeatedly 2026-07-08/09.

Impact: A memory tool whose whole purpose is to prevent cross-session loss will silently drop writes on any MCP client with a bounded tool timeout: the agent "remembers", gets a timeout, and cannot tell whether the write landed. This is the exact failure mode the tool exists to prevent, and it affects any MCP host with a per-call timeout, not just our setup.

Suspected root cause: the embedding provider is awaited synchronously in remember before returning; a slow/remote provider (proxy, rate limit, cold start) pushes total latency past 30s.

Proposed fix (open to discussion):

  1. Ack-first, embed-async (preferred): persist the neuron immediately (without embedding_vec), return success, compute the embedding in a background task, and backfill embedding_vec + reindex HNSW when ready. Recall works immediately on text/tags; the vector lands slightly later.
  2. Minimum: decouple embedding from the synchronous store path (embed=async|sync, default async) so the write path never depends on provider latency.
  3. Complementary: return an explicit pending_embedding state so the client knows the write succeeded and the vector is deferred.

Repro: smem_remember (MCP) with a ~1.5KB content → timed out after 30.0s; same content via smem remember --stdin → Remembered ... [type: insight] in one shot.

Activity

  1. acidkill commented on Jul 28, 2026

    @acidkill
    Owner

    Verified this is still live on main (d8233b1) rather than assuming: encoder.py:438 awaits _embed_created_neurons, which awaits provider.embed_batch with no bound, and there is no async/pending path (git grep pending_embedding on main is empty). None of today's merges touched it.

    Your root-cause read is right, and the sharpest part of the report is the CLI-vs-MCP asymmetry — same write, same content, different outcome purely because one side has a cap. That is what makes it a silent-drop bug rather than a slow-write annoyance.

    #99 implements the minimal form of your option 2. The reasoning for stopping there:

    The method already promises fail-soft behaviour in its docstring — "if embeddings are disabled or no provider is available, memories stay keyword-only — no error, no slowdown". It just did not extend that to a provider that is present but slow. Bounding the wait at 10s makes those two cases behave identically, which is a smaller and more defensible change than introducing a new write state. 10s is far above a local endpoint (~15 ms) and far below the 30s cap, so it only fires where the call was already doomed.

    Not taking option 1 (ack-first + async back-fill) or option 3 (pending_embedding) in this PR, deliberately. Both change the contract clients reason about, and option 1 in particular needs an answer for what happens when the background task dies — a memory silently stuck without a vector is a quieter version of the same problem. Worth doing, worth doing separately. #99 does not foreclose either.

    If you have a way to reproduce the >30s case on your proxied endpoint, a confirmation that the bound actually resolves it in your setup would be valuable — my local endpoint cannot exercise the slow path honestly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions