Skip to content

fix(build): prefer higher-info relation on same-pair edge collapse - #2397

Open
arimu1 wants to merge 1 commit into
Graphify-Labs:v8from
arimu1:fix/2391-relation-priority-collapse
Open

fix(build): prefer higher-info relation on same-pair edge collapse#2397
arimu1 wants to merge 1 commit into
Graphify-Labs:v8from
arimu1:fix/2391-relation-priority-collapse

Conversation

@arimu1

@arimu1 arimu1 commented Aug 2, 2026

Copy link
Copy Markdown

Summary

Fixes #2391.

build_from_json sorts edges by (source, target, relation) then inserts them into a simple nx.Graph / nx.DiGraph with last-write-wins add_edge. That made alphabetical order the survivor whenever two different relations landed on the same node pair — so references always overwrote calls ("calls" < "references"), silently deleting the higher-information call edge.

This adds a small _RELATION_PRIORITY table so the higher-information relation wins the collapse instead. Unlisted relations score 0 (first-wins), so obscure types do not pick up a new alphabetical bias. Equal priority keeps the first-seen edge, same spirit as the #1061 reverse-direction guard (left intact).

Out of scope (can follow up if wanted):

Test plan

Notes

  • Author: arimu1
  • Platform: macOS (local pytest); CI should cover Linux matrix
  • AI-assisted implementation (Grok 4.5 / Grok Build), human-reviewed

Simple Graph/DiGraph last-write-wins after a deterministic sort by
(source, target, relation) made alphabetical order delete calls when a
references edge shared the same node pair (Graphify-Labs#2391). Prefer higher-
information relations (calls > references, etc.); equal priority keeps
the first-seen edge so Graphify-Labs#1061 direction preservation stays intact.

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

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).


Graphify review — findings

This PR introduces a relation-priority scheme in build_from_json to control which edge survives when a simple Graph/DiGraph collapses parallel edges on the same node pair. It adds a _RELATION_PRIORITY table and _relation_priority helper, and modifies the edge-adding logic so that when two edges share a pair but have different relations, the higher-priority relation is kept instead of relying on alphabetical last-write-wins (covering both undirected and directed cases). New tests in test_build.py exercise these collapse scenarios (e.g., calls vs references, indirect_call vs contains, sole-relation retention, and the directed variant).

Worth a look

  • Undirected reverse-pair branch never applies relation prioritygraphify/build.py:1075 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 804 functions depend on the 202 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: build_from_json() — 146 callers, 15 callees

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

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

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.

Python: calls edges are deterministically deleted by references on the same node pair (alphabetical last-write-wins in build_from_json)

1 participant