-
-
Notifications
You must be signed in to change notification settings - Fork 69.3k
Pre-compaction 'write durable facts' overwrites workspace files (MEMORY.md destroyed) #38491
Copy link
Copy link
Closed
Description
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
- OpenClaw should snapshot workspace files before compaction
- The pre-compaction prompt should explicitly say 'Do NOT overwrite or replace workspace files'
- 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
- Bug: Anthropic rejects history with dangling tool_use blocks after compaction #33621 (compaction orphans tool_use/tool_result pairs)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.