You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ltm: assign_loop_ids relies on HashMap iteration order for multidigraph sibling cycles #497
After PR #494 (canonical edge-sequence dedup, fixes #308) lands, two distinct directed cycles over the same node set are correctly retained as separate loops. However, assign_loop_ids in src/simlin-engine/src/ltm.rs (around line 985) uses only the deduped variable set as its sort key. Two siblings like `a -> b -> c -> a` and `a -> c -> b -> a` therefore have identical sort keys, and the stable-sort fallback preserves whatever order Johnson's enumerator emitted them in -- which depends on `HashMap` iteration order in `IndexedGraph::from_edges`.
Why this matters
Within a single process the order is deterministic (Rust's `HashMap` randomizes per-process via DefaultHasher). Across processes, the same model can yield `r3` for the forward 3-cycle in one run and `r3` for the reverse 3-cycle in the next. Any downstream consumer that keys on loop IDs (model snapshots, persisted UI state, deterministic tests) sees flapping IDs for siblings.
PR #494's stability discussion only addresses rotations of a single cycle, not the new sibling-pair case the canonical-rotation dedup introduces.
Proposed fix
Extend the sort key on `assign_loop_ids` with a secondary tiebreaker: the canonical edge-sequence rotation of the loop's link list. Siblings differ on this, so the secondary key fully orders them. The primary key (deduped variable set) is unchanged so existing single-direction cycles keep their stable IDs.
Discovery context
Surfaced in the codex review pass on PR #494 after the canonical-rotation dedup landed. Confirmed independently by the post-#494 review thread.
Severity
medium (silent cross-process nondeterminism on multidigraph models; no incorrect simulation output, but breaks ID stability for any model containing reverse-direction cycle pairs)
Component
simlin-engine -- `src/simlin-engine/src/ltm.rs::assign_loop_ids` (post-#494; will move to `src/simlin-engine/src/ltm/graph.rs` after the module-split refactor lands)
Fixed in PR #668 (merged as f9f850d). Both assign_loop_ids sites (ltm/graph.rs exhaustive/tiered/element-level path and ltm_finding.rs discovery path) extend the sort key to (variable_set, canonical_edge_sequence) — the same canonical-rotation key the #308/#494 dedup guarantees unique per loop — so multidigraph sibling cycles order by content, never by HashMap emission order. The primary key is byte-identical to before, so existing single-direction loops keep their IDs. Pinned by assign_loop_ids_is_order_independent_for_sibling_cycles (red-verified: reversing input flipped u2/u3 pre-fix), the discovery twin, and an end-to-end arms-race fixture.
Activity
LTM hardening: close out the top tracked gaps from epic #488 (#668)
bpowers commentedon Jun 2, 2026
Fixed in PR #668 (merged as f9f850d). Both assign_loop_ids sites (ltm/graph.rs exhaustive/tiered/element-level path and ltm_finding.rs discovery path) extend the sort key to (variable_set, canonical_edge_sequence) — the same canonical-rotation key the #308/#494 dedup guarantees unique per loop — so multidigraph sibling cycles order by content, never by HashMap emission order. The primary key is byte-identical to before, so existing single-direction loops keep their IDs. Pinned by assign_loop_ids_is_order_independent_for_sibling_cycles (red-verified: reversing input flipped u2/u3 pre-fix), the discovery twin, and an end-to-end arms-race fixture.