openclaw - ✅(Solved) Fix Dreaming sessions pollute UI agent switcher — sessions.json not cleaned up after dream runs [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#70402Fetched 2026-04-23 07:25:16
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1

The Memory Dreaming Promotion cron job (runs daily at 03:00) creates 5-7 dreaming-narrative-{light,rem,deep}-xxx sessions under the main agent. These sessions appear in the Control UI agent switcher dropdown, cluttering the interface with "梦境叙事" (dream narrative) entries.

Root Cause

After dreaming completes, the .jsonl session files remain in agents/<agent>/sessions/, and the sessions.json registry retains dreaming session entries. The UI reads from sessions.json, so even deleting .jsonl files alone does not fix the display.

Fix Action

Fix / Workaround

Current Workaround

PR fix notes

PR #70464: fix(memory-core): allow bounded dreaming session cleanup

Description (problem / solution / changelog)

Summary

Fixes the two failure modes behind dreaming narrative session pollution:

  • keep dreaming-narrative-* session keys stable per workspace + phase, while retaining nowMs in idempotencyKey so runs do not dedupe incorrectly
  • allow only the built-in memory-core plugin to clean up its own dreaming-narrative-* transient sessions through the existing sessions.delete path
  • keep the default plugin fallback scope at operator.write; unrelated sessions and non-memory-core plugins still cannot delete sessions without operator.admin

This is intended to address the cleanup failure and UI/session-store leak reported in #68252, #69187, and #70402, while preserving the least-privilege behavior covered by the existing gateway subagent tests.

Tests

  • git apply --check /Users/shiheng/Desktop/openclaw-memory-dreaming-cleanup.patch against files fetched from upstream main
  • node --check dist/dreaming-narrative-DcGYNs84.js after applying the equivalent local hotfix to the installed package
  • node --check dist/server.impl-DLF59fRo.js after applying the equivalent local hotfix to the installed package
  • local smoke: verified buildNarrativeSessionKey is stable across timestamps and isolated across workspaces
  • local smoke: restarted OpenClaw gateway and verified openclaw daemon status reports running/connectivity ok/admin-capable
  • local smoke: deleted existing dreaming-narrative-* sessions via sessions.delete; verified dreaming_session_count=0

I could not run the full repo vitest commands locally because GitHub codeload/HTTPS clone timed out in this environment, so this PR relies on CI for the full official test matrix.

Changed files

  • extensions/memory-core/src/dreaming-narrative.test.ts (modified, +9/-6)
  • extensions/memory-core/src/dreaming-narrative.ts (modified, +11/-4)
  • extensions/memory-core/src/dreaming-phases.test.ts (modified, +3/-2)
  • extensions/memory-core/src/dreaming-phases.ts (modified, +0/-2)
  • extensions/ollama/.openclaw-runtime-deps.json (modified, +1/-1)
  • extensions/xai/.openclaw-runtime-deps.json (modified, +1/-1)
  • src/gateway/server-plugins.test.ts (modified, +96/-0)
  • src/gateway/server-plugins.ts (modified, +49/-4)

Code Example

# Step 1: Delete dreaming .jsonl files
for f in agents/main/sessions/*.jsonl; do
  grep -q "Write a dream" "$f" 2>/dev/null && rm "$f"
done

# Step 2 (critical): Remove dreaming entries from sessions.json registry
python3 -c "
import json
path = 'agents/main/sessions/sessions.json'
with open(path) as f:
    data = json.load(f)
for k in [k for k in data if 'dreaming' in k]:
    del data[k]
with open(path, 'w') as f:
    json.dump(data, f, indent=2)
"

# Step 3: Restart Gateway
openclaw gateway restart
RAW_BUFFERClick to expand / collapse

Description

The Memory Dreaming Promotion cron job (runs daily at 03:00) creates 5-7 dreaming-narrative-{light,rem,deep}-xxx sessions under the main agent. These sessions appear in the Control UI agent switcher dropdown, cluttering the interface with "梦境叙事" (dream narrative) entries.

Steps to Reproduce

  1. Enable Dreaming (default setting)
  2. Wait for the daily cron trigger (or run manually)
  3. Open Control UI → click agent switcher (top-left)
  4. Observe 5-7 dreaming-narrative-xxx entries mixed with real agents

Root Cause

After dreaming completes, the .jsonl session files remain in agents/<agent>/sessions/, and the sessions.json registry retains dreaming session entries. The UI reads from sessions.json, so even deleting .jsonl files alone does not fix the display.

Expected Behavior

Dreaming sessions should either:

  1. Be automatically cleaned from sessions.json after completion
  2. Be filtered out from the UI agent switcher (e.g., using a hidden session kind)
  3. Use a separate session namespace that the UI ignores

Current Workaround

Manual cleanup after each dream run:

# Step 1: Delete dreaming .jsonl files
for f in agents/main/sessions/*.jsonl; do
  grep -q "Write a dream" "$f" 2>/dev/null && rm "$f"
done

# Step 2 (critical): Remove dreaming entries from sessions.json registry
python3 -c "
import json
path = 'agents/main/sessions/sessions.json'
with open(path) as f:
    data = json.load(f)
for k in [k for k in data if 'dreaming' in k]:
    del data[k]
with open(path, 'w') as f:
    json.dump(data, f, indent=2)
"

# Step 3: Restart Gateway
openclaw gateway restart

Without Step 2, the UI continues to show dreaming sessions even after files are deleted.

Environment

  • OpenClaw version: 2026.4.21
  • OS: macOS Sequoia (ARM64)
  • Node: v22.22.0
  • Dreaming: enabled (default)
  • Cron job: Memory Dreaming Promotion (0 3 * * *)

extent analysis

TL;DR

Automatically cleaning up dreaming sessions from sessions.json after completion is likely the most effective fix.

Guidance

  • Modify the Memory Dreaming Promotion cron job to include a step that removes completed dreaming sessions from sessions.json, similar to the manual cleanup workaround provided.
  • Consider implementing a hidden session kind for dreaming sessions to filter them out from the UI agent switcher.
  • Review the cron job's logic to ensure it properly handles the removal of .jsonl files and updates sessions.json to prevent clutter in the Control UI.

Example

import json
import os

# Assuming this is part of the cron job script
def cleanup_dreaming_sessions():
    path = 'agents/main/sessions/sessions.json'
    with open(path) as f:
        data = json.load(f)
    for k in [k for k in data if 'dreaming' in k]:
        del data[k]
    with open(path, 'w') as f:
        json.dump(data, f, indent=2)

    # Remove.jsonl files
    for f in os.listdir('agents/main/sessions/'):
        if f.endswith('.jsonl') and 'dreaming' in f:
            os.remove(os.path.join('agents/main/sessions/', f))

cleanup_dreaming_sessions()

Notes

The provided workaround suggests that manual cleanup is effective, but automating this process within the cron job or through a separate maintenance task would be more efficient and less prone to errors.

Recommendation

Apply a workaround by modifying the cron job to automatically clean up dreaming sessions, as this approach directly addresses the issue without requiring an upgrade to a potentially non-existent fixed version.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix Dreaming sessions pollute UI agent switcher — sessions.json not cleaned up after dream runs [1 pull requests, 1 participants]