Skip to content

Conversation

@appyjuss
Copy link

Implement a new 'graph-code doctor' CLI command that verifies all critical dependencies and configurations are properly set up. The command checks:

  • Docker daemon is running
  • Memgraph database connection and responsiveness
  • Required API keys (GEMINI, OPENAI, ORCHESTRATOR, CYPHER)
  • External tools (ripgrep for code search)

Output displays clear pass/fail status with green checkmarks for passing checks and red x's for failures. The command exits with code 1 if any checks fail, enabling integration with CI/CD pipelines.

Changes:

  • codebase_rag/tools/health_checker.py: New HealthChecker class
  • codebase_rag/cli.py: New doctor command with Rich formatting
  • codebase_rag/cli_help.py: Added doctor command documentation

Implement a new 'graph-code doctor' CLI command that verifies all critical
dependencies and configurations are properly set up. The command checks:

- Docker daemon is running
- Memgraph database connection and responsiveness
- Required API keys (GEMINI, OPENAI, ORCHESTRATOR, CYPHER)
- External tools (ripgrep for code search)

Output displays clear pass/fail status with green checkmarks for passing
checks and red x's for failures. The command exits with code 1 if any
checks fail, enabling integration with CI/CD pipelines.

Changes:
- codebase_rag/tools/health_checker.py: New HealthChecker class
- codebase_rag/cli.py: New doctor command with Rich formatting
- codebase_rag/cli_help.py: Added doctor command documentation
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @appyjuss, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new doctor command to the CLI, designed to provide users with an immediate and clear assessment of their environment's readiness. By systematically verifying critical dependencies and configurations, this feature aims to significantly improve the developer experience by quickly identifying and diagnosing common setup issues, thereby streamlining the onboarding process and reducing debugging time.

Highlights

  • New 'doctor' CLI command: Introduces a new graph-code doctor command to perform comprehensive system health checks for critical dependencies and configurations.
  • Comprehensive Dependency Verification: The new command verifies essential components including the Docker daemon's running status, Memgraph database connectivity and responsiveness, the presence of required API keys (GEMINI, OPENAI, ORCHESTRATOR, CYPHER), and the installation of external tools like ripgrep and cmake.
  • Rich Output Formatting: Leverages the rich library to present check results with clear pass/fail statuses, using green checkmarks for success and red 'x's for failures. Detailed error messages are provided for failed checks, enhancing readability and diagnostic clarity.
  • CI/CD Integration Readiness: The doctor command is designed to exit with a non-zero status code (1) if any health checks fail, making it suitable for integration into automated CI/CD pipelines to ensure environment readiness before deployment or further testing.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a very useful doctor command for checking the health of the application's dependencies and configuration. The implementation is clean, with good use of the rich library for user-friendly output. My review focuses on enhancing the HealthChecker by making the failure messages more specific and actionable for the user. I've suggested explicitly handling command timeouts and providing guidance on how to fix missing API keys, aligning with best practices for robust error handling with external libraries. These changes will improve the diagnostic value of the doctor command.

@greptile-apps
Copy link

greptile-apps bot commented Jan 11, 2026

Greptile Overview

Greptile Summary

This PR implements a new graph-code doctor CLI command that performs health checks on critical dependencies and configurations. The feature adds a HealthChecker class that verifies Docker daemon status, Memgraph database connectivity, API key configuration, and external tool availability (ripgrep, cmake).

What Changed:

  • New codebase_rag/tools/health_checker.py with HealthChecker class and HealthCheckResult dataclass
  • New doctor command in codebase_rag/cli.py with Rich-formatted output
  • Added DOCTOR command enum and help text to codebase_rag/cli_help.py

Critical Issues Found:

