← Back to PRs

#21217: fix: memory prune command to prevent unbounded MEMORY.md growth

by theognis1002 open 2026-02-19 19:58 View on GitHub →
docs cli size: M
## Summary Closes #20720 - Add `openclaw memory prune` command that archives older MEMORY.md sections to `memory/YYYY-MM-DD-archived.md` when the file exceeds a configurable threshold - Surface MEMORY.md file size in `openclaw memory status` with warnings when approaching the 20k bootstrap truncation limit - Add `agents.defaults.memory.warnChars` and `agents.defaults.memory.pruneKeepChars` config options - Update AGENTS.md and healthcheck skill docs with size management guidance ## Test plan - Unit tests pass (12/12) — `pnpm test src/memory/prune.test.ts` - Build passes — `pnpm build` <!-- greptile_comment --> <h3>Greptile Summary</h3> This PR implements a memory pruning command to prevent `MEMORY.md` from growing beyond the 20k character bootstrap truncation limit. The implementation adds a `openclaw memory prune` CLI command that archives older sections to dated files in the `memory/` directory while keeping the most recent content. The `memory status` command now displays file size with warnings when approaching limits. Key changes: - Added `pruneMemoryFile()` function with smart heading-boundary splitting to preserve markdown structure - CLI command supports `--dry-run`, configurable thresholds, and JSON output - Config schema adds `agents.defaults.memory.warnChars` (default: 15k) and `agents.defaults.memory.pruneKeepChars` (default: 10k) - Updated docs to guide users on memory management - Comprehensive unit tests (12/12 passing) cover edge cases including dry-run, heading splits, appending to existing archives, and error handling <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with high confidence - The implementation is well-tested (12/12 unit tests passing), follows existing codebase patterns, handles edge cases properly (missing files, empty files, existing archives), and includes comprehensive documentation. The atomic file write pattern (write to `.tmp`, then rename) prevents data loss. The feature addresses a real need (preventing unbounded MEMORY.md growth) without breaking changes. - No files require special attention <sub>Last reviewed commit: 6678ce7</sub> <!-- greptile_other_comments_section --> <sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub> <!-- /greptile_comment -->

Most Similar PRs