Skip to content

fix(dedup): no id-collision warning for shared module nodes - #4756

Closed
idachev wants to merge 1 commit into
Graphify-Labs:v8from
idachev:dedup-module-collision-pr
Closed

idachev wants to merge 1 commit into
Graphify-Labs:v8from
idachev:dedup-module-collision-pr

Conversation

@idachev

@idachev idachev commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Every Swift file that imports a module (import Foundation) mints the same module node id by design, and the extractors already exempt module and namespace nodes from collision disambiguation. deduplicate_entities still reported each such group as a lost-node ID collision, so a build printed one spurious WARNING: node '...' is minted by two different files for every extra importing file. That noise teaches users to ignore the real data-loss warning.

_report_id_collision now stays silent only when every node in the group is a module (or namespace) node of the same type under the same label. A module colliding with a namespace, with any other node type, or with a differently named module still warns.

Refs #4754

Found during the work on #4754 (it is Phase 5 of the RFC in that Swift PR), but independent of it: this PR does not depend on the Swift PR, and the Swift PR does not depend on this one.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Verification & Invariants

Invariant: the collision warning fires exactly when dropping a node loses an entity. A shared module node is one entity, so dropping a duplicate of it loses nothing; any other collision is still reported. Only a warning changes: no node, edge, cache or persisted state is affected.

  • Read the CONTRIBUTING.md guide.
  • Reproduced the issue and identified the invariant.
  • Made the smallest fix necessary.
  • Added a regression test (if bug fix) or isolated boundary test.
  • Kept the PR description synchronized with the final implementation.
  • Documented any limitations / unsupported cases explicitly.

How was this tested?

Tests in tests/test_swift_import_resolution.py: test_shared_module_import_prints_no_collision_warning (two Swift files importing Foundation; fails on v8), and the controls test_mixed_module_collision_still_warns, test_module_namespace_collision_still_warns and test_differently_named_modules_collision_still_warns.

uv sync --all-extras
uv run pytest tests/test_swift_import_resolution.py   # 7 passed
uv run pytest tests                                   # 8729 passed, 16 skipped, 1 xfailed
uv run ruff check .                                   # All checks passed!
uv run pyright                                        # 657 errors, the same count as v8

Limitation: the exemption is by node type and label only. Two different modules that happen to share a label and an id are treated as one entity, the same way the extractors already treat them.

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. Not applicable: no skillgen fragments changed.
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

🤖 Generated with Claude Code

Every Swift file that imports a module (`import Foundation`) mints the
same module node id by design, and the extractors already exempt
module/namespace nodes from collision disambiguation.
deduplicate_entities still reported each such group as a lost-node ID
collision, printing a spurious WARNING for every extra importing file.
That noise trains users to ignore the real data-loss warning.

_report_id_collision now stays silent only when every member of the
group is a module (or namespace) node of the same type under the same
label. A module colliding with a namespace, with any other type, or
with a differently named module still warns.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@idachev
idachev requested a review from safishamsi as a code owner October 25, 2026 07:53
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @idachev. 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.

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

No issues found by static checks — no coupling regressions or blocking issues in the code graph. That is not the same as safe to merge: see what was not checked.

Not checked: tests were not run; formal verification proved 0 of 1 changed function(s) (1 sampled, not proven).

Formal verification. PR-changed functions: 1/1 verified (0 proven, 1 may-equivalent, 0 distinguished) · 0 not verified.


Graphify review — findings

Silences the "minted by two different files" ID-collision warning in deduplicate_entities for shared module/namespace nodes, such as the Foundation node every Swift file importing it creates. This matches how the extractors already exempt those types from collision disambiguation. The exemption applies only when the whole colliding group has the same type (module or namespace) and the same label. A module colliding with a namespace, a module colliding with a non-module node, or two differently named modules still warns. New Swift import tests cover the no-warning case plus the three still-warns controls.

No blocking issues surfaced. 1 lower-confidence candidate did not survive cross-model review.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 604 functions depend on the 93 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: deduplicate_entities() — 107 callers, 30 callees

Verification — 604 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: 304 function(s) in the blast radius were not formally verified this run

Test selection

Test selection

28 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_swift_import_resolution.py — impact, changed-test
  • 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

No difference found (not proven): No behavior difference found in \_report\_id\_collision (not a proof).

The verifier ran both versions of \_report\_id\_collision on many inputs and saw identical behavior every time. Strong evidence the change is safe, but evidence, not a proof.

Guarantee: Empirical: differential testing (both versions run on many generated inputs). A divergence on an untested input remains possible, so this is 'no counterexample found', not 'proven equivalent'.

Note: An input the sampler did not try could still differ.

· 1 more finding(s) on lines outside this diff (see the check run).

@bercedev bercedev 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.

Tests check out: the shared-module test fails on v8, all 7 pass here. The ("module", "namespace") set matches the exemption in extractors/resolution.py (node.get("type") in ("module", "namespace")), and the module-vs-namespace and two-different-labels cases still warn, so the real data-loss warning is intact. LGTM.

@safishamsi

Copy link
Copy Markdown
Member

Landed in v0.9.96, now on PyPI (pip install graphifyy==0.9.96). No id-collision warning for shared module nodes. Thanks for the fix, @idachev.

@safishamsi safishamsi closed this Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants