Skip to content

Bundled legacy context engine not registered in CLI compaction lifecycle worker — dreaming diary subagent fails silently (follow-up to #76576) #81843

Description

@evdevdev

Summary

The CLI turn compaction lifecycle resolves the active context engine without first calling ensureContextEnginesInitialized(), so the bundled legacy engine is missing from the registry when this code path runs in a worker that wasn't bootstrapped via pi-embedded or the subagent spawn path.

The visible symptom is the dreaming narrative diary subagent: every nightly sweep silently fails to append to DREAMS.md, and openclaw memory status --deep reports Dreaming artifacts: diary absent indefinitely. The underlying log line is buried at log.warn level:

CLI transcript persistence failed for agent:main:dreaming-narrative-light-<hash>: Context engine "legacy" is not registered. Available engines: (none)

This is a follow-up to #76576 / PR #76636: same class of "engine not registered yet" bug, different code path. #76636 fixed it for the gateway startup load plan when a custom plugins.slots.contextEngine plugin was selected. The CLI compaction lifecycle never got the same treatment, and it breaks even with the default (legacy) slot.

Repro

  1. Install [email protected].
  2. Use Claude CLI auth (provider: claude-cli) — i.e. the OpenClaw anthropic:claude-cli auth profile, not a direct ANTHROPIC_API_KEY. This is the trigger for the CLI runner path at agent-command-CYAAR35V.js:883 (result.meta.executionTrace?.runner === "cli").
  3. Enable dreaming with no other custom config:
    {
      plugins: {
        entries: {
          "memory-core": { config: { dreaming: { enabled: true } } }
        }
      }
    }
  4. Leave plugins.slots.contextEngine unset (= bundled legacy default).
  5. Let the nightly sweep run.

Expected: DREAMS.md gets a diary entry each night. memory status --deep shows diary present.

Actual: Light/REM/deep phase reports appear daily under memory/dreaming/{light,rem,deep}/YYYY-MM-DD.md, but DREAMS.md is never written. memory status --deep shows diary absent. The warning above appears in logs once per sweep.

The grounded backfill lane (openclaw memory rem-backfill --path …) bypasses the broken code path entirely and successfully writes DREAMS.md, which confirms the failure is specifically in the diary subagent's transcript-persistence path, not in dreaming generally.

Root cause

dist/cli-compaction-DUTxpPGR.js:95 defines runCliTurnCompactionLifecycle, which at line 99 calls:

const contextEngine = await cliCompactionDeps.resolveContextEngine(params.cfg);

without any prior call to ensureContextEnginesInitialized() (which is what registers the bundled legacy engine, per dist/init-CtKlTCAI.js:3756).

The other entry points that resolve the engine all do guard the registry:

  • Main runtime: pi-embedded-Bcz04p2i.js:85 and :2063
  • Subagent spawn: subagent-spawn-CZA9_Uwl.js:464
  • Subagent registry: subagent-registry-BTDmugmA.js:1366

So the failure is path-specific: the dreaming diary subagent (and any other subagent whose transcript-finalize step runs the CLI compaction lifecycle in a fresh worker) hits an empty registry. resolveContextEngine's default-engine branch (registry-CxcGD4Pv.js:253) then throws, and agent-command-CYAAR35V.js:918 swallows it as a log.warn — which is also why this has been silently broken for users on Claude-CLI auth with dreaming enabled.

Suggested fix

Add the same idempotent guard at the top of runCliTurnCompactionLifecycle in src/agents/command/cli-compaction.ts, before the resolveContextEngine call:

ensureContextEnginesInitialized();
const contextEngine = await cliCompactionDeps.resolveContextEngine(params.cfg);

ensureContextEnginesInitialized is already idempotent (guarded by an initialized flag), so adding this call is safe even on hot paths. Same shape as the existing guards in pi-embedded and the subagent spawn module.

Optional adjacent cleanup: bump the swallowed warning at agent-command-CYAAR35V.js:918 to also note when the cause is a missing engine registration — silent failure is the reason this took a while to notice.

Environment

  • [email protected]
  • macOS (darwin 25.5.0)
  • Auth: anthropic:claude-cli (provider claude-cli)
  • plugins.slots.contextEngine: unset (default legacy)
  • Dreaming: enabled: true, otherwise default config

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