Skip to content

memory search --json prints results but does not exit with QMD backend #91821

Closed

Description

@xpysgdhr

Summary

openclaw memory search <query> --json can print valid JSON results but keep the process alive when the QMD memory backend is active. Upstream callers then surface this as a timeout / embedding-provider style failure even though QMD itself is healthy and returns results quickly.

Environment

  • OpenClaw: 2026.6.5
  • Platform: macOS / Apple Silicon
  • Memory backend: QMD CLI backend (memory.backend=qmd)

Reproduction

openclaw memory search "QMD rebuild method" --json

Observed behavior in my environment:

  • The command emits valid JSON search results.
  • The process does not exit after output.
  • A caller with a 15s timeout reports a memory_search timeout / embedding-provider error.

Diagnostics

QMD itself appears healthy:

qmd doctor
qmd search "QMD rebuild method"

In my environment:

  • qmd doctor passes embedding freshness, fingerprint, and vector sample checks.
  • direct qmd search returns quickly.
  • openclaw memory search ... --json prints results, then hangs.

This makes the issue look like OpenClaw CLI/runtime exit handling after JSON output rather than a QMD index or embedding provider failure.

Local hotfix that resolves it

In the generated runtime, runMemorySearch() currently writes JSON and returns. Adding an explicit exit after JSON output resolves the hang locally:

if (opts.json) {
  defaultRuntime.writeJson({ results });
  setImmediate(() => process.exit(process.exitCode ?? 0));
  return;
}

After this local patch:

  • openclaw memory search ... --json exits with code 0 in ~3s.
  • the memory_search tool returns successfully with provider qmd.

Expected behavior

After printing JSON for memory search --json, the CLI should exit cleanly with status 0 when the search succeeds, even if the QMD manager leaves handles open internally.

Activity

  1. clawsweeper commented on Jun 10, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 9, 2026, 11:55 PM ET / 03:55 UTC.

    Summary
    Keep open: current main still has the same memory search --json control flow as the reported v2026.6.5 build, so there is not enough evidence to close this as fixed. The report is detailed and points at a real CLI/QMD cleanup boundary that should get a focused fix and regression proof.

    Reproducibility: yes. there is a high-confidence reproduction recipe from the report: run openclaw memory search "QMD rebuild method" --json with memory.backend=qmd on v2026.6.5. I did not run a live QMD setup here, but current main still follows the same JSON-return and cleanup path.

    Next step
    A focused repair is plausible, but the worker must first reproduce or instrument the QMD-backed hang rather than blindly adding process.exit.

    Review details

    Best possible solution:

    Make the QMD-backed memory search --json CLI path emit JSON and terminate cleanly by fixing or bounding the CLI-owned QMD manager/process cleanup path, then add regression proof that a successful JSON search exits.

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

    Yes, there is a high-confidence reproduction recipe from the report: run openclaw memory search "QMD rebuild method" --json with memory.backend=qmd on v2026.6.5. I did not run a live QMD setup here, but current main still follows the same JSON-return and cleanup path.

    Is this the best way to solve the issue?

    No, the proposed local process.exit hotfix is a useful signal but not clearly the best permanent fix because it can mask leaked handles. The better fix is to identify the QMD/manager handle that survives after JSON output and close or bound it in the CLI-owned path.

    AGENTS.md: found and applied where relevant.

    Remaining risk / open question:

    • The exact hang was not live-reproduced in this read-only review because QMD was not exercised, so the repair should include a real QMD or process-lifecycle regression proof before merge.
    • The reporter's process.exit hotfix proves a workaround but may bypass normal manager cleanup; a fix should avoid hiding leaked handles unless maintainers explicitly choose a forced-exit CLI policy.

    Codex review notes: model gpt-5.5, reasoning high; reviewed against bf89552e6783.

    Label changes

    Label changes:

    • add P2: This is a normal-priority memory/QMD CLI bug with real automation impact, but it is limited to a specific backend and command path.
    • add impact:crash-loop: The reported failure is a CLI process hang after successful output, which affects process availability for upstream callers.
    • add impact:session-state: The timeout makes memory_search appear unavailable even when QMD returned results, degrading agent memory/context retrieval.
    • add issue-rating: 🐚 platinum hermit: Current issue advisory state selects this label.
    • add clawsweeper:needs-live-repro: Current issue advisory state selects this label.

    Label justifications:

    • P2: This is a normal-priority memory/QMD CLI bug with real automation impact, but it is limited to a specific backend and command path.
    • impact:crash-loop: The reported failure is a CLI process hang after successful output, which affects process availability for upstream callers.
    • impact:session-state: The timeout makes memory_search appear unavailable even when QMD returned results, degrading agent memory/context retrieval.
    Evidence reviewed

    Acceptance criteria:

    • node scripts/run-vitest.mjs extensions/memory-core/src/cli.test.ts
    • node scripts/run-vitest.mjs extensions/memory-core/src/memory/qmd-manager.test.ts
    • A live or stubbed QMD CLI proof that openclaw memory search <query> --json exits with code 0 after printing results

    What I checked:

    Likely related people:

    • scotthuang: Current-main blame and shortlog for the memory CLI, QMD manager, QMD process helper, and short-term recall path all point to this author carrying the current implementation. (role: recent area contributor; confidence: medium; commits: 696c1ecd2068; files: extensions/memory-core/src/cli.runtime.ts, extensions/memory-core/src/memory/qmd-manager.ts, packages/memory-host-sdk/src/host/qmd-process.ts)
    • Vincent Koc: Blame on the v2026.6.5 tag shows the same memory search JSON branch shipped in the release commit, which helps route release-behavior questions even though it does not prove original feature authorship. (role: release-carried shipped behavior; confidence: low; commits: 5181e4f7c82b; files: extensions/memory-core/src/cli.runtime.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.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    on Jun 10, 2026
  3. bladin commented on Jun 10, 2026

    @bladin
    Contributor

    Fixed by #91864.

    The fix adds an explicit process.exit() call after JSON output in the memory search command, preventing the process from hanging when QMD backend leaves internal handles open.

    All unit tests pass.

  4. locked as resolved and limited conversation to collaborators on Jun 13, 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:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.impact:crash-loopCrash, hang, restart loop, or process-level availability failure.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions