Remove old checkpoints, keeping only the most recent ones. Args: keep_count: Number of recent checkpoints to keep
(keep_count: int = 5)
| 275 | |
| 276 | |
| 277 | def prune_checkpoints(keep_count: int = 5): |
| 278 | """ |
| 279 | Remove old checkpoints, keeping only the most recent ones. |
| 280 | |
| 281 | Args: |
| 282 | keep_count: Number of recent checkpoints to keep |
| 283 | """ |
| 284 | state = get_state_store() |
| 285 | checkpoints = state.get_checkpoints(100) # Get all |
| 286 | |
| 287 | if len(checkpoints) <= keep_count: |
| 288 | return |
| 289 | |
| 290 | to_remove = checkpoints[keep_count:] |
| 291 | |
| 292 | for cp in to_remove: |
| 293 | checkpoint_id = cp["id"] |
| 294 | backup_dir = CHECKPOINT_DIR / checkpoint_id |
| 295 | |
| 296 | # Remove backup directory |
| 297 | if backup_dir.exists(): |
| 298 | shutil.rmtree(backup_dir) |
| 299 | |
| 300 | # Remove from database |
| 301 | state.delete_checkpoint(checkpoint_id) |
| 302 | |
| 303 | info(f"Checkpoint: pruned '{checkpoint_id}'") |
| 304 | |
| 305 | success(f"Checkpoint: pruned {len(to_remove)} old checkpoints") |
| 306 | |
| 307 | |
| 308 | # State store extensions for checkpoints |
nothing calls this directly
no test coverage detected