Skip to content

[Bug]: Memory dreaming narrative/REM lane is given apply_patch and misuses it #91854

Closed as not planned

Description

@MahmutDehhan

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 --user openclaw-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.

Activity

  1. clawsweeper commented on Jun 10, 2026

    @clawsweeper
    Contributor

    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_patch exposure 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 toolsAllow leaves default coding tools available.

    Ways to help us reproduce this

    • Add a screenshot or short recording showing the behavior.
    • Add expected vs actual behavior.
    • Include redacted logs or terminal output.

    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 toolsAllow leaves 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:

    • The exact plugin subagent tool-scoping API is unresolved; a proper fix likely touches plugin runtime, gateway protocol, agent-method plumbing, and memory-core behavior.
    • A prompt-only mitigation would reduce model misuse but would not remove the workspace-mutating tool from the prose-only lane.

    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:

    • [low] Narrative lane can reach mutating workspace tools — extensions/memory-core/src/dreaming-narrative.ts:246
      Current 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_patch in writable contexts.
      Confidence: 0.82

    What I checked:

    Likely related people:

    • vincentkoc: Current blame and prior issue-history provenance connect this handle to recent memory-core narrative, plugin subagent type, and gateway bridge work across the affected path. (role: recent area contributor; confidence: medium; commits: 63fdc57b3ac2, c5623e72f3d9, 329fa44d23f4; files: extensions/memory-core/src/dreaming-narrative.ts, src/plugins/runtime/types.ts, src/gateway/server-plugins.ts)
    • steipete: Prior ClawSweeper history for this issue connected this handle to gateway and plugin-boundary commits on the same subagent runtime surface. (role: gateway/plugin boundary contributor; confidence: medium; commits: dfeaf6f7cf30, f25c246f6bf3, 6f2fbaaaf86d; files: src/gateway/server-plugins.ts, src/plugins/runtime/types.ts)
    • jalehman: Prior issue provenance identified this handle on plugin subagent override/forwarding history relevant to routing plugin-owned runs through the gateway agent path. (role: plugin subagent feature-history contributor; confidence: medium; commits: 1399ca5fcb51; files: src/gateway/server-plugins.ts)
    • vignesh07: Prior issue provenance connected this handle to Dream Diary feature history, which is the memory-core lane affected by the tool exposure report. (role: Dream Diary feature-history contributor; confidence: medium; commits: 61e61ccc182f; files: extensions/memory-core/src/dreaming-narrative.ts, extensions/memory-core/src/dreaming-phases.ts)
    How this review workflow works
    • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
    • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
    • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
    • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
    • Maintainers can also comment @clawsweeper review to request a fresh review only.
    • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
    • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
    • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
  2. added
    P3Low-priority cleanup, docs, polish, ergonomics, or speculative work.
    impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.
    clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.
    on Jun 10, 2026
  3. added
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    and removed
    clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.
    on Jun 19, 2026
  4. openclaw-barnacle commented on Jul 6, 2026

    @openclaw-barnacle

    This issue has been automatically marked as stale due to inactivity.
    Please add updates or it will be closed.

  5. openclaw-barnacle commented on Jul 14, 2026

    @openclaw-barnacle

    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.

  6. locked as resolved and limited conversation to collaborators on Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low-priority cleanup, docs, polish, ergonomics, or speculative work.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions