Skip to content

bug(builder): incremental rebuild drops edges when re-parsing a file #116

@carlos-alm

Description

@carlos-alm

Found during dogfooding v2.4.0

Severity: High
Command: codegraph build . (incremental)

Reproduction

# 1. Clean build
rm -f .codegraph/graph.db
codegraph build . --no-incremental
codegraph stats --json  # 906 edges

# 2. Touch one file and incremental rebuild
echo "// test" >> src/logger.js
codegraph build .
codegraph stats --json  # 860 edges (-46 edges!)

# 3. Full rebuild to confirm
codegraph build . --no-incremental
codegraph stats --json  # 906 edges (restored)

Expected behavior

Incremental rebuild touching one file should produce identical node/edge counts to a full rebuild.

Actual behavior

After touching src/logger.js (appending a comment), 46 edges are lost:

Kind Full Incremental Lost
calls 655 622 -33
imports 115 103 -12
reexports 25 24 -1
contains 111 111 0
Total 906 860 -46

The build output shows "Graph built: 579 nodes, 0 edges" in incremental mode, and the role distribution shifts.

Root cause

When a file is re-parsed incrementally, its old edges are deleted and new edges are re-inserted. However, import resolution in incremental mode may not re-resolve edges for files that import the changed file. The changed file's outgoing import/call edges are restored, but edges from OTHER files that reference the changed file may be dropped.

Suggested fix

During incremental rebuild, after re-parsing changed files, also re-resolve imports for all files that import the changed files (reverse dependency cascade).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdogfoodFound during dogfooding

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions