Skip to content

Commit cad5a07

Browse files
committed
delete all the checkpoint files for a given module root at the end of a successful run
1 parent b60a670 commit cad5a07

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

codeflash/code_utils/checkpoint.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ def _update_metadata_timestamp(self) -> None:
8181
f.write(json.dumps(metadata) + "\n")
8282
f.write(rest_content)
8383

84+
def cleanup(self) -> None:
85+
"""Unlink all the checkpoint files for this module_root."""
86+
to_delete = []
87+
self.checkpoint_path.unlink(missing_ok=True)
88+
89+
for file in self.checkpoint_dir.glob("codeflash_checkpoint_*.jsonl"):
90+
with file.open() as f:
91+
# Skip the first line (metadata)
92+
first_line = next(f)
93+
metadata = json.loads(first_line)
94+
if metadata.get("module_root", str(self.module_root)) == str(self.module_root):
95+
to_delete.append(file)
96+
for file in to_delete:
97+
file.unlink(missing_ok=True)
98+
8499

85100
def get_all_historical_functions(module_root: Path, checkpoint_dir: Path) -> dict[str, dict[str, str]]:
86101
"""Get information about all processed functions, regardless of status.

codeflash/optimization/optimizer.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ def run(self) -> None:
258258
console.rule()
259259
continue
260260
ph("cli-optimize-run-finished", {"optimizations_found": optimizations_found})
261+
if self.functions_checkpoint:
262+
self.functions_checkpoint.cleanup()
261263
if optimizations_found == 0:
262264
logger.info("❌ No optimizations found.")
263265
elif self.args.all:

0 commit comments

Comments
 (0)