Repository navigation
Description
Summary
In emit_agg_to_target_link_scores (src/simlin-engine/src/db/ltm/link_scores.rs, ~lines 1135-1142), when the target equation hoists two or more distinct reducers (e.g. x = SUM(a[*]) / SUM(b[*])), the agg→target partial for agg A holds A live and freezes every OTHER hoisted agg B by inserting B's name into all_deps so it gets PREVIOUS-wrapped (ceteris paribus):
// When `to` hoists 2+ reducers (e.g. `x = SUM(a[*]) / SUM(b[*])`), the
// substituted equation text references *every* agg name, not just the
// one this link starts from. The other aggs must be in `all_deps` so
// they get PREVIOUS-wrapped (ceteris paribus) -- otherwise they are
// left live and the agg→target link score collapses to ±1.
for other_agg in reducer_subst.values() {
all_deps.insert(Ident::<Canonical>::new(other_agg));
}But B is referenced bare in the per-target-element scalar partial: deps_to_subscript only pins deps found in source_vars (synthetic $⁚ltm⁚agg⁚{n} names are not model variables, so the filter never matches them), and the projection machinery added for the live agg (agg_pin_for_target → source_pin_element, commit bce4aa4c; and agg_source_ref_for_target → source_ref_override for the denominator) applies only to agg A -- the link's own agg -- never to a co-occurring agg B.
When B is arrayed (result_dims non-empty), PREVIOUS(B) with a bare B is a multi-slot reference in a scalar equation -- ill-typed, the same class as #528's two halves:
- the live agg's equation-body pin (fixed in
bce4aa4cviasource_pin_element), - the live agg's Δsource denominator (fixed via
source_ref_override),
but for the frozen co-agg rather than the live one. The fragment fails to compile and is silently stubbed to constant 0 (with an Assembly Warning via model_ltm_fragment_diagnostics), zeroing the agg→target half for every link through that target.
Reach
Latent -- NO current fixture or model reaches it. It requires two distinct arrayed sliced reducers in one target equation, e.g.
to[D1] = SUM(m1[D1,*]) + SUM(m2[D1,*])
(AST-identical reducer subexpressions dedupe to one AggNode by canonical equation text, so the reducers must differ; each then mints its own arrayed agg over [D1], and each agg's partial references the other bare.) Two arrayed whole-extent reducers (SUM(a[*]) / SUM(b[*]) with a scalar target) are fine -- both aggs are scalar there. The scalar-co-agg case is also fine (a bare scalar reference compiles).
Why it matters
Correctness when reached: a silent-0 link-score stub (an Assembly Warning is the only signal), corrupting every link and loop score routed through the target's aggs. Low severity today because the topology is unexercised, but the multi-reducer freeze comment above was added precisely because real equations combine reducers, and the arrayed-reducer variant is one dimension declaration away.
Components affected
src/simlin-engine/src/db/ltm/link_scores.rs--emit_agg_to_target_link_scores(thereducer_substother-agg freeze at ~1135-1142; the projection clusteragg_pin_for_target/agg_source_ref_for_targetat ~1187-1238 that the fix mirrors).src/simlin-engine/src/ltm_augment.rs--generate_scalar_to_element_equation/build_partial_equation_shaped(source_pin_elementcurrently pins exactly one ident -- the live source; freezing co-aggs needs the same per-ident slot projection on the PREVIOUS-wrapped side).
Possible approach
Mirror the bce4aa4c fix shape for each OTHER agg B with non-empty result_dims: compute B's result_dim_positions within to's dims and project the target element tuple onto B's axes (exactly what agg_pin_for_target does for the live agg), then pin B's reference in the per-target-element partial to PREVIOUS(B[<projected slot>]) instead of PREVIOUS(B). The plumbing change is generalizing the single source_pin_element: Option<String> into a per-ident pin map (or invoking the pin machinery once per arrayed agg in the equation), since today only one ident can carry a projected pin.
A characterization test should mint the two-distinct-arrayed-reducers fixture above and assert the agg→target fragments compile (no constant-0 stub / no Assembly Warning).
Discovery context
Identified as a latent pre-existing gap during the GH #528 fix on branch ltm-core-batch (commit bce4aa4c, "engine: project agg pin in broadcast agg-to-target score") -- the live-agg pin and denominator both needed the result_dims projection, and the review noted the frozen co-agg reference has the identical shape problem but was out of scope for #528.
Tracking
Part of LTM tracking epic #488. Related: #528 (the live-agg halves of the same projection problem; this is the frozen-co-agg third), #738 (a different agg fragment-compile-failure-to-stub topology), #741 (the silent-stub diagnostics gap on the implicit-helper leg).
Activity