Simple-Graph build silently drops 471 of 3178 edges (57 pairs differ in relation type); collapse is only reported after graph.json is written
Environment
- graphifyy 0.9.39, macOS 15, 116-file Python corpus, undirected build (skill default)
What happens
build_from_json produces a simple networkx.Graph, so every additional edge between an already-connected pair is silently dropped. Step 4.5 measures the loss accurately — but only after Step 4 has already written graph.json:
raw_edges: 3425
valid_candidate_edges: 3178
undirected_unique_endpoint_pairs: 2707
undirected_same_endpoint_collapsed_edges: 471
same_endpoint_group_count: 160
relation_variant_groups: 57
source_location_variant_groups: 96
post_build_graph_type: Graph
post_build_edges: 2707
471 edges (~15% of valid candidates) are gone from the artifact, across 160 endpoint pairs. Example from the report:
tests_test_channels_testchannelregistry -> agent_reach_channels_bilibili_bilibilichannel
edges=7 relations=['uses'] locations=['L1198','L1233','L1252','L1266','L1289','L1299','L13']
Seven distinct call sites become one edge with one source_location. And relation_variant_groups: 57 means 57 pairs collapsed edges that did not even share a relation type — a calls and a references between the same two nodes keep only whichever landed first.
Why it matters beyond tidiness
- Weight is lost. "Called from 7 places" and "called once" are the same edge afterwards, so anything ranking by coupling strength (god nodes, betweenness,
suggest_questions) is computed on a flattened graph. - Provenance is lost.
source_locationfor the surviving edge is arbitrary, so "where exactly does A use B" has one answer out of seven, with nothing marking it as partial. - The warning is unactionable as written. It says
graph may be incomplete/corruptafter the fact; there is no flag to re-run without the loss, so the only response is to accept it.
Suggested fix, in order of cost
- Aggregate rather than drop. On collision, keep one edge but set
weight(orcount) to the number of merged edges and carrysource_locationsas a list. No API change for consumers that ignore the extra fields, and the diagnostic drops to zero for the common case. - Do not merge across relation types — those 57 groups are a different fact being discarded, not a duplicate.
- Offer
--multigraphto build aMultiGraph/MultiDiGraphfor users who want every edge. Note #796 and #1606 showexplain/path/merge-graphshave had MultiGraph edge-access bugs before, so this is the expensive option and (1) probably delivers most of the value.
diagnose multigraph already computes everything needed for (1) — the numbers above came straight out of it.
Same bug measured on a directed build, in case the --directed numbers are useful — I hit this via diagnose multigraph on a 110-file Python package (graphifyy 0.9.55, --code-only --no-cluster):
raw_edges: 5663 valid_candidate_edges: 5239
dangling_endpoint_edges: 424
directed_unique_endpoint_pairs: 5061
directed_same_endpoint_collapsed_edges: 178
same_endpoint_group_count: 171 relation_variant_groups: 171
source_file_variant_groups: 0
source_location_variant_groups: 0
context_variant_groups: 0
post_build_graph_type: DiGraph post_build_edges: 5061
178 edges (3.4% of valid candidates) are lost across 171 pairs — and unlike your run, here every one of the 171 is a relation variant: 0 groups differ by file, line or context. So your fix #2 ("do not merge across relation types") would recover all 178 in this corpus, and source_location is never the distinguishing field. Example:
tests_test_api_discovery_tool -> oilwatch_api_discovery_apidiscoverytool
edges=3 relations=['calls', 'references', 'uses'] locations=['L55', 'L56']
(My own scan of the raw JSON agrees with the diagnostic: 172 node pairs carry more than one relation — calls+references ×46, inherits+uses ×38, references+uses ×33.)
One related observation about where the collapse shows up: the MCP server's graph_stats reports Edges: 5663 (the raw count) for this file, so the loss isn't visible through that path at all — only through diagnose multigraph. That same call also reports Nodes: 2613 where the file holds 2538, the difference being exactly the 75 distinct dangling endpoints, which god_nodes filters out but graph_stats appears to count.