Skip to content

fix: route Java/JavaScript/TypeScript to Optimizer instead of Python tracer#1398

Merged
mashraf-222 merged 1 commit intoomni-javafrom
fix/java-tracer-routing
Feb 5, 2026
Merged

fix: route Java/JavaScript/TypeScript to Optimizer instead of Python tracer#1398
mashraf-222 merged 1 commit intoomni-javafrom
fix/java-tracer-routing

Conversation

@mashraf-222
Copy link
Contributor

@mashraf-222 mashraf-222 commented Feb 5, 2026

Problem Fixed

Java, JavaScript, and TypeScript optimization was broken. When running codeflash optimize --file <file> on non-Python files, the CLI crashed with:

FileNotFoundError: [Errno 2] No such file or directory: '--file'
Error location: codeflash/tracing/tracing_new_process.py:855

Impact: Blocked all Java E2E optimization flows

Root Cause

tracer.py had no language check before invoking the Python tracer. All codeflash optimize commands were routed through tracing_new_process.py (Python-specific), regardless of the target file's language.

When Java files were passed with --file, the tracer tried to execute --file as a Python script, causing the error.

Solution

Added language detection at the start of tracer.py:main():

  1. Detect file language using get_language_support(file_path)
  2. If Java/JavaScript/TypeScript: Route directly to optimizer.run_with_args() instead of Python tracing
  3. If Python or detection fails: Continue with normal Python tracing flow

Java and JS/TS use their own test runners (Maven/JUnit, Jest) and should never go through Python tracing.

Code Changes

File: codeflash/tracer.py

  • Added language detection before argument parsing
  • Route non-Python languages directly to Optimizer
  • Parse and process args properly with process_pyproject_config()
  • Set previous_checkpoint_functions = None for single-file optimization

Testing

Before fix:

$ codeflash optimize --file QuickSort.java --function sort
FileNotFoundError: [Errno 2] No such file or directory: '--file'
❌ Failed to trace. Exiting...

After fix:

$ codeflash optimize --file QuickSort.java --function sort
INFO     Detected java file, routing to Optimizer instead of Python tracer
INFO     Found 1 function to optimize
INFO     Discovered 400 existing unit tests
✓ Java optimization flow works

Impact

Unblocks: All Java E2E optimization flows
Unblocks: JavaScript/TypeScript optimization flows
Fixes: Future Java testing and validation work

🤖 Generated with Claude Code

…tracer

Java, JavaScript, and TypeScript files were incorrectly being routed through
the Python tracing module when running `codeflash optimize --file <file>`,
causing a FileNotFoundError when the tracer attempted to execute CLI args
as Python scripts.

This fix adds language detection at the start of tracer.py main() function.
When a non-Python file is detected (Java, JS, TS), the function:
1. Detects the file language using get_language_support()
2. Parses and processes args properly with process_pyproject_config()
3. Routes directly to optimizer.run_with_args() instead of Python tracing

Java and JS/TS use their own test runners (Maven/JUnit, Jest) and should
never go through Python tracing. This fix unblocks all Java E2E optimization
flows.

Issue: Java optimization failed with "FileNotFoundError: '--file'" from
tracing_new_process.py:855

Root cause: tracer.py had no language check before invoking Python-specific
tracing subprocess

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@mashraf-222 mashraf-222 merged commit a9f3e80 into omni-java Feb 5, 2026
15 of 28 checks passed
@mashraf-222 mashraf-222 deleted the fix/java-tracer-routing branch February 5, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant