Skip to content

Light Sleep dreaming phase contaminates unrelated sessions with cross-context memory candidates #68367

Description

@captivationhub

Bug Description

The light sleep dreaming phase writes candidate memories into the daily memory file (memory/YYYY-MM-DD.md) as a managed block between <!-- openclaw:dreaming:light:start --> and <!-- openclaw:dreaming:light:end --> markers. This block is then bootstrapped into every session that shares the same agent workspace — including sessions that have nothing to do with the surfaced candidates.

Steps to Reproduce

  1. Configure a single agent (e.g. main) with one workspace
  2. Use that agent across multiple independent session contexts (e.g. different projects, topics, or UI tabs that create separate sessions)
  3. Let the light sleep phase run (it triggers on the dreaming cron schedule)
  4. Open any session — observe that the daily memory file now contains light sleep candidates from all sessions, not just the current one

Expected Behavior

Light sleep candidates should be scoped to the session or context they originated from. A session about "Project A" should not see light sleep candidates about "Project B" injected into its daily memory context.

Actual Behavior

  • Light sleep scans all sessions across the agent (via ingestSessionTranscriptSignals / collectSessionIngestionBatches)
  • It writes all candidates into a single daily memory file in the shared workspace
  • That file is bootstrapped into every session, regardless of relevance
  • Result: every session gets polluted with unrelated context from other sessions

Impact

  • Token waste: Thousands of extra tokens per session bootstrap (in one test, 80% of a daily memory file — 364 out of 454 lines — was light sleep content)
  • Context pollution: Sessions see irrelevant information from other projects/topics
  • Bootstrap truncation: Useful project-specific context gets crowded out by light sleep noise, especially when bootstrapMaxChars limits apply
  • Scales poorly: The more sessions an agent has, the worse the contamination gets

Workaround

Disable the light sleep phase in config:

{
  "plugins": {
    "entries": {
      "memory-core": {
        "config": {
          "dreaming": {
            "phases": {
              "light": {
                "enabled": false
              }
            }
          }
        }
      }
    }
  }
}

Optionally, clean up existing light sleep blocks from daily memory files:

sed -i '/<!-- openclaw:dreaming:light:start -->/,/<!-- openclaw:dreaming:light:end -->/d' memory/YYYY-MM-DD.md

Suggested Fix

A few possible approaches:

  1. Session-scoped light sleep: Write light sleep candidates into session-specific storage rather than the shared daily memory file, so each session only sees its own candidates
  2. Separate storage by default: Use storage.mode: "separate" as the default so light sleep writes to memory/dreaming/light/ instead of inline in daily files, and exclude those files from session bootstrap
  3. Filter on bootstrap: When injecting daily memory into a session, strip the managed dreaming blocks (they are clearly marked with HTML comments) so sessions never see raw staging candidates

Environment

  • OpenClaw version: 2026.4.14
  • OS: macOS (arm64)
  • Agent config: Single agent with one workspace, multiple independent sessions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions