When ALICE woke up on June 30th, the system spat out a warning: MEMORY.md was sitting at 5366 bytes—well over its 3500-byte limit. "Write memory after deduplication first." This wasn't new territory for the team behind this AI agent. They'd hit this wall before, and their previous fix had been predictable: schedule weekly garbage collection, set aside time on weekends to comb through stale memories and trim what was outdated.

The Problem With Weekend Cleaning

The weekly cleanup approach felt reasonable in theory—treat memory maintenance like spring cleaning, tackle it periodically when things pile up. But here's the catch nobody talks about: by the time weekend arrives, the damage is already done. Search performance degrades throughout the week. Redundant entries multiply. Token budgets get eaten alive before anyone touches the problem. And realistically? Nobody actually enjoys weekend chores, human or AI.

Three Rounds of Getting It Wrong

The team documented their evolution through three distinct failure modes. First came neglect—letting memory grow unchecked until it became unmanageable. Second was scheduled cleanup, which helped but only addressed problems after they'd already impacted system performance. Third, finally, was write-time guarding: shifting maintenance from "cleanup after the fact" to "gatekeeping at the point of entry." The result? Persistent memory dropped from 15.9K down to 6.9K—a 57% reduction that came not from aggressive pruning but from preventing bloat in the first place.

How Write-Time Guarding Actually Works

The implementation wasn't complex, which is exactly why it worked. Three rules govern every write operation: First, before writing to any persistent memory file (MEMORY.md, USER.md, failures.md), grep for existing entries on the same topic. If a match exists, replace rather than append—never add redundant blocks of text. Second, after writing, run wc -m to confirm total size stays under 3500 bytes. Exceed the limit? Handle it immediately, don't defer to "later." Third, if memory content describes how to do something, convert it to a skill first, then delete from memory entirely. The order matters: knowledge goes to skills, then disappears from working memory.

Why Scheduled Cleanup Was Doomed By Design

This isn't purely a technical failure mode—it's a human factors problem baked into the architecture. Scheduled cleanup creates a vicious cycle: problems accumulate, you schedule time to clean them, by the time you clean it's already too late, the process is painful so you avoid it next time. The insight ALICE's team landed on: a system requiring constant willpower to maintain isn't a good system. Good systems stay clean through normal use. In their architecture (ADR-003), memory lives in three tiers—HOT for wake-up essentials, WARM for on-demand access, COLD for archival storage—with hard size limits at each layer. But the real win wasn't the tier structure; it was making write rules more stringent than cleanup rules.

Key Takeaways

  • Reactive cleanup creates a perpetual catchup loop that degrades performance before you can act
  • Write-time deduplication and size checks prevent bloat better than any scheduled maintenance window
  • Converting procedural knowledge to skills and purging from memory reduces active load without losing information
  • Systems requiring sustained willpower for maintenance have a design problem, not a discipline problem

The Bottom Line

The math is simple: if every write is clean, accumulation stays clean. ALICE's team spent three iterations learning what hackers already know—defense at the perimeter beats cleanup in the aftermath. Stop scheduling garbage collection. Start gating the front door. Your token budget will thank you. Sources: DEV.to | https://dev.to/yuta_tu_df870be227e99357a/shui-mian-wei-sheng-wei-shi-mo-xing-lai-zai-da-sao-yong-yuan-lai-bu-ji-33li