Skip to content

fix(memory): nightly dreaming fails after plugin reloads with "runtime is no longer active" - #167724

Merged
steipete merged 1 commit into
mainfrom
codex/stab-dreaming-reload
Oct 9, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/stab-dreaming-reload

Conversation

@steipete

@steipete steipete commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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 several plugins.load hot reloads (2026-10-07 03:00):

[plugins] memory-core: dreaming sweep failed for workspace <state>/workspace-main: Plugin "memory-core" runtime is no longer active.
[plugins] memory-core: dreaming sweep failed for workspace <state>/workspace-codex: Plugin "memory-core" runtime is no longer active.

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.ts kept 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 named createPluginRuntimeStore capability, 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-approved api.lifecycle.runInBackgroundContext from #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 only dreaming-state.ts fails with the exact Plugin "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-reload 3/3 and dreaming.test.ts 44/44.

  • Live non-regression on a dev Gateway with lived-in state (real OpenAI provider): two back-to-back plugins.load hot reloads, then the managed dreaming cron fired via cron.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=1 passed 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.

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.
@clawsweeper

clawsweeper Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: memory-core Extension: memory-core size: M labels Oct 9, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 9, 2026
@clawsweeper

clawsweeper Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Dreaming, 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.

  • Before: The sweep can fail with Plugin "memory-core" runtime is no longer active.
  • After: The active instance completes the sweep and finishes pending writes to DREAMS.md before replacement.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused ownership repair with live sweep evidence, meaningful loader coverage, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): Supplied live output exercises managed cron after two reloads on a Gateway with existing state and a real provider, reporting three successful workspace sweeps and no runtime-inactive errors. The loader regression separately covers intervening registration and diary settlement; unchanged stored formats establish a no-migration case.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Scheduled memory promotion and dream diary generation stop after plugin reloads, leaving users needing a Gateway restart.
Reason: The change restores documented background behavior through existing ownership contracts. Current-main area history establishes the author’s relevant ownership, and the repair adds no configuration or public API.

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
Reviewed head: f8055b2a4aa00146e6ce441ffd1f3705509af5e0

Before merge

None.

Findings

None.

Agent review details

How this fits together

Memory 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
Loading

Technical review

Best 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

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Current main still contains the failure mechanism: Current main stores the state opener in one mutable module variable. A subsequent registration can overwrite it with a runtime belonging to an instance that later retires. (extensions/memory-core/src/dreaming-state.ts:51, 1c3a4248bdad)
  • Existing SDK capability supplies the correct owner: The named runtime store resolves its slot from the invoking managed instance, retaining standalone behavior outside managed scope. The patch uses this existing contract rather than adding a parallel ownership mechanism. (src/plugin-sdk/runtime-store.ts:79, f8055b2a4aa0)
  • Background admission preserves lifecycle fencing: The existing background runner selects the exact instance’s adopted registry and enters through managed admission. The documented contract rejects new work after admission closes and drains returned asynchronous work: https://docs.openclaw.ai/plugins/sdk-runtime#instance-bound-background-context. (src/plugins/plugin-instance-background.ts:40, f8055b2a4aa0)
  • Loader and publication regression: The added regression loads actual bundled registrations, retires an intervening registration, exercises successor sweeps against SQLite, and checks that service stop waits for generated diary text to reach the filesystem. Provider completion is synthetic; this is supporting boundary coverage, not a live-provider run. (src/plugins/memory-dreaming-reload.test.ts:134, f8055b2a4aa0)
  • Supplied live Gateway result: The complete PR body, captured under sourceRevision 1de87b9064c247bea4882069a5097cbe317a8541d1c91524f7f3726ee89ee3c1, reports two plugins.load reloads followed by cron.run on a development Gateway with existing state and a real OpenAI provider: dreaming promotion completed across three workspaces with failed=0 and no runtime-inactive errors. It expressly distinguishes this live non-regression from the intervening-registration negative control. (f8055b2a4aa0)
  • Related repair supplies the capability, not this state fix: fix(memory): bind background sync to plugin lifecycle owners #167679 is verified merged and records approval of the instance-bound background capability. Its repair addresses stale memory-sync context; current main still retains the separate dreaming opener defect. (ee5dea9d11f9)

Likely related people:

  • Peter Steinberger: Raw commit 3f5e001 adds extensions/memory-core/src/dreaming-state.ts:10 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3f5e00184431; files: extensions/memory-core/src/dreaming-state.ts)
  • Robin Winkelewski: Raw commit 1aa3d84 adds extensions/memory-core/src/dreaming.ts:933 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1aa3d8462bfc; files: extensions/memory-core/src/dreaming.ts)

PR surface

Source -6, Tests +168, Docs +4. Total +166 across 9 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 5 57 63 -6
Tests 3 171 3 +168
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 9 232 66 +166

Review metrics

Metric Value Why it matters
Production versus test delta Production +57/-63; tests +171/-3 Production shrinks while the added loader regression protects cross-registration ownership and pending diary publication.

Labels

Label changes:

  • add P1: Reloads can silently stop scheduled memory consolidation across every workspace until the Gateway restarts.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: Reloads can silently stop scheduled memory consolidation across every workspace until the Gateway restarts.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 9, 2026, 4:47 AM ET / 08:47 UTC.

@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

@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.

@clawsweeper

clawsweeper Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@steipete
steipete merged commit 226b033 into main Oct 9, 2026
124 of 125 checks passed
@steipete
steipete deleted the codex/stab-dreaming-reload branch October 9, 2026 08:55
@steipete

steipete commented Oct 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Oct 9, 2026
…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.
RomneyDa pushed a commit that referenced this pull request Oct 9, 2026
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)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: memory-core Extension: memory-core P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant