Skip to content

ltm: loop-score builder's PureScalar fast path never routes a loop through a scalar synthetic agg node (silent zero loop score) #737

Closed

Description

@bpowers

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 → total classifies as PureScalar, so build_loops_from_tiered takes the fast path: it materializes the Loop straight from the variable-level circuit via var_graph.circuit_to_links(&var_level_nodes), producing a direct scale → total link.
  • The cross-element-through-aggregate recovery (recover_cross_agg_loops) -- the only machinery that knows how to splice from → $⁚ltm⁚agg⁚{n} → to hops 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 via circuit_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 from circuit_to_links; instead splice the from → $⁚ltm⁚agg⁚{n} → to hop into the link chain (the same substitution recover_cross_agg_loops performs on the slow path), so the loop score composes score(scale→agg) * score(agg→total).
  • Alternatively, classify a variable-level cycle that traverses a ThroughAgg site 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

  1. added
    ltm
    on Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ltm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions