Commit graph

5568 commits

Author SHA1 Message Date
Aseem Saxena
30f355240f
restore version 2026-02-23 07:50:53 -08:00
Aseem Saxena
002334c7d1
Merge branch 'main' into dir-option 2026-01-28 15:09:22 -08:00
Aseem Saxena
95d1f6e5c2
Merge pull request #1193 from codeflash-ai/feat/tempfile-path-normalization
feat/ensure comparator works for temp paths
2026-01-28 14:54:58 -08:00
aseembits93
01d8aa72b9 ready to review 2026-01-28 13:46:37 -08:00
Aseem Saxena
0736e4e994 fix tests 2026-01-27 19:37:58 -08:00
Aseem Saxena
0e16699386 dir option 2026-01-27 19:18:38 -08:00
Saurabh Misra
fa1f93c24b
Merge pull request #1176 from codeflash-ai/clean-docs
clean up docs
2026-01-26 19:10:25 -08:00
Saurabh Misra
31f7090fb0
Merge branch 'main' into clean-docs 2026-01-26 19:10:09 -08:00
misrasaurabh1
fb320f2748 clean up docs 2026-01-26 19:09:33 -08:00
Kevin Turcios
ff6465b3b9
Merge pull request #1175 from codeflash-ai/disable-jit-optimizations
add --no-jit-opts to disable JIT optimizations
2026-01-26 21:14:39 -05:00
Kevin Turcios
63cc8e7d30 disable JIT optimizations 2026-01-26 20:35:16 -05:00
Aseem Saxena
87894e8299
Merge pull request #1173 from codeflash-ai/v0.20
v0.20
2026-01-26 11:49:52 -08:00
aseembits93
e6f4021663 lets merge 2026-01-26 10:54:20 -08:00
Kevin Turcios
1dae2b0d5a
Merge pull request #1170 from codeflash-ai/tessl-update
chore: add tessl registry for AI agent library docs
2026-01-25 04:56:58 -05:00
Kevin Turcios
22b6df9465 chore: add comments for tessl auto-generated content
Ignore AGENTS.md in git (auto-created by tessl install) and add
explanatory comment in CLAUDE.md for the tessl-managed section.
2026-01-25 04:53:05 -05:00
Kevin Turcios
3990378252
Merge pull request #1147 from codeflash-ai/mappingcheck
support MappingProxyType
2026-01-25 02:33:14 -05:00
Kevin Turcios
67ece97150
Merge branch 'main' into mappingcheck 2026-01-25 02:31:56 -05:00
Kevin Turcios
5e61a8b109
Merge pull request #1166 from codeflash-ai/skyvern-grace
feat: improve dependency tracking and base class extraction
2026-01-25 02:31:37 -05:00
Kevin Turcios
214d891735
Merge branch 'main' into skyvern-grace 2026-01-25 00:40:06 -05:00
Aseem Saxena
53fbe57773
Merge pull request #1164 from codeflash-ai/tracer-with-jit
Disable jit during tracing
2026-01-24 21:39:49 -08:00
Kevin Turcios
7e3d6ec7ba
Merge pull request #1169 from codeflash-ai/codeflash/optimize-pr1166-2026-01-24T15.53.33
️ Speed up function `detect_unused_helper_functions` by 15% in PR #1166 (`skyvern-grace`)
2026-01-24 19:39:51 -05:00
codeflash-ai[bot]
b54dfca0a9
Optimize detect_unused_helper_functions
This optimization achieves a **14% runtime improvement** (4.80ms → 4.19ms) through several targeted micro-optimizations that reduce overhead in hot code paths:

## Key Performance Improvements

### 1. **Eliminated Redundant Dictionary Lookups via Caching**
In `CodeStringsMarkdown` properties (`flat`, `file_to_path`), the original code called `self._cache.get("key")` twice per invocation. The optimized version caches the result in a local variable:
```python
# Before: two lookups
if self._cache.get("flat") is not None:
    return self._cache["flat"]

# After: one lookup
cached = self._cache.get("flat")
if cached is not None:
    return cached
```
This eliminates redundant hash table lookups in frequently accessed properties.

### 2. **Replaced `dict.setdefault()` for Atomic List Operations**
In `_analyze_imports_in_optimized_code`, the original code used an if-check followed by assignment for the helpers dictionary:
```python
# Before: check + assign (two operations)
if func_name in file_entry:
    file_entry[func_name].append(helper)
else:
    file_entry[func_name] = [helper]

# After: single atomic operation
helpers_by_file_and_func[module_name].setdefault(func_name, []).append(helper)
```
The `setdefault()` approach reduces the operation to a single dictionary call, eliminating the membership test.

### 3. **Hoisted `as_posix()` Calls Outside String Formatting**
In the `markdown` property, path conversion was moved outside the f-string:
```python
# Before: as_posix() called inside f-string
f"```python:{code_string.file_path.as_posix()}\n..."

