feat: Dreaming engine for periodic memory consolidation#592
feat: Dreaming engine for periodic memory consolidation#592helal-muneer wants to merge 1 commit intoCortexReach:masterfrom
Conversation
Implements CortexReach#577 - Dreaming functionality for memory-lancedb-pro Three-phase dreaming cycle: - Light Sleep: Decay scoring + tier re-evaluation for recent memories - Deep Sleep: Promote high-performing Working memories to Core tier - REM: Pattern detection across categories + reflection memory creation Changes: - Add dreaming config schema to openclaw.plugin.json with UI hints - Create src/dreaming-engine.ts with createDreamingEngine factory - Wire dreaming into service lifecycle (start/stop) in index.ts - Add DreamingConfig to PluginConfig interface + parsePluginConfig - Fix resolveEnvVars to return empty string instead of throwing when env var is missing (prevents plugin startup failure) Dreaming runs on a 6-hour interval after 5-minute initial delay, configurable via plugins.entries.memory-lancedb-pro.config.dreaming
rwmjhb
left a comment
There was a problem hiding this comment.
Interesting feature with a sound architecture (bridging existing tier-manager and decay-engine). Branch needs a rebase and one scope isolation issue needs fixing before merge.
Please rebase onto current main — stale_base=true and index.ts has had significant recent activity. Rebase needed to surface any conflicts before this can land.
Must fix
MR1 — Dreaming ignores scope isolation and synthesizes cross-scope memories into global
The engine fetches memories across all scopes, then stores REM reflections with a hardcoded scope: 'global'. In multi-user or multi-workspace deployments this leaks content between isolated memory spaces — a user's private memories can influence another user's global reflection entries.
Fix: filter store.list() by the active scope in each phase, and tag REM reflections with the same scope as the source memories.
Non-blocking
- F1 —
resolveEnvVarsnow returns''instead of throwing for unset env vars. This silently propagates an empty API key throughresolveFirstApiKey'sif (!key)guard (which only checks the raw config string, before resolution). Users with"${JINA_API_KEY}"configured but the env var unset will get opaque HTTP 401 failures instead of a clear startup error. - F2 — REM stores reflection with
vector: []. LanceDB uses fixed-dimension Arrow columns — a 0-dimension vector will throw an Arrow schema mismatch on every cycle. The error is caught and logged as⚠️ REM failed, so the REM phase silently never creates any reflection memories. - F3 —
config.phases.light(and.deep,.rem) accessed without null guard. A minimal config like{ "dreaming": { "enabled": true } }crashes withTypeError: Cannot read properties of undefinedon first cycle. Add aDEFAULT_DREAMING_CONFIGand deep-merge it at parse time. - F6 —
storageMode('separate'/'both') andcronfields are exposed inconfigSchemaand UI hints but never read at runtime. Users selecting these options silently getinlinebehavior and 6-hour fixed intervals. Remove from schema until implemented, or log a warning when set.
Summary
Closes #577
Implements Dreaming functionality — periodic memory consolidation and tier promotion that bridges LanceDB Pro's existing , , and into OpenClaw's dreaming lifecycle.
Three-Phase Dreaming Cycle
💤 Light Sleep — Decay + Tier Re-evaluation
decayEngine.scoreAll()tierManager.evaluateAll()store.patchMetadata()🧠 Deep Sleep — Working → Core Promotion
patchMetadata()💫 REM — Pattern Detection & Reflection
category: "reflection") with discovered patternsChanges
src/dreaming-engine.tsopenclaw.plugin.jsondreamingconfig schema + UI hintsindex.tsBug Fix Included
resolveEnvVars()now returns empty string instead of throwing when env var is missing (prevents plugin startup failure whenJINA_API_KEYetc. are unset)Configuration
{ "dreaming": { "enabled": true, "timezone": "UTC", "storageMode": "inline", "verboseLogging": false, "phases": { "light": { "lookbackDays": 7, "limit": 50 }, "deep": { "limit": 20, "minScore": 0.5, "minRecallCount": 2 }, "rem": { "lookbackDays": 30, "limit": 10, "minPatternStrength": 0.6 } } } }Testing