Skip to content

end to end test with prod aiserver - #8

Merged
alvin-r merged 11 commits into
mainfrom
github-actions
Feb 15, 2025
Merged

end to end test with prod aiserver#8
alvin-r merged 11 commits into
mainfrom
github-actions

Conversation

@alvin-r

@alvin-r alvin-r commented Feb 14, 2025

Copy link
Copy Markdown
Contributor

No description provided.

Comment thread .github/workflows/end-to-end-test-bubblesort-pytest-no-git.yaml Outdated
@alvin-r
alvin-r marked this pull request as ready for review February 14, 2025 05:42
Comment thread codeflash/update_license_version.py Outdated
Comment thread codeflash/update_license_version.py Outdated
Comment thread .gitignore
@alvin-r
alvin-r merged commit 4a15907 into main Feb 15, 2025
mohammedahmed18 added a commit that referenced this pull request Apr 4, 2026
**Issue #8: CLI incorrectly calls adaptive_optimize for JavaScript/TypeScript**

**Problem:**
When a refined candidate (source=REFINE) succeeds for JS/TS, the next
iteration calls adaptive_optimize (Python-only endpoint) instead of
optimize_code_refinement (all languages). This results in "422 - Invalid
code generated" from the AI service because adaptive_optimize tries to
parse JS/TS code using libcst (Python AST parser).

**Root Cause:**
File: codeflash/languages/function_optimizer.py (line 1266)
The code checked if a REFINE candidate existed but did not check the
language before calling adaptive_optimize.

**Evidence:**
- Trace ID: 1417a6da-796c-4a38-8c44-00401dbab6c7
- Function: formatBytes (TypeScript)
- Error: "POST /ai/adaptive_optimize HTTP/1.1" 422 36
- AI service logs: "adaptive_optimize invalid code"

**Fix:**
Added language check at line 1266:
```python
if is_candidate_refined_before and self.function_to_optimize.language == "python":
    # Call adaptive_optimize (Python-only)
else:
    # Call optimize_code_refinement (all languages)
```

**Testing:**
- Added 4 regression tests in test_adaptive_optimize_language_bug.py
- All tests pass
- No linting errors from `uv run prek`

**Impact:**
- Fixes systematic bug affecting JS/TS optimizations with successful REFINE candidates
- Allows second refinement iteration to proceed for JS/TS
- Python behavior unchanged (still uses adaptive_optimize after REFINE)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
mohammedahmed18 added a commit that referenced this pull request Apr 4, 2026
Issue #9: process_review() called get_new_explanation() and
get_optimization_review() without checking language. These are Python-only
endpoints that would fail or return incorrect results for JavaScript/TypeScript.

Root Cause:
- process_review() (line 2459) calls two Python-only endpoints:
  - get_new_explanation() (line 2575) - no language check
  - get_optimization_review() (line 2638) - no language check
- Same pattern as Issue #8 (adaptive_optimize) which was already fixed
- Latent bug - only manifests when JS/TS optimization succeeds

Fix:
- Added language guard before get_new_explanation: if language == "python"
- Added language guard before get_optimization_review: if language == "python"
- For non-Python languages, use original explanation from AI service
- For non-Python languages, skip optimization review (sets empty review)

Impact:
- Latent bug (not yet triggered because all JS/TS optimizations fail at baseline)
- Would block JS/TS optimization success once baseline issues are resolved
- Severity: MEDIUM (latent, not blocking current work)

Testing:
- Existing function_optimizer tests pass
- No linting/type errors

Category: Latent bug (will reproduce when JS/TS optimizations succeed)
Type: Missing language guard in CLI

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
mohammedahmed18 added a commit that referenced this pull request Apr 4, 2026
**Problem:**
The `maybe_repair_optimization()` method called `/ai/code_repair` (a Python-only
endpoint) without checking if the language is Python first. This would cause
errors when JavaScript/TypeScript optimizations reach the repair stage.

**Root Cause:**
File: codeflash/languages/function_optimizer.py (line 2957)
- `repair_optimization()` calls `/ai/code_repair` endpoint
- `/ai/code_repair` uses Python-specific tools (libcst for AST manipulation)
- No language check before calling repair

**Impact:**
- Latent bug (not yet triggered in production)
- Would block JS/TS optimization success once candidates reach repair stage
- Severity: MEDIUM

**Fix:**
Added language guard at line 2948:
- Check `self.function_to_optimize.language != "python"`
- Skip repair for JavaScript/TypeScript/Java
- Log debug message explaining why repair was skipped

**Testing:**
- Added tests/test_languages/test_code_repair_language_guard.py
- Documents expected behavior for language checks
- All existing tests pass
- No linting/type errors

**Trace IDs:**
N/A (latent bug, not yet triggered)

**Related Issues:**
- Similar pattern to Issue #8 (adaptive_optimize) - PR #1995
- Similar pattern to Issue #9 (get_new_explanation, get_optimization_review) - PR #1997

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@KRRT7 KRRT7 mentioned this pull request Apr 10, 2026
9 tasks
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.

3 participants