From 8db19d6c85735e034f4d2c7818349c87f52654ad Mon Sep 17 00:00:00 2001 From: Safi Date: Sun, 31 May 2026 10:20:18 +0100 Subject: [PATCH] sort file list lexicographically in detect() for deterministic graph output os.walk order is non-deterministic across runs (filesystem b-tree order shifts with cache/mount state), causing first-writer-wins decisions in cross-file resolution to produce different node IDs each run; sorting all_files and per-FileType lists stabilises graph.json without changing any parent-child or connectivity semantics (closes #1090) Co-Authored-By: Claude Sonnet 4.6 --- graphify/detect.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/graphify/detect.py b/graphify/detect.py index 36a0a184..a3af585a 100644 --- a/graphify/detect.py +++ b/graphify/detect.py @@ -930,6 +930,8 @@ def detect(root: Path, *, follow_symlinks: bool | None = None, google_workspace: seen.add(p) all_files.append(p) + all_files.sort(key=lambda p: str(p)) + converted_dir = root / "graphify-out" / "converted" for p in all_files: @@ -983,6 +985,9 @@ def detect(root: Path, *, follow_symlinks: bool | None = None, google_workspace: if ftype != FileType.VIDEO: total_words += count_words(p) + for ftype in files: + files[ftype].sort() + total_files = sum(len(v) for v in files.values()) needs_graph = total_words >= CORPUS_WARN_THRESHOLD