Skip to content

Commit 909e1df

Browse files
committed
fix(wasm): sort call targets by confidence before emit to match native engine
1 parent 184d221 commit 909e1df

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

src/domain/graph/builder/stages/build-edges.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,6 +1107,19 @@ function buildFileCallEdges(
11071107
}
11081108
}
11091109

1110+
// Sort targets by confidence descending before emitting edges.
1111+
// For multi-target calls with duplicate (source_id, target_id) pairs the
1112+
// stored confidence depends on which duplicate is processed last — sorting
1113+
// here guarantees the highest-confidence target wins on dedup, matching the
1114+
// native engine's sort_targets_by_confidence call in build_edges.rs.
1115+
if (targets.length > 1) {
1116+
targets = [...targets].sort(
1117+
(a, b) =>
1118+
computeConfidence(relPath, b.file, importedFrom ?? null) -
1119+
computeConfidence(relPath, a.file, importedFrom ?? null),
1120+
);
1121+
}
1122+
11101123
for (const t of targets) {
11111124
const edgeKey = `${caller.id}|${t.id}`;
11121125
if (t.id !== caller.id) {

0 commit comments

Comments
 (0)