Skip to content

ltm: model_ltm_variables' stock-free early return is module-blind -- a root whose only state is module-internal silently emits no LTM variables #748

Closed

Description

@bpowers

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_loops is 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

Suggested fix direction

Make the early-return condition module-aware:

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

  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