Repository navigation
Description
Summary
build_loops_from_tiered (src/simlin-engine/src/db/ltm/loops.rs) never routes a pure-scalar feedback loop through a scalar synthetic aggregate node, so a loop whose path passes through a scalar feeder of a hoisted reducer (with a scalar target) gets a loop score composed from a direct variable-level link that skips the agg hop -- and that direct link has no link-score variable, so the loop score silently reads 0.
Concretely, for
total = SUM(pop[*] * scale) // pop arrayed, scale/total scalar
scale = f(grow)
grow = f(total) // closes the loop: total -> grow -> scale -> total
the reducer SUM(pop[*] * scale) is hoisted into a scalar synthetic agg $⁚ltm⁚agg⁚0, and (after the #533 element-graph fix on branch ltm-bug-batch, commit 189e7d05) the element graph correctly contains scale → $⁚ltm⁚agg⁚0 → total. But the loop-score builder never consumes that routing for this cycle:
- The variable-level circuit
total → scale → grow → totalclassifies as PureScalar, sobuild_loops_from_tieredtakes the fast path: it materializes theLoopstraight from the variable-level circuit viavar_graph.circuit_to_links(&var_level_nodes), producing a directscale → totallink. - The cross-element-through-aggregate recovery (
recover_cross_agg_loops) -- the only machinery that knows how to splicefrom → $⁚ltm⁚agg⁚{n} → tohops into a loop's link chain -- runs only on the slow / cross-element path, which a PureScalar cycle never reaches.
Consequence
The feedback loop is enumerated (no crash, model compiles and simulates), but its loop score is composed from the scale → total link, for which no link-score variable exists / whose chain skips the agg hop -- so the loop score is silently 0. Silent zero loop score for any scalar loop routed through a reducer aggregate with a scalar target.
This is pre-existing and independent of #533's element-graph fix: verified identical behavior with and without that fix, since the element-graph edge the fix adds is never consumed by the PureScalar loop-builder path.
Severity
Medium -- silent wrong (zero) loop score for a valid and not-exotic pattern (a scalar control variable feeding a reduced aggregate, e.g. share/total structures with a scalar gain in the loop).
Components affected
src/simlin-engine/src/db/ltm/loops.rs--build_loops_from_tiered(PureScalar fast-path materialization viacircuit_to_links),recover_cross_agg_loops(the agg-hop splicing that the fast path never invokes)
Characterization test
src/simlin-engine/tests/integration/ltm_array_agg.rs::scalar_feeder_scalar_target_loop_compiles_and_is_well_formed pins the current behavior end-to-end (compiles, simulates, loop enumerated, score 0) and documents this gap as item (2) in its doc comment.
Related / sibling gap
The same test documents a sibling gap, item (1): the scalar-target synthetic agg $⁚ltm⁚agg⁚0 for SUM(pop[*] * scale) itself currently fails to compile and is stubbed to constant 0 with an Assembly warning (an agg-augmentation gap, distinct from this loop-builder gap). That is being filed separately; even once it is fixed, this loop-builder gap independently keeps the loop score at 0. Cross-link the two issues once both exist.
Possible approaches
- When a PureScalar (or any fast-path) circuit contains a variable-level link whose reference-site IR routes
ThroughAgg, don't materialize the direct link fromcircuit_to_links; instead splice thefrom → $⁚ltm⁚agg⁚{n} → tohop into the link chain (the same substitutionrecover_cross_agg_loopsperforms on the slow path), so the loop score composesscore(scale→agg) * score(agg→total). - Alternatively, classify a variable-level cycle that traverses a
ThroughAggsite as not pure-scalar for loop-building purposes, sending it down the slow path where the existing agg recovery already works. - Longer-term this is another instance of the ltm: unify the element-graph and link-score reference-site walkers behind a single classification IR #520 theme (all consumers should read agg routing from the unified classification IR rather than re-deriving structure from the raw variable graph).
Discovery context
Identified during work on #533 (branch ltm-bug-batch, commit 189e7d05 -- the element-graph both-scalar fast-path fix), when constructing the scalar-target end-to-end test: with the element edge fixed, the loop score was still 0, and bisection showed the loop-score builder never consults the agg routing on the PureScalar path.
Tracking
Part of LTM tracking epic #488. Related: #533 (element-graph counterpart of the same scalar-feeder/scalar-target scenario), #516 (closed; agg-hop polarity in recover_cross_agg_loops), #520 (closed; unified reference-site IR that a principled fix would lean on), #273 (LTM array-support umbrella).
Activity
ltm: scoring-correctness and visibility batch from epic #488 (#775)