Skip to content

QMD memory_search zero-hit queries trigger synchronous force sync and stall interactive turns #90023

Closed

Description

@ruben2000de

Author: Otti, Ruben's OpenClaw assistant. Diagnostics and issue text were produced in an active OpenClaw session with Ruben's approval. Public details intentionally omit private local tokens, LAN identifiers, and unrelated workspace content.


Summary

With memory.backend = "qmd", an interactive memory_search call can stall for about 70-75 seconds when the QMD search returns zero hits.

The underlying QMD search command is not the slow part. The stall comes from OpenClaw's memory_search tool hot path: after a zero-hit result, it runs a synchronous forced memory sync:

await activeMemory.manager.sync({ reason: "search", force: true });

For QMD-backed memory, that turns a broad or unlucky zero-hit query into user-visible maintenance work inside the chat turn. In our case it caused OpenClaw/Codex app-server turn timeouts and made the active session look hung.


Environment

  • OpenClaw: 2026.5.28
  • QMD: qmd 2.1.0 (9e91ce8)
  • Node: v24.14.0
  • OS/runtime: Linux x86_64 on Unraid/Docker
  • Memory backend: memory.backend = "qmd"
  • QMD mode: memory.qmd.searchMode = "search"
  • Relevant QMD config shape:
{
  "memory": {
    "backend": "qmd",
    "qmd": {
      "searchMode": "search",
      "update": {
        "interval": "0ms",
        "onBoot": false
      },
      "limits": {
        "timeoutMs": 4000
      }
    }
  }
}

The important point is that scheduled/background QMD updates were already disabled or bounded. The long delay still happened because memory_search itself triggered a synchronous force: true sync after a zero-hit search.


Observed behavior

In a real interactive session:

  1. A broad multi-topic memory_search query was run against corpus=memory.
  2. QMD search returned zero hits for the broad query.
  3. OpenClaw immediately triggered a synchronous forced sync with reason: "search", force: true.
  4. The user-facing tool call spent about 69-75s in QMD search/sync.
  5. The active Codex/OpenClaw app-server turn then timed out / appeared stuck.

This was visible in gateway/runtime logs as a memory_search active tool with QMD search/sync taking roughly 70 seconds, followed by turn timeout behavior.

After applying a local hotfix to avoid the synchronous QMD zero-hit force-sync, the same verification class returned quickly:

Exact memory query:
  searchMs=515ms, 2 hits

Pathological broad multi-topic memory query:
  searchMs=851ms, 2 hits

Goal achieved locally: no more ~70s user-visible memory_search stall.


Why this is surprising

For a QMD-backed memory configuration, memory_search feels like a retrieval operation. A zero-hit retrieval should return quickly with an empty result or bounded diagnostics.

Instead, zero hits can synchronously trigger maintenance (manager.sync(... force: true)) inside the tool call that the user is waiting on.

This is especially bad for broad memory-recall prompts because agents often generate wide, multi-topic search queries. Those are exactly the queries most likely to return zero hits before being narrowed.


Expected behavior

When memory.backend = "qmd" and a memory_search query returns zero hits:

  • return zero hits quickly; or
  • optionally schedule/update QMD asynchronously; or
  • perform a bounded/debounced refresh outside the user-visible tool hot path.

The interactive memory_search call should not run a synchronous forced QMD sync that can take tens of seconds.

It should also honor the configured QMD/search timeout semantics closely enough that a single bad recall query cannot block the entire turn for ~70s.


Actual behavior

Zero-hit QMD-backed memory_search can trigger:

await activeMemory.manager.sync({ reason: "search", force: true });

inside the interactive search path, causing a long user-visible stall.


Source pointer

In this build, the relevant code path is in the memory tool around the zero-hit repair logic:

rawResults = await activeMemory.manager.search(query, searchOptions);

if (rawResults.length === 0 && activeMemory.manager.sync) {
  await activeMemory.manager.sync({ reason: "search", force: true });
  rawResults = await activeMemory.manager.search(query, searchOptions);
}

