Repository navigation
Description
Summary
During scheduled memory dreaming, the narrative / REM diary subagent (dreaming-narrative-light, dreaming-narrative-rem) is spawned with the full agent toolset including apply_patch. With a cheap default model (openrouter/openai/gpt-4.1-nano) it intermittently wraps the diary prose in *** Begin Patch / *** End Patch markers and calls apply_patch. The parser rejects it and the lane falls back to writing the diary directly — so there is no functional impact, but it produces recurring error-log noise.
Environment
- openclaw
2026.6.5 - Narrative model:
openrouter/openai/gpt-4.1-nano(the default; cheap models trigger it) - Linux, systemd
--useropenclaw-gateway
Frequency / impact
- ~7 failures / 14 days; each immediately followed by a successful fallback diary write
- Zero file/workflow corruption — log noise only
Logs
[tools] apply_patch failed: Invalid patch hunk at line 2: '...' is not a valid hunk header.
Valid hunk headers: '*** Add File: {path}', '*** Delete File: {path}', '*** Update File: {path}'
[plugins] memory-core: narrative generation produced no text for <phase> phase; writing fallback diary entry.
Root cause
The dreaming narrative subagent (dist/dreaming-narrative-*.js, NARRATIVE_SYSTEM_PROMPT) is given the full default toolset, which includes apply_patch. That lane only ever emits prose, but a weak model "decides" to save its output via apply_patch and formats prose as a patch, which the parser (dist/agent-tools-*.js) correctly rejects.
Suggested fix
Remove apply_patch (and other file-mutation tools) from the narrative/REM lane's toolset, or constrain that lane to a prose-only tool profile. The lane writes the diary via its own path, so it should not have a patch tool available at all. Tightening NARRATIVE_SYSTEM_PROMPT to "output plain text only, never call tools" would also help but the structural fix is removing the tool.
Workaround (no config to remove the tool today)
There is no supported config to strip apply_patch from the lane. The only supported mitigation is pointing the narrative lane at a more capable model via plugins.entries.memory-core.config.dreaming.model (+ subagent.allowModelOverride: true), which stops the misuse behaviorally but leaves the tool present.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Activity
clawsweeper commentedon Jun 10, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed June 21, 2026, 3:44 PM ET / 19:44 UTC.
Summary
Keep open: current main still routes memory-core Dream Diary narrative runs through the generic plugin subagent path without a no-tools or restricted-tools control, so the reported
apply_patchexposure remains valid.Reproducibility: no. live reproduction was run for the intermittent cheap-model behavior. Source inspection gives a clear path: the narrative subagent has no tool restriction, the plugin gateway path cannot carry one, and undefined downstream
toolsAllowleaves default coding tools available.Ways to help us reproduce this
Next step
Manual review is appropriate because the narrow repair needs a maintainer-approved plugin subagent tool-scoping contract across gateway, protocol, runtime, and memory-core boundaries.
Security
Needs attention: The issue is security-sensitive because a prose-only background subagent can currently receive a workspace-mutating tool it does not need.
Review details
Best possible solution:
Add a typed plugin subagent tool restriction, such as a no-tools or explicit allowlist path, and use it for memory-core narrative runs with regression coverage that fallback diary writes still work.
Do we have a high-confidence way to reproduce the issue?
No live reproduction was run for the intermittent cheap-model behavior. Source inspection gives a clear path: the narrative subagent has no tool restriction, the plugin gateway path cannot carry one, and undefined downstream
toolsAllowleaves default coding tools available.Is this the best way to solve the issue?
The requested direction is right, but the API shape needs maintainer review. Removing the tool structurally is stronger than only tightening
NARRATIVE_SYSTEM_PROMPT, because the reported failure is caused by tool exposure rather than prose generation alone.AGENTS.md: found and applied where relevant.
Remaining risk / open question:
Codex review notes: model internal, reasoning high; reviewed against 6daf9307e0b9.
Label changes
Label justifications:
P3: The reported behavior is recurring background log noise with no reported corruption, but it still merits cleanup because it exposes a mutating tool to a prose-only lane.impact:security: The issue is about a background subagent receiving a workspace-mutating tool that the lane should not need.Evidence reviewed
Security concerns:
extensions/memory-core/src/dreaming-narrative.ts:246Current source shows the memory-core narrative subagent has no no-tools/allowlist control before the gateway agent runtime builds default coding tools, which can include
apply_patchin writable contexts.Confidence: 0.82
What I checked:
startNarrativeRunOrFallbackcalls the plugin subagent with the narrative prompt, lane, light context, and delivery flags, but no allowlist, denylist, or no-tools setting. (extensions/memory-core/src/dreaming-narrative.ts:246, 6daf9307e0b9)generateAndAppendDreamNarrativeorrunDetachedDreamNarrative, so the affected narrative surface is reachable from scheduled dreaming. (extensions/memory-core/src/dreaming-phases.ts:1742, 6daf9307e0b9)SubagentRunParamscontains session/message/model/prompt/lane/context/delivery/idempotency fields only, leaving plugins without a typed way to request no tools for a prose-only subagent. (src/plugins/runtime/types.ts:10, 6daf9307e0b9)agentmethod with model, prompt, lane, context, delivery, and idempotency data but no tool allowlist. (src/gateway/server-plugins.ts:574, 6daf9307e0b9)AgentParamsSchemais strict and has notoolsAllowor equivalent field, so the plugin-to-gateway protocol cannot currently carry the requested restriction. (packages/gateway-protocol/src/schema/agent.ts:185, 6daf9307e0b9)src/agents/embedded-agent-runner/run/attempt-tool-construction-plan.ts:151, 6daf9307e0b9)Likely related people:
extensions/memory-core/src/dreaming-narrative.ts,src/plugins/runtime/types.ts,src/gateway/server-plugins.ts)src/gateway/server-plugins.ts,src/plugins/runtime/types.ts)src/gateway/server-plugins.ts)extensions/memory-core/src/dreaming-narrative.ts,extensions/memory-core/src/dreaming-phases.ts)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.openclaw-barnacle commentedon Jul 6, 2026
This issue has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.
openclaw-barnacle commentedon Jul 14, 2026
Closing due to inactivity.
If this is still an issue, please retry on the latest OpenClaw release and share updated details.
If you are absolutely sure it still happens on the latest release, open a new issue with fresh steps to reproduce.