Repository navigation
Description
Problem
model_ltm_variables' stock-free early return (src/simlin-engine/src/db/ltm/mod.rs:960) tests parent-level stocks only:
if edges_result.stocks.is_empty() && !has_input_ports {
// A stock-free model with no input-port pathways has nothing to
// score: ... Report the exhaustive default.
return LtmVariablesResult { vars: vec![], ... };
}edges_result.stocks comes from model_causal_edges and contains only the model's own Stock variables -- a DynamicModule node carrying internal state (a SMOOTH/DELAY instance, or a user sub-model with an INTEG) is not in that set. So a root model whose only state lives inside modules -- e.g. driver -> sub_model(with internal stock) -> reader -> driver -- has genuine feedback and genuine state, but zero parent-level stocks and (being a root, with no parent reading module·var) zero input-port pathways. The early return fires and LTM emits nothing, silently:
- no link scores, no loop scores;
- pinned loops on such a model silently produce nothing -- not even the invalid-pin warning, because the whole LTM variable pass bailed before pin processing (
model_pinned_loopsis never consulted).
The comment at mod.rs:949-951 ("A genuinely stock-free ROOT model ... the early return below still fires") encodes the same parent-level-only assumption: a module-heavy root is not genuinely stock-free, just stock-free at the parent level.
How it was demonstrated
During #673 test development, the integration fixture pinned_loop_through_module_internal_stock_scored (src/simlin-engine/tests/integration/simulate_ltm_pinned.rs, commit a98d7106 on branch ltm-core-batch) needed a disjoint bystander stock added purely to sidestep this early return; the workaround is documented in the fixture's comment. Without the bystander, the #673 fix (module-aware pin validation) is unreachable on a module-only root because the pass exits first.
Why it matters
Silent no-LTM-output for a legal model class (module-heavy roots). Same "silent nothing instead of a diagnostic" family as the closed #660 (analyze_model swallowed compile errors) and #662 (LTM diagnostics never surfaced): the user sees "no loops" and learns the wrong lesson ("my model has no feedback" / "LTM is broken") instead of getting scores or a diagnostic.
Component(s) affected
src/simlin-engine/src/db/ltm/mod.rs(model_ltm_variables, the early return at ~line 960; themodel_ltm_modequery's stock-free => Exhaustive arm encodes the same parent-level test)- Downstream: pinned-loop processing (
db/ltm/pinned.rs) is never reached, so ltm: pin whose only stock is module-internal is wrongly rejected as 'contains no stock' #673's invalid-pin warnings can't fire either.
Suggested fix direction
Make the early-return condition module-aware:
- also check that the model references no dynamic modules (
classify_module_for_ltmalready distinguishes stock-carrying modules from passthroughs), since a dynamic module carries internal state; or - reuse the enrichment semantics the ltm: pin whose only stock is module-internal is wrongly rejected as 'contains no stock' #673 fix applied to pin validation (
enrich_with_module_stocks): any module-internal stock reachable from the model's cycles counts as state.
Either way, the pinned_loop_through_module_internal_stock_scored fixture's bystander workaround should be removable as the regression test.
Discovery context
Identified during GH #673 implementation on branch ltm-core-batch (2026-06). Related: #673 (module-internal-stock pin rejection -- the downstream validation this early return masks), #282 (enrichment misses cycle-only internal stocks -- different code site), PR #684 (refined the early return to spare passthrough sub-models, but left the parent-level-stocks test for roots), #274 (module-support umbrella). Part of epic #488.
Severity: low-medium.
Activity