Repository navigation
fix(build): ghost-merge nodes whose source_file is the referencing doc, not the referenced file - #3345
fix(build): ghost-merge nodes whose source_file is the referencing doc, not the referenced file#3345leninherrera94 wants to merge 1 commit into
Conversation
…c, not the referenced file The Graphify-Labs#1145-extended ghost-merge (build_from_json) keys exclusively on (source_file, label). When a semantic pass reads a document that only *mentions* a real file by name (a saved graphify-out/memory/*.md query answer, a runbook like "see App.tsx"/"backup.sh does X"), the new node it mints gets source_file = the document being read, not the file actually named in the prose. That wrong source_file means the key can never match the real AST node's, so the ghost survives every rebuild. Add a conservative label-only fallback pass reusing the existing _is_file_node_label() predicate (already used for file-node label disambiguation) against every AST file-self node collected in Pass 1. Only remaps when the match is unique across the graph — 0 or 2+ candidates (e.g. two different index.ts files) are left alone, same conservatism the existing (source_file, label) key already applies via _loc_collisions. Verified against a real ~4600-node project graph: 10 long-standing ghost nodes removed across two unrelated documents (a memory query file and an ops runbook), confirming this is a general failure mode of the "document mentions a file by name" pattern, not a narrow edge case. Both hyperedges that had cited the phantoms now correctly cite only real, AST-backed nodes. Fixes Graphify-Labs#3344
There was a problem hiding this comment.
Graphify reviewed this change.
Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).
Formal verification. No changes could be formally verified in this run.
Graphify review — findings
Adds a label-only ghost-merge fallback (Pass 2b in build_from_json) that folds semantic nodes which merely mention a file into the real AST file node, covering the case where a self-referential pass over a memory doc/README stamps the document's path as source_file instead of the mentioned file's, so the exact (source_file, label) key can never match. Matching reuses _is_file_node_label, so bare basenames and directory-qualified suffixes ("customer-app/index.ts" vs "apps/customer-app/index.ts") resolve, while a label hitting 0 or 2+ AST files is left untouched to avoid arbitrary merges.
No blocking issues surfaced. 5 lower-confidence candidates did not survive cross-model review.
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 1243 functions depend on the 233 functions this change touches.
Health — this change adds coupling hotspots:
- new:
_rebuild_code()— 113 callers, 50 callees - new:
build_from_json()— 199 callers, 19 callees - new:
build_merge()— 62 callers, 13 callees - new:
to_obsidian()— 38 callers, 14 callees - new:
extract_files_direct()— 17 callers, 20 callees - new:
to_wiki()— 41 callers, 7 callees - new:
extract_corpus_parallel()— 26 callers, 11 callees - new:
_call_claude_cli()— 31 callers, 9 callees - …and 38 more — each is listed as a finding
Verification — 1243 functions in the blast radius were not formally verified this run (proofs are advisory here).
Gate & verification
graphify gate
PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.
Advisory (not blocking):
- verification_scope: 839 function(s) in the blast radius were not formally verified this run
Formal verification
Could not verify: Could not verify build\_from\_json.
The verifier did not have enough to check build\_from\_json, so it is saying so rather than guessing. No false assurance is the whole point.
Guarantee: No guarantee either way, this is an honest abstention, not a pass.
Note: Reason: not verifiable: all 6 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly NameError — names the real obstacle, not a sampling gap)
· 46 more finding(s) on lines outside this diff (see the check run).
|
Shipped in v0.9.55 — landed on |
Fixes #3344.
Problem
build_from_json()'s ghost-merge pass (the "#1145-extended" logic collapsing a semantic/LLM-extracted duplicate into its AST-canonical twin) keys exclusively on(source_file, label). When a semantic pass reads a document that only mentions a real source file by name in prose — a savedgraphify-out/memory/*.mdquery answer, a runbook narrating "seeApp.tsx" or "backup.shdoes X" — the node it mints getssource_file= the document being read, not the file actually named in the text. That wrongsource_filemeans the key can never match the real AST node's key, so the ghost survives every subsequent rebuild, forever.Fix
Add a conservative label-only fallback ("Pass 2b") that reuses the already-existing
_is_file_node_label()predicate (currently only used for file-node label disambiguation) to match a ghost against every AST file-self node collected in Pass 1, when the exact(source_file, label)key doesn't resolve it. Only remaps when the match is unique across the graph — a label matching 0 or 2+ real files (e.g. two differentindex.tsfiles) is left alone, mirroring the conservatism the existing key-based path already applies via_loc_collisions.No other code needed to change:
_ghost_remapalready flows into the existingnorm_to_idmap that both edge endpoints and hyperedge members resolve through.Testing
tests/test_build.py:test_ghost_merge_wrong_source_file_resolved_by_label— the fix's core positive case, including the "prose dropped a leading path segment" variant (customer-app/index.tsvs the realapps/customer-app/index.ts).test_ghost_merge_wrong_source_file_ambiguous_basename_left_alone— confirms the fallback stays conservative when a basename is shared by two real files.uv run pytest -q→ 5228 passed, 93 skipped (unchanged from the pre-patch baseline on this checkout — the only failures present with or without this patch are pre-existing and unrelated:test_ollama_retry_cap.pyneeds the optionalopenaiextra not installed here, andtest_skillgen.py's git-history audits need a commit ref my shallow clone doesn't have).ruff checkclean on both changed files.