You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cancel_event is created and set in the CancelledError handler but never passed into downstream calls; verify that cancellation actually propagates to the optimization workflow or remove the unused event.
asyncdefstart_demo_optimization(params: DemoOptimizationParams) ->dict[str, str]:
try:
_init()
cancel_event=threading.Event()
# start by creating the worktree so that the demo file is not created in user workspaceserver.optimizer.worktree_mode()
file_path=create_find_common_tags_file(server.args, params.functionName+".py")
# commit the new file for diff generation latercreate_worktree_snapshot_commit(server.optimizer.current_worktree, "added sample optimization file")
server.optimizer.args.file=file_pathserver.optimizer.args.function=params.functionNameserver.optimizer.args.previous_checkpoint_functions=Falseinitialization_result=_initialize_current_function_optimizer()
ifisinstance(initialization_result, dict):
returninitialization_resultserver.current_optimization_init_result=initialization_result.unwrap()
returnawaitperform_function_optimization(
FunctionOptimizationParams(functionName=params.functionName, task_id=None)
)
exceptasyncio.CancelledError:
cancel_event.set()
returnget_cancelled_reponse()
Returning raw runtime objects may not be JSON-serializable; ensure original_runtime and optimized_runtime are primitive types (e.g., float) or serialized strings as expected by the LSP client.
Removed backticks around file path may degrade markdown rendering; confirm intended formatting in LSP clients and that paths with special characters render safely.
cancel_event may be undefined here if the exception occurs before its creation, leading to UnboundLocalError. Guard its use and ensure a correctly spelled cancel response function is called.
except asyncio.CancelledError:
- cancel_event.set()- return get_cancelled_reponse()+ try:+ cancel_event.set() # may not exist if raised earlier+ except UnboundLocalError:+ pass+ return get_cancelled_response()
Suggestion importance[1-10]: 7
__
Why: If asyncio.CancelledError is raised before line 494, cancel_event would be undefined, causing UnboundLocalError; also the function call appears misspelled (get_cancelled_reponse). Guarding access and fixing the name improves robustness.
Medium
General
Preserve Markdown code formatting
Removing backticks can break Markdown formatting and paths with underscores may render as italics, degrading readability. Restore code formatting with backticks to preserve output fidelity.
Why: The PR removes backticks around explanation.file_path, which can harm Markdown rendering (e.g., underscores). Restoring backticks improves output readability without changing logic.
Low
Remove unused cancel flag
The cancel_event is created but never used or propagated, which can mislead and fail to cancel long-running work. Either pass cancel_event into downstream functions that support cancellation or remove it to avoid dead code and false assumptions.
_init()
-cancel_event = threading.Event()+# Removed unused cancel_event to avoid dead code; ensure downstream receives a real cancel handle if needed.
...
Suggestion importance[1-10]: 5
__
Why: cancel_event is created at line 494 but never passed or used except in the except block, which can mislead; removing it or properly wiring it improves clarity. Impact is moderate since it's not functionally used for cancellation in the shown code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Type
Enhancement
Description
Add cancel handling for demo optimization
Return original and optimized runtimes
Minor formatting in optimization summary
Diagram Walkthrough
File Walkthrough
beta.py
Add cancel handling to demo optimization flowcodeflash/lsp/beta.py
cancel_eventfor demo optimization.asyncio.CancelledErrorand set event.perform_optimization.py
Return original and optimized runtimes in resultcodeflash/lsp/features/perform_optimization.py
original_runtimein response payload.optimized_runtimein response payload.function_optimizer.py
Tweak file path formatting in summarycodeflash/optimization/function_optimizer.py
explanation.file_pathin summary.