Repository navigation
Description
Summary
In non-discovery (exhaustive) LTM mode, an LTM link score whose target is a stdlib-macro module instance (SMTH1/SMTH3/DELAY1/DELAY3/TREND/NPV/...) is generated as a composite-reference equation -- "{module}·$⁚ltm⁚composite⁚{port}" -- but that fragment fails to compile in compile_ltm_equation_fragment, so assemble_module silently drops it. The synthetic link-score variable keeps its layout slot, no bytecode writes it, and it reads a constant 0 for the entire simulation. Because the loop score for any loop through that macro is the product of its link scores, the whole loop score collapses to 0.
Net effect: in exhaustive mode, any feedback loop that passes through a stdlib macro (SMOOTH/DELAY/TREND/NPV) gets a silently-zero loop score.
This is the same hazard class as #546 (empty tables map -> link scores into graphical-function targets stub to 0) and the arrayed flow-to-stock link score that originally motivated model_ltm_fragment_diagnostics -- "the fragment compiler can't handle a particular target shape, the var stubs to 0, the model still simulates, so the degraded score masquerades as correct" -- but the root cause here is distinct from #546 and is currently untracked.
Root cause (traced)
The link level → $⁚smoothed_level⁚0⁚smth1 (level a stock, target the implicit SMTH1 module instance) takes the !from_is_module && to_is_module branch in link_score_equation_text_shaped (src/simlin-engine/src/db_ltm.rs ~lines 342-393). level is found in the module's inputs, and since we are not in discovery mode it emits the composite-reference form (db_ltm.rs ~lines 358-364):
format!(
"\"{module}\u{00B7}$\u{205A}ltm\u{205A}composite\u{205A}{port}\"",
module = to_ident.as_str(), // "$⁚smoothed_level⁚0⁚smth1"
port = input.dst.as_str(), // "input"
)-> equation text "$⁚smoothed_level⁚0⁚smth1·$⁚ltm⁚composite⁚input".
This references a synthetic composite-score variable that lives inside the LTM-augmented submodel. The full assembly path (assemble_module, src/simlin-engine/src/db.rs ~lines 2098-2126 generate it, ~3712 resolves module·var deps) does arrange for the submodel to be LTM-augmented, so the composite var $⁚ltm⁚composite⁚input genuinely exists in the final layout (verified: the slot is allocated). But the standalone fragment compiler compile_ltm_equation_fragment (db_ltm.rs ~line 557) cannot resolve a module·$⁚ltm⁚composite⁚port dependency: when it builds the Variable::Module for the dependency and registers implicit_submodels, the submodel it reconstructs is the un-LTM-augmented stdlib⁚smth1, which has no $⁚ltm⁚composite⁚input variable. The dep is unresolvable, the fragment fails to compile, assemble_module drops it, and the var is a constant 0.
compile_ltm_synthetic_fragment dispatches this case -- a scalar link score with no element subscript, no synthetic-agg endpoint, and compile_directly: false -- to the salsa-cached (from, to)-keyed compile_ltm_var_fragment path (not compile_direct()); that path re-derives the equation via the legacy link_score_equation_text (whose module-target branch emits the same composite-reference form) and then calls compile_ltm_equation_fragment. Either way the failure surfaces inside compile_ltm_equation_fragment.
Verified behavior (probe on build_smooth_loop_with_failing_fragment)
For the fixture build_smooth_loop_with_failing_fragment in src/simlin-engine/src/db_ltm_unified_tests.rs (level -> smoothed_level (SMTH1) -> gap -> adjustment -> level), with ltm_enabled = true, exhaustive mode:
$⁚ltm⁚link_score⁚level→$⁚smoothed_level⁚0⁚smth1: equation"$⁚smoothed_level⁚0⁚smth1·$⁚ltm⁚composite⁚input",compile_ltm_synthetic_fragment-> fails to compile (flow_bytecodes: None).- Full project compile succeeds and the variable gets an offset slot.
- In the actual simulation the link score is
[0.0, 0.0, 0.0, ...](constant 0) --assemble_modulesilently dropped the fragment. - Consequently
$⁚ltm⁚loop_score⁚b1(the product of all five link scores in the loop) is also constant 0 -- even though the other four link scores compute fine. - The submodel
stdlib⁚smth1, when LTM-augmented, does carry$⁚ltm⁚composite⁚inputand$⁚ltm⁚composite⁚delay_time-- i.e. the referenced variable is real; only the standalone fragment compile can't see it.
Discovery mode is unaffected
In discovery mode the same link routes through black_box_delta_ratio_equation instead, which references $⁚smoothed_level⁚0⁚smth1·output -- the module's real output port -- and that compiles fine (verified: flow_bytecodes present). The bug is specific to non-discovery / exhaustive mode, which is the default exhaustive LTM path.
Component(s) affected
src/simlin-engine/src/db_ltm.rs--link_score_equation_text_shaped(composite-reference emission, ~lines 358-364),compile_ltm_equation_fragment(~line 557; themodule·vardependency-resolution path, ~lines 762-990, does not LTM-augment the reconstructed submodel),compile_ltm_synthetic_fragment(~line 1328).src/simlin-engine/src/db.rs--assemble_modulecomposite-reference dep handling (~line 3712) for the contrast: the full path can resolve it.- Downstream: every LTM link/loop/relative-loop score for an exhaustive-mode loop that passes through a SMOOTH/DELAY/TREND/NPV stdlib macro.
Why it matters
- Correctness. SMOOTH and DELAY are among the most common constructs in real SD models, and they very frequently sit inside feedback loops (goal-seeking with perception/reporting delays is the canonical example). For every such loop, exhaustive-mode LTM silently reports a loop score of 0 -- the loop looks inactive when it is not.
- Silent. As with ltm: synthetic-fragment compilation uses an empty tables map, so link scores into graphical-function targets stub to 0 #546, the only thing standing between this and complete silence is the
model_ltm_fragment_diagnosticsWarning(commitdbc0844e); the warning reports the failure but the wrong0score remains, and the warning itself only reaches FFI callers whenltm_enabledis set (see LTM auto-flip warning unreachable through simlin_project_get_errors #466). - The diagnostic infrastructure already knows.
build_smooth_loop_with_failing_fragmentexists precisely because this compile failure exists -- see ltm: Piece 3 fragment-diagnostics positive tests are coupled to the lifetime of real fragment-compile bugs #547, which is about the resulting test coupling, not this underlying compile bug.
Suggested fix direction
The composite-reference equation is correct; what is missing is making the standalone fragment compiler resolve a module·$⁚ltm⁚composite⁚port dependency the same way assemble_module does. Options:
- LTM-augment the reconstructed submodel in the fragment-compile path. When
compile_ltm_equation_fragmentreconstructs an implicit/explicit module dependency and registers it inimplicit_submodels, the submodel's compiled form needs to include its LTM synthetic variables ($⁚ltm⁚composite⁚*, etc.) so themodule·composite_varreference resolves -- mirroring whateverassemble_moduledoes to make the full path work. - Treat a
module·$⁚ltm⁚composite⁚portreference as a known layout-dependent resolution (analogous to the documented sub-model dedup case thatmodel_ltm_fragment_diagnosticsdeliberately leaves silent) -- but only if the full assembly path genuinely produces a correct non-zero score, which the probe shows it does not here (the score is 0 in the real sim). So option 2 alone would just hide a real bug; the score must actually be computed.
The fix should be paired with a regression test that asserts the loop score for a SMOOTH-in-loop model is non-zero in exhaustive mode (the current build_smooth_loop_with_failing_fragment fixture would need to be repurposed or replaced -- see #547, which already proposes a test-injection hook so the fragment-diagnostics positive tests stop depending on this bug's lifetime).
How it was discovered
Identified during an adversarial review of the LTM-hardening effort, while tracing why build_smooth_loop_with_failing_fragment produces a fragment-compile failure. #547 (test coupling) and #546 (GF-tables, "names confirming the GF pattern ... alongside some SMOOTH-macro-internal ones") both gesture at this SMOOTH-internal compile failure but neither tracks it: #547 is about the fixture's coupling and #546's fix (threading the tables map) would not resolve the composite-reference resolution failure.
Linkage
- Part of the LTM epic epic: Loops that Matter (LTM) -- open work #488.
- Same hazard class as ltm: synthetic-fragment compilation uses an empty tables map, so link scores into graphical-function targets stub to 0 #546 (GF-table targets stub to 0) and engine: bare arrayed name inside nested PREVIOUS() in an apply-to-all equation fails to compile #541 (bare arrayed name in nested
PREVIOUSfails to compile) -- "fragment compiler can't handle a particular target shape" -- but a distinct root cause (submodel LTM-augmentation not visible to the standalone fragment compiler). - ltm: Piece 3 fragment-diagnostics positive tests are coupled to the lifetime of real fragment-compile bugs #547 is the test-debt sibling: its
build_smooth_loop_with_failing_fragmentfixture depends on this bug existing. - Falls under the LTM: improve/generalize module support #274 module-support umbrella.
Activity
LTM usability: discovery exposure, mode visibility, #548 fix, loop pi…
bpowers commentedon Jun 2, 2026
Fixed by e012ebc (PR #648; the commit message notes the fix was not auto-closed). build_submodel_metadata (src/simlin-engine/src/db/assemble.rs) now registers a sub-model's LTM composite vars at their layout offsets, so the standalone fragment compiler resolves the {module}·$⁚ltm⁚composite⁚{port} reference instead of dropping it.
Verified empirically on main (521fc37): smooth_macro_composite_flows_into_parent_loop_score_gh548 and macro_in_loop_score_varies_over_run_gh548 pass (SMOOTH and DELAY in-loop link scores are non-zero and vary over the run). The coupled #547 fixture was retargeted at the still-open #528 broadcast case, decoupling the diagnostic tests from this bug's lifetime.
LTM hardening: close out the top tracked gaps from epic #488 (#668)