This PR has severe coding standards violations that must be addressed before merging:

  1. Missing from __future__ import annotations in health_checker.py
  2. Forbidden # type: ignore comment used on mgclient import
  3. Docstrings present in 3 locations (violates "No Comments or Docstrings" policy)
  4. Wrong data structure: HealthCheckResult uses dataclass but should be Pydantic BaseModel (it's a result schema, not a behavioral class)
  5. Massive hardcoded strings violation: health_checker.py contains ~50+ hardcoded string literals that violate the "Almost No Strings in Code Files" rule - all must move to constants.py
  6. Bizarre no-op logic: Line 112 has env_name.replace("_API_KEY", "_API_KEY") which does nothing
  7. Unexplained cmake check: The code checks for cmake availability but this isn't mentioned in PR description or requirements - may cause false failures

The functionality itself appears sound, but the implementation significantly deviates from the project's strict coding standards around string constants, type annotations, and data structure selection.

Confidence Score: 1/5

  • This PR has critical coding standards violations and logic issues that must be resolved before merging
  • Score of 1 reflects multiple critical issues: forbidden type:ignore usage, missing required imports, wrong data structure choice (dataclass vs BaseModel), massive hardcoded strings violations (~50+ strings that must move to constants.py), bizarre no-op logic that appears to be a bug, and unexplained cmake dependency. While the core functionality appears to work, the implementation severely violates the project's strict coding standards which are enforced by custom instructions
  • codebase_rag/tools/health_checker.py requires major refactoring to move all hardcoded strings to constants.py, fix the dataclass→BaseModel change, remove type:ignore and docstrings, and fix the no-op replace logic

Important Files Changed

File Analysis

Filename Score Overview
codebase_rag/tools/health_checker.py 1/5 New HealthChecker class with critical coding standards violations: missing future annotations import, uses forbidden type:ignore, has docstrings, uses dataclass instead of Pydantic BaseModel for result schema, contains massive amounts of hardcoded strings that must move to constants.py, has bizarre no-op logic in check_api_key, and checks for cmake without justification
codebase_rag/cli.py 3/5 New doctor command added with hardcoded strings (checkmarks, titles, messages) that should be moved to constants.py, and has a docstring that should be removed per coding standards
codebase_rag/cli_help.py 5/5 Added DOCTOR command to StrEnum and help text constant - properly follows coding standards, no issues found

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI as cli.py::doctor()
    participant Checker as HealthChecker
    participant Docker as Docker Daemon
    participant Memgraph as Memgraph DB
    participant OS as Operating System
    participant Settings as settings (config)

    User->>CLI: graph-code doctor
    CLI->>Checker: HealthChecker()
    CLI->>Checker: run_all_checks()
    
    Checker->>Checker: check_docker()
    Checker->>Docker: subprocess.run(docker info)
    alt Docker Running
        Docker-->>Checker: returncode=0, version
        Checker->>Checker: HealthCheckResult(passed=True)
    else Docker Not Running
        Docker-->>Checker: returncode!=0
        Checker->>Checker: HealthCheckResult(passed=False)
    end
    
    Checker->>Checker: check_memgraph_connection()
    Checker->>Settings: Get MEMGRAPH_HOST, MEMGRAPH_PORT
    Settings-->>Checker: host, port
    Checker->>Memgraph: mgclient.connect(host, port)
    alt Connection Success
        Memgraph-->>Checker: connection
        Checker->>Memgraph: execute(RETURN 1)
        Memgraph-->>Checker: query result
        Checker->>Checker: HealthCheckResult(passed=True)
    else Connection Failed
        Memgraph-->>Checker: MemgraphError
        Checker->>Checker: HealthCheckResult(passed=False)
    end
    
    Checker->>Checker: check_api_keys()
    loop For each API key (GEMINI, OPENAI, ORCHESTRATOR, CYPHER)
        Checker->>OS: os.getenv(env_name)
        OS-->>Checker: value or None
        Checker->>Settings: getattr(settings, env_name)
        Settings-->>Checker: value or None
        Checker->>Checker: HealthCheckResult(passed)
    end
    
    Checker->>Checker: check_external_tool(ripgrep)
    Checker->>OS: subprocess.run(which rg)
    OS-->>Checker: returncode, path
    Checker->>Checker: HealthCheckResult(passed)
    
    Checker->>Checker: check_external_tool(cmake)
    Checker->>OS: subprocess.run(which cmake)
    OS-->>Checker: returncode, path
    Checker->>Checker: HealthCheckResult(passed)
    
    Checker-->>CLI: List of HealthCheckResults
    CLI->>Checker: get_summary()
    Checker-->>CLI: (passed_count, total_count)
    
    CLI->>CLI: Build Rich Table with results
    CLI->>User: Display Panel with checkmarks
    CLI->>User: Display summary text
    
    alt Any check failed
        CLI->>User: Display failed checks details
        CLI->>User: Exit with code 1
    else All passed
        CLI->>User: Exit with code 0
    end
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

12 files reviewed, 12 comments

Edit Code Review Agent Settings | Greptile

- Move HealthCheckResult to schemas.py as BaseModel
- Add from __future__ import annotations
- Move ~50 hardcoded strings to constants.py
- Add TimeoutExpired exception handling
- Add error messages to API key checks
- Remove docstrings (self-documenting code)
- Keep cmake check (required for pymgclient, documented in README)
@vitali87
Copy link
Owner

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a new doctor command to perform health checks on critical dependencies and configurations. The implementation is well-structured, with a dedicated HealthChecker class and clear output formatting using rich. My review focuses on improving error handling, consistency in subprocess calls, and standardizing import practices. I've provided specific code suggestions for these improvements, including a modification to clarify the rationale for broad exception catching in resource cleanup.


import typer
from loguru import logger
from rich.panel import Panel
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For consistency and better code organization, all imports should be at the top of the file. Table should be imported here along with Panel. The local import inside the doctor function (line 384) should then be removed.

Suggested change
from rich.panel import Panel
from rich.panel import Panel
from rich.table import Table

Comment on lines +100 to +109
if cursor is not None:
try:
cursor.close()
except Exception:
pass
if conn is not None:
try:
conn.close()
except Exception:
pass
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Silently swallowing exceptions in a finally block can hide underlying issues with resource cleanup, such as problems with the connection or cursor. It's better to log these exceptions at a warning level to aid in debugging potential resource leaks or other unexpected behavior. This change requires importing logger from loguru at the top of the file.

Suggested change
if cursor is not None:
try:
cursor.close()
except Exception:
pass
if conn is not None:
try:
conn.close()
except Exception:
pass
if cursor is not None:
try:
cursor.close()
except Exception as e: # Catching broad Exception as Memgraph's close() method can raise various, unpredictable exceptions from an external library.
logger.warning(f"Failed to close Memgraph cursor: {e}")
if conn is not None:
try:
conn.close()
except Exception as e: # Catching broad Exception as Memgraph's close() method can raise various, unpredictable exceptions from an external library.
logger.warning(f"Failed to close Memgraph connection: {e}")
References
  1. If catching a broad Exception is a pragmatic choice due to a wide and unpredictable variety of exceptions from external libraries, add a comment explaining the rationale to improve code maintainability.

Comment on lines +146 to +153
result = subprocess.run(
check_cmd,
capture_output=True,
timeout=4,
check=False,
)
if result.returncode == 0:
path = result.stdout.decode().strip().splitlines()[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For consistency with the check_docker method and to simplify the code, it's better to use text=True in the subprocess.run call. This will automatically decode the output streams as text, removing the need for result.stdout.decode().

            result = subprocess.run(
                check_cmd,
                capture_output=True,
                text=True,
                timeout=4,
                check=False,
            )
            if result.returncode == 0:
                path = result.stdout.strip().splitlines()[0]

@vitali87
Copy link
Owner

@appyjuss please address the bots comments. They are minor but valid points.
Thanks for this PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants