Repository navigation
Description
Problem
compute_rel_loop_scores in src/simlin-engine/src/ltm_post.rs (lines 139-153) computes each loop's relative loop score by normalizing the loop's loop_score series against a per-cycle-partition denominator: the sum of absolute loop scores across every loop in that partition, at each timestep.
for row in results.iter() {
for indices in partition_groups.values() {
let denom: f64 = indices
.iter()
.filter_map(|&i| offsets[i].map(|off| row[off].abs()))
.sum();
for &i in indices {
let Some(off) = offsets[i] else { continue };
let num = row[off];
let val = if denom == 0.0 { 0.0 } else { num / denom };
series[i].push(val);
}
}
}If any single loop in a partition has a NaN loop_score at a timestep, that NaN flows into the .sum(), so denom becomes NaN at that timestep. The SAFEDIV-0 guard is denom == 0.0, and NaN == 0.0 is false, so the guard does not fire -- every loop in that partition then gets num / NaN == NaN as its relative score at that step. One bad loop poisons the entire partition's relative scores for that timestep.
The sibling function compute_rel_loop_scores_per_element (same file) has the identical structure per (partition, slot) bucket; its rustdoc explicitly states "SAFEDIV-0 and NaN propagation match compute_rel_loop_scores", so the same poisoning applies bucket-wide there.
By contrast, the discovery path discover_loops_with_graph (src/simlin-engine/src/ltm_finding.rs) handles per-link NaN gracefully -- so the post-simulation relative-score computation is the weak link in NaN resilience.
Note: compute_rel_loop_scores's own rustdoc (ltm_post.rs ~lines 96-99) currently frames this non-finite propagation as intentional -- "Non-finite loop_score values ... propagate through normal IEEE-754 arithmetic, matching the behaviour of the removed SAFEDIV equation." That phrasing only means the post-simulation refactor preserved the old synthetic-equation semantics bug-for-bug; the removed SAFEDIV equation never promised NaN-resilience either (SAFEDIV only guards a zero denominator), so this is a latent flaw carried forward, not a deliberate design choice. Whoever fixes the guard must update that rustdoc -- and the matching "SAFEDIV-0 and NaN propagation match compute_rel_loop_scores" note on compute_rel_loop_scores_per_element -- in the same change.
Why it matters
- Correctness: a localized numerical problem (one loop's
loop_scoregoing non-finite -- e.g. from a division orsqrtin a ceteris-paribus partial, or an arrayed edge that degrades) silently corrupts the relative scores of every other loop sharing the cycle partition, not just the affected loop. Relative loop score drives loop-dominance ranking, so a single poisoned loop can blank out the ranking for an entire partition. - Consistency: the discovery path tolerates per-link
NaN, so the two LTM paths disagree onNaNhandling for the same underlying model condition.
Component(s) affected
src/simlin-engine/src/ltm_post.rs--compute_rel_loop_scores(lines ~139-153) andcompute_rel_loop_scores_per_element(samedenom == 0.0guard pattern)
Possible fix directions (not yet implemented)
- Treat a non-finite denominator as the SAFEDIV-0 case:
if !denom.is_finite() { 0.0 } else { num / denom }(ordenom == 0.0 || !denom.is_finite()). Simple, but lumpsNaN-poisoning in with the legitimate all-zero partition. - Exclude non-finite summands from the partition sum (
.filter(|v| v.is_finite())), so a healthy loop in the partition still normalizes against the healthy loops. This isolates the bad loop instead of zeroing the whole partition. The bad loop's own numerator is stillNaN, so its own relative score staysNaN-- which is arguably the correct signal for that one loop. - Pick whichever matches the intended SAFEDIV/
NaNsemantics elsewhere in LTM; whichever is chosen, apply it identically to both functions and add a regression test with a fixture where one loop in a multi-loop partition produces aNaNloop_score.
Discovery context
Identified during an LTM-subsystem review pass (one of a batch of LTM-review findings being filed). This is the post-simulation relative-score NaN-poisoning finding specifically. Part of epic #488.
Activity
[-]ltm: a single NaN loop_score poisons every rel_loop_score in its cycle partition[/-][+]ltm-post: a single NaN loop_score poisons every rel_loop_score in its cycle partition[/+]LTM hardening: close out the top tracked gaps from epic #488 (#668)
bpowers commentedon Jun 2, 2026
Fixed in PR #668 (merged as f9f850d). All four partition-sum sites in ltm_post.rs route summands through denom_summand: NaN summands are excluded (matching the discovery path's philosophy) so healthy loops normalize against the healthy denominator and only the bad loop's own score reads NaN; Inf is deliberately retained (real dominance-inflection signal, bug-for-bug with the removed SAFEDIV equations). Rustdoc updated on all affected functions. Pinned by nan_loop_score_isolated_to_its_own_loop (red-verified — the old test pinned the poisoning), the per-element twin, Inf-semantics tests, and streaming-helper parity tests.
engine: disclose and pin the LTM omission's non-finite value change