Skip to content

Commit cef9f44

Browse files
committed
fix(locate): determinism layer 9 — sort entity-BFS relations before the frontier-limit prefix cut
get_all_relations_for_entity returns adjacency-iteration order (per-process random via hashbrown), so &rels[..frontier_limit] kept a different relation subset each process: different BFS reachability (136 vs 142 multihop files on c5d5fa00), score drift at 1e-4..7e-3, and adaptive-cap set flips between three attractor states. Every other raw signal byte-identical across reps. Sort = the artifact-branch comparator (kind priority, origin priority, id).
1 parent 286b6c4 commit cef9f44

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

crates/kin-cli/src/commands/locate.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6532,7 +6532,21 @@ fn extract_multihop_signals(
65326532
continue;
65336533
}
65346534

6535-
let rels = graph.get_all_relations_for_entity(&current)?;
6535+
let mut rels = graph.get_all_relations_for_entity(&current)?;
6536+
// The frontier cut below keeps a PREFIX, so the order must be
6537+
// deterministic (adjacency iteration order is per-process):
6538+
// highest-priority relations first, id as the total tie-break —
6539+
// mirrors the artifact-branch sort above.
6540+
rels.sort_by(|left, right| {
6541+
let left_kind = resolve_relation_kind_priority(left.kind);
6542+
let right_kind = resolve_relation_kind_priority(right.kind);
6543+
let left_origin = resolve_relation_origin_priority(left.origin);
6544+
let right_origin = resolve_relation_origin_priority(right.origin);
6545+
right_kind
6546+
.cmp(&left_kind)
6547+
.then_with(|| right_origin.cmp(&left_origin))
6548+
.then_with(|| format!("{:?}", left.id).cmp(&format!("{:?}", right.id)))
6549+
});
65366550
// Frontier size limit: only process up to frontier_limit relations per BFS level
65376551
let rels_to_process = if rels.len() > frontier_limit {
65386552
&rels[..frontier_limit]

0 commit comments

Comments
 (0)