Repository navigation
fix(build): rewire doc-to-code edges whose endpoint was replaced by re-extraction (#1711) - #4604
ayushcodes10 wants to merge 2 commits into
Conversation
An edge owned by a file that was not freshly extracted this run survived build_merge's and merge_raw_extraction's replace per source filter untouched, since that filter only looks at an edge's own source file. But the filter had already dropped the OTHER endpoint's node when that endpoint's own file WAS extracted again this run, and extraction is not id stable across runs, so the surviving edge kept naming an id that no longer existed under that spelling even though the symbol itself was still there. The dangling reference then either vanished silently in the generic drop that follows (build_merge) or rode along as an unresolvable raw reference (merge_raw_extraction). An unchanged doc citing a function that got requalified this run lost that citation permanently, since the doc is never extracted again on its own to emit it a second time. Both functions now resolve such an endpoint again by its source file and label against the fresh chunk, the same identity build_from_json's own ghost merge already trusts for AST and LLM twin detection, and rewrite the edge onto the one fresh node that claims that pair. Zero or two or more candidates leave the edge exactly as it was before this change, so an ambiguous case still reaches the ordinary dangling edge drop rather than guessing. A genuinely deleted endpoint is unaffected: the rewiring only ever looks at nodes dropped for being replaced, never ones dropped for being pruned, so deletion still removes the edge as before. merge_raw_extraction's own docstring already promises its replace and prune semantics mirror build_merge exactly so the raw and clustered incremental paths cannot drift, so both needed the same fix rather than just the one the report's own repro exercised.
Covers both merge functions against the report's own repro: a doc edge into a code symbol survives once that symbol's own file is extracted again under a new id. Two controls pin down the boundaries the fix must respect: a dropped node with two equally plausible fresh candidates stays unresolved rather than guessing, and a genuinely deleted file still loses its edges exactly as before, since deletion was never meant to be rescued by this. A fifth test is a plain no op update, confirming nothing about an untouched graph changes when nothing was extracted again at all.
|
Thanks for the pull request, @ayushcodes10. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.10 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify reviewed this change.
Worth a look — the grounded gate found no coupling regressions or blocking issues, but 2 advisory finding(s) below merit a look before merge.
Not checked: tests were not run; formal verification proved 0 of 2 changed function(s) (2 not verified).
Formal verification. PR-changed functions: 0/2 verified (0 proven, 0 may-equivalent, 0 distinguished) · 2 not verified (1 vacuous, 1 unsupported).
Not verified on this run: build\_merge (vacuous: never exercised), merge\_raw\_extraction (unsupported).
Graphify review — findings
Fixes incremental merges losing edges from unchanged files into a re-extracted file's nodes when extraction mints a different id for the same symbol (#1711). A new _rewire_edges_through_replaced_nodes re-points each surviving edge endpoint onto the fresh node that shares its (source_file, label), trying the raw path first and then the normalised one, and runs in both build_merge and merge_raw_extraction. It only rewrites when exactly one fresh node claims that pair, so endpoints that are ambiguous, unmatched or genuinely pruned fall through to the ordinary dangling-edge drop as before, but the label-keyed match means distinct old nodes sharing a (source_file, label) get collapsed onto one fresh node. Splits the new _replaced check out of _dropped so rewiring applies only to nodes superseded by their own tier's re-extraction, never to deletion or exclusion prunes, and prints a stderr count of rewired edges. The new tests cover rewiring in both merge paths, the unchanged-edge no-op, a genuinely deleted endpoint still pruned, and an ambiguous replacement left to drop.
Worth a look
- Rewire collapses distinct old nodes sharing (source_file, label) onto one fresh node —
graphify/build.py:2179· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
- Rewiring crashes with TypeError on unhashable edge endpoints or node ids —
graphify/build.py:2183· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 1782 functions depend on the 120 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
build_merge()— 106 callers, 17 callees - worse:
to_json()— 85 callers, 11 callees - worse:
build()— 84 callers, 6 callees - worse:
merge_raw_extraction()— 11 callers, 12 callees
Verification — 1782 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: 1212 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
129 of 437 test file(s) selected (30%) via static blast radius.
tests/test_alias_folding.py— impacttests/test_analyze.py— impacttests/test_atomic_canvas_export.py— impacttests/test_atomic_writes.py— impacttests/test_backend_opt_in.py— impacttests/test_benchmark.py— impacttests/test_benchmark_raw_graph.py— impacttests/test_benchmark_real_query.py— impacttests/test_build.py— impacttests/test_build_located_semantic_identity.py— impacttests/test_build_merge_dedup_scope.py— impacttests/test_build_merge_edge_survival.py— impact, changed-testtests/test_build_merge_hyperedges_and_prune.py— impacttests/test_build_merge_shrink_guard.py— impacttests/test_c_include_resolution.py— impacttests/test_carried_hyperedge_remap.py— impacttests/test_charmap_encoding.py— impacttests/test_chunking.py— impacttests/test_claude_cli_backend.py— impacttests/test_cli_export.py— impacttests/test_cluster.py— impacttests/test_community_labels_skill.py— impacttests/test_compact_graph_json.py— impacttests/test_confidence.py— impacttests/test_corrupt_graph_json.py— impacttests/test_cpp_objc_cross_file_calls.py— impacttests/test_cross_extension_reexport_self_cycle.py— impacttests/test_cross_repo_external_call_guards.py— impacttests/test_csharp_object_creation.py— impacttests/test_dedup.py— impacttests/test_dedup_remaps_hyperedges.py— impacttests/test_dedup_shrink_refuses_force_write.py— impacttests/test_dedup_survivor_richness.py— impacttests/test_definition_file_portability.py— impacttests/test_duplicate_annotation_edges.py— impacttests/test_evidence_binding.py— impacttests/test_export.py— impacttests/test_export_control_characters.py— impacttests/test_export_direction.py— impacttests/test_export_idempotent_writes.py— impacttests/test_export_path_length.py— impacttests/test_ext_tagged_id_clash.py— impacttests/test_external_stub_endpoints.py— impacttests/test_extract.py— impacttests/test_falkordb_integration.py— impacttests/test_file_label_disambiguation.py— impacttests/test_global_add_tag_inference.py— impacttests/test_global_graph.py— impacttests/test_go_qualified_resolution.py— impacttests/test_god_nodes_exclude_hubs.py— impact- … and 79 more
Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.
Formal verification
Could not verify: Could not verify build\_merge.
The verifier did not have enough to check build\_merge, 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: no capturable inputs from the test suite; property tier: not verifiable: all 224 sampled inputs raised on both versions — the function never executed, so 'no divergence' would be vacuous (mostly AttributeError — names the real obstacle, not a sampling gap)
Could not verify: Could not verify merge\_raw\_extraction.
The verifier did not have enough to check merge\_raw\_extraction, 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: no capturable inputs from the test suite; property tier: parameter `prune_sources` is annotated `'list[str] | None'` — outside the synthesizable primitive/collection set
· 1 grounded finding(s) anchored inline below; 3 more finding(s) on lines outside this diff (see the check run).
| return rescued | ||
|
|
||
|
|
||
| def merge_raw_extraction( |
There was a problem hiding this comment.
merge_raw_extraction()
fans out to 12 callees (efferent coupling); 11 callers depend on it (afferent coupling).
Grounded coupling-delta finding (deterministic), not an LLM guess.
Fixes #1711.
build_merge's andmerge_raw_extraction's replace-per-source step correctly drops a re-extracted file's own stale nodes/edges, keyed on the item's OWNsource_file. An edge owned by an UNCHANGED file (e.g. a doc referencing a function) survives that filter untouched, since the edge's ownsource_filewasn't re-extracted — but if the edge's target lives in a file that WAS re-extracted, that target node was just dropped by the same filter. Extraction is not id-stable across runs (#1695), so the re-extracted file's new node for the same symbol often gets a different id (e.g. requalified with a file-stem prefix). The surviving edge keeps naming the old id, which no longer exists.That dangling reference then either vanishes silently in
build_from_json's generic dangling-edge drop (thebuild_mergepath) or rides along as an unresolvable raw reference (merge_raw_extraction, the--no-clusterincremental path). Because the surviving endpoint's own file was never re-extracted, nothing ever re-emits the edge against the target's new id on a later run either — the loss is permanent, not just until the next rebuild, matching what both the original report and the independent production-corpus comment on the issue describe.Fix
Both functions now re-resolve a dropped endpoint by
(source_file, label)against the fresh chunk — the same identitybuild_from_json's own ghost-merge already trusts for AST/LLM twin detection — and rewrite the edge onto the one fresh node that claims that pair. Matching both the rawsource_filestring and its_norm_source_fileform, same as the rest of this replace machinery.Conservative by construction: an edge is only rewired when EXACTLY ONE fresh node matches; zero or 2+ candidates leave it exactly as before, so it still reaches the ordinary dangling-edge drop rather than guessing. A genuinely deleted endpoint (via
prune_sources) is unaffected — the new logic only ever looks at nodes dropped for being replaced, never ones dropped for being pruned — so deletion still removes the edge as before.merge_raw_extraction's own docstring already states its replace/prune semantics "mirrorbuild_mergeexactly, so the raw and clustered incremental paths can't drift" — it has the identical bug via the identical mechanism, so this fixes both rather than just the one the issue's own repro exercises.Out of scope, left as a documented follow-up: the issue's "residual hyperedge gap" (item 2 of its proposed fix) — a dropped hyperedge whose full member set is still resolvable in the merged graph. That's a related but separate carry-forward mechanism from ordinary edges and deserves its own focused change.
Verification
v8before the fix: a doc→code edge disappears entirely after re-extracting only the code file (0 edges after, where 1 is expected).git show+file-swap (nevergit stash) that the pre-fix code reproduces this exactly, and that restoring the fixed file is byte-identical to the working tree.tests/test_build_merge_edge_survival.py: the repro for bothbuild_mergeandmerge_raw_extraction, an ambiguous-candidates control (left unresolved), a genuine-deletion control (still pruned), and a no-op-update control (nothing spuriously rewritten).python3 -m pytest tests/ -q) andpython3 -m tools.skillgen --checkboth clean.