# After: precomputed in conditional branch
if code_string.file_path:
    file_path_str = code_string.file_path.as_posix()
    result.append(f"```python:{file_path_str}\n...")
```
This avoids repeated method calls during string formatting.

### 4. **Optimized Set Membership Tests with Early Exit**
The most impactful change replaced `set.intersection()` with short-circuit boolean checks:
```python
# Before: creates intermediate set via intersection
is_called = bool(possible_call_names.intersection(called_function_names))

# After: early-exit on first match
if (helper_qualified_name in called_function_names or 
    helper_simple_name in called_function_names or 
    helper_fully_qualified_name in called_function_names):
    is_called = True
```
With ~200 helpers in large-scale tests, this avoids creating temporary sets for every comparison, showing **50% speedup** in the large helper test (1.31ms → 868μs).

### 5. **Minimized Repeated Attribute Access**
Variables like `entrypoint_file_path`, `attr_name`, and `value_id` are now cached before use, reducing attribute lookups in the AST traversal loop.

## Impact Based on Test Results

- **Small workloads** (10-50 helpers): 10-16% speedup from reduced dict lookups
- **Large workloads** (200 helpers): 50% speedup due to eliminated set operations in the helper-checking loop
- **Edge cases** (syntax errors, missing functions): Minimal overhead, consistent 2-3% improvement

This optimization is particularly valuable when `detect_unused_helper_functions` is called repeatedly during code analysis pipelines, as the cumulative effect of these micro-optimizations scales with the number of helper functions and code blocks analyzed.
2026-01-24 15:53:37 +00:00
Kevin Turcios
65ff392d20 add tests 2026-01-24 10:14:54 -05:00
Kevin Turcios
69740f0340 refactor: simplify code_context_extractor by extracting helper and removing dead code
- Extract build_testgen_context helper to reduce duplication in testgen
  token limit handling (~50 lines to ~20 lines)
- Remove unused extract_code_string_context_from_files function (~100 lines)
- Import get_section_names from unused_definition_remover instead of duplicating
2026-01-24 09:25:41 -05:00
Kevin Turcios
47b5235978 refactor: remove unused code and simplify return pattern in unused_definition_remover
Remove unused print_definitions debug function and simplify
detect_unused_helper_functions to use try/except/else pattern.
2026-01-24 09:25:36 -05:00
Kevin Turcios
571b2ba694 skip for 3.9 2026-01-24 07:05:27 -05:00
Kevin Turcios
aba3e79648 Merge branch 'skyvern-grace' of https://github.com/codeflash-ai/codeflash into skyvern-grace 2026-01-24 06:52:10 -05:00
Kevin Turcios
1b92d11058 Update mypy.yml 2026-01-24 06:51:43 -05:00
Kevin Turcios
9c9593aec0 refactor: merge duplicate CST pruning functions into single parameterized function
Consolidated prune_cst_for_read_only_code and prune_cst_for_testgen_code into
prune_cst_for_context with include_target_in_output and include_init_dunder flags.
2026-01-24 06:50:50 -05:00
Kevin Turcios
48b5ff379f refactor: merge duplicate CST pruning functions into single parameterized function
Consolidated prune_cst_for_read_only_code and prune_cst_for_testgen_code into
prune_cst_for_context with include_target_in_output and include_init_dunder flags.
2026-01-24 06:47:33 -05:00
Kevin Turcios
7b33e8b7f6 refactor: smarter placement of global assignments based on dependencies
Assignments that don't reference module-level definitions are now placed
right after imports. Only assignments that reference classes/functions
are placed after those definitions to prevent NameError.
2026-01-24 06:29:39 -05:00
Kevin Turcios
257c5f2b8f test: update test expectations for global assignment placement changes
Update test_no_targets_found to expect outer class to be kept when
targeting nested class methods, and add test for nonexistent targets.
Update test_multi_file_replcement01 to expect global assignments at
module end rather than after imports.
2026-01-24 06:19:48 -05:00
Kevin Turcios
50fba096f7 fix: insert global statements after function definitions to prevent NameError
When LLM-generated optimizations include module-level function calls like
`_register(MessageKind.ASK, ...)`, they were being inserted right after
imports, BEFORE the function definition they reference, causing NameError
at module load time.

Changes:
- Add GlobalStatementTransformer to append global statements at module end
- Reorder transformations: functions → assignments → statements
- Remove unused ImportInserter class
- Update test expectations to reflect new placement behavior
2026-01-24 02:09:38 -05:00
Kevin Turcios
abfa640578 fix: insert global assignments after class definitions to prevent NameError
When LLM-generated optimizations include module-level code like
`_REIFIERS = {MessageKind.XXX: ...}`, the global assignment was being
inserted right after imports, BEFORE the class definition it referenced,
causing NameError at module load time.

Changes:
- GlobalAssignmentTransformer now inserts assignments after all
  class/function definitions instead of right after imports
- GlobalStatementCollector now skips AnnAssign (annotated assignments)
  so they are handled by GlobalAssignmentCollector instead
2026-01-24 01:37:15 -05:00
Kevin Turcios
1bb9d147f4
Merge branch 'main' into skyvern-grace 2026-01-24 01:31:02 -05:00
Kevin Turcios
6b3b10e7fa fix: include dependency classes in read-writable optimization context
Classes used as dependencies (enums, dataclasses, types) were being
excluded from the optimization context even when marked as used by
the target function. This caused NameError when the LLM used these
types in generated optimizations.
2026-01-24 01:19:22 -05:00
Kevin Turcios
34de67681e fix: track attribute access base names as dependencies in DependencyCollector
Fix issue where enum/class attribute access like `MessageKind.VALUE` was not
tracking `MessageKind` as a dependency. The original code skipped all Names
inside Attribute nodes within classes, but this incorrectly filtered out
legitimate references.

Now properly distinguishes between:
- `.attr` part (e.g., `x` in `self.x`) - not tracked (attribute names)
- `.value` part (e.g., `MessageKind` in `MessageKind.VALUE`) - tracked
2026-01-24 00:57:48 -05:00
Kevin Turcios
323e52ed99 fix: use PicklePatcher for instance state to handle unpicklable async objects
When instrumenting classes that inherit from Playwright's Page (like
SkyvernPage), the instance state contains async event loop references
including asyncgen_hooks which cannot be pickled. PicklePatcher gracefully
handles these by replacing unpicklable objects with placeholders.
2026-01-23 21:06:44 -05:00
Kevin Turcios
dbc88ad105 feat: extract __init__ from external library base classes for test context
Add get_external_base_class_inits to extract __init__ methods from external
library base classes (e.g., collections.UserDict) when project classes inherit
from them. This helps the LLM understand constructor signatures for mocking.
2026-01-23 20:46:51 -05:00
Kevin Turcios
6009b83f20 fix: handle module-level function definitions in add_global_assignments
Add GlobalFunctionCollector and GlobalFunctionTransformer to collect and
insert module-level function definitions introduced by LLM optimizations.
This fixes NameError when optimized code introduces new helper functions
like @lru_cache decorated functions that are used by the optimized method.
2026-01-23 18:59:00 -05:00
Kevin Turcios
9f929c2151 fix: handle annotated assignments in GlobalAssignmentCollector
GlobalAssignmentCollector only handled cst.Assign but not cst.AnnAssign
(annotated assignments like `X: int = 1`). When the LLM generated
optimizations with annotated module-level variables, these weren't
copied to the target file, causing NameError at runtime.

- Add visit_AnnAssign to GlobalAssignmentCollector
- Add leave_AnnAssign to GlobalAssignmentTransformer
- Update type hints to include cst.AnnAssign
- Add test for annotated assignment handling
2026-01-23 18:46:49 -05:00
Kevin Turcios
412779d7ba fix: handle repr failures for Mock objects in test result comparison
Mock objects from unittest.mock can have corrupted internal state after
pickling, causing __repr__ to raise AttributeError. Added safe_repr
wrapper to gracefully handle these failures during test result comparison.
2026-01-23 17:58:14 -05:00
Kevin Turcios
9cefc0340b fix: handle instance state capture for classes without __dict__
Support classes using __slots__ and C extension types (like Playwright's
Page) that don't have a __dict__ attribute. Previously raised ValueError,
now captures slot values or public non-callable attributes as fallback.
2026-01-23 17:49:02 -05:00
aseembits93
2b11d372bf disable jit during tracing 2026-01-23 11:31:58 -08:00
Kevin Turcios
ebf77033ba test: add tests for base class extraction in imported dataclasses
- Update test_get_imported_class_definitions_includes_dataclass_decorators
  to expect both base class and derived class to be extracted
- Add test_get_imported_class_definitions_extracts_multilevel_inheritance
  to verify multi-level inheritance chains are fully extracted
2026-01-23 07:26:03 -05:00
Kevin Turcios
4e310324b4 fix: recursively extract base classes for imported dataclasses
When extracting imported class definitions for testgen context, also
extract base classes from the same module. This ensures the full
inheritance chain is available for understanding constructor signatures.

For example, when LLMConfig inherits from LLMConfigBase, both classes
are now included in the context so the LLM can see all required
positional arguments from parent classes.
2026-01-23 07:25:56 -05:00
Kevin Turcios
722d05345d decorators & annotations 2026-01-23 06:52:45 -05:00
Kevin Turcios
ec673479b5
Merge branch 'main' into mappingcheck 2026-01-23 01:50:09 -05:00
Kevin Turcios
d53e6d23a7
Merge pull request #1149 from codeflash-ai/async-improvements
feat: clarify improvement type in async optimization display
2026-01-23 01:47:48 -05:00
Kevin Turcios
f87b30403a test: validate concurrency acceptance reason in async E2E test
Ensure the async E2E test verifies that optimizations are accepted
for the correct reason (concurrency improvement).
2026-01-23 01:45:03 -05:00