Description
Labels: bug, windows, extract, node-identity
Version: 0.9.38 (commit 10ad921)
Environment: Windows 11, Python 3.13.6
Summary
When extract() is handed relative paths, the source_file written onto nodes keeps the
native separator for some extractors and is normalised to POSIX for others — inside one
extraction run. The graph then contains two spellings of the same directory layout, which is
the fragmentation #683 described.
Steps to reproduce
project/
src/lib/content.ts export function getPosts() { return []; }
src/pages/index.astro ---
import { getPosts } from '../lib/content';
const posts = getPosts();
---
<h1>{posts.length}</h1>
Using the module's own documented entry point, with relative arguments:
$ python -m graphify.extract src/lib/content.ts src/pages/index.astro
Actual behavior
"id": "lib_content", "source_file": "src\\lib\\content.ts"
"id": "lib_content_getposts", "source_file": "src\\lib\\content.ts"
"id": "pages_index", "source_file": "src/pages/index.astro"
"id": "src_pages_index_posts", "source_file": "src/pages/index.astro"
Two separator conventions in one document. The .ts nodes use \, the .astro nodes use
/.
Expected behavior
Every source_file is the canonical root-relative POSIX form, matching what the CLI
already produces. For contrast, the same project through the normal CLI path is correct:
$ python -m graphify extract .
...
"id": "src_a", "source_file": "src/a.py" # POSIX, consistent
and passing an explicit root is also correct:
extract(paths, root=Path(".").resolve())
# source_file = "src/lib/content.ts" and "src/pages/index.astro" -- both POSIXSo the canonical behaviour exists; the relative-input path just misses the normalisation.
Impact
source_file is compared as a string in several places, so the two spellings are
different files as far as graphify is concerned:
build._norm_source_file/_abs_identitykeyingbuild._build_prune_sets/_derive_prune_root(theprune_sourcesno-op class of --update: build_merge(prune_sources=...) silently no-ops when root is not passed (absolute vs relative source_file mismatch, Windows) #1151,
build_merge prune_sources silently no-ops on absolute paths and reports 'already clean' (deleted nodes never pruned on Windows) #2446)analyze.find_import_cycles, which matchesdata["source_file"]against
G.nodes[...]["source_file"]by equality — a backslash node never matches a POSIX edge- dedup and the semantic-cache key path (Semantic cache never hits: save_semantic_cache silently drops entries when source_file is corpus-root-relative #2314)
Reachability
Reachable from the documented python -m graphify.extract <file> ... entry point
(graphify/extract.py:6513-6523), which calls extract(paths) with no root, and from
any library caller following ARCHITECTURE.md (see issue_9.md — that document advertises
extract(path) as the public API).
The primary graphify extract CLI passes root and is not affected.
Root cause
The source_file value is taken from the input path as given, and only the explicit-root
branch runs it through the POSIX normalisation. The inferred-root fallback
(graphify/extract.py:5197-5211) computes a root but the per-extractor source_file
assignment is not uniformly as_posix()-normalised — the .astro extractor happens to
normalise, the shared jsts path does not.
Suggested fix
Normalise once, centrally, in the extract() post-pass that already walks every node to
canonicalise IDs — rather than in each extractor:
for n in nodes:
sf = n.get("source_file")
if sf:
n["source_file"] = PurePath(sf).as_posix()That is the single choke point all extractors route through, so it also covers the ones not
exercised here.
Collateral evidence
tests/test_astro_import_ids.py::test_astro_relative_inputs_keep_canonical_ids fails on
Windows on a clean checkout for exactly this reason:
assert 'src\\lib\\content.ts' == 'src/lib/content.ts'
Related
- Graph fragmentation: path-separator inconsistency splits same file into 2 components + Louvain over-merging via doc-hub edges #683 (CLOSED) — "path-separator inconsistency splits same file into 2 components". Same
class, resurfaced on a different code path. - source_file written as absolute path on some runs, relative on others — causes --update to duplicate the whole graph #2259 (OPEN) —
source_fileabsolute on some runs, relative on others. Adjacent but
distinct: this report is about the separator, within a single run.
Activity
Normalize relative source_file to POSIX separators
Normalize relative source_file to POSIX separators
omsenjalia commentedon Oct 18, 2026
This looks fixed on the
v8branch by ce942e14 (fix(extract): canonicalize source_file to POSIX separators (#2627)). Could a maintainer confirm and close?