Skip to content

fix(dedup): prefer defining file on node ID collisions - #4743

Closed
SinghAman21 wants to merge 2 commits into
Graphify-Labs:v8from
SinghAman21:fix/4738-reference-node-collisions
Closed

SinghAman21 wants to merge 2 commits into
Graphify-Labs:v8from
SinghAman21:fix/4738-reference-node-collisions

Conversation

@SinghAman21

@SinghAman21 SinghAman21 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

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.

@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Oct 24, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 — impact
  • tests/test_build_located_semantic_identity.py — impact
  • tests/test_build_merge_dedup_scope.py — impact
  • tests/test_build_merge_hyperedges_and_prune.py — impact
  • tests/test_build_merge_shrink_guard.py — impact
  • tests/test_c_include_resolution.py — impact
  • tests/test_carried_hyperedge_remap.py — impact
  • tests/test_chunking.py — impact
  • tests/test_corrupt_graph_json.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_dedup.py — impact
  • tests/test_dedup_remaps_hyperedges.py — impact
  • tests/test_dedup_shrink_refuses_force_write.py — impact
  • tests/test_dedup_survivor_richness.py — impact
  • tests/test_ext_tagged_id_clash.py — impact
  • tests/test_global_graph.py — impact
  • tests/test_go_qualified_resolution.py — impact
  • tests/test_issue_3472_source_file_collision.py — impact
  • tests/test_js_member_collisions.py — impact
  • tests/test_merge_sweeps_reextract_orphans.py — impact
  • tests/test_no_dedup_flag.py — impact
  • tests/test_non_string_node_ids.py — impact
  • tests/test_prune_sweeps_orphans.py — impact
  • tests/test_python_underscore_resolution.py — impact
  • tests/test_r_extractor.py — impact
  • tests/test_semantic_origin_stamp.py — impact
  • tests/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 nothariharan left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. 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
  1. 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.

@SinghAman21 SinghAman21 changed the title fix(dedup): prefer defining file on node ID collisions fix(dedup): preserve cross-document reference stubs Oct 25, 2026
@SinghAman21 SinghAman21 changed the title fix(dedup): preserve cross-document reference stubs fix(dedup): prefer defining file on node ID collisions Oct 25, 2026
@SinghAman21

Copy link
Copy Markdown
Contributor Author

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.

@safishamsi

Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Node ID collisions silently drop nodes on documentation-heavy corpora

3 participants