openclaw - 💡(How to fix) Fix Dreaming narrative sessions become orphaned — visible in sidebar but undeletable via session management

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…

Error Message

params.logger.warn(...narrative session cleanup failed...); 5. Try to delete — UI may not show delete option, or RPC returns error

Root Cause

🔍 Root Cause

Code Example

catch (cleanupErr) {
    params.logger.warn(`...narrative session cleanup failed...`);
}

---

async function forceRemoveDreamingSession(sessionKey: string): Promise<void> {
    const cfg = getRuntimeConfig();
    const canonicalKey = `agent:${resolveDefaultStoreAgentId(cfg)}:${sessionKey}`;
    const storePath = resolveSessionStorePath(cfg, canonicalKey);
    await updateSessionStore(storePath, (store) => {
        if (store[canonicalKey]) {
            delete store[canonicalKey];
            return true;
        }
        return false;
    });
}
RAW_BUFFERClick to expand / collapse

🐛 Bug Description

When the memory-core dreaming pipeline runs (light/deep phases), it creates subagent sessions with keys like agent:main:dreaming-narrative-{phase}-{workspaceHash} via generateAndAppendDreamNarrative(). After the dream diary entry is written to DREAMS.md, the cleanup in the finally block (subagent.deleteSession() + scrubDreamingNarrativeArtifacts()) silently fails, leaving orphaned sessions in the gateway store.

Symptoms

  • Sessions appear in the "recent sessions" sidebar
  • Sessions have no kind, status, or endedAt fields (they look like running sessions)
  • Cannot be deleted via the session management UI
  • Persist across restarts and accumulate over time

🔍 Root Cause

1. subagent.deleteSession() fails silently

In extensions/memory-core/src/dreaming-narrative.ts, the finally block tries to delete the narrative session. When running in a request-scoped subagent runtime (isolated cron session), deleteSession() throws RequestScopedSubagentRuntimeError. The catch block only logs a warning and continues:

catch (cleanupErr) {
    params.logger.warn(`...narrative session cleanup failed...`);
}

No fallback cleanup path exists.

2. scrubDreamingNarrativeArtifacts() has gaps

The scrub function (DREAMING_ORPHAN_MIN_AGE_MS = 300000 = 5 minutes):

  • Only prunes store entries where the transcript file is MISSING
  • Only archives transcript files not referenced by any store entry
  • So when BOTH the transcript file AND store entry exist, nothing gets cleaned

3. No kind/status on dreaming sessions

The dreaming subagent run doesn't set kind, status, or endedAt. The session appears as "active" indefinitely.

✅ To Reproduce

  1. Enable dreaming (dreaming.enabled: true)
  2. Wait for dreaming cron (default 3 AM) or trigger manually
  3. Open WebChat → Sessions tab
  4. Look for agent:main:dreaming-narrative-* entries
  5. Try to delete — UI may not show delete option, or RPC returns error

🛠️ Proposed Fixes

Fix 1: Direct store cleanup fallback in generateAndAppendDreamNarrative

When subagent.deleteSession() fails, directly remove the session from the store:

async function forceRemoveDreamingSession(sessionKey: string): Promise<void> {
    const cfg = getRuntimeConfig();
    const canonicalKey = `agent:${resolveDefaultStoreAgentId(cfg)}:${sessionKey}`;
    const storePath = resolveSessionStorePath(cfg, canonicalKey);
    await updateSessionStore(storePath, (store) => {
        if (store[canonicalKey]) {
            delete store[canonicalKey];
            return true;
        }
        return false;
    });
}

Fix 2: Reduce orphan cleanup delay

Lower DREAMING_ORPHAN_MIN_AGE_MS from 300000 to 30000 (30 seconds).

Fix 3: Expand scrub criteria

In scrubDreamingNarrativeArtifacts(), also prune dreaming store entries where:

  • The transcript file has been archived (.deleted.* suffix)
  • The entry is older than 1 hour (completed dreaming never needs its narrative session)

📸 Evidence from production

Found at /agents/main/sessions/sessions.json:

  • agent:main:dreaming-narrative-deep-{hash}: inputTokens=13,687, outputTokens=264, pluginOwnerId=memory-core, no kind/status/endedAt
  • agent:main:dreaming-narrative-light-{hash}: inputTokens=15,793, outputTokens=399, pluginOwnerId=memory-core, no kind/status/endedAt

Both with valid .jsonl transcript files on disk that never got cleaned.

🌐 Environment

Latest OpenClaw (built 2026-05-29), memory-core plugin, dreaming via isolated cron session.

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 - 💡(How to fix) Fix Dreaming narrative sessions become orphaned — visible in sidebar but undeletable via session management