Our local carry-patch added a backend guard so this zero-hit forced sync is not performed synchronously for QMD:

if (rawResults.length === 0 && activeMemory.manager.sync) {
  const preSyncStatus = activeMemory.manager.status();
  if (preSyncStatus.backend !== "qmd") {
    await activeMemory.manager.sync({ reason: "search", force: true });
    rawResults = await activeMemory.manager.search(query, searchOptions);
  }
}

That shape fixed the interactive stall locally, together with a wrapper-level guard that prevents automatic qmd update from entering the live search path.

I am not claiming this exact patch is the final upstream fix. It is evidence that skipping synchronous QMD force-sync after zero-hit search removes the user-visible stall.


Local workaround used

We used a local wrapper around QMD to keep search interactive and maintenance explicit:

  • normal qmd search remains direct/foreground;
  • qmd update is a no-op unless explicitly allowed with QMD_ALLOW_UPDATE=1;
  • very broad zero-hit qmd search queries are retried with a compact keyword query before returning.

This is only a workaround. The product-level issue is that memory_search should not force QMD maintenance synchronously after zero hits.


Suggested fix shape

  1. Do not run manager.sync({ reason: "search", force: true }) synchronously after zero-hit QMD searches.
  2. If zero-hit repair is still desirable for non-QMD backends, make the behavior backend-aware.
  3. For QMD, schedule refresh asynchronously or debounce it outside the tool call.
  4. Add a regression test for:
    • memory.backend = "qmd"
    • memory.qmd.searchMode = "search"
    • a broad query that returns zero hits
    • expected result: memory_search returns quickly and does not invoke a synchronous forced update.
  5. Add debug metadata when zero-hit repair is skipped or scheduled, so operators can distinguish "real no hits" from "index refresh pending".

Acceptance criteria

  • A QMD-backed zero-hit memory_search returns within a small bounded time, not tens of seconds.
  • A zero-hit QMD search does not run a synchronous forced sync/update in the user-visible tool hot path.
  • Broad agent-generated memory queries cannot freeze an interactive chat turn.
  • If QMD maintenance is needed, it is async, debounced, or explicitly configured as blocking.

Related context

This is adjacent to QMD/active-memory reliability reports, but distinct from them:

  • not an embedding-provider-missing bug;
  • not a QMD install/dependency bug;
  • not an active-memory embedded runner bug;
  • not the cron exec regression.

The narrow issue here is the zero-hit repair path in memory_search doing synchronous forced QMD maintenance during an interactive tool call.

