Repository navigation
fix(memory): nightly dreaming fails after plugin reloads with "runtime is no longer active" - #167724
Conversation
Keep the dreaming state opener in its managed plugin instance instead of a shared module variable that a later retired registration can overwrite. Remove the redundant workspace classifier rebind. Run timer callbacks and detached diary completion/publication through the instance background context and drain them before service replacement. Preserve standalone hosts and the existing retirement and startup fences. Prove successor cron sweeps survive a retired registration, only the successor starts completions, and service stop waits for diary publication. The regression fails with the original runtime-inactive error when the state fix is removed.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesDreaming, OpenClaw’s background memory consolidation, keeps state access and pending diary writes bound to the correct plugin instance across reloads. Example: A nightly sweep runs after another Memory Core registration has retired.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR remains useful: current main retains the shared state opener that causes the failure, and the earlier lifecycle repair does not supersede it. No actionable patch defect was found. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherMemory Core runs scheduled sweeps over workspace notes and short-term memory, promoting durable material and writing a dream diary. Plugin lifecycle services own its background callbacks and settle accepted work during replacement. flowchart TD
A[Scheduled dreaming sweep] --> B[Invoking Memory Core instance]
C[Plugin reload] --> B
B --> D[Instance-scoped state opener]
D --> E[Workspace SQLite state]
B --> F[Owned background narrative]
F --> G[Dream diary publication]
C --> H[Stop callbacks and settle pending work]
H --> G
Technical reviewBest possible solution: Keep dreaming state and asynchronous publication within the existing managed plugin instance and service lifecycle. Do we have a high-confidence way to reproduce the issue? Yes, source establishes the intervening-registration failure path, and the supplied regression reports the exact runtime-inactive error when the state repair is reverted. No runtime reproduction was executed during this read-only review. Is this the best way to solve the issue? Yes. The patch repairs ownership at the shared state opener and reuses the approved lifecycle runner while preserving scheduling, completion limits, and persisted formats. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 1c3a4248bdad. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -6, Tests +168, Docs +4. Total +166 across 9 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 9, 2026, 4:47 AM ET / 08:47 UTC. |
|
@clawsweeper approve Maintainer decision (coordinator for Peter, 2026-10-09): bug fix using existing plugin SDK capabilities (createPluginRuntimeStore, api.lifecycle.runInBackgroundContext approved in #167679); no new SDK surface. |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
Merged via squash.
|
…tance #167724 made the Memory Core dreaming state store instance-owned. The Gateway close memory fixture configured it once outside any plugin instance, while its memory sync runs inside the fixture plugin's background context, so indexing failed with 'memory-core dreaming SQLite state store is not configured'. Configure the store inside each fixture instance, as Memory Core's own registration does.
Backport #167724 together with its required #167679 lifecycle background-context owner. Preserve the release branch database admission implementation and its existing detached context owner. (cherry picked from commit ee5dea9) (cherry picked from commit 226b033) (cherry picked from commit 474bbab335a6cf7b1157097612b81d2d6098e260)
…w#167724) Keep the dreaming state opener in its managed plugin instance instead of a shared module variable that a later retired registration can overwrite. Remove the redundant workspace classifier rebind. Run timer callbacks and detached diary completion/publication through the instance background context and drain them before service replacement. Preserve standalone hosts and the existing retirement and startup fences. Prove successor cron sweeps survive a retired registration, only the successor starts completions, and service stop waits for diary publication. The regression fails with the original runtime-inactive error when the state fix is removed.
…tance openclaw#167724 made the Memory Core dreaming state store instance-owned. The Gateway close memory fixture configured it once outside any plugin instance, while its memory sync runs inside the fixture plugin's background context, so indexing failed with 'memory-core dreaming SQLite state store is not configured'. Configure the store inside each fixture instance, as Memory Core's own registration does.
What Problem This Solves
Fixes: Memory Core's nightly dreaming sweep fails for every workspace after hot plugin reloads, with
Plugin "memory-core" runtime is no longer active.Seen on a long-running dev Gateway after severalplugins.loadhot reloads (2026-10-07 03:00):Nights without a preceding reload succeeded, so promotion and diary narratives silently stopped until a restart.
User Impact
Dreaming sweeps, reconcile timers, deferred startup cleanup, and narrative (light/REM/deep) publication keep working across plugin reloads, always on the current Memory Core instance; a retired instance starts no new completions.
Why This Change Was Made
extensions/memory-core/src/dreaming-state.tskept the dreaming state-store opener in one module variable that every registration overwrote with an opener bound to its own plugin runtime. When another registration overwrote it and then retired, the live successor's sweep read state through the retired instance and hit the registry's authority rejection. The opener now uses the existing namedcreatePluginRuntimeStorecapability, so it belongs to the exact invoking managed instance. Dreaming's tracked background work (sweep, reconcile timer, deferred startup cleanup, narrative completion and diary publication) runs through the already-approvedapi.lifecycle.runInBackgroundContextfrom #167679. No new SDK surface, configuration, schema, or migration. Production +57/−63.Evidence
src/plugins/memory-dreaming-reload.test.ts(real bundled loader, managed registration/disposal, reply hooks, service start/stop, SQLite state, filesystem diary): successor sweeps succeed after another registration retires, retired instances start no completions, shutdown waits for pending diary publication. Reverting onlydreaming-state.tsfails with the exactPlugin "memory-core" runtime is no longer active.error.Focused suites (dreaming, startup cleanup, narrative, phases, state, memory-core index, reload): 142 tests passed; rebased on current main:
memory-dreaming-reload+memory-background-reload3/3 anddreaming.test.ts44/44.Live non-regression on a dev Gateway with lived-in state (real OpenAI provider): two back-to-back
plugins.loadhot reloads, then the managed dreaming cron fired viacron.run:dreaming promotion complete (workspaces=3, ... failed=0), no runtime-inactive errors. Note: with fix(memory): bind background sync to plugin lifecycle owners #167679 merged, plain reloads alone no longer reproduce the failure live; the deterministic regression covers the intervening-registration case that the original live failure hit.Types (core + task scope), lint, format, import cycles pass; autoreview clean.
Landing verification on
f8055b2a4aa00146e6ce441ffd1f3705509af5e0:pnpm test src/plugins/memory-dreaming-reload.test.ts src/plugins/memory-background-reload.test.ts src/plugin-sdk/memory-core-bundled-runtime.test.ts extensions/memory-core/src/dreaming-state.test.ts --maxWorkers=1passed 11 tests across four files in 207.10s wall. The new reload regression took 14.537s execution; the reload shard took 161.95s including imports. Whitespace validation and an independent P0–P2 autoreview passed with no actionable findings.