fix(plugin): add fallback for runtime.state.resolveStateDir on OpenClaw >=2026.5.x#79
fix(plugin): add fallback for runtime.state.resolveStateDir on OpenClaw >=2026.5.x#79leoge007 wants to merge 1 commit into
Conversation
…aw >=2026.5.x On OpenClaw 2026.5.20, api.runtime.state is undefined during plugin registration, causing memory-tencentdb to fail register with 'Cannot read properties of undefined (reading resolveStateDir)'. Add optional chaining with os.homedir() fallback so the plugin can resolve its data directory even when the runtime.state API isn't yet populated at registration time. Fixes Tencent#78
|
Thanks for the fix and the thorough testing! The root cause analysis is clear and the change is well-scoped. We'll review internally and get back to you with feedback. |
|
Reviewer triage notes from a local pass: Verification I ran locally on this branch:
Functional risk to address before merge:
Suggested safer shape: import { homedir } from "node:os";
function resolveOpenClawStateDir(api: OpenClawPluginApi): string {
return api.runtime.state?.resolveStateDir?.() ?? path.join(homedir(), ".openclaw");
}Then reuse that helper for both |
|
Thanks a lot for the fix and the detailed investigation! 🙏 We’ve reviewed both approaches (#79 vs #85) internally, and we’re going to move forward with #85 as the canonical fix. The main reasons are:
That said, the diagnosis here was spot-on and really helped us confirm the root cause quickly. Thanks again @leoge007 and @YOMXXX for driving this forward — really appreciate the collaboration! 🚀 |
Summary
Fixes #78
Problem
TDB 0.3.5 fails to register on OpenClaw 2026.5.20 because
api.runtime.stateisundefinedduring plugin registration:The TypeScript types declare
runtime.stateexists, but at registration time on 2026.5.x the object isn't yet populated.Fix
Add optional chaining with
os.homedir()fallback at the two call sites.resolveStateDir()returns~/.openclaw(or$OPENCLAW_STATE_DIR), so the fallback is well-defined and has no side effects.Testing
tdai_memory_searchandtdai_conversation_searchwork correctlyopenclaw memory-tdai --help)Changes
2 lines changed in
index.ts:const pluginDataDir = path.join((api.runtime.state?.resolveStateDir ? ... : require('os').homedir() + '/.openclaw'), "memory-tdai");stateDir: (api.runtime.state?.resolveStateDir ? ... : require('os').homedir() + '/.openclaw'),