openclaw - ✅(Solved) Fix memory_search can fail with `Cannot read properties of undefined (reading 'get')` due to corrupted shared singleton cache [2 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#70527Fetched 2026-04-24 05:56:55
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
cross-referenced ×2closed ×1commented ×1

memory_search can become unavailable in the long-running gateway process even while fresh CLI invocations still work.

The user-visible tool result is:

{
  "results": [],
  "disabled": true,
  "unavailable": true,
  "error": "Cannot read properties of undefined (reading 'get')",
  "warning": "Memory search is unavailable due to an embedding/provider error."
}

The warning is misleading here. The actual failure can be a corrupted global singleton cache shape, not an embedding/provider failure.

Error Message

TypeError: Cannot read properties of undefined (reading 'get')

Root Cause

The failure is reproducible by corrupting the shared singleton cache on globalThis before loading the memory runtime.

Relevant compiled runtime areas in 2026.4.15:

  • extensions/memory-core/src/memory/search-manager.ts
  • extensions/memory-core/src/memory/manager-cache.ts

Current behavior:

  1. memory_search uses a shared singleton cache keyed by:
    • Symbol.for("openclaw.memorySearchManagerCache")
    • Symbol.for("openclaw.memoryIndexManagerCache")
  2. The returned singleton object shape is not validated before code uses .get(...)
  3. If some prior code path or mixed runtime state leaves an invalid object in that global slot, later access crashes with:
    • Cannot read properties of undefined (reading 'get')
  4. The exception is then wrapped into the generic "embedding/provider error" unavailable result

Fix Action

Fixed

PR fix notes

PR #70548: Fix memory_search failures from corrupted singleton cache state

Description (problem / solution / changelog)

Closes #70527

Summary

  • validate the shared singleton store used by memory search manager caching
  • rebuild corrupted singleton cache objects instead of crashing on undefined .get(...) access
  • apply the same repair logic to the shared managed cache helper used by memory index managers

Why

A corrupted global singleton cache shape can cause memory_search to fail with Cannot read properties of undefined (reading 'get'). In the current runtime this gets surfaced as an embedding/provider error, even though the actual failure is shared cache state corruption in a long-lived process.

This change makes the cache access path defensive so the runtime can recover by rebuilding the shared store instead of crashing.

Changed files

  • extensions/memory-core/src/memory/manager-cache.ts (modified, +12/-1)
  • extensions/memory-core/src/memory/search-manager.ts (modified, +15/-1)

PR #70925: fix(memory-core): harden singleton cache recovery

Description (problem / solution / changelog)

Resolves #70527.

Summary

  • Validate memory singleton cache shapes before use
  • Rebuild corrupted search and index manager cache stores
  • Add regressions for corrupted global cache state

Validation

  • pnpm test extensions/memory-core/src/memory/search-manager.test.ts
  • pnpm test extensions/memory-core/src/memory/manager-cache.test.ts
  • scripts/committer scoped pre-commit checks

Changed files

  • extensions/memory-core/src/memory/manager-cache.test.ts (modified, +19/-0)
  • extensions/memory-core/src/memory/manager-cache.ts (modified, +15/-1)
  • extensions/memory-core/src/memory/search-manager.test.ts (modified, +19/-0)
  • extensions/memory-core/src/memory/search-manager.ts (modified, +20/-5)

Code Example

{
  "results": [],
  "disabled": true,
  "unavailable": true,
  "error": "Cannot read properties of undefined (reading 'get')",
  "warning": "Memory search is unavailable due to an embedding/provider error."
}

---

node --input-type=module -e '
globalThis[Symbol.for("openclaw.memorySearchManagerCache")] = {};
import("/path/to/openclaw/dist/memory-CJrwLxmz.js").then(async (m) => {
  await m.n({ cfg: { memory: { backend: "qmd", qmd: {} } }, agentId: "main", purpose: "search" });
});
'

---

TypeError: Cannot read properties of undefined (reading 'get')

---

function getMemorySearchManagerCacheStore() {
  const existing = resolveGlobalSingleton(MEMORY_SEARCH_MANAGER_CACHE_KEY, () => ({
    qmdManagerCache: new Map()
  }));
  if (existing && existing.qmdManagerCache instanceof Map) return existing;

  const repaired = {
    ...(existing && typeof existing === "object" ? existing : {}),
    qmdManagerCache: new Map()
  };
  globalThis[MEMORY_SEARCH_MANAGER_CACHE_KEY] = repaired;
  return repaired;
}

---

function resolveSingletonManagedCache(cacheKey) {
  const existing = resolveGlobalSingleton(cacheKey, () => ({
    cache: new Map(),
    pending: new Map()
  }));
  if (existing && existing.cache instanceof Map && existing.pending instanceof Map) {
    return existing;
  }

  const repaired = {
    ...(existing && typeof existing === "object" ? existing : {}),
    cache: new Map(),
    pending: new Map()
  };
  globalThis[cacheKey] = repaired;
  return repaired;
}
RAW_BUFFERClick to expand / collapse

memory_search can fail with Cannot read properties of undefined (reading 'get') due to corrupted shared singleton cache

Summary

memory_search can become unavailable in the long-running gateway process even while fresh CLI invocations still work.

The user-visible tool result is:

{
  "results": [],
  "disabled": true,
  "unavailable": true,
  "error": "Cannot read properties of undefined (reading 'get')",
  "warning": "Memory search is unavailable due to an embedding/provider error."
}

The warning is misleading here. The actual failure can be a corrupted global singleton cache shape, not an embedding/provider failure.

Environment

  • OpenClaw: 2026.4.15
  • Node: 22.22.0
  • Gateway mode: long-running systemd user service
  • Memory provider: local
  • No usable GPU; local embeddings fall back to CPU successfully

What I observed

Fresh CLI works:

  • openclaw memory status --agent main reports Provider: local, Vector: ready, FTS: ready
  • openclaw memory search ... returns normal results

But the gateway process could still return the broken memory_search result above.

Root cause

The failure is reproducible by corrupting the shared singleton cache on globalThis before loading the memory runtime.

Relevant compiled runtime areas in 2026.4.15:

  • extensions/memory-core/src/memory/search-manager.ts
  • extensions/memory-core/src/memory/manager-cache.ts

Current behavior:

  1. memory_search uses a shared singleton cache keyed by:
    • Symbol.for("openclaw.memorySearchManagerCache")
    • Symbol.for("openclaw.memoryIndexManagerCache")
  2. The returned singleton object shape is not validated before code uses .get(...)
  3. If some prior code path or mixed runtime state leaves an invalid object in that global slot, later access crashes with:
    • Cannot read properties of undefined (reading 'get')
  4. The exception is then wrapped into the generic "embedding/provider error" unavailable result

Minimal repro

This reproduces the exact undefined.get failure for the search manager cache:

node --input-type=module -e '
globalThis[Symbol.for("openclaw.memorySearchManagerCache")] = {};
import("/path/to/openclaw/dist/memory-CJrwLxmz.js").then(async (m) => {
  await m.n({ cfg: { memory: { backend: "qmd", qmd: {} } }, agentId: "main", purpose: "search" });
});
'

Before adding shape validation, this crashes with:

TypeError: Cannot read properties of undefined (reading 'get')

Proposed fix

Validate the singleton cache shape when resolving these global stores. If the object shape is invalid, rebuild it instead of trusting it.

Pseudo-fix:

function getMemorySearchManagerCacheStore() {
  const existing = resolveGlobalSingleton(MEMORY_SEARCH_MANAGER_CACHE_KEY, () => ({
    qmdManagerCache: new Map()
  }));
  if (existing && existing.qmdManagerCache instanceof Map) return existing;

  const repaired = {
    ...(existing && typeof existing === "object" ? existing : {}),
    qmdManagerCache: new Map()
  };
  globalThis[MEMORY_SEARCH_MANAGER_CACHE_KEY] = repaired;
  return repaired;
}

And similarly for the managed cache used by the memory index manager:

function resolveSingletonManagedCache(cacheKey) {
  const existing = resolveGlobalSingleton(cacheKey, () => ({
    cache: new Map(),
    pending: new Map()
  }));
  if (existing && existing.cache instanceof Map && existing.pending instanceof Map) {
    return existing;
  }

  const repaired = {
    ...(existing && typeof existing === "object" ? existing : {}),
    cache: new Map(),
    pending: new Map()
  };
  globalThis[cacheKey] = repaired;
  return repaired;
}

Secondary issue

The user-facing wrapper currently reports this as:

  • "Memory search is unavailable due to an embedding/provider error."

That is too broad. It hides non-provider failures like singleton cache corruption.

It would help to:

  1. Preserve a more accurate error classification
  2. Include the real underlying failure reason in logs
  3. Avoid defaulting all memory manager exceptions to "embedding/provider error"

Why this matters

This creates a confusing split-brain state:

  • CLI appears healthy
  • gateway/user-facing memory_search is broken

That makes the issue hard to diagnose and easy to misattribute to the local embedding provider.

extent analysis

TL;DR

Validate the singleton cache shape when resolving global stores to prevent crashes due to corrupted cache.

Guidance

  • Validate the singleton cache shape in getMemorySearchManagerCacheStore and resolveSingletonManagedCache functions to ensure the object has the expected properties before using it.
  • Rebuild the cache if the object shape is invalid instead of trusting it.
  • Update the user-facing wrapper to preserve a more accurate error classification and include the real underlying failure reason in logs.
  • Avoid defaulting all memory manager exceptions to "embedding/provider error".

Example

The proposed fix provides a pseudo-fix in TypeScript, which can be used as a starting point:

function getMemorySearchManagerCacheStore() {
  const existing = resolveGlobalSingleton(MEMORY_SEARCH_MANAGER_CACHE_KEY, () => ({
    qmdManagerCache: new Map()
  }));
  if (existing && existing.qmdManagerCache instanceof Map) return existing;

  const repaired = {
    ...(existing && typeof existing === "object" ? existing : {}),
    qmdManagerCache: new Map()
  };
  globalThis[MEMORY_SEARCH_MANAGER_CACHE_KEY] = repaired;
  return repaired;
}

Notes

The provided pseudo-fix is a starting point, and the actual implementation may vary depending on the specific requirements and constraints of the project. Additionally, the secondary issue of inaccurate error reporting should be addressed to improve diagnostic capabilities.

Recommendation

Apply the proposed fix to validate the singleton cache shape and update the error reporting mechanism to provide more accurate information. This will help prevent crashes due to corrupted cache and improve the overall reliability of the system.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix memory_search can fail with `Cannot read properties of undefined (reading 'get')` due to corrupted shared singleton cache [2 pull requests, 1 comments, 2 participants]