From d7c89ad25b0691573be40d60f2d3de1494affcb1 Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Mon, 23 Jun 2025 19:04:32 -0700 Subject: [PATCH 1/5] cleanup properly add verbose mode to --verify-setup --- codeflash/cli_cmds/cmd_init.py | 6 +++-- codeflash/optimization/function_optimizer.py | 24 +++++--------------- codeflash/optimization/optimizer.py | 8 ++++++- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/codeflash/cli_cmds/cmd_init.py b/codeflash/cli_cmds/cmd_init.py index 42efad106..b551a146b 100644 --- a/codeflash/cli_cmds/cmd_init.py +++ b/codeflash/cli_cmds/cmd_init.py @@ -34,7 +34,7 @@ from argparse import Namespace CODEFLASH_LOGO: str = ( - f"{LF}" # noqa: ISC003 + f"{LF}" r" _ ___ _ _ " + f"{LF}" r" | | / __)| | | | " + f"{LF}" r" ____ ___ _ | | ____ | |__ | | ____ ___ | | _ " + f"{LF}" @@ -941,6 +941,8 @@ def run_end_to_end_test(args: Namespace, bubble_sort_path: str, bubble_sort_test command = ["codeflash", "--file", "bubble_sort.py", "--function", "sorter"] if args.no_pr: command.append("--no-pr") + if args.verbose: + command.append("--verbose") logger.info("Running sample optimization…") console.rule() @@ -953,7 +955,7 @@ def run_end_to_end_test(args: Namespace, bubble_sort_path: str, bubble_sort_test if process.stdout: for line in process.stdout: stripped = line.strip() - console.print(stripped) + console.out(stripped) output.append(stripped) process.wait() console.rule() diff --git a/codeflash/optimization/function_optimizer.py b/codeflash/optimization/function_optimizer.py index c94759369..ad596c006 100644 --- a/codeflash/optimization/function_optimizer.py +++ b/codeflash/optimization/function_optimizer.py @@ -908,7 +908,7 @@ def generate_tests_and_optimizations( function_to_concolic_tests, concolic_test_str = future_concolic_tests.result() logger.info(f"Generated {len(tests)} tests for {self.function_to_optimize.function_name}") console.rule() - generated_tests = GeneratedTestsList(generated_tests=tests) + generated_tests = GeneratedTestsList(generated_tests=[]) return Success( ( @@ -1321,23 +1321,11 @@ def generate_and_instrument_tests( ] def cleanup_generated_files(self) -> None: - paths_to_cleanup = ( - [ - test_file.instrumented_behavior_file_path - for test_type in [ - TestType.GENERATED_REGRESSION, - TestType.EXISTING_UNIT_TEST, - TestType.CONCOLIC_COVERAGE_TEST, - ] - for test_file in self.test_files.get_by_type(test_type).test_files - ] - + [ - test_file.benchmarking_file_path - for test_type in [TestType.GENERATED_REGRESSION, TestType.EXISTING_UNIT_TEST] - for test_file in self.test_files.get_by_type(test_type).test_files - ] - + [self.test_cfg.concolic_test_root_dir] - ) + paths_to_cleanup = [self.test_cfg.concolic_test_root_dir] + for test_file in self.test_files: + paths_to_cleanup.append(test_file.instrumented_behavior_file_path) + paths_to_cleanup.append(test_file.benchmarking_file_path) + cleanup_paths(paths_to_cleanup) if hasattr(get_run_tmp_file, "tmpdir"): get_run_tmp_file.tmpdir.cleanup() diff --git a/codeflash/optimization/optimizer.py b/codeflash/optimization/optimizer.py index f1c22a9dd..23b5594f8 100644 --- a/codeflash/optimization/optimizer.py +++ b/codeflash/optimization/optimizer.py @@ -45,6 +45,7 @@ def __init__(self, args: Namespace) -> None: self.local_aiservice_client = LocalAiServiceClient() if self.experiment_id else None self.replay_tests_dir = None self.functions_checkpoint: CodeflashRunCheckpoint | None = None + self.current_function_optimizer: FunctionOptimizer | None = None def create_function_optimizer( self, @@ -265,7 +266,9 @@ def run(self) -> None: function_to_tests, validated_original_code[original_module_path].source_code, ) - + self.current_function_optimizer = ( + function_optimizer # needed to clean up from the outside of this function + ) best_optimization = function_optimizer.optimize_function() if self.functions_checkpoint: self.functions_checkpoint.add_function_to_checkpoint( @@ -293,6 +296,9 @@ def run(self) -> None: def cleanup_temporary_paths(self) -> None: from codeflash.code_utils.code_utils import cleanup_paths + if self.current_function_optimizer: + self.current_function_optimizer.cleanup_generated_files() + cleanup_paths([self.test_cfg.concolic_test_root_dir, self.replay_tests_dir]) From 7729e264865b8e08b78da36daf585918604570d0 Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Mon, 23 Jun 2025 19:13:29 -0700 Subject: [PATCH 2/5] revert --- codeflash/optimization/function_optimizer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codeflash/optimization/function_optimizer.py b/codeflash/optimization/function_optimizer.py index ad596c006..96f0caf64 100644 --- a/codeflash/optimization/function_optimizer.py +++ b/codeflash/optimization/function_optimizer.py @@ -908,7 +908,7 @@ def generate_tests_and_optimizations( function_to_concolic_tests, concolic_test_str = future_concolic_tests.result() logger.info(f"Generated {len(tests)} tests for {self.function_to_optimize.function_name}") console.rule() - generated_tests = GeneratedTestsList(generated_tests=[]) + generated_tests = GeneratedTestsList(generated_tests=tests) return Success( ( From 41a32f6b853a80ebc19f5cff91f8c87c5f4df328 Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Mon, 23 Jun 2025 19:14:07 -0700 Subject: [PATCH 3/5] Update codeflash/cli_cmds/cmd_init.py --- codeflash/cli_cmds/cmd_init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codeflash/cli_cmds/cmd_init.py b/codeflash/cli_cmds/cmd_init.py index b551a146b..35d6aeb45 100644 --- a/codeflash/cli_cmds/cmd_init.py +++ b/codeflash/cli_cmds/cmd_init.py @@ -34,7 +34,7 @@ from argparse import Namespace CODEFLASH_LOGO: str = ( - f"{LF}" + f"{LF}" # noqa: ISC003 r" _ ___ _ _ " + f"{LF}" r" | | / __)| | | | " + f"{LF}" r" ____ ___ _ | | ____ | |__ | | ____ ___ | | _ " + f"{LF}" From 0fd3c016b4c50152b700a7e410e2cabef9214b1f Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Mon, 23 Jun 2025 19:14:22 -0700 Subject: [PATCH 4/5] Update codeflash/cli_cmds/cmd_init.py --- codeflash/cli_cmds/cmd_init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codeflash/cli_cmds/cmd_init.py b/codeflash/cli_cmds/cmd_init.py index 35d6aeb45..b7ed556b9 100644 --- a/codeflash/cli_cmds/cmd_init.py +++ b/codeflash/cli_cmds/cmd_init.py @@ -34,7 +34,7 @@ from argparse import Namespace CODEFLASH_LOGO: str = ( - f"{LF}" # noqa: ISC003 + f"{LF}" # noqa: ISC003 r" _ ___ _ _ " + f"{LF}" r" | | / __)| | | | " + f"{LF}" r" ____ ___ _ | | ____ | |__ | | ____ ___ | | _ " + f"{LF}" From 05ed518544517b24df4e45dd9502eb87587af05a Mon Sep 17 00:00:00 2001 From: Saurabh Misra Date: Mon, 23 Jun 2025 20:55:37 -0700 Subject: [PATCH 5/5] exclude keyboard interrupt we don't want this event + slows down cleanup, and the user might exit the cleanup before we get a chance --- codeflash/telemetry/sentry.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codeflash/telemetry/sentry.py b/codeflash/telemetry/sentry.py index 3c35d2fd8..b7ff00094 100644 --- a/codeflash/telemetry/sentry.py +++ b/codeflash/telemetry/sentry.py @@ -12,6 +12,7 @@ def init_sentry(enabled: bool = False, exclude_errors: bool = False) -> None: # if exclude_errors else logging.ERROR, # Otherwise, error logs will create sentry events ) + sentry_sdk.init( dsn="https://4b9a1902f9361b48c04376df6483bc96@o4506833230561280.ingest.sentry.io/4506833262477312", integrations=[sentry_logging], @@ -22,4 +23,5 @@ def init_sentry(enabled: bool = False, exclude_errors: bool = False) -> None: # # of sampled transactions. # We recommend adjusting this value in production. profiles_sample_rate=1.0, + ignore_errors=[KeyboardInterrupt], )