Skip to content

cgc index . says repo "exists but has no files" immediately after successful cgc index --force . #701

Closed

Description

@edreyer

Summary

cgc index . reports:

Repository '.' exists but has no files (likely interrupted). Re-indexing...

even when run immediately after a successful cgc index --force . against the same repository.

This makes it look like the index is not persisting correctly, or that cgc is mis-detecting the repo state on the next run.

Environment

  • CodeGraphContext: 0.3.0
  • Neo4j: Docker image neo4j:5.21
  • OS: macOS 26.3.1
  • Architecture: x86_64
  • Install method: pipx

Database config

Using the global CGC config in ~/.codegraphcontext/.env:

DEFAULT_DATABASE=neo4j
NEO4J_URI=neo4j://localhost:7687
NEO4J_USERNAME=neo4j

I also removed separate Codex MCP env overrides so the CLI and MCP are not using different DB settings.

Reproduction

From the repo root:

cgc --version
cgc index --force .
cgc index .

Actual behavior

First command succeeds:

Loaded configuration from: /Users/.../.codegraphcontext/.env
Using database: Neo4j
Force re-indexing (--force flag detected)
Initializing services and database connection...
Services initialized.
Deleting existing index for: /Users/.../modulith
✓ Deleted old index
Re-indexing: /Users/.../modulith

Successfully re-indexed: . in 74.58 seconds

Then the very next plain index says the repo has no files:

Loaded configuration from: /Users/.../.codegraphcontext/.env
Using database: Neo4j
Initializing services and database connection...
Services initialized.
Repository '.' exists but has no files (likely interrupted). Re-indexing...
Starting indexing for: /Users/.../modulith

Successfully finished indexing: . in 58.05 seconds

This happens repeatedly.

Expected behavior

After a successful cgc index --force ., a subsequent cgc index . should detect a healthy existing index and should not say the repository has no files.

Additional notes

I also observed inconsistent graph state after indexing:

  • repository stats reported 0 files / 0 functions / 0 classes / 0 modules
  • but code search could still return real hits from the repository

That may be related to the same underlying issue.

Probable root cause

This looks like a false negative in the CLI's "already indexed" check, not necessarily a failed index write.

In the installed cgc 0.3.0 source, the relevant code is in codegraphcontext/cli/cli_helpers.py:

result = session.run(
    "MATCH (r:Repository {path: $path})-[:CONTAINS]->(f:File) RETURN count(f) as file_count",
    path=str(path_obj)
)

That query only counts direct Repository -> File relationships.

However, the graph builder appears to model most files under directories, e.g.:

  • Repository -> Directory -> ... -> File

not necessarily:

  • Repository -> File

In my local Neo4j data for this repository, a direct query showed:

direct_files, nested_files
0, 156

So the repository is not empty. It has files reachable through transitive [:CONTAINS*] paths, but the CLI check only looks one hop deep and therefore concludes incorrectly
that the repo "has no files".

This matches the observed behavior exactly:

  1. cgc index --force . succeeds
  2. immediate cgc index . checks only direct Repository -> File
  3. query returns 0
  4. CLI prints Repository '.' exists but has no files (likely interrupted). Re-indexing...

Suggested fix

The file-count query in the CLI should probably use a transitive CONTAINS traversal instead of a single hop.

Current logic appears to be equivalent to:

MATCH (r:Repository {path: $path})-[:CONTAINS]->(f:File)
RETURN count(f) as file_count

Suggested replacement:

MATCH (r:Repository {path: $path})-[:CONTAINS*]->(f:File)
RETURN count(DISTINCT f) as file_count

Using DISTINCT would also avoid overcounting if there are multiple paths.

This would align the "already indexed" check with the actual graph shape created by the indexer and with other parts of the codebase that already use transitive [:CONTAINS*]
traversal for repository stats.

Activity

  1. github-actions commented on Mar 11, 2026

    @github-actions
    Contributor

    Hi! 👋 Join our CodeGraphContext Discord channel to collaborate: https://discord.gg/dR4QY32uYQ

  2. Shashankss1205 commented on Mar 11, 2026

    @Shashankss1205
    Collaborator

    Can you show me the output of cgc stats and cgc list

  3. edreyer commented on Mar 11, 2026

    @edreyer
    Author

    I got it working locally by having Codex patch my local install. It applied the change recommended in the description.

    Given I got it working now, I'm not sure that the output from your requests will be useful now. What do you think?

  4. Shashankss1205 commented on Mar 12, 2026

    @Shashankss1205
    Collaborator

    Can you please explain me what was the issue here? I wanted to know and fix it if possible...

  5. added a commit that references this issue on Apr 7, 2026
  6. added a commit that references this issue on Apr 8, 2026
  7. Shashankss1205 commented on Jul 25, 2026

    @Shashankss1205
    Collaborator

    Resolved: normalized any_repo_matches_path + DISTINCT count (cli_helpers.py, commit e288331). Closing.

  8. moved this from Backlog tasks to Done in CGC Progress Boardon Jul 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions