Repository navigation
Description
Summary
When files are moved out of the scan root, graphify detects them as deleted but fails to remove their nodes and edges from the graph. Both extract and update report "already clean — no matching nodes or edges in graph", yet the stale nodes remain.
Steps to Reproduce
1. Create a minimal corpus:
mkdir -p corpus/module-a corpus/module-bcorpus/module-a/auth.py:
def login(user, password):
return validate(user, password)
def validate(user, password):
return user == "admin"
def logout(user):
passcorpus/module-b/utils.py:
def format_date(date):
return str(date)
def parse_date(s):
return s.strip()2. Build initial graph:
cd corpus
graphify extract .
# → graph.json: 7 nodes, 6 edges (4 from module-a, 3 from module-b)3. Move module-b out of scan root:
mv module-b ../module-b-moved4. Re-run extraction:
graphify extract .5. Alternatively — same result with update:
graphify update .Expected Behavior
After steps 4 or 5 — graph updated to 4 nodes, 4 edges, only module-a nodes remain. module-b/utils.py, format_date(), parse_date() and their edges removed.
Actual Behavior
graphify extract . output:
[graphify extract] 0 code changed; 1 unchanged; 1 deleted
[graphify] 1 source file(s) deleted since last run — no matching nodes or edges in graph, already clean.
[graphify extract] wrote graph.json: 7 nodes, 6 edges ← unchanged
graphify update . output:
[graphify watch] No code-graph topology changes detected; outputs left untouched.
In both cases graph still contains 7 nodes, 6 edges including all 3 nodes from the deleted file:
module-b/utils.py | utils.py
module-b/utils.py | format_date()
module-b/utils.py | parse_date()
Root Cause Hypothesis
Likely a path normalization mismatch: the manifest stores absolute paths (e.g. D:\corpus\module-b\utils.py) while node source_file attributes store relative paths (e.g. module-b/utils.py). The pruning lookup fails to match them, reports "already clean", and skips deletion.
Impact
The only workaround is to delete both graphify-out/manifest.json and graphify-out/cache/ and rebuild from scratch. Incremental pruning is silently broken — the graph accumulates ghost nodes indefinitely with no warning to the user.
Environment
- graphify:
0.8.17 - OS: Windows 11
- Python: 3.13
- Reproduced with both
graphify extractandgraphify update
Related Issues
#777 confirms the root cause hypothesis: manifest.json stores absolute paths while graph.json nodes store relative paths (correctly relativized via watch._relativize_source_files). This mismatch is likely why the pruning lookup fails to match deleted files to their nodes, producing the "already clean" false negative.
Activity
[-]Bug: Nodes from deleted/moved files persist in graph — "already clean" false negative[/-][+]Bug: Nodes and edges from deleted/moved files persist in graph — "already clean" false negative[/+]sub4biz commentedon May 26, 2026
Root cause analysis (v0.8.19)
The pruning failure has two independent layers, both in
watch.py::_rebuild_code.Layer 1 — Call order:
_relativize_source_filesruns after evictionThe existing graph is loaded at line 408, and node eviction happens at lines 418–422:
But
_relativize_source_files— which converts absolutesource_filevalues to relative — is only called at line 438, after the eviction list is already built:So if
graph.jsoncontains absolute paths insource_file, they are never normalized before the comparison, and no nodes are evicted.Fix: call
_relativize_source_files(existing, project_root)on the loaded graph before line 418.Layer 2 — Windows path separator mismatch
Even with the call order fixed, the comparison still fails on Windows.
deleted_pathsis built usingstr()on aPathobject (line 379):Same for
evict_sourcesat line 415:Meanwhile
_relativize_source_filesalso usesstr()(line 141):But
build.py::_norm_source_filenormalizes via.as_posix(), sograph.jsonstores forward-slash paths (module-b/utils.py). The comparison between"module-b\utils.py"and"module-b/utils.py"always fails → nodes are never evicted → silent ghost accumulation.The same pattern appears in
extract.py:8640:Fix: replace
str(...)with.as_posix()atwatch.py:141,watch.py:379,watch.py:415, andextract.py:8640to match the forward-slash convention already established bybuild.py.Relation to #777
Issue #777 addresses a related but distinct layer: absolute paths being persisted to
manifest.json,.graphify_root, andcache/ast/*.jsonat write time. The fixes above are about the comparison logic at read/eviction time and would be needed even after #777 is fully resolved, because the separator mismatch is independent of whether paths are stored as absolute or relative.improve #1007 fix: use _norm_source_file with resolve() for symlink s…
sub4biz commentedon May 26, 2026
graphify updatestill broken after eef623a (v8 branch)Tested with the v8 branch installed directly from git (
uv tool install "graphifyy[gemini] @ git+https://github.com/safishamsi/graphify.git@v8").Reproduction
Why
The fix in
build_merge(build.py) correctly handles the absolute→relative path mismatch for thegraphify extractcode path. Butgraphify updategoes through_rebuild_codeinwatch.py, which has its own eviction logic that was not touched:Two issues remain in
_rebuild_code:Call order —
_relativize_source_files(existing, project_root)needs to be called on the loaded graph before line 418, not onresultafter the eviction list is already built.Separator mismatch —
str(cand.relative_to(project_root))produces backslashes on Windows (module-b\utils.py), whilegraph.jsonstores forward slashes (module-b/utils.py) via_norm_source_file. Replacingstr(...)with.as_posix()at lines 379 and 415 — or routing through_norm_source_filethe same way the newbuild_mergefix does — would resolve this.safishamsi commentedon May 26, 2026
fix stale nodes persisting after file deletion when manifest uses abs…
fix graphify update ghost nodes: as_posix() and relativize existing g…
safishamsi commentedon May 26, 2026
Good catch — both layers are now fixed on v8 (3f8efae).
watch.pyfixes:_relativize_source_files(existing, project_root)now called on the loaded graph before the eviction list is built, so absolutesource_filevalues in an existinggraph.jsonare normalized before the comparisondeleted_pathsandevict_sourcesnow use.as_posix()instead ofstr()— consistent forward slashes on Windows_relativize_source_filesitself now uses.as_posix()internally (line 141)extract.pyfix:source_filerelativization at line 8640 also switched to.as_posix()All 1355 tests pass. Will ship in the next PyPI release.
test: add _rebuild_code eviction test for deleted files (Graphify-Lab…
sub4biz commentedon May 26, 2026
by the way — this was my first ever pull request 🎉 a bit nerve-wracking but worth it!
sub4biz commentedon May 26, 2026
Thanks for staying on this — quick verification of v0.8.20 to close the loop. The
_relativize_source_filescall-order change and.as_posix()ondeleted_paths/evict_sourcesare exactly right and verified working for the watcher path.Timeline:
graphify updateleaves stale nodes after file deletionbuild_merge→ coversgraphify extractpath ✅graphify updatestill broken after eef623a_relativize_source_filescall order +.as_posix()ondeleted_paths/evict_sources→ watcher path ✅changed_paths is Nonecase was not included in that release)One case is still open: plain
graphify update(changed_paths is None).Reproduction on v0.8.20:
Root cause: In
_rebuild_code, whenchanged_paths is None,deleted_pathsis never populated — soevict_sourcesstays empty and the guard short-circuits, preserving all non-new-id nodes unconditionally:The fix: for the
elsebranch, walk existing graph nodes, compare theirsource_fileagainst current disk state (normalised via_norm_source_file), and add any whose file is gone to bothevict_sourcesanddeleted_paths(so the shrink-guard also passes without--force).Fix + test in #1036 (47 passed on Windows).
Note: #1036 targets v0.8.19 and may need a rebase onto current
v8before merge.fix(watch): evict stale nodes in full re-extraction path when changed…
Merge origin/v8 (18 commits) into falkordb-backend
fix(build): relativize source_file across a symlinked root (#1571 fol…
fix stale nodes persisting after file deletion when manifest uses abs…
improve Graphify-Labs#1007 fix: use _norm_source_file with resolve() …
fix graphify update ghost nodes: as_posix() and relativize existing g…
fix(watch): evict stale nodes in full re-extraction path when changed…
fix(build): relativize source_file across a symlinked root (Graphify-…