Skill: thebrierfox/free-compaction-primer (version 1.0.1)

--- name: Context Death Spiral Prevention — OpenClaw Compaction Primer slug: context-death-spiral-prevention-compaction-primer version: 1.0.1 author: IntuiTek tags: [production, engineering, compaction, context-management, hardening] description: Learn to recognize and prevent context death spirals in OpenClaw agents. Covers symptoms, root causes, configuration categories, and why most default setups have no protection. Free primer for the Production Agent Ops bundle. --- # Context Death Spiral Prevention — OpenClaw Compaction Primer ## What Is a Context Death Spiral? A context death spiral is what happens when an OpenClaw agent accumulates so much conversation history that its reasoning quality degrades — and then the degradation makes it handle the accumulation worse, which accelerates the degradation. You've seen the symptoms: - Agent starts forgetting instructions it acknowledged 20 turns ago - Response quality drops noticeably mid-session without any obvious trigger - Agent begins contradicting itself or repeating earlier failed attempts - Sudden unexplained context resets that wipe work in progress - Tool calls become erratic — the agent loses track of what it already tried These aren't model failures. They're architecture failures. The agent isn't broken — its context management is. ## Why Default OpenClaw Setups Don't Handle This Out of the box, OpenClaw has no compaction architecture. There is no: - Threshold configuration that triggers compaction before quality degrades - Circuit breaker that catches failed compactions before they cascade - Post-compaction cleanup sequence that verifies the context was actually reduced - Sequencing logic that governs what gets compacted in what order - Guard against recursive compaction (compacting a compaction summary) Without these, the agent operates until it hits the model's hard context limit. At that point, OpenClaw either crashes, truncates silently, or enters an error loop. None of these are recoverable without manual intervention. ## The Four Categories That Control Compaction Behavior Production compaction architecture covers four distinct areas. You need all four: **1. Threshold Management** The threshold determines when compaction fires. Set it too high and the agent degrades before compaction helps. Set it too low and you waste tokens on unnecessary compaction. The right thresholds are not intuitive — they depend on the model's actual quality degradation curve, not its advertised context window. Most operators guess. Production deployments measure. **2. Autocompact Gate Logic** Compaction shouldn't fire on every threshold breach — some breaches are transient. A production gate evaluates multiple conditions before triggering: token count, session age, tool call density, the shape of recent content. A simple token threshold is not a gate. It's a single condition, and it fires at the wrong time roughly 30% of the time in active sessions. **3. Circuit Breaker** Compaction can fail. When it does, naive implementations retry immediately — which can send the agent into an infinite compaction loop that burns tokens and produces nothing. A production circuit breaker counts consecutive failures, backs off, and eventually halts with a recoverable state. Without a circuit breaker, one bad compaction attempt can destroy a session. **4. Post-Compaction Cleanup** After compaction runs, the context window needs to be verified. Did it actually reduce? Was the summary written correctly? Are there orphaned references to content that no longer exists? Post-compaction cleanup is not optional — without it, you have no guarantee compaction worked. ## Why This Is Harder Than It Looks The threshold problem alone has three sub-problems: - **Warning threshold** — when to signal that compaction is approaching - **Trigger threshold** — when to actually compact - **Block threshold** — when the context is too full to compact safely and the session must halt These three values interact. Setting any one of them wrong creates either unnecessary interruptions or silent degradation. Production deployments derive all three from the same empirical baseline. Guessing independently at each one is how operators end up with agents that compact too aggressively, lose important context, and then compound the problem on the next session. ## The Bottom Line If your OpenClaw agent runs sessions longer than 30 minutes, handles multi-step autonomous tasks, or operates without supervision — you have a context management problem, whether you've seen the symptoms yet or not. Most operators discover this the hard way. --- *Full production architecture with all 7 SKILL.md files — including exact production-validated constants validated in production Claude Code deployments — available in the **Production Agent Ops bundle** on Claw Mart:* *https://www.shopclawmart.com/listings/production-agent-ops-battle-tested-architecture-pack-0d1bb129*


Security scan verdicts — ClawScan: clean | static analysis: clean | VirusTotal:  | SkillSpector: clean (LOW)