Skip to content

Conversation

@aseembits93
Copy link
Contributor

@aseembits93 aseembits93 commented Nov 15, 2025

PR Type

Bug fix, Enhancement


Description

  • Skip formatting when formatter disabled

  • Simplify diff generation for reviews

  • Always compute optimization review

  • Surface optimization review in LSP response


Diagram Walkthrough

flowchart LR
  Formatter["Formatting generated code"] -- "no formatter provided" --> NoFmt["Return normalized newlines"]
  AIReview["AI optimization review"] -- "simplified diff" --> ReviewReq["Service request payload"]
  Optimizer["Function optimizer"] -- "always run review" --> ReviewRes["optimization_review stored"]
  LSPResp["LSP optimization response"] -- "add field" --> Client["Editor client"]
Loading

File Walkthrough

Relevant files
Enhancement
aiservice.py
Simplify review diff and adjust logging                                   

codeflash/api/aiservice.py

  • Import Path only in TYPE_CHECKING.
  • Remove root_dir parameter from review method.
  • Simplify unified diff call without filenames.
  • Update log message to "loading|Reviewing Optimization…".
+4/-9     
perform_optimization.py
Add optimization review to LSP response                                   

codeflash/lsp/features/perform_optimization.py

  • Include optimization review (capitalized) in response payload.
+1/-0     
function_optimizer.py
Always compute and store optimization review                         

codeflash/optimization/function_optimizer.py

  • Initialize optimization_review attribute.
  • Always request optimization review regardless of PR flags.
  • Store review in data and instance attribute.
  • Limit PR creation based on review and flags.
+10/-7   
Bug fix
formatter.py
Skip formatting when formatter is disabled                             

codeflash/code_utils/formatter.py

  • Detect missing formatter and short-circuit.
  • Return code with normalized blank lines if disabled.
+3/-0     

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Codeflash Bot seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

@aseembits93
Copy link
Contributor Author

buiilt from another branch

@github-actions
Copy link

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Behavior Change

Returning normalized newlines when formatter is disabled changes previous semantics; verify callers expect "disabled" to skip formatting and that downstream logic relying on formatter exit codes or formatting diffs still behaves correctly.

formatter_name = formatter_cmds[0].lower() if formatter_cmds else "disabled"
if formatter_name == "disabled":  # nothing to do if no formatter provided
    return re.sub(r"\n{2,}", "\n\n", generated_test_source)
with tempfile.TemporaryDirectory() as test_dir_str:
Logging Change

The log message prefix changed from '!lsp|Computing Optimization Review…' to 'loading|Reviewing Optimization…'; ensure any log parsers or UX elements depending on the old tag are updated.

logger.info("loading|Reviewing Optimization…")
Always Run Review

Optimization review now runs unconditionally; confirm performance impact and that empty or failed responses are handled correctly where 'optimization_review' is consumed.

# this will now run regardless of pr, staging review flags
try:
    opt_review_response = self.aiservice_client.get_optimization_review(
        **data, calling_fn_details=function_references
    )
except Exception as e:
    logger.debug(f"optimization review response failed, investigate {e}")
data["optimization_review"] = opt_review_response
self.optimization_review = opt_review_response
if raise_pr or staging_review:

@github-actions
Copy link

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Safely capitalize review value

Guard against empty or non-string optimization_review to avoid AttributeError on
.capitalize(). Provide a safe default for clients expecting a value.

codeflash/lsp/features/perform_optimization.py [129-138]

 "explanation": best_optimization.explanation_v2,
-"optimizationReview": function_optimizer.optimization_review.capitalize(),
+"optimizationReview": (function_optimizer.optimization_review or "low").capitalize(),
Suggestion importance[1-10]: 8

__

Why: Prevents a potential AttributeError when optimization_review is empty by providing a safe default before .capitalize(), directly improving robustness with minimal change.

Medium
Restore filenames in diffs

Preserve filenames in diffs to keep reviews meaningful. Pass stable file identifiers
to unified_diff_strings so downstream consumers and humans can understand which file
each hunk refers to.

codeflash/api/aiservice.py [584-590]

 diff_str = "\n".join(
     [
-        unified_diff_strings(code1=original_code[p], code2=new_code[p])
+        unified_diff_strings(
+            code1=original_code[p],
+            code2=new_code[p],
+            fromfile=str(p),
+            tofile=str(p),
+        )
         for p in original_code
         if not is_zero_diff(original_code[p], new_code[p])
     ]
 )
Suggestion importance[1-10]: 7

__

Why: Correctly identifies that filenames were removed from unified_diff_strings, reducing diff clarity; the proposed change is accurate and aligns with the prior behavior, improving review usefulness without functional risk.

Medium
General
Avoid passing obsolete parameters

The API signature dropped root_dir, but you still set it in data for PR/staging,
risking accidental leakage to other calls. Only add root_dir when it's actually
required downstream and ensure it's not passed to get_optimization_review.

codeflash/optimization/function_optimizer.py [1507-1516]

 opt_review_response = ""
 # this will now run regardless of pr, staging review flags
 try:
     opt_review_response = self.aiservice_client.get_optimization_review(
         **data, calling_fn_details=function_references
     )
 except Exception as e:
     logger.debug(f"optimization review response failed, investigate {e}")
 data["optimization_review"] = opt_review_response
 self.optimization_review = opt_review_response
 if raise_pr or staging_review:
-    data["root_dir"] = git_root_dir()
+    pr_data = {**data, "root_dir": git_root_dir()}
Suggestion importance[1-10]: 6

__

Why: It rightly avoids polluting data with root_dir for the API that no longer accepts it, reducing risk of accidental leakage; however, the change is relatively minor and partly stylistic since the current code doesn't pass data again until PR creation.

Low

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants