Skip to content

Pre-compaction 'write durable facts' overwrites workspace files (MEMORY.md destroyed) #38491

@thalesfsp

Description

@thalesfsp

Bug

During pre-compaction, the agent receives: 'Before compaction, write only durable/promotable facts to memory.'

The agent interprets this as overwriting MEMORY.md with a tiny snippet of 'durable facts', destroying the entire file (438 lines → 8 lines). This has happened multiple times.

Expected behavior

  • Pre-compaction should NEVER overwrite workspace files
  • If writing durable facts, it should APPEND, not replace
  • Workspace files (MEMORY.md, SOUL.md, TOOLS.md) should be treated as read-only during compaction

Actual behavior

  • Agent uses Write tool to replace MEMORY.md with a small snippet
  • All rules, procedures, memory resolution order, project routing tables are lost
  • User must manually restore from git

Workaround

Added a sacred header to MEMORY.md: 'NEVER OVERWRITE, NEVER COMPACT' with restore instructions. But this relies on the agent reading and obeying the header — which is the same agent that's about to compact.

Suggested fix

  1. OpenClaw should snapshot workspace files before compaction
  2. The pre-compaction prompt should explicitly say 'Do NOT overwrite or replace workspace files'
  3. Or: make workspace files read-only during compaction (block Write tool for injected files)

Environment

  • OpenClaw 2026.2.17 (e2dd827)
  • Model: anthropic/claude-opus-4-6
  • Also reproduced with xai/grok-4-1-fast-reasoning

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions