Skip to content

Conversation

@SWAROOP323
Copy link
Contributor

@SWAROOP323 SWAROOP323 commented Dec 21, 2025

This PR adds a benchmark suite to evaluate the impact of Python 3.13's
experimental JIT compiler on Cortex operations.

Benchmarks included:

  • CLI startup time
  • Command parsing overhead
  • Cache-like dictionary workloads
  • Streaming / generator iteration

Benchmarks are executed with JIT enabled and disabled to compare results.

Closes cortexlinux/cortex-pro#3.

Summary by CodeRabbit

  • New Features

    • Package suggestions now surface when installs or lookups fail, offering alternatives and quick install prompts.
    • New notify command to manage desktop notifications (config, enable/disable, DND, send).
  • Documentation

    • Added benchmark documentation and a suite + runner to compare CLI startup, command parsing, cache-like ops, and streaming with/without the JIT.
  • Tests

    • Added tests covering package suggestion behavior.
  • Chores

    • Benchmarks excluded from linting.

✏️ Tip: You can customize this high-level summary in your review settings.

Copilot AI review requested due to automatic review settings December 21, 2025 14:41
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 21, 2025

Warning

Rate limit exceeded

@Anshgrover23 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 15 minutes and 23 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 91fa2be and fd09c59.

📒 Files selected for processing (1)
  • cortex/cli.py
📝 Walkthrough

Walkthrough

Adds a JIT benchmarking suite (README, runner, four benchmarks), a package suggestion utility with tests, and CLI changes: pre-install/package-not-found suggestion flow and a new notify subcommand.

Changes

Cohort / File(s) Summary
JIT Benchmarking Suite
benchmarks/README.md, benchmarks/run_benchmarks.py, benchmarks/benchmark_cli_startup.py, benchmarks/benchmark_command_parsing.py, benchmarks/benchmark_cache_ops.py, benchmarks/benchmark_streaming.py
New README, runner that toggles PYTHON_JIT and executes benchmark scripts; four benchmark scripts expose benchmark() and/or print durations (CLI startup, command parsing, cache ops, streaming).
Package Suggestion Utility
cortex/suggestions/package_suggester.py
New module with KNOWN_PACKAGES, suggest_alternatives(query, limit) using RapidFuzz, and show_suggestions(packages) for console output.
CLI Feature & Integration
cortex/cli.py
Adds pre-install and package-not-found suggestion flows that call suggestion helpers, display suggestions, prompt user and may recurse to install with an alternative; adds CortexCLI.notify(self, args) and updates help text.
Tests
test/test_package_suggester.py
Unit tests for suggest_alternatives() covering fuzzy suggestion, exact match, and return type.
Tooling config
pyproject.toml
Adds extend-exclude = ["benchmarks"] under [tool.ruff] to exclude benchmarks from Ruff linting.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CLI as CortexCLI
  participant Suggester as PackageSuggester
  participant Notif as NotificationHandler

  rect rgb(240,248,255)
  Note over CLI,Suggester: Pre-install / package-not-found suggestion flow
  User->>CLI: install "apache-server"
  CLI->>Suggester: suggest_alternatives("apache-server")
  Suggester-->>CLI: [apache2, ...]
  CLI->>User: show_suggestions(...) + "Install apache2?"
  alt user accepts
    User-->>CLI: "y"
    CLI->>CLI: install("apache2")
  else user declines
    User-->>CLI: "n"
    CLI-->>User: return error/abort
  end
  end

  rect rgb(245,255,240)
  Note over CLI,Notif: notify subcommand flow
  User->>CLI: notify send --title ... --body ...
  CLI->>Notif: validate & dispatch notification
  Notif-->>CLI: success / failure
  CLI-->>User: print feedback
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • mikejmorgan-ai

Poem

🐇 I hopped through code to time each run,

