Skip to content

Commit 2c49ec7

Browse files
committed
fix: ensure is_optimization_found is set in no-pr flow
1 parent 6136528 commit 2c49ec7

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

codeflash/api/cfapi.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,3 +224,18 @@ def add_code_context_hash(code_context_hash: str) -> None:
224224
"POST",
225225
{"owner": owner, "repo": repo, "pr_number": pr_number, "code_hash": code_context_hash},
226226
)
227+
228+
def mark_optimization_success(trace_id: str, is_optimization_found: bool) -> Response:
229+
"""Mark an optimization event as success or not.
230+
231+
:param trace_id: The unique identifier for the optimization event.
232+
:param is_optimization_found: Boolean indicating whether the optimization was found.
233+
:return: The response object from the API.
234+
"""
235+
payload = {
236+
"trace_id": trace_id,
237+
"is_optimization_found": is_optimization_found,
238+
}
239+
return make_cfapi_request(
240+
endpoint="/mark-as-success", method="POST", payload=payload
241+
)

codeflash/optimization/function_optimizer.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from rich.tree import Tree
2020

2121
from codeflash.api.aiservice import AiServiceClient, LocalAiServiceClient
22-
from codeflash.api.cfapi import add_code_context_hash
22+
from codeflash.api.cfapi import add_code_context_hash, mark_optimization_success
2323
from codeflash.benchmarking.utils import process_benchmark_data
2424
from codeflash.cli_cmds.console import code_print, console, logger, progress_bar
2525
from codeflash.code_utils import env_utils
@@ -387,6 +387,12 @@ def optimize_function(self) -> Result[BestOptimization, str]: # noqa: PLR0911
387387
original_helper_code,
388388
self.function_to_optimize.file_path,
389389
)
390+
else:
391+
# Mark optimization success since no PR will be created
392+
mark_optimization_success(
393+
trace_id=self.function_trace_id,
394+
is_optimization_found=best_optimization is not None
395+
)
390396
self.log_successful_optimization(explanation, generated_tests, exp_type)
391397

392398
# Add function to code context hash if in gh actions

0 commit comments

Comments
 (0)