Repository navigation
Description
Summary
The per-row source[e] -> $⁚ltm⁚agg⁚{n} runtime link-score series is wrong-signed (and wrong-magnitude) when a hoisted multi-source reducer's body applies a non-unit coefficient to that source. The SUM/MEAN linear-shortcut partial scores each co-source's row as if the reducer body were the bare source element (implicit ∂agg/∂source[e] = 1), ignoring the body's coefficient on that source -- which can be negative.
Repro fixture
grow = 1 + SUM(pop[*] * (1 - weight[*]))
weight[region] = 0.001 * total + 0.01 ; 1 - weight stays positive
total = INTEG(grow, ...) ; stock closing the loop
The reducer SUM(pop[*] * (1 - weight[*])) is hoisted as a multi-source agg: combined_read_slice (src/simlin-engine/src/ltm_agg.rs) accepts pop and weight as co-sources (both axes [Reduced], slices agree), so each gets per-row source[e] -> agg link scores.
The true partial is ∂agg/∂weight[e] = -pop[e] < 0, yet the runtime weight[e] -> agg link-score series is sustained POSITIVE (~ +0.0027). Any loop through the weight -> agg hop gets a wrong-signed runtime score contribution, and runtime polarity reclassification then confirms (rather than corrects) a wrong static label.
Verified pre-existing: identical at ltm-core-batch HEAD a14a6bee and at the branch base (effectively main); NOT a regression of the ltm-core-batch work.
Root cause
emit_source_to_agg_link_scores(src/simlin-engine/src/db/ltm/link_scores.rs, ~line 921; the per-row calls at ~1038/~1054) classifies the agg's reducer viaclassify_reducer(&agg_var, from)and callsgenerate_element_to_scalar_equation/generate_element_to_reduced_equationwith a hardcodedis_bare = true.classify_reducer_in_expr->classify_builtin_if_references_source(src/simlin-engine/src/ltm_augment.rs, ~2955-3015) classifies SUM/MEAN asReducerKind::Linearwhenever the reducer argument references the source anywhere -- it never checks the argument IS the bare source element.generate_linear_partial(ltm_augment.rs, ~3259) then emitsPREVIOUS(agg) + (source[e] - PREVIOUS(source[e]))(MEAN divides by N), i.e. it asserts∂agg/∂source[e] = 1.- The existing
is_bareguard inbuild_element_reducer_link_score(~3214) only covers arithmetic AROUND the reducer (2 * SUM(...)); arithmetic INSIDE the reducer argument is unguarded. ForSUM(pop[*] * (1 - weight[*]))the shortcut is wrong for BOTH co-sources: forweight[e]the true coefficient is-pop[e](sign flip -> wrong-signed series); forpop[e]it is(1 - weight[e])(sign preserved while positive, magnitude wrong).
Why it matters
Medium severity: silent wrong-signed link scores for a legal, hoisted multi-source reducer shape. The wrong sign propagates into every loop score through that hop, and into runtime loop-polarity (re)classification -- the runtime check rubber-stamps a wrong static polarity instead of correcting it.
Possible approaches
- In
emit_source_to_agg_link_scores, detect that the reducer argument is not the bare source reference (an expression over the source / multiple co-sources) and fall back from the linear shortcut to a true ceteris-paribus partial: hold the OTHER co-sources and the other rows offromatPREVIOUSwhilefrom[e]varies (the same selective-PREVIOUS machinerygenerate_nonlinear_partial/build_partial_equation_shapedalready use), instead of the bare-element delta. - Alternatively (cheaper, conservative): extend
classify_reducerto return Linear only when the reducer argument is exactly the bare source subscript expression for THIS source; otherwise treat it like the existing!is_baredelta-ratio fallback. This fixes the sign at the cost of per-row attribution precision. - Either way, a regression test with the fixture above asserting the
weight[e] -> aggseries sign matchesSIGN(-pop[e]).
Cross-references (related, NOT duplicates)
- ltm: loop-score builder's PureScalar fast path never routes a loop through a scalar synthetic agg node (silent zero loop score) #737 -- loop routing through scalar-feeder aggs (routing, fixed on
ltm-bug-batch); this issue is about the per-row partial's VALUE, not routing. - ltm: un-hoisted multi-source iterated-dim-feeder reducer emits silent garbage arrayed loop score (combined_read_slice slice-disagreement carve-out) #743 -- un-hoisted multi-source slice-disagreement carve-out garbage; that one covers reducers that are NOT hoisted; this one covers reducers that ARE hoisted but whose per-row partial mis-attributes.
- ltm: PREVIOUS-captured array-valued non-reducing builtin (RANK) scalarizes into ill-typed stubbed helpers, corrupting link scores #742 -- PREVIOUS-captured array-valued builtin (RANK) corruption; different code path.
- Epic epic: Loops that Matter (LTM) -- open work #488 (Augmentation group).
Discovery context
Identified during adversarial review of the ltm-core-batch branch (out of scope for that batch; filed for tracking).
Activity