Carry call-site counts on call edges (callers ≠ call sites)
Problem. Edges are deduplicated per caller function: a function that calls a helper 5 times shows as one edge. For impact analysis ("change this signature — how many places do I touch?") the call-site count is the number that matters. Example from our repo: 186 caller functions vs 303 actual call sites for one security helper — the difference had to come from grep.
Proposal. Store an occurrence count (and ideally line numbers) per call edge during AST extraction, and surface it in explain output (e.g. <-- foo() [calls x3]) and any JSON export. Tree-sitter already visits every call expression, so the data exists at extraction time.
Environment. graphifyy 0.8.36, code-only graph (tree-sitter, no LLM pass), PHP/JS repo.
Still the case on 0.9.57, with a minimal repro and a pointer to where the count is lost.
Repro
src/components/Widget.tsx
export function Widget({ label }: { label: string }) { return <span>{label}</span>; }
export function helper(n: number): number { return n + 1; }
src/screens/Home.tsx
import { Widget, helper } from '../components/Widget';
function Widget() { return <div>local</div>; }
export function HomeScreen(flag: boolean) {
const a = flag ? helper(1) : helper(2);
const jobs = [];
if (flag) jobs.push(helper(3));
return a + jobs.length;
}
git init && git add -A && git commit -m init && GRAPHIFY_FORCE=1 graphify update . --force
HomeScreen calls helper three times (lines 8, 8 and 10). The graph holds one calls edge, anchored at the first site:
$ graphify explain helper --graph graphify-out/graph.json
Connections (3):
<-- Home.tsx [imports] [EXTRACTED] src/screens/Home.tsx:L1
<-- Widget.tsx [contains] [EXTRACTED] src/components/Widget.tsx:L4
<-- HomeScreen() [calls] [EXTRACTED] src/screens/Home.tsx:L8
In graph.json that edge has weight: 1.0 and source_location: "L8"; nothing says there were three sites.
Where it is lost
build.dedupe_edges collapses on (source, target, relation), first-wins, and its docstring calls the collapse "zero-signal-loss". Connectivity is preserved; multiplicity is not. The clustered path collapses the same way through NetworkX DiGraph, so it is not specific to --no-cluster or incremental updates.
diagnostics.py already computes exactly the missing data for its duplicate-edge report (edge_count, source_locations per directed pair), so the shape exists in the codebase.
Related: #2849 measures the same mechanism at scale on a TypeScript monorepo ("same-endpoint collision": several edge records share an ordered source and target, the graph stores one), from the angle of lost distinct relationships rather than lost call counts.
A backwards-compatible shape
Keep one edge per (source, target, relation) so nothing downstream changes, and when edges collapse set occurrences: N (default 1) and source_locations: [...] on the survivor, then render [calls ×3] ...:L8,L10 in explain. weight already means something to clustering, so a separate field seems safer than overloading it. Extractors that emit one edge per (caller, callee) pair could count at emission time as well, which gives the number even where no dedup runs.
A real case this week: three call expressions in one block (two arms of a ternary plus a queued job) showed as one edge, and a reviewer counting edges to size a change undercounted by two at the exact spot under review.
Version: graphify 0.9.57 (graphifyy on PyPI), Python 3.12.3, Linux.