Repository navigation
Description
Summary
A cross-element feedback loop that runs through a hoisted reducer (a synthetic $⁚ltm⁚agg⁚{n} aggregate node) visits the agg node more than once -- e.g. pop[a] → agg → pop[b] → agg → pop[a] -- so it is not an elementary circuit and Johnson never emits it. recover_cross_agg_loops (in src/simlin-engine/src/db_ltm.rs:2712) reconstructs these by combining k ≥ 2 pairwise-disjoint "petals" -- agg → … → agg segments extracted from the agg-touching elementary circuits. Two combinatorial trade-offs in that recovery:
1. MAX_AGG_PETALS = 8 caps the recovery -- and drops, doesn't truncate
recover_cross_agg_loops does (src/simlin-engine/src/db_ltm.rs:2768):
if petals.len() < 2 || petals.len() > MAX_AGG_PETALS { continue; }MAX_AGG_PETALS is 8 (db_ltm.rs:2697). So a reducer in a feedback loop over a dimension with more than 8 elements gets zero cross-element-through-agg loops recovered for that agg -- not a truncated subset, none. The same-element-through-agg loops (pop[a] → agg → pop[a]) and the agg-touching elementary circuits themselves are still present; it's the genuinely-cross-element ones that are silently dropped.
2. For the ≤8 case, only one ordering per ≥2-element subset is enumerated
For k petals, the recovery iterates 2^k bitmasks and emits one loop per ≥2-bit mask -- 2^k - k - 1 loops (≈247 at k=8). That's one cyclic concatenation order per ≥2-element subset, not all distinct cyclic orderings of that subset. For k ≥ 3 this under-enumerates: pop[a]→agg→pop[b]→agg→pop[c]→agg→… and pop[a]→agg→pop[c]→agg→pop[b]→agg→… are genuinely different loops (different link sets, potentially different scores) but only one of them is recovered. The doc comment on MAX_AGG_PETALS already says "≤ 219 recovered loops per agg" -- it knowingly enumerates subsets, not orderings.
Why this matters
Silent incompleteness in cross-element loop discovery whenever a reducer (SUM/MEAN/…) sits inside a feedback loop over a large-ish (>8-element) dimension: the cross-element loops through that aggregate that LTM would surface for ≤8 elements simply don't appear, and even at ≤8 elements with k ≥ 3 some orderings are missed. The elementary circuits and same-element loops are unaffected, so this degrades gracefully -- but a model author looking at the loop list won't know loops are missing.
Both are acknowledged trade-offs (there are explanatory comments at MAX_AGG_PETALS and inside recover_cross_agg_loops). The combinatorics are real: 2^k masks already, and "all cyclic orderings of all subsets" is sum over m of C(k,m) * (m-1)!/2 which blows up fast.
Possible approaches
- For the cap: raise it (the constant is a knob), or switch from a hard cutoff to a budgeted enumeration (emit the highest-fan-in petals first up to a loop budget, mark the result truncated -- mirroring how the element-graph auto-flip backstop handles dense graphs), so a >8-element reducer-in-a-loop gets some cross-element loops rather than none.
- For the ordering gap: only matters for
k ≥ 3with petals that have genuinely different link sets; if the per-element link scores for different orderings differ, enumerate cyclic orderings (Heap's algorithm over the chosen petal subset, fixing the first to kill rotations and skipping mirror reversals) instead of just subsets -- bounded by the same loop budget. - If neither is worth the combinatorial cost, document the limitation in the user-facing LTM reference (a reducer-in-a-feedback-loop over a wide dimension has incomplete cross-element loop coverage) so it isn't a silent surprise.
Locations
src/simlin-engine/src/db_ltm.rs:2697--const MAX_AGG_PETALS: usize = 8src/simlin-engine/src/db_ltm.rs:2712--recover_cross_agg_loops(petal extraction, thepetals.len() > MAX_AGG_PETALScutoff at line 2768, the2^k-bitmask subset enumeration starting line 2772)src/simlin-engine/src/db_ltm.rs:2683-- the call site (recover_cross_agg_loops(&circuit_strs, var_graph, source_vars, db, project))
Discovery context
Identified during code review of Phase 5 ("reducer hoist / aggregate nodes") of the "LTM Cross-Element Aggregate Scoring" implementation plan (branch ltm-503-cross-element-agg; design plan under docs/implementation-plans/2026-05-09-ltm-503-cross-element-agg/). Acknowledged combinatorial trade-offs, not a Phase 5 blocker.
Tracking
Part of LTM tracking epic: #488. Related to the LTM array-support umbrella #273.
Activity
engine: LTM cross-element aggregate scoring (aggregate nodes) (#519)
doc: add LTM arrays hardening design plan
bpowers commentedon May 13, 2026
Resolved by b4eac79, 2dbd658, 6a63d5b — Phase 5 of the LTM arrays hardening plan (docs/design-plans/2026-05-11-ltm-arrays-hardening.md).
recover_cross_agg_loopsdrops theMAX_AGG_PETALS = 8hard drop for a deterministic petal priority + a threaded model-wide loop-count budget (MAX_CROSS_AGG_LOOPS = 256,#[cfg(test)]-overridable;MAX_AGG_PETALSsurvives as a soft per-agg petal cap), surfaces truncation onLtmVariablesResult.agg_recovery_truncated+ aWarningnaming the truncated aggs, and enumerates each disjoint petal subset's distinct cyclic orderings (cyclic_orderings(m)— (m-1)!/2 for m≥3, mirror reversals skipped, via Heap's algorithm) instead of one ordering per subset.