fix(memory-core): prevent dreaming-narrative session leaks (#66358)#1
Open
chiyouYCH wants to merge 1508 commits into
Open
fix(memory-core): prevent dreaming-narrative session leaks (#66358)#1chiyouYCH wants to merge 1508 commits into
chiyouYCH wants to merge 1508 commits into
Conversation
jalehman
force-pushed
the
fix/dreaming-session-leak-66358
branch
2 times, most recently
from
April 20, 2026 16:41
c11d14f to
9c2690c
Compare
jalehman
force-pushed
the
fix/dreaming-session-leak-66358
branch
2 times, most recently
from
April 20, 2026 22:32
3805afb to
88964cc
Compare
…enclaw#66358) Root cause: `runDreamingSweepPhases` passed `params.nowMs` through to each phase without normalizing it first. Each phase recomputed `Date.now()` at call time, producing a slightly different timestamp than the session key used by `generateAndAppendDreamNarrative`. The resulting session key mismatch meant the `deleteSession` call cleaned up a different (or non-existent) key than the one that was created. Fix: - Normalize `nowMs` once at the top of `runDreamingSweepPhases` and pass the consistent value to all phases. - Add a defensive `deleteSession` call in `runDreamingSweepPhases` for each phase after `runLightDreaming`/`runRemDreaming` completes. This acts as a safety net even if the narrative function's primary cleanup is skipped. - Guard the `finally` block in `generateAndAppendDreamNarrative` with `if (params.subagent)` to prevent TypeError if the subagent runtime becomes unavailable mid-flight. This fixes the observed session list pollution where `dreaming-narrative-*-<timestamp>` entries accumulated indefinitely.
jalehman
force-pushed
the
fix/dreaming-session-leak-66358
branch
from
April 20, 2026 22:40
88964cc to
51f72b2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
runDreamingSweepPhasespassesparams.nowMsthrough torunLightDreaming/runRemDreamingwithout normalizing it. Each of those functions (and the nestedgenerateAndAppendDreamNarrative) recomputesDate.now()independently:The session key written at creation and the key used in the
finallyblock'sdeleteSessioncan differ by a few milliseconds, so the deletion hits a non-existent key and the session leaks.Fix
runDreamingSweepPhases: NormalizenowMsonce at the top and pass the consistent value to all phases. Add a defensivedeleteSessioncall after each phase as a safety net.generateAndAppendDreamNarrativefinally block: Guardparams.subagentwithif (params.subagent)to prevent TypeError if the runtime becomes unavailable mid-flight.Testing
Manual trigger of the Dreaming sweep confirms no new
dreaming-narrative-*sessions remain in the session store after sweep completion.Fixes openclaw#66358.