Skip to content

Commit a60de79

Browse files
Merge pull request #625 from codeflash-ai/fix/revert-code-issue
[FIX] keep optimization if no pr and no staging-review
2 parents f7adce8 + f611f40 commit a60de79

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

codeflash/optimization/function_optimizer.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,9 @@ def process_review(
12411241
"concolic_tests": concolic_tests,
12421242
}
12431243

1244-
if not self.args.no_pr and not self.args.staging_review:
1244+
raise_pr = not self.args.no_pr
1245+
1246+
if raise_pr and not self.args.staging_review:
12451247
data["git_remote"] = self.args.git_remote
12461248
check_create_pr(**data)
12471249
elif self.args.staging_review:
@@ -1252,12 +1254,24 @@ def process_review(
12521254
trace_id=self.function_trace_id, is_optimization_found=best_optimization is not None
12531255
)
12541256

1255-
if ((not self.args.no_pr) or not self.args.staging_review) and (
1256-
self.args.all or env_utils.get_pr_number() or (self.args.file and not self.args.function)
1257+
if raise_pr and (
1258+
self.args.all
1259+
or env_utils.get_pr_number()
1260+
or self.args.replay_test
1261+
or (self.args.file and not self.args.function)
12571262
):
1258-
self.write_code_and_helpers(
1259-
self.function_to_optimize_source_code, original_helper_code, self.function_to_optimize.file_path
1260-
)
1263+
self.revert_code_and_helpers(original_helper_code)
1264+
return
1265+
1266+
if self.args.staging_review:
1267+
# always revert code and helpers when staging review
1268+
self.revert_code_and_helpers(original_helper_code)
1269+
return
1270+
1271+
def revert_code_and_helpers(self, original_helper_code: dict[Path, str]) -> None:
1272+
self.write_code_and_helpers(
1273+
self.function_to_optimize_source_code, original_helper_code, self.function_to_optimize.file_path
1274+
)
12611275

12621276
def establish_original_code_baseline(
12631277
self,

0 commit comments

Comments
 (0)