tirth8205/code-review-graph · error · SystemExit

No graph found at {db_path}. Run `code-review-graph build` f

Error message

No graph found at {db_path}. Run `code-review-graph build` first.

What it means

The CLI commands that operate on an existing knowledge graph require a prebuilt graph database. Before running, main() resolves the repo root and checks that the graph DB file exists; if it does not, it prints this message and exits with code 1. The graph must be created with `code-review-graph build` before query/serve commands can work.

Source

Thrown at code_review_graph/cli.py:1395

        return

    if args.command in _GRAPH_TOOL_COMMANDS:
        from .incremental import find_project_root, get_db_path

        if args.repo:
            # For an explicit --repo the walk must treat .code-review-graph
            # as a project boundary too: the plain .git/.svn walk resolves a
            # registered monorepo subdirectory to the monorepo root and the
            # graph built at the --repo path is never found (#697). Nearest
            # marker wins, so pointing inside a repo still works.
            repo_root = _find_explicit_repo_root(Path(args.repo).expanduser())
            if repo_root is None:
                print(
                    f"--repo does not look like a project root (no .git, .svn, "
                    f"or .code-review-graph found at or above): {args.repo}",
                    file=sys.stderr,
                )
                raise SystemExit(1)
        else:
            repo_root = find_project_root()
        db_path = get_db_path(repo_root)
        if not db_path.exists():
            print(
                f"No graph found at {db_path}. Run `code-review-graph build` first.",
                file=sys.stderr,
            )
            raise SystemExit(1)
        _run_graph_tool_command(args, repo_root)
        return

    embedding_refresh_kwargs = _embedding_refresh_kwargs(args, ap)

    if args.command in ("serve", "mcp"):
        from .main import main as serve_main

        auto_watch = getattr(args, "auto_watch", False)

View on GitHub (pinned to b58668751a)

Solutions

  1. Run `code-review-graph build` in the repository root to generate the graph DB
  2. Verify you are in the correct repository root (or pass --repo /path/to/project) so get_db_path() resolves to where the graph was built
  3. If the build directory was deleted (e.g. by clean/gitignore rules), rebuild it and consider persisting it in CI caches

Example fix

# before
$ code-review-graph query "login flow"
No graph found at /repo/.code-review-graph/graph.db. Run `code-review-graph build` first.

# after
$ code-review-graph build
$ code-review-graph query "login flow"
Defensive patterns

Strategy: validation

Validate before calling

import subprocess, sys
from pathlib import Path

def graph_exists(repo: Path) -> bool:
    # mirror get_db_path: DB lives under .code-review-graph in the project root
    return any((repo / ".code-review-graph").rglob("*.db")) or (repo / ".code-review-graph").exists()

if not graph_exists(Path.cwd()):
    subprocess.run([sys.executable, "-m", "code_review_graph", "build"], check=True)

Prevention

When it happens

Trigger: Running any graph-dependent subcommand (query, serve, mcp, review tools, etc.) in a repository where `code-review-graph build` has never been executed, or where the DB path resolution points somewhere without the .code-review-graph database. Also triggered when --repo points at a directory that is not the intended project root.

Common situations: Fresh clone of a repo (graph DB is not committed), CI pipelines that assume the graph exists, running the command from a subdirectory so find_project_root() resolves to an unexpected parent, or specifying a wrong --repo path.

Related errors


AI-assisted analysis of tirth8205/code-review-graph@b58668751a (2026-08-28). Data as JSON: /api/errors/f72658de76c93447. Report an issue: GitHub.