← Back to PRs

#20877: Store config backups in their own directory

by pierreeurope open 2026-02-19 11:15 View on GitHub →
size: S
Config backup files were piling up directly in the .openclaw/ directory (openclaw.json.bak.1, .bak.2, etc). This moves them into a dedicated .openclaw/config-backup/ subdirectory and switches to datetime-based naming like openclaw.json.bak.2026-02-18T14-37-28.123Z. Changes: - backup-rotation.ts: new helpers to resolve backup dir/path, pruning now works with datetime-sorted files in the subdirectory - io.ts: creates the config-backup/ dir and copies backups there instead of alongside the config - Updated tests to match the new behavior Keeps the same max backup count (5). Old numbered backups in .openclaw/ won't be cleaned up automatically but they can be deleted manually. Fixes #20460 <!-- greptile_comment --> <h3>Greptile Summary</h3> Moves config backups from `.openclaw/` to `.openclaw/config-backup/` with datetime-based naming (`openclaw.json.bak.2026-02-18T14-37-28.123Z` instead of `.bak.1`, `.bak.2`, etc). - New helper functions `resolveConfigBackupDir()` and `resolveConfigBackupPath()` encapsulate backup path logic - Backup rotation now creates the subdirectory and prunes datetime-sorted files - Tests updated to verify datetime naming and max backup count - Log messages updated to reference the new backup directory **Issue found**: The pruning logic has an off-by-one error on line 50 of `backup-rotation.ts`. The expression `backups.length - maxExisting + 1` removes one too many files, resulting in only 4 backups being kept instead of the intended 5 (`CONFIG_BACKUP_COUNT`). <h3>Confidence Score: 2/5</h3> - Has a logical error that prevents correct backup rotation behavior - The off-by-one error in the pruning logic means the PR doesn't deliver on its promise to "keep the same max backup count (5)". While the test passes (it only checks `<= 5`), the actual behavior keeps only 4 backups. The rest of the refactoring (directory structure, datetime naming) is well-implemented, but this bug affects the core rotation logic. - src/config/backup-rotation.ts line 50 requires correction to maintain 5 backups as intended <sub>Last reviewed commit: cef6a59</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment -->

Most Similar PRs