Skip to content

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

@leoge007

Description

@leoge007

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions