Repository navigation
fix(dedup): prefer defining file on node ID collisions - #4743
SinghAman21 wants to merge 2 commits into
Conversation
|
Thanks for the pull request, @SinghAman21. 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 1 advisory finding(s) below merit a look before merge.
Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 not verified).
Formal verification. PR-changed functions: 0/1 verified (0 proven, 0 may-equivalent, 0 distinguished) · 1 not verified (1 unsupported).
Not verified on this run: \_collision\_rank (unsupported).
Graphify review — findings
Fixes ID-collision resolution so a reference stub that shares a parent directory prefix with its target no longer wins over the real definer. A new _definition_path_specificity helper returns the length of the longest source-path prefix encoded in a node's ID, and _collision_rank now sorts on it first, treating mentions as zero. Because specificity now ranks ahead of the lifecycle penalty, path depth can override the active-over-archived preference when the two disagree.
Worth a look
- Path specificity now outranks lifecycle penalty, so a deeper archived definer can beat an active one —
graphify/dedup.py:507· Escalate · medium- NOT verified (no proof, no reproducing execution) — needs human review
Analysis details — impact, health, verification
Impact & health
Graphify review
Impact — 594 functions depend on the 83 functions this change touches.
Health — this change adds coupling hotspots:
- worse:
_collision_rank()— 4 callers, 4 callees
Verification — 594 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: 291 function(s) in the blast radius were not formally verified this run
Test selection
Test selection
27 of 453 test file(s) selected (6%) via static blast radius.
tests/test_build.py— impacttests/test_build_located_semantic_identity.py— impacttests/test_build_merge_dedup_scope.py— impacttests/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_chunking.py— impacttests/test_corrupt_graph_json.py— impacttests/test_cross_extension_reexport_self_cycle.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_ext_tagged_id_clash.py— impacttests/test_global_graph.py— impacttests/test_go_qualified_resolution.py— impacttests/test_issue_3472_source_file_collision.py— impacttests/test_js_member_collisions.py— impacttests/test_merge_sweeps_reextract_orphans.py— impacttests/test_no_dedup_flag.py— impacttests/test_non_string_node_ids.py— impacttests/test_prune_sweeps_orphans.py— impacttests/test_python_underscore_resolution.py— impacttests/test_r_extractor.py— impacttests/test_semantic_origin_stamp.py— impacttests/test_unverified_semantic_shrink.py— impact
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 \_collision\_rank.
The verifier did not have enough to check \_collision\_rank, 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 `mentions` is annotated `'frozenset | set'` — outside the synthesizable primitive/collection set
· 1 more finding(s) on lines outside this diff (see the check run).
nothariharan
left a comment
There was a problem hiding this comment.
Thanks for the patch. I tested it against the three collisions reported in #4738 on this branch (6f6270a) and on v8 (92741d1), replaying the exact node records from the warnings through deduplicate_entities.
It does not change any of the reported collisions
| Case from #4738 | v8 | this PR |
|---|---|---|
warning 1, specifications_20_architecture_operational_logging_document |
keeps delivery/change-policy.md |
keeps delivery/change-policy.md |
warning 2, functional_agent_runtime_doc |
keeps functional/agents/agent-operator.md |
keeps functional/agents/agent-operator.md |
warning 3, company_license_schedule_c |
keeps company/license-schedule-c.md (the definer) |
keeps company/license-schedule-c.md |
Warnings 1 and 2 are stub-vs-stub: neither source path encodes the ID, so _definition_path_specificity returns 0 for both nodes and the new first key ties. The rest of the rank is unchanged, so the same node is dropped. Warning 3 already kept the defining file on v8, because that node already had the longer matching prefix.
So as written this does not fix #4738, and it should not carry Fixes #4738.
What it does change
It does fix a narrower case, where a citing file's path is a proper prefix of the target path so _defines_id is true for both, and the stub has the shorter label:
v8: specs/operational.md (stub wins on label length)
this PR: specs/operational/logging.md (target wins on specificity)
That is a real improvement, but it is not any of the three cases in the issue.
Two survivor regressions
Because specificity is now ordered ahead of _lifecycle_penalty and the rest of the rank:
- An archived definer now beats an active one, contradicting #2532.
plans.md (active)
plans/_done/spec.md (archived)
v8: plans.md
this PR: plans/_done/spec.md
- A deeper coincidental path can beat the canonical
<path>_<entity>node.
docs/protocol.md id=docs_protocol_firmware_protocol label="Firmware Protocol"
docs/protocol/firmware.md id=docs_protocol_firmware_protocol label="Firmware protocol notes"
v8: docs/protocol.md
this PR: docs/protocol/firmware.md
A longer path prefix is not proof that the ID was minted from that file. In the second case the longer path is a file-level ID coincidentally matching another file's <path>_<entity> ID.
Tests
The change adds no tests. For a survivor rule with four callers I would want at least:
- the parent-prefix case above, to lock in the intended improvement;
- active vs archived, to prove #2532 still holds;
- a non-definer vs definer guard.
tests/test_dedup.py does pass on this branch (138 passed), but it has no coverage for the new key.
Suggestion
If the goal is to close #4738, the stub-vs-stub case needs a different mechanism, for example not minting a node for a cross-document reference, or namespacing the stub ID by the citing file. This branch does not move that case.
If the goal is a hardening for parent-prefix definers, retitle it and drop Fixes #4738, and put specificity after the lifecycle key so #2532 is not regressed. I am happy to re-review either version.
|
Thanks for the review. I reworked this to avoid path-specific survivor ranking. Native semantic extraction now marks cross-document reference stubs with explicit provenance, and dedup namespaces only marked stubs. The build-level regression replays all three #4738 collisions: v8 retains 3 source records, while the updated pipeline retains all 6. The active/archived and unmarked nested-path cases retain their existing behavior. Existing graphs need a semantic re-extraction to add the new provenance marker. Tests: 373 passed. |
|
Landed in v0.9.96, now on PyPI (pip install graphifyy==0.9.96). Node ID collisions prefer the defining file. Thanks for the fix, @SinghAman21. |
Fixes #4738.
Semantic extraction marks cross-document reference stubs. Dedup namespaces marked stubs by citing file, preserving the reported records without changing unmarked nested-path collisions.