{"skill":{"slug":"openclaw-memory-resilience","displayName":"OpenClaw Memory Resilience","summary":"Configure OpenClaw agent memory to survive compaction and session restarts. Use when: (1) setting up a new OpenClaw agent or workspace, (2) agents are forget...","description":"---\nname: openclaw-memory-resilience\ndescription: \"Configure OpenClaw agent memory to survive compaction and session restarts. Use when: (1) setting up a new OpenClaw agent or workspace, (2) agents are forgetting instructions or context between sessions, (3) configuring the pre-compaction memory flush, (4) setting up the file archival pattern for memory/archive/, (5) diagnosing why an agent forgot something, or (6) tuning compaction headroom and context pruning. Covers Layer 1 (gateway compaction config) and Layer 3 (file architecture) of the three-layer memory defense.\"\n---\n\n# OpenClaw Memory Resilience\n\nCovers the two highest-impact layers of memory durability for OpenClaw agents.\n\n## The Four Memory Layers (quick reference)\n\n| Layer | What it is | Survives compaction? |\n|-------|-----------|---------------------|\n| Bootstrap files (SOUL.md, AGENTS.md, etc.) | Injected from disk at every session start | Yes — reloaded from disk |\n| Session transcript (JSONL on disk) | Conversation history | Lossy — summarized on compaction |\n| LLM context window | What the model currently sees | No — fixed size, overflows |\n| Retrieval index (memory_search / QMD) | Searchable index over memory files | Yes — rebuilt from files |\n\n**Core rule:** If it's not written to a file, it doesn't exist after compaction.\n\n## Three Failure Modes\n\n- **Failure A** — Instruction only existed in conversation, never written to a file. Most common.\n- **Failure B** — Compaction summarized it away. Lossy. Nuance lost.\n- **Failure C** — Session pruning trimmed old tool results. Temporary, lossless.\n\nDiagnostic: *Forgot a preference?* → Failure A. *Forgot what a tool returned?* → Failure C. *Forgot the whole thread?* → Failure B.\n\n## Layer 1: Gateway Compaction Config\n\nApply via `gateway config.patch`. This is a global default — applies to all agents:\n\n```json\n{\n  \"agents\": {\n    \"defaults\": {\n      \"compaction\": {\n        \"mode\": \"safeguard\",\n        \"reserveTokensFloor\": 40000,\n        \"memoryFlush\": {\n          \"enabled\": true,\n          \"softThresholdTokens\": 4000,\n          \"systemPrompt\": \"Session nearing compaction. Store durable memories now.\",\n          \"prompt\": \"Write any lasting notes to memory/YYYY-MM-DD.md; reply with NO_REPLY if nothing to store.\"\n        }\n      },\n      \"contextPruning\": {\n        \"mode\": \"cache-ttl\",\n        \"ttl\": \"1h\"\n      }\n    }\n  }\n}\n```\n\nSee `references/config-explained.md` for why each value is set the way it is.\n\n## Layer 3: File Architecture\n\nSee `references/file-architecture.md` for the full pattern — bootstrap files, daily notes, archival, and QMD indexing.\n\n## Context Footer Standard\n\nAdd to every agent's SOUL.md. This gives you real-time visibility into context fill and compaction count — the single fastest way to know when to act before you hit the bad compaction path.\n\n```markdown\n## Context Management (Auto-Applied)\n**Every response:** fetch live status via `session_status`, append footer: `🧠 [used]/[total] ([%]) | 🧹 [compactions]`\n- Auto-clear: **85% context** OR **6 compactions**\n- Warn: **70% context** OR **4 compactions**\n- Before clearing: file critical info to memory, then reset\n```\n\nSee `references/context-footer.md` for why this matters and how to tune the thresholds.\n\n## Diagnosing Problems\n\nRun `/context list` in any OpenClaw session to see:\n- Which bootstrap files loaded and at what size\n- Whether any files are TRUNCATED (over per-file limit)\n- Total injected chars vs raw chars\n\nIf a file shows TRUNCATED: reduce it or raise `bootstrapMaxChars` in config.\nIf a file is missing entirely: check the workspace path in agent config.\n","topics":["Agent Memory"],"tags":{"compaction":"1.0.0","context":"1.0.0","latest":"1.0.0","memory":"1.0.0","openclaw":"1.0.0"},"stats":{"comments":0,"downloads":844,"installsAllTime":32,"installsCurrent":3,"stars":0,"versions":1},"createdAt":1772861726456,"updatedAt":1779077805426},"latestVersion":{"version":"1.0.0","createdAt":1772861726456,"changelog":"Initial release — Layer 1 compaction config, Layer 3 file architecture, context footer diagnostic pattern","license":null},"metadata":null,"owner":{"handle":"ferosin","userId":"s17dpdyt900gg369tnjfwm4r31884cat","displayName":"Ferosin","image":"https://avatars.githubusercontent.com/u/11545868?v=4"},"moderation":{"isSuspicious":false,"isMalwareBlocked":false,"verdict":"clean","reasonCodes":["review.llm_review"],"summary":"Review: review.llm_review","engineVersion":"v2.4.24","updatedAt":1780089791416}}