JIT warmed up and benchmarks begun,
I nudged suggestions when packages strayed,
I rang a tiny notify and gently displayed,
A carrot cheer for tests well spun 🥕

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Most changes (benchmarks, run_benchmarks.py, README, pyproject.toml) are directly aligned with issue cortexlinux/cortex-pro#3 requirements. However, additions to cortex/cli.py (notify method, package suggestion flow) and cortex/suggestions/package_suggester.py appear unrelated to the JIT benchmarking objectives. Remove or separate changes to cortex/cli.py and cortex/suggestions/package_suggester.py as they are unrelated to JIT benchmarking. Consider submitting these as a separate PR.
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Add JIT Compiler Benchmarking for Cortex Operations' clearly and directly summarizes the main focus of the PR: adding a comprehensive benchmark suite to evaluate Python 3.13's JIT compiler impact on Cortex operations.
Description check ✅ Passed The PR description provides a clear summary of changes and explicitly references the closed issue (#275), matching the required template structure with issue closure and summary sections.
Linked Issues check ✅ Passed The PR comprehensively addresses issue cortexlinux/cortex-pro#3 requirements: it includes benchmark scripts for CLI startup, command parsing, cache operations, and streaming, with infrastructure to run benchmarks with JIT enabled/disabled for comparison.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 14

🧹 Nitpick comments (8)
benchmarks/run_benchmarks.py (3)

16-20: Preserve existing PYTHONPATH.

Line 20 overwrites PYTHONPATH entirely. If a user has existing paths in their PYTHONPATH, they will be lost, potentially causing import errors.

🔎 Proposed fix
 def run(jit_enabled):
     env = os.environ.copy()
     env["PYTHON_JIT"] = "1" if jit_enabled else "0"

     # Add project root to PYTHONPATH
-    env["PYTHONPATH"] = str(PROJECT_ROOT)
+    existing_pythonpath = env.get("PYTHONPATH", "")
+    env["PYTHONPATH"] = f"{PROJECT_ROOT}{os.pathsep}{existing_pythonpath}" if existing_pythonpath else str(PROJECT_ROOT)

27-27: Add error handling for subprocess failures.

If any benchmark script fails, the error is silently ignored and execution continues. Consider checking the return code to surface failures.

🔎 Proposed fix
     for bench in benchmarks:
-        subprocess.run([sys.executable, bench], env=env)
+        result = subprocess.run([sys.executable, bench], env=env)
+        if result.returncode != 0:
+            print(f"Warning: {bench} failed with return code {result.returncode}")

Or use check=True to raise an exception on failure:

     for bench in benchmarks:
-        subprocess.run([sys.executable, bench], env=env)
+        subprocess.run([sys.executable, bench], env=env, check=True)

1-31: Consider verifying Python 3.13+ is available.

The benchmark suite targets Python 3.13's experimental JIT compiler. Consider adding a version check to ensure users are running the appropriate Python version, or at least document this requirement.

🔎 Proposed addition

Add a version check at the module level:

if __name__ == "__main__":
    if sys.version_info < (3, 13):
        print("Warning: Python 3.13+ is required for JIT benchmarking.")
        print(f"Current version: {sys.version}")
        # Continue anyway or exit based on preference
    
    run(False)
    run(True)
test/test_package_suggester.py (2)

4-7: Add docstring to test function.

As per coding guidelines, docstrings are required for all public APIs. While test functions aren't strictly "public APIs," adding brief docstrings improves test documentation and clarifies intent.

🔎 Suggested improvement
 def test_suggests_apache_for_apache_server():
+    """Test that 'apache-server' query suggests 'apache2' package."""
     results = suggest_alternatives("apache-server")
     names = [pkg["name"] for pkg in results]
     assert "apache2" in names

10-12: Add docstring to test function.

As per coding guidelines, docstrings are required for all public APIs. Adding a brief docstring clarifies the test's purpose.

🔎 Suggested improvement
 def test_suggest_returns_list():
+    """Test that suggest_alternatives returns a list for any input."""
     results = suggest_alternatives("randompkg")
     assert isinstance(results, list)
cortex/suggestions/package_suggester.py (1)

6-28: Consider expanding KNOWN_PACKAGES or using an external data source.

The package database contains only 3 entries (apache2, nginx, docker), which severely limits the utility's usefulness. Consider:

  • Adding more common packages
  • Loading from an external file or API
  • Documenting that this is a temporary/demo implementation (comment on line 5 mentions this but it's easy to miss)
cortex/cli.py (2)

312-316: Move imports to module level.

Importing inside functions (lines 313-316 and again at 373-376) adds overhead on every call. Move these imports to the module level with the other imports.

🔎 Proposed fix

At the top of the file with other imports (around line 24):

 from cortex.validators import (
     validate_api_key,
     validate_install_request,
 )
+from cortex.suggestions.package_suggester import (
+    show_suggestions,
+    suggest_alternatives,
+)

Then remove the local imports at lines 313-316 and 373-376.


132-133: Consider adding a public save method to NotificationManager.

Lines 132, 138, and 157 call the private method mgr._save_config(). The comment on line 130-131 acknowledges this but suggests it's acceptable "for a simple fix."

However, calling private methods breaks encapsulation and could lead to maintenance issues if NotificationManager's internal implementation changes. Consider adding a public save() method to NotificationManager.

💡 Recommended approach

In NotificationManager:

def save(self) -> None:
    """Save current configuration to disk."""
    self._save_config()

Then update the calls in cli.py:

-        mgr._save_config()
+        mgr.save()

Also applies to: 138-138, 157-157

📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between f6bfa49 and ce15403.

📒 Files selected for processing (9)
  • benchmarks/README.md (1 hunks)
  • benchmarks/benchmark_cache_ops.py (1 hunks)
  • benchmarks/benchmark_cli_startup.py (1 hunks)
  • benchmarks/benchmark_command_parsing.py (1 hunks)
  • benchmarks/benchmark_streaming.py (1 hunks)
  • benchmarks/run_benchmarks.py (1 hunks)
  • cortex/cli.py (2 hunks)
  • cortex/suggestions/package_suggester.py (1 hunks)
  • test/test_package_suggester.py (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

**/*.py: Follow PEP 8 style guide
Type hints required in Python code
Docstrings required for all public APIs

Files:

  • benchmarks/benchmark_cache_ops.py
  • benchmarks/run_benchmarks.py
  • benchmarks/benchmark_streaming.py
  • cortex/suggestions/package_suggester.py
  • benchmarks/benchmark_cli_startup.py
  • cortex/cli.py
  • test/test_package_suggester.py
  • benchmarks/benchmark_command_parsing.py
🧬 Code graph analysis (6)
benchmarks/benchmark_streaming.py (3)
benchmarks/benchmark_cache_ops.py (1)
  • benchmark (3-11)
benchmarks/benchmark_cli_startup.py (1)
  • benchmark (4-11)
benchmarks/benchmark_command_parsing.py (1)
  • benchmark (5-13)
cortex/suggestions/package_suggester.py (2)
src/intent/llm_agent.py (1)
  • process (45-88)
cortex/branding.py (1)
  • cx_print (49-69)
benchmarks/benchmark_cli_startup.py (4)
benchmarks/benchmark_cache_ops.py (1)
  • benchmark (3-11)
benchmarks/benchmark_command_parsing.py (1)
  • benchmark (5-13)
benchmarks/benchmark_streaming.py (1)
  • benchmark (7-11)
benchmarks/run_benchmarks.py (1)
  • run (15-27)
cortex/cli.py (2)
cortex/suggestions/package_suggester.py (2)
  • show_suggestions (43-52)
  • suggest_alternatives (31-40)
cortex/first_run_wizard.py (1)
  • _print_error (746-748)
test/test_package_suggester.py (1)
cortex/suggestions/package_suggester.py (1)
  • suggest_alternatives (31-40)
benchmarks/benchmark_command_parsing.py (1)
cortex/cli.py (1)
  • CortexCLI (33-787)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Agent
🔇 Additional comments (2)
cortex/cli.py (2)

105-171: LGTM with minor suggestions!

The notify method implementation is well-structured with:

  • Proper input validation (line 108-110 handles missing subcommand)
  • Time format validation for DND (lines 148-153)
  • Type hints and docstring
  • Clear user feedback with appropriate status indicators

The addressed CodeRabbit feedback improvements are visible and improve robustness.

Note: See separate comments about using the private _save_config() method and consider moving it to a public API.


812-812: LGTM!

The help table entry for the notify command is correctly added.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds JIT compiler benchmarking capabilities for Python 3.13, along with a new package suggestion feature for the Cortex CLI. However, the PR description focuses on JIT benchmarking while a significant portion of the changes implement package suggestions, which appears to be outside the stated scope.

Key changes:

  • Added benchmark suite with 4 benchmarks for CLI startup, command parsing, cache operations, and streaming
  • Implemented package suggester using fuzzy matching to recommend alternatives when packages aren't found
  • Integrated package suggestions into the CLI install flow with user prompts

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
benchmarks/run_benchmarks.py Main benchmark runner that attempts to toggle JIT via PYTHON_JIT environment variable
benchmarks/benchmark_cli_startup.py Benchmarks CLI startup time across multiple runs
benchmarks/benchmark_command_parsing.py Benchmarks argparse command parsing overhead
benchmarks/benchmark_cache_ops.py Benchmarks dictionary operations simulating cache workloads
benchmarks/benchmark_streaming.py Benchmarks generator iteration performance
benchmarks/README.md Documentation for the benchmark suite with usage instructions and findings
cortex/suggestions/package_suggester.py New module implementing fuzzy package matching and suggestion display
test/test_package_suggester.py Unit tests for the package suggester functionality
cortex/cli.py Integrates package suggestions into the install command at two points in the flow
Comments suppressed due to low confidence (1)

benchmarks/benchmark_command_parsing.py:6

  • Variable cli is not used.
    cli = CortexCLI(verbose=False)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@SWAROOP323
Copy link
Contributor Author

can you assign this to me

Copy link
Collaborator

@Anshgrover23 Anshgrover23 left a comment

Choose a reason for hiding this comment

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

@SWAROOP323 CI Checks are failing, Also can u raise a new PR with the CLA Information following #401 PR as a reference.

@Anshgrover23
Copy link
Collaborator

@SWAROOP323 Update your branch.

@github-actions
Copy link

github-actions bot commented Jan 1, 2026

CLA Verification Passed

All contributors have signed the CLA.

Contributor Signed As
@SWAROOP323 @SWAROOP323
@SWAROOP323 @SWAROOP323
@Anshgrover23 @Anshgrover23

@SWAROOP323
Copy link
Contributor Author

@SWAROOP323 Update your branch.

@Anshgrover23 CI failures have been resolved and the branch has been updated.
Could you please review now?

Copy link
Collaborator

@Anshgrover23 Anshgrover23 left a comment

Choose a reason for hiding this comment

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

@SWAROOP323 Follow Contributing.md guideliness i.e add a demonstration video.

Copy link
Collaborator

@Anshgrover23 Anshgrover23 left a comment

Choose a reason for hiding this comment

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

@SWAROOP323 Please follow the updated contribution guidelines. We’ve added new rules around AI usage in CONTRIBUTING.md. 2e68b29
Kindly Update in your all PRs.

@Anshgrover23 Anshgrover23 marked this pull request as draft January 7, 2026 19:59
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 7, 2026

@SWAROOP323 SWAROOP323 closed this Jan 10, 2026
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