openclaw - ✅(Solved) Fix memory-core narrative session cleanup fails with missing scope: operator.admin [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#69886Fetched 2026-04-22 07:46:59
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1

Error Message

Every night at 03:00 (local) the Memory Dreaming Promotion cron produces three warn-level gateway log lines: 3. Observe warn lines in ~/.openclaw/logs/gateway.err.log.

Root Cause

Root cause (bundled dist inspection)

dreaming-narrative-BFx7ugb_.js calls params.subagent.deleteSession({ sessionKey }) in a finally block after the narrative generation run settles. The subagent is built by createGatewaySubagentRuntime() in server.impl-GQ72oJBa.js:17094, which invokes dispatchGatewayMethod("sessions.delete", {...}) with no options argument.

Fix Action

Fix / Workaround

Root cause (bundled dist inspection)

dreaming-narrative-BFx7ugb_.js calls params.subagent.deleteSession({ sessionKey }) in a finally block after the narrative generation run settles. The subagent is built by createGatewaySubagentRuntime() in server.impl-GQ72oJBa.js:17094, which invokes dispatchGatewayMethod("sessions.delete", {...}) with no options argument.

dispatchGatewayMethod (server.impl-GQ72oJBa.js:17008) falls back to createSyntheticOperatorClient() when no plugin-runtime request scope is active. That factory (line 16985) defaults scopes to ["operator.write"]. But sessions.delete is gated under the ADMIN_SCOPE bucket in method-scopes-D3xbsVVt.js (line 150), so it requires operator.admin.

  1. In createGatewaySubagentRuntime().deleteSession, pass { syntheticScopes: ['operator.admin'] } as the third arg to dispatchGatewayMethod — narrowest possible patch.
  2. In dreaming-narrative-BFx7ugb_.js, capture/restore the gateway request scope across the narrative generation boundary so the finally block inherits the cron's scope instead of falling through to synthetic.
  3. Give plugin-runtime-dispatched internal calls a dedicated scope set that includes the minimum privileges each plugin needs (admin for memory-core cleanup).

PR fix notes

PR #69890: fix(plugins): grant admin scope to synthetic subagent deleteSession

Description (problem / solution / changelog)

Summary

Fixes #69886. memory-core's Memory Dreaming Promotion cron invokes narrative cleanup in a `finally` block after the narrative run settles. By that point the cron's original request scope has unwound, so `createGatewaySubagentRuntime().deleteSession` falls through to `createSyntheticOperatorClient`, which defaults to `["operator.write"]`.

`sessions.delete` is gated under `ADMIN_SCOPE` in `method-scopes.ts` (line 165), so the synthetic fallback fails nightly with:

``` [plugins] memory-core: narrative session cleanup failed for light phase: missing scope: operator.admin [plugins] memory-core: narrative session cleanup failed for rem phase: missing scope: operator.admin [plugins] memory-core: narrative session cleanup failed for deep phase: missing scope: operator.admin ```

Dream diary entries are written fine — only the spawned narrative sessions end up orphaned.

Fix

Pass `{ syntheticScopes: [ADMIN_SCOPE] }` to the `dispatchGatewayMethod` call for `sessions.delete` — the surgical patch from the issue report's option 1. Other methods on the subagent runtime (`run`, `getSession`, etc.) still use their default write scope; only the admin-gated one asks for admin.

Test

The existing test `rejects fallback session deletion without minting admin scope` asserted the buggy behavior (it locked in the regression). Updated it to the regression test for #69886: asserts `resolves.toBeUndefined()` and that `getLastDispatchedClientScopes()` returns exactly `["operator.admin"]` — admin-only, not a broader bundle, so plugins cannot escalate beyond the specific method requirement.

oxlint passes on both changed files.

Closes #69886.

Changed files

  • src/gateway/server-plugins.test.ts (modified, +11/-6)
  • src/gateway/server-plugins.ts (modified, +16/-4)

Code Example

[plugins] memory-core: narrative session cleanup failed for light phase: missing scope: operator.admin
[plugins] memory-core: narrative session cleanup failed for rem phase: missing scope: operator.admin
[plugins] memory-core: narrative session cleanup failed for deep phase: missing scope: operator.admin
RAW_BUFFERClick to expand / collapse

Version

OpenClaw 2026.4.15 (041266a), darwin 25.4.0.

Symptom

Every night at 03:00 (local) the Memory Dreaming Promotion cron produces three warn-level gateway log lines:

[plugins] memory-core: narrative session cleanup failed for light phase: missing scope: operator.admin
[plugins] memory-core: narrative session cleanup failed for rem phase: missing scope: operator.admin
[plugins] memory-core: narrative session cleanup failed for deep phase: missing scope: operator.admin

The dream diary entry itself is written successfully (info log memory-core: dream diary entry written for <phase>), so this is non-functional at the data layer — only the spawned narrative session row is orphaned.

Root cause (bundled dist inspection)

dreaming-narrative-BFx7ugb_.js calls params.subagent.deleteSession({ sessionKey }) in a finally block after the narrative generation run settles. The subagent is built by createGatewaySubagentRuntime() in server.impl-GQ72oJBa.js:17094, which invokes dispatchGatewayMethod("sessions.delete", {...}) with no options argument.

dispatchGatewayMethod (server.impl-GQ72oJBa.js:17008) falls back to createSyntheticOperatorClient() when no plugin-runtime request scope is active. That factory (line 16985) defaults scopes to ["operator.write"]. But sessions.delete is gated under the ADMIN_SCOPE bucket in method-scopes-D3xbsVVt.js (line 150), so it requires operator.admin.

By the time the finally block runs, the original cron-scheduled request scope has unwound — so the synthetic fallback kicks in and the cleanup is rejected. Result: repeated nightly warnings and orphaned narrative sessions.

Suggested fix

One of:

  1. In createGatewaySubagentRuntime().deleteSession, pass { syntheticScopes: ['operator.admin'] } as the third arg to dispatchGatewayMethod — narrowest possible patch.
  2. In dreaming-narrative-BFx7ugb_.js, capture/restore the gateway request scope across the narrative generation boundary so the finally block inherits the cron's scope instead of falling through to synthetic.
  3. Give plugin-runtime-dispatched internal calls a dedicated scope set that includes the minimum privileges each plugin needs (admin for memory-core cleanup).

Option 1 is surgical; option 2 is more correct for any future plugin doing similar cleanup.

Repro

  1. Enable plugins.entries.memory-core.config.dreaming.enabled: true
  2. Let the Memory Dreaming Promotion cron (default 0 3 * * *) run overnight with sufficient short-term memory to trigger narrative generation for all three phases.
  3. Observe warn lines in ~/.openclaw/logs/gateway.err.log.

Workaround in use

Added noise filter in our local ops-issue tracker for plugins + narrative *cleanup failed/wait failed/generation used fallback lines so we stop filing dup issues nightly. Underlying cleanup still fails — orphaned sessions accumulate but haven't caused observable harm yet.

extent analysis

TL;DR

Passing { syntheticScopes: ['operator.admin'] } as the third argument to dispatchGatewayMethod in createGatewaySubagentRuntime().deleteSession is the most likely fix.

Guidance

  • Verify the createGatewaySubagentRuntime() function is being called with the correct arguments and that the dispatchGatewayMethod function is correctly handling the syntheticScopes option.
  • Check the method-scopes-D3xbsVVt.js file to ensure that the ADMIN_SCOPE bucket is correctly defined and that sessions.delete is gated under it.
  • Consider implementing option 2 from the suggested fix, which involves capturing and restoring the gateway request scope across the narrative generation boundary, for a more comprehensive solution.
  • Review the dreaming-narrative-BFx7ugb_.js file to ensure that the finally block is correctly handling the cleanup and that the params.subagent.deleteSession({ sessionKey }) call is being made with the correct scope.

Example

// In createGatewaySubagentRuntime().deleteSession
dispatchGatewayMethod("sessions.delete", {...}, { syntheticScopes: ['operator.admin'] });

Notes

The provided fix options assume that the issue is due to the missing operator.admin scope when calling dispatchGatewayMethod. However, it's essential to verify that this is indeed the root cause and that the suggested fixes do not introduce any unintended consequences.

Recommendation

Apply workaround by passing { syntheticScopes: ['operator.admin'] } as the third argument to dispatchGatewayMethod in createGatewaySubagentRuntime().deleteSession, as it is a surgical and targeted fix that addresses the specific issue at hand.

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 memory-core narrative session cleanup fails with missing scope: operator.admin [1 pull requests, 1 participants]