Repository navigation
Description
Summary
In module_link_score_equation (src/simlin-engine/src/db.rs ~line 693; the module -> variable arm at ~lines 808-816), the live module-output reference for the ceteris-paribus partial is selected by iterating a HashSet:
let from_output = to_var
.ast()
.map(|ast| crate::variable::identifier_set(ast, &[], None))
.and_then(|deps| {
let prefix = format!("{from_name}\u{00B7}");
deps.into_iter()
.find(|d| d.as_str().starts_with(&prefix))
.map(|d| d.to_string())
});crate::variable::identifier_set returns HashSet<Ident<Canonical>> (src/simlin-engine/src/variable.rs ~line 1196), and Rust's HashSet iteration order is randomized per process (DefaultHasher seeding). For a target variable whose equation reads TWO (or more) outputs of the same module instance (e.g. y = mod\u{00B7}out1 + mod\u{00B7}out2), .find() picks whichever {from}\u{00B7}-prefixed dependency happens to come first, so WHICH output is held live in the LTM partial link-score equation for the mod -> y edge is arbitrary and can vary run-to-run.
Why it matters
- Determinism / salsa caching: the selected output ref feeds
generate_link_score_equation_for_linkand hence the generated equation text; salsa cache values should be byte-stable across processes. This site can produce different equation text (and different fallbackblack_box_unit_transfer_equationreferences on the Err path) for the same model in different processes. - Reproducible link scores: the two outputs generally have different partials, so the
mod -> ylink score series itself (not just its text) can differ run-to-run, flapping loop scores and dominance analysis downstream.
Single-output module reads (the common case, all stdlib SMOOTH/DELAY usage) are unaffected, which is why this has gone unnoticed.
Distinct from the closed #680, which fixed the unordered output-port set in find_model_output_ports / enumerate_pathways_to_outputs (src/db/ltm/loops.rs); this is a separate site in db.rs's module_link_score_equation. Also distinct from #595 (init runlist ordering).
Component(s) affected
src/simlin-engine/src/db.rs(module_link_score_equation, module -> variable arm)
Possible approaches
- Collect the
{from}\u{00B7}-prefixed deps and pick deterministically, e.g.deps.into_iter().filter(...).min()(lexicographically smallest canonical ident), or sort into aVec/BTreeSetbefore selecting. - Better still, consider whether a target reading multiple outputs of the same instance should get one partial per output (or a combined partial holding all
{from}\u{00B7}refs live) rather than singling out one; at minimum the selection should be stable. - Add a regression test with a two-output module read twice by one target, asserting stable generated equation text across repeated db builds.
Severity
Minor -- reachable only when one variable reads multiple outputs of the same module instance; latent determinism gap otherwise.
Context
Identified during a 2026-07-17 LTM design review. Tracking epic: #488. Related (different sites): #680 (closed), #595.
Activity