Skip to content

Conversation

@KRRT7
Copy link
Contributor

@KRRT7 KRRT7 commented Nov 23, 2025

PR Type

Enhancement, Bug fix, Tests, Documentation


Description

  • Enable async optimization by default

  • Deprecate and ignore --async flag

  • Remove async filtering in discovery

  • Update tests and dependencies


Diagram Walkthrough

flowchart LR
  CLI["CLI flags"] -- "--async deprecated" --> Args["Args processing"]
  Args -- "no gating by pytest-asyncio" --> Discover["Function discovery"]
  Discover -- "remove async filtering" --> Optimizer["Optimizer inputs"]
  Tests["Tests"] -- "expect async included" --> Discover
  Deps["Dependencies"] -- "add pytest-asyncio base dep" --> Project["Project"]
Loading

File Walkthrough

Relevant files
Enhancement
3 files
cli.py
Deprecate --async flag and stop hard failure                         
+4/-7     
functions_to_optimize.py
Always include async; remove enable_async plumbing             
+1/-21   
optimizer.py
Stop passing enable_async to discovery                                     
+0/-1     
Tests
3 files
end_to_end_test_async.py
Remove enable_async from test config                                         
+0/-1     
end_to_end_test_utilities.py
Drop enable_async option and flag wiring                                 
+0/-3     
test_async_function_discovery.py
Update expectations: async functions always included         
+7/-6     
Dependencies
1 files
pyproject.toml
Make pytest-asyncio a core dependency; remove extra           
+1/-7     

@github-actions
Copy link

github-actions bot commented Nov 23, 2025

PR Reviewer Guide 🔍

(Review updated until commit 7fd5889)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Deprecated Flag Handling

The deprecated --async flag is now ignored and only logs a warning. Confirm that downstream logic no longer depends on this flag and that ignoring it won’t cause unexpected behavior for users/scripts relying on previous failure when pytest-asyncio was missing.

if getattr(args, "async", False):
    logger.warning(
        "The --async flag is deprecated and will be removed in a future version. "
        "Async function optimization is now enabled by default."
    )
Type Consistency

The type of previous_checkpoint_functions changed to use Path keys in filter_functions signature while callers pass a dict[str, dict]. Validate types are consistent across callers and internal usage to avoid runtime issues.

def filter_functions(
    modified_functions: dict[Path, list[FunctionToOptimize]],
    tests_root: Path,
    ignore_paths: list[Path],
    project_root: Path,
    module_root: Path,
    previous_checkpoint_functions: dict[Path, dict[str, Any]] | None = None,
    *,
    disable_logs: bool = False,
) -> tuple[dict[Path, list[FunctionToOptimize]], int]:
Logging Counters

Removed async filter but kept aggregated logging. Ensure removed async-related counters are not referenced elsewhere and that totals (functions_count) remain accurate after including async functions.

    "Test functions removed": (test_functions_removed_count, "yellow"),
    "Site-package functions removed": (site_packages_removed_count, "magenta"),
    "Non-importable file paths": (malformed_paths_count, "red"),
    "Functions outside module-root": (non_modules_removed_count, "cyan"),
    "Files from ignored paths": (ignore_paths_removed_count, "blue"),
    "Files from ignored submodules": (submodule_ignored_paths_count, "bright_black"),
    "Blocklisted functions removed": (blocklist_funcs_removed_count, "bright_red"),
    "Functions skipped from checkpoint": (previous_checkpoint_functions_removed_count, "green"),
}
tree = Tree(Text("Ignored functions and files", style="bold"))

@github-actions
Copy link

github-actions bot commented Nov 23, 2025

PR Code Suggestions ✨

Latest suggestions up to 7fd5889
Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
Avoid keyword-named attribute usage

Using the attribute name async shadows a Python keyword and can cause confusion with
linters and tooling. Normalize this flag into a non-keyword attribute after parsing
to avoid keyword usage throughout the codebase.

codeflash/cli_cmds/cli.py [157-161]

 if getattr(args, "async", False):
     logger.warning(
         "The --async flag is deprecated and will be removed in a future version. "
         "Async function optimization is now enabled by default."
     )
+    # Normalize away the keyword attribute to prevent downstream usage
+    setattr(args, "enable_async_flag", True)
+    delattr(args, "async")
Suggestion importance[1-10]: 5

__

Why: Normalizing away an attribute named async can reduce linting/tooling confusion, but the current code only reads it and logs a warning; deleting/renaming it may break other consumers expecting the attribute. Impact is minor and somewhat speculative.

