--update: build_merge(prune_sources=...) silently no-ops when root is not passed (absolute vs relative source_file mismatch, Windows)
Version: graphifyy 0.8.33 · Windows 10 · Python 3.12
Summary
In the incremental-update flow, build_merge(prune_sources=...) silently no-ops when root is not passed: detect_incremental() returns absolute paths in deleted_files, but graph nodes store relative posix source_file values, and the normalization added for #1007 only relativizes when root is provided.
Repro
- Build a full graph of a repo (nodes get relative
source_file, e.g.src/database/customers.py). - Delete some source files, run the documented incremental flow:
result = detect_incremental(Path('.')) # deleted_files = ['C:\\Users\\...\\src\\database\\customers.py', ...]
G = build_merge([new_extraction],
graph_path='graphify-out/graph.json',
prune_sources=deleted) # root NOT passed (matches the skill's references/update.md recipe)
- Output:
[graphify] 7 source file(s) deleted since last run — no matching nodes or edges in graph, already clean.
…but the graph still contained 42 nodes from the 7 deleted files (verified by filtering nodes on source_file).
Root cause
build.py::build_merge (~L413):
_root_str = str(Path(root).resolve()) if root is not None else None
...
norm = _norm_source_file(p, _root_str)
and _norm_source_file (~L68) only does relative_to(root) when root is truthy — with root=None it just flips backslashes, so C:/Users/.../src/database/customers.py never matches the stored src/database/customers.py. The #1007 comment says this mismatch is handled, but only for callers who pass root, and the documented update recipe (skill references/update.md) doesn't.
The misleading part is the "already clean" message — the caller has no signal that pruning failed.
Suggested fix (any of)
- In
build_merge, whenroot is None, fall back toPath.cwd().resolve()for prune normalization (prune is called from the repo root in the documented flow), and/or - Match by path suffix as a last resort (
p_rel.endswith('/' + stored)), and/or - Have
detect_incrementalemitdeleted_filesin the same normalized relative form the graph stores, so the two sides can't drift, and - Update the skill's
references/update.mdto passroot='.'tobuild_merge.
Workaround used
Post-merge manual prune: filter nodes/edges/hyperedge.members where normalized relative source_file ∈ deleted set, then re-export. Verified 0 stale nodes afterwards.
(Same setup that produced #1146/#1147 — happy to test a fix build.)
Confirming this is alive and biting on the latest version — graphifyy 0.8.35, Windows 11, Python 3.11, driven through the Claude Code integration (graphify claude install).
Real scenario: I deleted a module during a refactor (src/chamber/engine/sound/binding_library.py — a dead by-ID binding API we'd replaced with a declarative catalog). Then I ran the documented clean-rebuild, explicitly with --force:
graphify extract . --force --backend gemini
The log prints the exact reassurance from this issue:
[graphify] 3 source file(s) deleted since last run — no matching nodes or edges in graph, already clean.
…but it isn't clean. graphify query "body to FX binding default sources" still returns the deleted file as its top hits:
NODE binding_library.py [src=.../binding_library.py L1]
NODE validate_binding() [src=.../binding_library.py L211]
NODE compute_binding_value() [src=.../binding_library.py L235]
NODE Binding / get_binding() / bindings_for_role() [.../binding_library.py]
So your root-cause read (absolute deleted_files vs relative stored source_file, prune normalization only firing when root is passed) matches exactly what I see — including the misleading "already clean" line. --force doesn't help, since it's still the grow-merge path. I also hit #1152 in the same commit: I removed functions from files that still exist (dead tuning_* fields from a Pydantic schema, a couple of binding helpers from another module) and those ghost too.
The part that makes this more than cosmetic, specifically for the Claude integration: graphify claude install registers PreToolUse hooks that nudge the assistant to "run graphify query instead of grepping." So immediately after a refactor that deletes code, the agent the integration is meant to help gets actively routed to a file that no longer exists — the stale graph becomes its first answer rather than sitting quietly.
Two asks:
- What's the recommended way today to force a genuinely clean rebuild on Windows? Nuke
graph.json+.graphify_analysis.json(the semantic cache) and re-extract from scratch? Passroot='.'? The post-merge manual prune you described? A one-liner in the docs for "I just deleted files, give me a clean graph" would cover the common case nicely. - Is the
root-fallback fix (your suggestion #1 here) likely to land soon? And a strong +1 on suggestion #4 — updating the skill'sreferences/update.mdto passroot='.'— because the Claude hooks lean hard onquery, so a silently-failing prune does the most damage exactly there.
Happy to test a fix build on Windows. Thanks for the tool, and for the unusually thorough root-causing in this thread.
Reproduced on macOS — graphifyy 0.8.39, Darwin 25.5.0, Python 3.12, markdown-only corpus (an Obsidian vault), via the skill's documented --update recipe. Both reports on this issue so far are Windows, so this at least confirms it isn't platform-specific. The console output differed from the Windows reports in a way that seems worth recording.
Result: a directory rename (wiki/skills/ → wiki/mirrors/skills/, new path added to .graphifyignore) left 151 stale nodes in a 662-node graph — about 23% — after a merge that looked successful.
The macOS console output
Rather than the "already clean" line from the Windows reports, I got:
[graphify] Deduplicated 8 node(s) (7 exact, 1 fuzzy).
[graphify] Pruned 45 edge(s) from deleted source file(s).
MERGED: 662 nodes, 910 edges
The run reported 45 pruned edges, while 151 nodes whose source_file still began with wiki/skills/ remained. At a glance that reads as a successful prune, so I didn't look closer until I grepped source_file in the output graph.json. I haven't investigated why edges reported a non-zero count here while the stale nodes survived — recording it as an observation, not a claim about internals.
Runtime confirmation of the normalization behavior
Consistent with your root-cause analysis, against the installed package:
from graphify.build import _norm_source_file
p = '/Users/…/brain/wiki/skills/README.md'
_norm_source_file(p, None) # -> '/Users/…/brain/wiki/skills/README.md' (unchanged)
_norm_source_file(p, '/Users/…/brain') # -> 'wiki/skills/README.md' (relative form)
The relative form is what the stored source_file values look like here. I have not tested a patched build_merge end to end, so I can't confirm suggestion #4 as a complete fix — only that the normalization behaves as you describe.
I patched my local copy of the skill's references/update.md to pass root, and the post-merge manual prune from your original report also worked for me — I used it to recover this graph without a full re-extract (0 stale nodes afterward).
Possible regression check
Since the node-pruning failure is easy to miss from the log alone, it might be worth having the documented recipe verify the prune rather than rely on the printed counts:
deleted_sources = {_norm_source_file(p, root_str) for p in deleted}
stale = [d.get('source_file') for _, d in G.nodes(data=True)
if d.get('source_file') in deleted_sources]
if stale:
print(f'!! PRUNE FAILED — {len(stale)} nodes remain for deleted files')
Happy to test a fix build on macOS.
Already fixed on current v8.
build_merge now has _infer_merge_root (reads the .graphify_root marker, #1571) and _derive_prune_root (#2446, infers the root from unmatched absolute prune paths when the marker's guess is wrong) — a fix well beyond this issue's original scope. build_merge(prune_sources=...) no longer silently no-ops when root isn't passed explicitly.
This looks fixed on the v8 branch by 717b7b46 (fix(paths): implement cross-platform absolute path detection for stored paths). Could a maintainer confirm and close?