openclaw - 💡(How to fix) Fix memory-core: narrative session cleanup logs spurious warning when subagent runtime is request-scoped [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#68562Fetched 2026-04-19 15:10:06
View on GitHub
Comments
0
Participants
1
Timeline
0
Reactions
0
Author
Participants

In dreaming-narrative (bundled as dist/dreaming-narrative-BFx7ugb_.js), generateAndAppendDreamNarrative() correctly falls back when the subagent runtime is request-scoped during subagent.run() — but the finally block still calls subagent.deleteSession(), which throws the same RequestScopedSubagentRuntimeError and gets logged as a warning. The cleanup path does not recognize the error class that the start path handles.

Error Message

In dreaming-narrative (bundled as dist/dreaming-narrative-BFx7ugb_.js), generateAndAppendDreamNarrative() correctly falls back when the subagent runtime is request-scoped during subagent.run() — but the finally block still calls subagent.deleteSession(), which throws the same RequestScopedSubagentRuntimeError and gets logged as a warning. The cleanup path does not recognize the error class that the start path handles. 2. Check gateway logs: the fallback path runs (narrative generation used fallback ... because subagent runtime is request-scoped), but immediately after, narrative session cleanup failed is logged — same underlying error class.

  • The finally block unconditionally calls params.subagent.deleteSession({ sessionKey }). In the fallback case no session was created, and the call itself throws RequestScopedSubagentRuntimeError. The catch block does not filter on error type, so it emits the misleading cleanup warning. Skip deleteSession entirely when no runId exists, and filter the request-scoped error class in the catch (symmetric with the start path):
  •   	params.logger.warn(`memory-core: narrative session cleanup failed for ${params.data.phase} phase: ${formatErrorMessage(cleanupErr)}`);
  •   	if (!isRequestScopedSubagentRuntimeError(cleanupErr)) params.logger.warn(`memory-core: narrative session cleanup failed for ${params.data.phase} phase: ${formatErrorMessage(cleanupErr)}`);

Root Cause

In generateAndAppendDreamNarrative:

  • startNarrativeRunOrFallback catches RequestScopedSubagentRuntimeError, writes a fallback entry, logs the expected warning, and returns null.
  • The outer try then early-returns on runId === null.
  • The finally block unconditionally calls params.subagent.deleteSession({ sessionKey }). In the fallback case no session was created, and the call itself throws RequestScopedSubagentRuntimeError. The catch block does not filter on error type, so it emits the misleading cleanup warning.

Fix Action

Fix / Workaround

I've applied this patch locally against the installed dist bundle and confirmed it compiles/loads. Happy to send a PR if helpful — just needs to target the source (TS) file rather than the compiled bundle.

Code Example

[plugins] memory-core: narrative session cleanup failed for light phase:
  Plugin runtime subagent methods are only available during a gateway request.
[plugins] memory-core: narrative session cleanup failed for rem phase:
  Plugin runtime subagent methods are only available during a gateway request.

---

--- a/src/memory-core/dreaming-narrative.ts
+++ b/src/memory-core/dreaming-narrative.ts
-		try {
+		if (runId !== null) try {
 			await params.subagent.deleteSession({ sessionKey });
 		} catch (cleanupErr) {
-			params.logger.warn(`memory-core: narrative session cleanup failed for ${params.data.phase} phase: ${formatErrorMessage(cleanupErr)}`);
+			if (!isRequestScopedSubagentRuntimeError(cleanupErr)) params.logger.warn(`memory-core: narrative session cleanup failed for ${params.data.phase} phase: ${formatErrorMessage(cleanupErr)}`);
 		}
RAW_BUFFERClick to expand / collapse

Summary

In dreaming-narrative (bundled as dist/dreaming-narrative-BFx7ugb_.js), generateAndAppendDreamNarrative() correctly falls back when the subagent runtime is request-scoped during subagent.run() — but the finally block still calls subagent.deleteSession(), which throws the same RequestScopedSubagentRuntimeError and gets logged as a warning. The cleanup path does not recognize the error class that the start path handles.

Impact

Every scheduled dreaming run (via the managed cron) produces two spurious warnings per workspace:

[plugins] memory-core: narrative session cleanup failed for light phase:
  Plugin runtime subagent methods are only available during a gateway request.
[plugins] memory-core: narrative session cleanup failed for rem phase:
  Plugin runtime subagent methods are only available during a gateway request.

Cosmetic — functionality is unaffected (fallback narrative is written correctly) — but misleading during log triage.

Reproduction

  1. Let the managed short-term promotion dreaming cron fire from the scheduler (i.e. outside an active gateway request). This is the default path for the 03:00 job.
  2. Check gateway logs: the fallback path runs (narrative generation used fallback ... because subagent runtime is request-scoped), but immediately after, narrative session cleanup failed is logged — same underlying error class.

Root cause

In generateAndAppendDreamNarrative:

  • startNarrativeRunOrFallback catches RequestScopedSubagentRuntimeError, writes a fallback entry, logs the expected warning, and returns null.
  • The outer try then early-returns on runId === null.
  • The finally block unconditionally calls params.subagent.deleteSession({ sessionKey }). In the fallback case no session was created, and the call itself throws RequestScopedSubagentRuntimeError. The catch block does not filter on error type, so it emits the misleading cleanup warning.

Proposed fix

Skip deleteSession entirely when no runId exists, and filter the request-scoped error class in the catch (symmetric with the start path):

--- a/src/memory-core/dreaming-narrative.ts
+++ b/src/memory-core/dreaming-narrative.ts
-		try {
+		if (runId !== null) try {
 			await params.subagent.deleteSession({ sessionKey });
 		} catch (cleanupErr) {
-			params.logger.warn(`memory-core: narrative session cleanup failed for ${params.data.phase} phase: ${formatErrorMessage(cleanupErr)}`);
+			if (!isRequestScopedSubagentRuntimeError(cleanupErr)) params.logger.warn(`memory-core: narrative session cleanup failed for ${params.data.phase} phase: ${formatErrorMessage(cleanupErr)}`);
 		}

(isRequestScopedSubagentRuntimeError already exists in the same module at line 53.)

I've applied this patch locally against the installed dist bundle and confirmed it compiles/loads. Happy to send a PR if helpful — just needs to target the source (TS) file rather than the compiled bundle.

Environment

  • openclaw: 2026.4.15
  • node: v24.12.0
  • Linux (Ubuntu 24.04)
  • Workspace with managed short-term promotion dreaming enabled

extent analysis

TL;DR

The proposed fix involves modifying the generateAndAppendDreamNarrative function to skip deleteSession when no runId exists and filter the RequestScopedSubagentRuntimeError in the catch block.

Guidance

  • Verify that the isRequestScopedSubagentRuntimeError function is correctly implemented and available in the same module.
  • Apply the proposed patch to the dreaming-narrative.ts file, ensuring to target the source file rather than the compiled bundle.
  • Test the modified function to confirm that it correctly handles the RequestScopedSubagentRuntimeError and prevents the misleading cleanup warnings.
  • Consider submitting a pull request with the proposed fix to update the source code.

Example

The proposed fix involves modifying the try block to conditionally call deleteSession and filter the error in the catch block:

--- a/src/memory-core/dreaming-narrative.ts
+++ b/src/memory-core/dreaming-narrative.ts
-		try {
+		if (runId !== null) try {
 			await params.subagent.deleteSession({ sessionKey });
 		} catch (cleanupErr) {
-			params.logger.warn(`memory-core: narrative session cleanup failed for ${params.data.phase} phase: ${formatErrorMessage(cleanupErr)}`);
+			if (!isRequestScopedSubagentRuntimeError(cleanupErr)) params.logger.warn(`memory-core: narrative session cleanup failed for ${params.data.phase} phase: ${formatErrorMessage(cleanupErr)}`);
 		}

Notes

The proposed fix assumes that the isRequestScopedSubagentRuntimeError function is correctly implemented and available in the same module. Additionally, the fix should be applied to the source dreaming-narrative.ts file rather than the compiled bundle.

Recommendation

Apply the proposed workaround by modifying the generateAndAppendDreamNarrative function to skip deleteSession when no runId exists and filter the RequestScopedSubagentRuntimeError in the catch block, as it directly addresses the root cause of the issue and prevents the misleading cleanup warnings.

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