Low
Run async test on Windows

The skip-on-Windows marker keeps the new default untested on Windows. If Windows
support is expected, remove the skip to catch platform-specific regressions;
otherwise, update the reason to reflect current support status.

tests/test_async_function_discovery.py [260-263]

-@pytest.mark.skipif(sys.platform == "win32", reason="pending support for asyncio on windows")
 def test_async_functions_always_included(temp_dir):
     """Test that async functions are always included now (no longer filtered out)."""
Suggestion importance[1-10]: 4

__

Why: Removing the Windows skip could improve coverage if Windows is supported, but the PR explicitly cites pending Windows asyncio support; this change risks CI instability and may not align with project constraints.

Low
Clarify async inclusion intent

Since async functions are now always included, ensure downstream relies solely on
discovery and not on removed filtering logic. Add an explicit comment to prevent
future reintroduction of accidental filtering and clarify intent.

codeflash/discovery/functions_to_optimize.py [242-244]

+# Async functions are intentionally always included. Do not add filtering here.
 filtered_modified_functions, functions_count = filter_functions(
     functions, test_cfg.tests_root, ignore_paths, project_root, module_root, previous_checkpoint_functions
 )
Suggestion importance[1-10]: 3

__

Why: Adding a clarifying comment about async inclusion is harmless and slightly improves maintainability, but it does not change behavior and offers only marginal value.

Low

Previous suggestions

Suggestions up to commit 313e957
CategorySuggestion                                                                                                                                    Impact
Possible issue
Prevent stale argv entries

Preserve the original sys.argv length when replacing it to avoid leaving stale
arguments from previous runs in certain embedded/invoked contexts. Slice-assign
exactly the new list length to prevent residual entries.

codeflash/cli_cmds/cli.py [103-105]

 args, unknown_args = parser.parse_known_args()
-sys.argv[:] = [sys.argv[0], *unknown_args]
+new_argv = [sys.argv[0], *unknown_args]
+sys.argv[:len(new_argv)] = new_argv
+del sys.argv[len(new_argv):]
 return process_and_validate_cmd_args(args)
Suggestion importance[1-10]: 5

__

Why: The change prevents potential stale argv entries in certain runtimes and is a safe refinement, but it's a minor improvement and the current code already works in typical CLI contexts.

Low
General
Clarify async inclusion in logs

Since async functions are now always included, explicitly communicating this in logs
will aid users. Add an informational entry indicating async inclusion instead of
silently removing the prior counter.

codeflash/discovery/functions_to_optimize.py [737-745]

 log_info = {
     "Test functions removed": (test_functions_removed_count, "yellow"),
     "Site-package functions removed": (site_packages_removed_count, "magenta"),
     "Non-importable file paths": (malformed_paths_count, "red"),
     "Functions outside module-root": (non_modules_removed_count, "cyan"),
     "Files from ignored paths": (ignore_paths_removed_count, "blue"),
     "Files from ignored submodules": (submodule_ignored_paths_count, "bright_black"),
     "Blocklisted functions removed": (blocklist_funcs_removed_count, "bright_red"),
     "Functions skipped from checkpoint": (previous_checkpoint_functions_removed_count, "green"),
+    "Async functions included by default": (0, "bright_magenta"),
 }
Suggestion importance[1-10]: 4

__

Why: The 'existing_code' matches the new log_info block and the addition is accurate; however, it only adds a cosmetic log entry with zero count, offering limited functional impact.

Low

@KRRT7 KRRT7 changed the title allow async optimizations by default CF-900 allow async optimizations by default Nov 23, 2025
@KRRT7
Copy link
Contributor Author

KRRT7 commented Nov 23, 2025

CF-900

@KRRT7 KRRT7 marked this pull request as ready for review November 23, 2025 21:04
@github-actions
Copy link

Persistent review updated to latest commit 7fd5889

@KRRT7 KRRT7 requested a review from misrasaurabh1 November 23, 2025 21:06
"Please install it using:\n"
' pip install "codeflash[asyncio]"'
"The --async flag is deprecated and will be removed in a future version. "
"Async function optimization is now enabled by default."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make it actionable. "You can remove this flag"

@KRRT7 KRRT7 merged commit 321640c into main Nov 23, 2025
23 checks passed
@KRRT7 KRRT7 deleted the make-async-default branch November 23, 2025 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants