-
-
Notifications
You must be signed in to change notification settings - Fork 495
Open
Description
Description
codegraph_get_repository_stats reports an inflated function count for repositories that contain classes with methods. The count includes duplicates because class methods are reachable via two CONTAINS paths.
Steps to Reproduce
pip install codegraphcontext==0.3.1
cgc index /path/to/go/project # Go project with 31 structs and their methodsThen via MCP:
# Per-repo stats reports inflated count:
codegraph_get_repository_stats(repo_path="/path/to/project")
# → functions: 325
# But actual unique functions in the graph:
codegraph_execute_cypher_query("MATCH (f:Function) WHERE f.path STARTS WITH '/path/to/project' RETURN count(f)")
# → 226
# The root cause — CONTAINS* traversal double-counts:
codegraph_execute_cypher_query("MATCH (r:Repository {path: '/path/to/project'})-[:CONTAINS*]->(f:Function) RETURN count(f) AS with_dupes, count(DISTINCT f) AS no_dupes")
# → with_dupes: 325, no_dupes: 226
Root Cause
Class methods are reachable via two paths in the graph:
Repository → File → Function(direct)Repository → File → Class → Function(via class)
The stats query uses count(f) on CONTAINS* traversal, which counts each method twice. The difference (325 - 226 = 99) exactly matches the number of class methods:
MATCH (c:Class)-[:CONTAINS]->(f:Function) WHERE c.path STARTS WITH '/path/to/project'
RETURN count(f)
-- → 99Fix
Change count(f) to count(DISTINCT f) in the repository stats query.
Environment
- codegraphcontext: 0.3.1
- Database backend: KùzuDB (default)
- Python: 3.12.3
- OS: Linux (Ubuntu)
- Test repo: Go project with 21 files, 31 structs, 226 unique functions
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels