Repository navigation
Description
Found while working on
#1936 / #2593 — while looking for a weight signal worth feeding to the now weight-aware native Leiden binding.
The gap
A function that calls another once and one that calls it thirty times produce an identical edge, everywhere. This is not a graph-builder artifact that could be recovered downstream — the information never reaches the database.
idx_edges_content_unique (#2072) is a UNIQUE index over (source_id, target_id, kind, confidence, dynamic, COALESCE(dynamic_kind,''), COALESCE(technique,'')), so duplicate rows are impossible in both engines. Measured on this repo's own graph:
| rows | distinct pairs | max multiplicity | |
|---|---|---|---|
calls |
10712 | 10711 | 2 |
imports |
2139 | 2139 | 1 |
The single pair with 2 rows is two different resolution techniques on the same pair, not two call sites.
buildDependencyGraph compounds this cosmetically — both builders guard with if (!graph.hasEdge(...)) — but removing that guard would change nothing, because the rows it would be accumulating do not exist.
Why it matters
Coupling strength is the natural weight for several existing analyses, and none of them can have it:
- community detection — Leiden now reads per-edge weights natively (feat(communities): native Leiden reads per-edge weights #2593), but there is no multiplicity to feed it
- triage / risk ranking — a hot 30-call edge and a single incidental call contribute equally to fan-in
- impact / blast radius — same flattening
Suggested fix
Add a count column rather than storing one row per call site (which would multiply the edges table and defeat the unique index that exists for good reason):
- Migration adding
call_count INTEGER NOT NULL DEFAULT 1toedges. - Full-build path (
stages/build-edges.ts) and incremental path (builder/incremental.ts) increment it on the conflict instead of ignoring the duplicate — plus the mirrored Rust modules, since both engines insert edges. - Expose it on
CallEdgeRow/ImportGraphEdgeRow(and theNative*mirrors) so graph builders can read it. - Set it as the edge
weightinbuildDependencyGraphand re-measure community quality — the methodology and numbers to beat are in Extend native Leiden port to cover full LeidenOptions surface (directed, CPM, weights, candidate strategies) #1936's closing comment (file-level directory purity 0.7771, function-level 0.9647).
Note on expected value
Worth measuring before assuming it helps. Confidence-weighting was the analogous experiment and came out neutral-to-slightly-worse (see #1936). Multiplicity has a much wider natural spread than confidence does, so it is a better candidate — but it should be held to the same measured bar rather than enabled on the assumption.
Activity