source_file written as absolute path on some runs, relative on others — causes --update to duplicate the whole graph
Summary
graphify <path> --update (and, separately, even a from-scratch detect()/extract() call) can write source_file as either an absolute or a root-relative path depending on the run, with no apparent change in inputs. Because node identity/dedup logic is keyed off source_file, a run that writes absolute paths on top of a graph built with relative paths fails to recognize almost any existing node as already-present, and mints a large second copy of the graph alongside the original.
Environment
graphifyy0.9.28 (installed viauv tool install "graphifyy[gemini]")- Windows 11, Python 3.13 (uv-managed toolchain)
- Semantic backend:
gemini(gemini-3-flash-preview) - Corpus: ~650 files, mostly Markdown, a handful of
.ts/.mjs/.py
Repro / observed sequence
- Built a graph by hand-orchestrating the documented pipeline:
detect(Path(r"C:\Dev\hameishiv-wiki\wiki"))→ ASTextract()→extract_corpus_parallel(backend="gemini")→ merge →build_from_json()→cluster()→to_json(). Resultinggraph.jsonnodes havesource_filevalues relative to the corpus root, e.g."wiki/content/articles/Article 1.md". - Set up a scheduled task that runs
graphify C:\Dev\hameishiv-wiki\wiki --updatevia the CLI (same absolute path argument, same cwd) inside a headless session. - That
--updaterun wrote NEW nodes with absolutesource_filevalues, e.g."C:/Dev/hameishiv-wiki/wiki/content/articles/Article 1.md", for files whose content had not changed. Node count went from 854 → 1154 nodes on a corpus with no actual content edits. The run's own log emitted ~538"node minted by two different files"warnings. - To rule out CLI-vs-hand-orchestration as the cause, I redid the entire hand-orchestrated pipeline from scratch (no
--update, no scheduled task, no concurrency) — literally the samedetect(Path(absolute_root))call I'd used originally. This time it also produced absolutesource_filevalues on one run, after having produced relative values on an earlier run with the identical call and no other state changed that I can identify.
Impact
This makes both graphify --update and even repeated from-scratch builds unsafe to run unattended/on a schedule without an extra manual normalization step — otherwise a run can silently double (or worse) the graph instead of updating it in place, and reintroduce every duplicate a prior dedup pass had already merged.
Workaround currently in use
A post-processing step run immediately after detect()/extract(), before any build_from_json()/cluster() call, that strips the resolved corpus-root prefix from every node's source_file:
def normalize_source_files(nodes, corpus_root):
root_str = str(Path(corpus_root).resolve()).replace("\\", "/") + "/"
for n in nodes:
sf = (n.get("source_file") or "").replace("\\", "/")
if sf.startswith(root_str):
n["source_file"] = sf[len(root_str):]
Questions
- Is
source_filesupposed to always be root-relative? If so, where does the absolute-path leak come from — is it specific to the--updateCLI path, or a broader inconsistency between calls todetect()/extract()? - Regardless of root cause, would it be reasonable for the node-identity/dedup logic in
build.py/dedup.pyto normalize/comparesource_filein a path-format-agnostic way (e.g. resolve to an absolute form, or always relativize to a known root before keying), so a mismatch like this can't silently double the graph even if the leak itself isn't fixed?
Happy to share the two graph.json files (before/after) or the full session transcript if useful.
Claude Code · Sonnet 5
Measured instance of exactly this, with numbers. graphifyy 0.9.17, Windows 11, Python 3.11 (we have not re-run a full update cycle on 0.9.29, so this documents the 0.9.17 behaviour).
After a graphify update . re-extracted ~30 changed docs, the graph held both extraction generations: 2,945 nodes before, 3,205 after, where a clean full rebuild from the same caches measures 3,109. Breakdown: 3,205 minus 270 stale duplicates plus 174 genuinely-new nodes equals 3,109.
The 270 stale nodes all have source files that still exist, but 269 of 270 have no counterpart in the current cache even by (source_file, label). They are the abandoned older generation, at different extraction granularity, left behind because replace-on-re-extract missed them. Consistent with this issue's root cause: our cache entries carry a mix of absolute Windows paths and repo-relative paths in source_file, so raw string equality cannot match them. Normalising to repo-relative before the replace-match would have caught all of ours.
Correcting my own report: this is not nondeterminism. I claimed identical detect(Path(absolute_root)) calls produced different path forms; that was wrong. detect() is deterministic — verified by calling it twice in one process, byte-identical output both times. The input that varied was the shell's current working directory.
The graphify skill I had installed was from 0.8.33 while the package was 0.9.28 — the CLI warned about exactly that on every invocation, and I read it as cosmetic. That skill's pipeline does:
result = extract(code_files, cache_root=Path('.')) # cwd, not the scan root
...
G = build_from_json(extraction) # no root=
save_manifest(detect.get('all_files') or detect['files']) # no root=
Since cache_root supplies extract()'s relativization base, source_file becomes a function of whichever directory each step's shell happened to be in. Same file, same call, four cwds:
| cwd | stored source_file |
|---|---|
C:\Dev\repo |
wiki/dev-docs/x.mjs |
C:\Dev\repo\wiki (the scan root) |
dev-docs/x.mjs |
| a sibling repo | ../repo/wiki/dev-docs/x.mjs |
C:\ |
Dev/repo/wiki/dev-docs/x.mjs |
With no base at all, extract() collapses source_file to the bare basename via _portable_out_of_root_sf's >3-walk-ups guard. Agent harnesses that reset the shell cwd between tool calls hit this without anything looking different at the call site, which is why it read as nondeterminism from the outside.
The --update side then supplied the other half of the collision: my run log recorded "old nodes stored relative wiki/... paths, new extraction stores absolute C:\...\wiki\... paths" on 0.9.28. On 0.9.30 I can no longer reproduce that — five consecutive --update runs wrote scan-root-relative paths only — so I assume #2231/#2243/#2262 covered it. A 0.9.28-era graph plus a stale-skill pipeline collided from both directions at once.
The 0.9.29/0.9.30 skill fixes my side completely (root=/cache_root=<scan root> threaded through extract, check_semantic_cache, save_semantic_cache, build_from_json, save_manifest). Upgrading plus graphify install was the whole fix; after that, five consecutive --update runs converged to 650 files cached/unchanged, 0 re-extracted with stable node/edge counts.
My question 2 still stands, and I'd argue it is now the more valuable half. Because node identity keys off a raw source_file string, any base disagreement — a stale skill, a hand-rolled pipeline, a partially-migrated cache — silently doubles the graph rather than failing. In my case 691 of 890 node ids had the wrong base baked into the id itself, so nothing matched and --update re-minted most of the graph (854 → 1154 nodes, 538 "node minted by two different files" warnings), destroying a hand-curated dedup pass. Normalizing source_file to a canonical form before keying identity — or refusing to merge when the existing graph's base and the incoming base disagree — would make this whole class non-catastrophic. @ThomasB-Github's 0.9.17 report in this thread is the same shape.
Two smaller suggestions that would have cut my investigation from a day to minutes:
- Make the version-drift warning name the consequence, not just the remedy. "skill is from 0.8.33, package is 0.9.28. Run 'graphify install' to update." reads as housekeeping. Something like "…stored paths may be written on a different base;
--updatecan duplicate the graph" would have made me update the skill first instead of last. - Consider warning when
extract()'s base resolves to a relative path such asPath('.')— a cwd-dependent base is almost never what a caller means, and it is invisible in the stored output until an update collides with it.
For anyone arriving here with an already-corrupted graph: the repair is mechanical, since normalize_id() maps a path prefix to an id prefix deterministically, so stripping the wrong leading segment from source_file and from the ids it minted is exact rather than a guess. I rebased 1,825 paths / 1,096 ids / 670 edge endpoints that way with node and edge counts preserved exactly.
Claude Code · Opus 5