openclaw - 💡(How to fix) Fix [Bug] memory_store tool fails when contextEngineRef is null (lazy initialization) [1 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#55496Fetched 2026-04-08 01:38:49
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

Error Message

The memory_store tool returns error "Either sessionKey or sessionId is required to store memory." even when sessionKey parameter is provided. Tool returns error even when valid sessionKey is provided. 3. Receive error: "Either sessionKey or sessionId is required to store memory."

Root Cause

In extensions/openviking/index.ts (lines 260-270), the tool checks for contextEngineRef before resolving the session:

if (!sessionId && sessionKeyIn && contextEngineRef) {
  sessionId = await contextEngineRef.resolveOVSession(sessionKeyIn);
}
if (!sessionId) {
  return { content: [{ type: "text", text: "Either sessionKey or sessionId is required to store memory." }] };
}

However, contextEngineRef is set via a factory function registered with api.registerContextEngine(), which is lazily initialized. When memory_store is called before the factory is invoked, contextEngineRef is still null.

Since resolveOVSession simply returns the sessionKey unchanged (context-engine.ts line 189), the check for contextEngineRef is unnecessary and causes the tool to fail.

Code Example

if (!sessionId && sessionKeyIn && contextEngineRef) {
  sessionId = await contextEngineRef.resolveOVSession(sessionKeyIn);
}
if (!sessionId) {
  return { content: [{ type: "text", text: "Either sessionKey or sessionId is required to store memory." }] };
}

---

// Before
if (!sessionId && sessionKeyIn && contextEngineRef) {
  sessionId = await contextEngineRef.resolveOVSession(sessionKeyIn);
}

// After
if (!sessionId && sessionKeyIn) {
  sessionId = contextEngineRef 
    ? await contextEngineRef.resolveOVSession(sessionKeyIn)
    : sessionKeyIn;
}
RAW_BUFFERClick to expand / collapse

Problem

The memory_store tool returns error "Either sessionKey or sessionId is required to store memory." even when sessionKey parameter is provided.

Root Cause

In extensions/openviking/index.ts (lines 260-270), the tool checks for contextEngineRef before resolving the session:

if (!sessionId && sessionKeyIn && contextEngineRef) {
  sessionId = await contextEngineRef.resolveOVSession(sessionKeyIn);
}
if (!sessionId) {
  return { content: [{ type: "text", text: "Either sessionKey or sessionId is required to store memory." }] };
}

However, contextEngineRef is set via a factory function registered with api.registerContextEngine(), which is lazily initialized. When memory_store is called before the factory is invoked, contextEngineRef is still null.

Since resolveOVSession simply returns the sessionKey unchanged (context-engine.ts line 189), the check for contextEngineRef is unnecessary and causes the tool to fail.

Expected Behavior

memory_store should accept sessionKey and use it directly as the sessionId when contextEngineRef is not yet initialized.

Actual Behavior

Tool returns error even when valid sessionKey is provided.

Steps to Reproduce

  1. Start OpenClaw with OpenViking plugin enabled
  2. Call memory_store with sessionKey parameter early in session
  3. Receive error: "Either sessionKey or sessionId is required to store memory."

Suggested Fix

// Before
if (!sessionId && sessionKeyIn && contextEngineRef) {
  sessionId = await contextEngineRef.resolveOVSession(sessionKeyIn);
}

// After
if (!sessionId && sessionKeyIn) {
  sessionId = contextEngineRef 
    ? await contextEngineRef.resolveOVSession(sessionKeyIn)
    : sessionKeyIn;
}

Environment

  • OpenClaw version: 2026.3.23-2
  • OpenViking plugin: local mode
  • Node.js: v22.22.1

Related

  • #52145 (shared mutable client agentId issue)

extent analysis

Fix Plan

To resolve the issue, update the memory_store tool in extensions/openviking/index.ts to handle the case when contextEngineRef is not yet initialized.

  • Replace the existing conditional statement with the following code:
if (!sessionId && sessionKeyIn) {
  sessionId = contextEngineRef 
   ? await contextEngineRef.resolveOVSession(sessionKeyIn)
    : sessionKeyIn;
}

This change allows the tool to use the provided sessionKey directly as the sessionId when contextEngineRef is null or undefined.

Verification

To verify the fix, follow these steps:

  • Restart OpenClaw with the OpenViking plugin enabled.
  • Call memory_store with a valid sessionKey parameter early in the session.
  • The tool should now accept the sessionKey and store the memory without returning an error.

Extra Tips

  • Ensure that the resolveOVSession method in context-engine.ts is correctly implemented to handle cases where contextEngineRef is not initialized.
  • Review related issues, such as #52145, to address any potential regressions or shared mutable client agentId issues.

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