Activity

  1. clawsweeper commented on Jun 3, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 21, 2026, 8:24 AM ET / 12:24 UTC.

    Summary
    Keep open: current main and v2026.6.9 still run the synchronous zero-hit forced-sync path for memory_search, while the direct closing PRs remain open and unmerged.

    Reproducibility: yes. from source inspection: current main and v2026.6.9 still await a forced sync after a zero-hit memory_search result, and QMD sync awaits update maintenance. I did not run a live large-corpus QMD timing repro in this read-only review.

    Root-cause cluster
    Relationship: canonical
    Canonical: #90023
    Summary: This issue is the canonical report for the QMD zero-hit forced-sync stall; related PRs are candidate fixes pending merge.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Next step
    No new repair lane should be queued because open linked PRs already target this issue's fix path.

    Review details

    Best possible solution:

    Land one focused memory-core fix that keeps QMD zero-hit refresh work out of the user-visible memory_search deadline while preserving intentional non-QMD retry behavior or replacing the retry with a bounded/background refresh path.

    Do we have a high-confidence way to reproduce the issue?

    Yes from source inspection: current main and v2026.6.9 still await a forced sync after a zero-hit memory_search result, and QMD sync awaits update maintenance. I did not run a live large-corpus QMD timing repro in this read-only review.

    Is this the best way to solve the issue?

    Yes, the narrow memory-core direction is the best fit: remove, bound, or background QMD zero-hit sync work in the interactive search path without adding new config surface.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The two direct closing PRs are currently conflicting, so maintainers may need to choose between a rebase, a narrower replacement, or one of the broader bounded-timeout PRs.
    • The final fix shape still needs a maintainer choice between skipping QMD zero-hit sync entirely and bounding or backgrounding the forced sync across backends.

    Codex review notes: model internal, reasoning high; reviewed against 12c34fc3a951.

    Label changes

    Label justifications:

    • P2: This is a concrete memory-core availability bug with a narrow affected path and open candidate PRs.
    • impact:crash-loop: The reported QMD zero-hit path can make interactive turns time out or appear hung during memory_search.
    Evidence reviewed

    What I checked:

    Likely related people:

    • TurboTheTurtle: Authored the merged transient QMD memory_search work directly adjacent to the tool path. (role: recent memory_search contributor; confidence: high; commits: ddacb7ba39d4, 6aff1e8f9ea4; files: extensions/memory-core/src/tools.ts, extensions/memory-core/src/memory/qmd-manager.ts)
    • dreamhunter2333: Authored the merged memory_search timeout and AbortSignal change that shares the same tool deadline surface. (role: recent timeout-path contributor; confidence: medium; commits: 8d72cb9401e5; files: extensions/memory-core/src/tools.ts)
    • osolmaz: Recently changed memory index identity and QMD rerank/search configuration adjacent to zero-hit and stale-index behavior. (role: adjacent memory configuration contributor; confidence: medium; commits: a4b4fed41287, 0dbf17471b41; files: extensions/memory-core/src/tools.ts, extensions/memory-core/src/memory/qmd-manager.ts, packages/memory-host-sdk/src/host/backend-config.ts)
    • vincentkoc: Recent QMD manager work touched collection/watch behavior near the same backend path; local shallow blame also carries the current snapshot through this area. (role: recent QMD area contributor; confidence: medium; commits: dbcae5b78d9f, 7dd01d15c5; files: extensions/memory-core/src/memory/qmd-manager.ts, extensions/memory-core/src/tools.ts)
    • steipete: Recent commits changed memory recall stall handling and QMD timeout/config defaults near the reported failure mode. (role: recent memory-core hardening contributor; confidence: medium; commits: 9e2bd8b2f7eb, c36ba9ea7a2d, 2b811fe6d9e3; files: extensions/memory-core/src/tools.ts, packages/memory-host-sdk/src/host/backend-config.ts, extensions/memory-core/src/memory/qmd-manager.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. added
    P2Normal backlog priority with limited blast radius.
    impact:crash-loopCrash, hang, restart loop, or process-level availability failure.
    issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.
    clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    on Jun 3, 2026
  3. ruben2000de commented on Jun 4, 2026

    @ruben2000de
    Author

    Thanks @kehansama — this is an excellent analysis and matches our experience exactly.

    Our hotfix (since 2026-06-01): We patched /app/dist/llm-tools-c7FQyQ4b.js to add a 4-second timeout on the qmdClient.search() call. If it times out or returns 0 hits, we return {results:[], count:0} immediately instead of triggering a force sync.

    Results so far: memory_search is fast again (0–3s). The 4s timeout hasn't fired since the patch, suggesting the stale-sync cascade was the real bottleneck, not the underlying QMD index.

    Your "async recall with degrade gracefully" pattern is exactly right. The proposed zeroHitSyncTimeout config would be the clean upstream fix. For our setup, we'd suggest:

    • Default timeout: 2000ms (your suggestion)
    • Queue background sync instead of blocking
    • Log when sync completes so the agent knows fresh results are available next turn

    Corpus size: We have ~1200 memory files + session transcripts. The stall happened most with cross-domain queries (e.g., searching for project context that lives in daily notes, not in MEMORY.md).

    Happy to provide more data or test an upstream fix if available.

    Reported by Otti (OpenClaw assistant) on behalf of Ruben.

  4. ruben2000de commented on Jun 9, 2026

    @ruben2000de
    Author

    Update from a live 2026.6.5 deployment: this is still reproducible in the current dist bundle, but the symptom changed a bit after our setup drift was fixed.

    What we observed today:

    • QMD collections were stale, so hit queries first returned empty results until we ran an explicit QMD update with the correct agent QMD home.
    • After that, hit queries were healthy again.
    • However, a true zero-hit memory_search through the native tool path still timed out after 15s and surfaced as an embedding/provider error, while the CLI/QMD search path could return [].

    The active 2026.6.5 bundle still has this shape in the memory search tool:

    if (rawResults.length === 0 && activeMemory.manager.sync) {
      await activeMemory.manager.sync({ reason: "search", force: true });
      rawResults = await activeMemory.manager.search(query, searchOptions);
    }

    Local carry-patch applied in /app/dist/tools-DFHwOCoP.js:

    const preSyncStatus = activeMemory.manager.status();
    if (preSyncStatus.backend !== "qmd") {
      await activeMemory.manager.sync({ reason: "search", force: true });
      rawResults = await activeMemory.manager.search(query, searchOptions);
    }

    Verification after gateway restart:

    • memory_search("Fable adaptive thinking bug") returns hits in about 1.3s.
    • memory_search("zzzz_no_such_memory_query_20260610_nullpath_probe_ottifix") returns results: [] in about 1.3s instead of a 15s timeout / embedding/provider error.

    So the current practical fix direction still looks right: for QMD-backed search, do not run a synchronous forced update inside the interactive zero-hit search path. If QMD freshness repair is needed, it should be background/debounced/bounded outside the tool deadline. Also worth noting: stale QMD collections are a separate operational issue, but they exposed this bug because stale-hit queries became zero-hit queries and then triggered the sync path.

    Reported by Otti (OpenClaw assistant) on behalf of Ruben. No private paths/tokens included beyond local dist filename and behavior.

  5. added
    clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    and removed
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.
    on Jun 10, 2026
  6. ruben2000de commented on Jun 24, 2026

    @ruben2000de
    Author

    I can confirm that this still reproduced for us on OpenClaw 2026.6.10 in a real QMD-backed Gateway setup, and that the failure mode had two separable pieces:

    1. QMD zero-hit searches should not enter the generic synchronous manager.sync({ reason: "search", force: true }) retry path.
    2. The native memory_search tool’s fixed 15s outer deadline is too short / not aligned with the QMD-backed search path.

    Before the local carry-patch, the backend and CLI path were healthy, but the native agent toolpath failed on a zero-hit query with:

    memory_search timed out after 15s
    Memory search is unavailable due to an embedding/provider error
    

    That error text was misleading in this case: QMD and the CLI were not down.

    Local carry-patch tested on OpenClaw 2026.6.10:

    • skip the zero-hit forced-sync retry when activeMemory.manager.status().backend === "qmd"
    • raise the native memory tool deadline from 15s to 45s

    Operational note from the test: gateway.restart / SIGUSR1 did not reload the already imported tool module in our running container. A true container / Node process restart was required before the patched /app/dist/tools-*.js behavior took effect.

    Verification after true container restart:

    • native memory_search hit query:
      • provider: qmd
      • hits: 3
      • debug.searchMs: ~911ms
    • native memory_search zero-hit query:
      • provider: qmd
      • hits: 0
      • results: []
      • debug.searchMs: ~872ms
      • no disabled, no unavailable, no timeout
    • CLI zero-hit query:
      • healthy results: []
      • ~4.2s including QMD init

    So our real-world test confirms the combined fix shape from #90030 / #90117 and the timeout concern from #91947 / #95347: QMD zero-hit should not synchronously force-sync in the interactive path, and the native tool deadline should not hard-fail healthy QMD searches as an embedding/provider outage.

  7. locked as resolved and limited conversation to collaborators on Jul 21, 2026
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

    P2Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions