Skip to content

Commit 7944e43

Browse files
fix: handle Windows 8.3 short-name path mismatch in target block reordering
On Windows, Path.resolve() expands 8.3 short names for directories but not always for files. After project_root_path.resolve() converts RUNNER~1 to runneradmin, file_path.resolve() may still return the 8.3 form, causing relative_to() to raise ValueError and silently returning empty target_code. Wrap the cosmetic reordering block in try/except to match the existing pattern in process_file_context, preventing the crash without any correctness loss. Co-authored-by: Aseem Saxena <aseembits93@users.noreply.github.com>
1 parent 04b1e30 commit 7944e43

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

codeflash/languages/python/context/code_context_extractor.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,14 @@ def get_code_optimization_context(
152152
)
153153

154154
# Ensure the target file is first in the code blocks so the LLM knows which file to optimize
155-
target_relative = function_to_optimize.file_path.resolve().relative_to(project_root_path.resolve())
156-
target_blocks = [cs for cs in final_read_writable_code.code_strings if cs.file_path == target_relative]
157-
other_blocks = [cs for cs in final_read_writable_code.code_strings if cs.file_path != target_relative]
158-
if target_blocks:
159-
final_read_writable_code.code_strings = target_blocks + other_blocks
155+
try:
156+
target_relative = function_to_optimize.file_path.resolve().relative_to(project_root_path)
157+
target_blocks = [cs for cs in final_read_writable_code.code_strings if cs.file_path == target_relative]
158+
other_blocks = [cs for cs in final_read_writable_code.code_strings if cs.file_path != target_relative]
159+
if target_blocks:
160+
final_read_writable_code.code_strings = target_blocks + other_blocks
161+
except ValueError:
162+
pass
160163

161164
read_only_code_markdown = extract_code_markdown_context_from_files(
162165
helpers_of_fto_dict,

0 commit comments

Comments
 (0)