Skip to content

ltm: PREVIOUS inside a sub-model is not counted as state #773

Open

Description

@bpowers

LTM treats PREVIOUS() as state in the model being analyzed, but not inside a sub-model.
A model whose only state is a PREVIOUS lag inside a module is treated as having no state, so LTM produces no link or loop scores for it, and a pinned loop is dropped with no warning.
The loop list (model_detected_loops) still reports the loop, so the user sees a loop that never gets a score.

Example

main:  driver = 1 + 0.5 * reader
       sub    = module lag (in = driver)
       reader = sub.out
lag:   out    = PREVIOUS(in, 0)

This compiles and simulates as a one-step lag in a feedback loop.
Expected: one scored loop driver -> sub -> reader -> driver.
Actual: no LTM variables; a pin on {driver, sub, reader} is silently ignored.
With the same PREVIOUS written in main (reader = PREVIOUS(driver, 0)) the loop is scored.

Why it matters

Hits a user sub-model that implements a custom delay or smoothing with PREVIOUS instead of a stock.
No real model reported; the shape was found by reading the code.
The result is missing output, not wrong numbers.

Fix

Count module-internal lags as state on both surfaces together:

  • the stateless check: modules_carry_state walks sub-models looking for stocks; also count a sub-model variable that reads something only through PREVIOUS;
  • pin validation, which rejects a pinned loop with no state on it; it must see the lag inside the module's path too, or the loop becomes scored but unpinnable.

Changing only the first recreates a loop that is scored but cannot be pinned.

Pointers

Activity

  1. added
    ltm
    on Jun 11, 2026
  2. changed the title [-]ltm: module-internal PREVIOUS lag is uncounted state on every surface (lag-only sub-model loops unscored and unpinnable)[/-] [+]ltm: PREVIOUS inside a sub-model is not counted as state[/+] on Oct 12, 2026
  3. added
    bug
    on Oct 12, 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

    bugltm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions