From b19c0b353f20f91a8a0d8f19f710c575a2d4bddb Mon Sep 17 00:00:00 2001 From: ali Date: Thu, 18 Sep 2025 15:34:10 +0300 Subject: [PATCH] Ensure cleanup after every candidate testing --- codeflash/optimization/function_optimizer.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/codeflash/optimization/function_optimizer.py b/codeflash/optimization/function_optimizer.py index 30d6d4022..078edc9f5 100644 --- a/codeflash/optimization/function_optimizer.py +++ b/codeflash/optimization/function_optimizer.py @@ -649,16 +649,14 @@ def determine_best_candidate( if self.args.benchmark and benchmark_tree: console.print(benchmark_tree) console.rule() - - self.write_code_and_helpers( - self.function_to_optimize_source_code, original_helper_code, self.function_to_optimize.file_path - ) except KeyboardInterrupt as e: + logger.exception(f"Optimization interrupted: {e}") + raise + finally: + # reset for the next candidate self.write_code_and_helpers( self.function_to_optimize_source_code, original_helper_code, self.function_to_optimize.file_path ) - logger.exception(f"Optimization interrupted: {e}") - raise if not valid_optimizations: return None # need to figure out the best candidate here before we return best_optimization