TencentDB-Agent-Memory icon indicating copy to clipboard operation
TencentDB-Agent-Memory copied to clipboard

fix: runtime.state.resolveStateDir undefined on OpenClaw >=2026.5.x

Open leoge007 opened this issue 6 months ago • 2 comments

Summary

TDB 0.3.5 (built with OpenClaw SDK 2026.3.13) fails to register on OpenClaw 2026.5.20 because api.runtime.state is undefined during plugin registration.

Error

[plugins] memory-tencentdb failed during register: 
TypeError: Cannot read properties of undefined (reading 'resolveStateDir')

Root Cause

index.ts calls api.runtime.state.resolveStateDir() at two points during registration:

  1. L220: const pluginDataDir = path.join(api.runtime.state.resolveStateDir(), "memory-tdai");
  2. L826: stateDir: api.runtime.state.resolveStateDir()

On OpenClaw 2026.5.20, the runtime.state object is not yet populated at the point TDB calls it, even though the TypeScript types declare it exists.

Fix

Add optional chaining with a sensible fallback. Since resolveStateDir() is well-defined (returns ~/.openclaw or $OPENCLAW_STATE_DIR), the fallback can be os.homedir() + "/.openclaw":

// Before
const pluginDataDir = path.join(api.runtime.state.resolveStateDir(), "memory-tdai");

// After
const stateDir = api.runtime.state?.resolveStateDir?.() ?? 
  path.join(os.homedir(), ".openclaw");
const pluginDataDir = path.join(stateDir, "memory-tdai");

This is safe because resolveStateDir() is a pure directory resolution with no side effects. The call sites that don't have access to process.env can hardcode the homedir fallback.

Environment

  • TDB: 0.3.5
  • OpenClaw: 2026.5.20
  • macOS 15.5 (Apple Silicon)
  • Plugin SDK compat declared: pluginApi >=2026.3.13

Related

Similar to #57 (CLI registration break after OpenClaw upgrade) — this is the same class of SDK compat issue.

leoge007 avatar May 23 '26 17:05 leoge007

Thanks for the detailed report! Quick question — how did you upgrade to OpenClaw 2026.5.20,Was it a fresh install or an in-place upgrade from a previous version?

Maxwell-Code07 avatar May 24 '26 04:05 Maxwell-Code07

Opened #85 with an ESM-safe fallback for this startup failure. It avoids bare require in index.ts, reuses the resolved state dir for plugin data + CLI registration, and has full CI green including Size Guard.

YOMXXX avatar May 24 '26 16:05 YOMXXX