Skip to content

disable concolic testing in LSP mode #450

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 27, 2025
Merged

disable concolic testing in LSP mode #450

merged 2 commits into from
Jun 27, 2025

Conversation

KRRT7
Copy link
Contributor

@KRRT7 KRRT7 commented Jun 27, 2025

PR Type

Enhancement


Description

  • Add is_LSP_enabled utility for LSP detection

  • Skip concolic test generation in LSP mode

  • Include lsp_mode flag in API requests

  • Adjust imports for console usage


Changes walkthrough 📝

Relevant files
Enhancement
aiservice.py
Add LSP flag to API optimizer payload                                       

codeflash/api/aiservice.py

  • Imported is_LSP_enabled from env_utils
  • Added lsp_mode flag to optimizer payload
  • +2/-1     
    env_utils.py
    Introduce is_LSP_enabled utility                                                 

    codeflash/code_utils/env_utils.py

  • Imported console for quiet mode detection
  • Added cached is_LSP_enabled function
  • +6/-1     
    concolic_testing.py
    Skip concolic tests under LSP mode                                             

    codeflash/verification/concolic_testing.py

  • Imported is_LSP_enabled
  • Skip concolic tests in LSP mode
  • Early return empty results when LSP enabled
  • +6/-0     

    Need help?
  • Type /help how to ... in the comments thread for any questions about PR-Agent usage.
  • Check out the documentation for more information.
  • Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

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

    Unused Import

    The import get_codeflash_api_key is added but never used in this file, which may lead to linter warnings or confusion. Consider removing it or integrating its usage if intended.

    from codeflash.code_utils.env_utils import get_codeflash_api_key, is_LSP_enabled
    LSP Mode Detection

    The function is_LSP_enabled relies on console.quiet to infer LSP mode, conflating logging verbosity with editor mode. Consider using a dedicated environment variable or CLI flag for reliable LSP detection.

    @lru_cache(maxsize=1)
    def is_LSP_enabled() -> bool:
        return console.quiet

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Use explicit env var for LSP mode

    Distinguish LSP mode from quiet mode by checking an explicit environment variable
    instead of relying on console.quiet. This prevents accidental LSP detection when the
    CLI is run in quiet mode. Cache the lookup for performance.

    codeflash/code_utils/env_utils.py [115-117]

     @lru_cache(maxsize=1)
     def is_LSP_enabled() -> bool:
    -    return console.quiet
    +    # Detect LSP mode explicitly via environment variable
    +    return os.getenv("CODEFLASH_LSP_MODE", "").lower() in ("1", "true", "yes")
    Suggestion importance[1-10]: 6

    __

    Why: The change replaces the fragile console.quiet check with an explicit CODEFLASH_LSP_MODE environment variable lookup, improving accuracy without major side effects.

    Low
    Inform when skipping tests

    Notify users at runtime when concolic test generation is skipped, not just in debug
    logs. Emit an info-level log or print to the console so that LSP users understand
    why tests are absent.

    codeflash/verification/concolic_testing.py [33-35]

     if is_LSP_enabled():
    -    logger.debug("Skipping concolic test generation in LSP mode")
    +    message = "Concolic test generation skipped in LSP mode"
    +    logger.info(message)
    +    console.print(f"[yellow]{message}[/yellow]")
         return function_to_concolic_tests, concolic_test_suite_code
    Suggestion importance[1-10]: 5

    __

    Why: Adding an info-level log and console output helps users understand why concolic tests are omitted, enhancing UX but not impacting core functionality.

    Low
    Conditionally include LSP flag

    Only include the lsp_mode flag in the payload when it’s enabled to avoid breaking
    API contracts that might not expect this field. This also reduces unnecessary data
    in standard calls.

    codeflash/api/aiservice.py [185]

    -"lsp_mode": is_LSP_enabled(),
    +if is_LSP_enabled():
    +    payload["lsp_mode"] = True
    Suggestion importance[1-10]: 5

    __

    Why: Omitting the lsp_mode field when false maintains API compatibility and reduces payload noise, though it’s a non-critical optimization.

    Low


    @lru_cache(maxsize=1)
    def is_LSP_enabled() -> bool:
    return console.quiet
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Q: Isnt it redundant as we already have it in main function in beta.py?

    Copy link
    Contributor Author

    Choose a reason for hiding this comment

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

    no, console.quiet by default is False, beta.py sets it to True & this function let's other parts of the codebase when it's been set to true.

    @@ -182,6 +182,7 @@ def optimize_python_code_line_profiler( # noqa: D417
    "python_version": platform.python_version(),
    "experiment_metadata": experiment_metadata,
    "codeflash_version": codeflash_version,
    "lsp_mode": is_LSP_enabled(),
    Copy link
    Contributor

    Choose a reason for hiding this comment

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

    Q: What changes in aiservices are we thinking to change for LSP server?
    No of candidates and tests?

    Copy link
    Contributor Author

    Choose a reason for hiding this comment

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

    currently we only limit the number of line profiler candidates to 5, the aiservice already is ready for this change

    @KRRT7 KRRT7 enabled auto-merge June 27, 2025 19:20
    @KRRT7 KRRT7 merged commit 2185af9 into main Jun 27, 2025
    16 of 17 checks passed
    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.

    2 participants