Skip to content

ltm: stockless PREVIOUS-lagged cycle is scored by the enumerator but rejected by pin validation (false 'no stock' rationale) #749

Closed

Description

@bpowers

Problem

A stockless cycle whose only "state" is a PREVIOUS() lag is scored by the LTM enumerator but rejected by pin validation, and the pin rejection's stated rationale is false for this case.

Fixture:

a = PREVIOUS(b, 0)
b = a * k

No stock anywhere. Three facts about this model:

  1. The LTM causal graph carries the cycle. dt_deps come from classification.all, which INCLUDES lagged refs (src/simlin-engine/src/variable.rs ~930-932; src/simlin-engine/src/db/query.rs ~336-340). So a -> b -> a is a cycle in the LTM graph.
  2. The model compiles. The dependency-graph ordering gate prunes PREVIOUS edges, so there is no compile-time circular-dependency error.
  3. The loop enumerator scores it. There is no stock filter anywhere on the enumeration path, so discovery/exhaustive emit a scored loop for this cycle.

But model_pinned_loops' stock validation (src/simlin-engine/src/db/ltm/pinned.rs ~line 163; post-#673 shape: enriched find_stocks_in_loop + enrich_with_module_stocks both empty => reject) rejects a pin over {a, b} with "contains no stock". The validation's comment claims a purely-instantaneous cycle "would be a compile-time circular dependency" -- false for the PREVIOUS-lagged case, which is exactly the cycle shape that passes the compiler while containing no stock. (The comment falsity itself is being fixed in a doc commit on ltm-core-batch; this issue tracks the behavioral cross-surface disagreement.)

So the cycle is enumerable-but-unpinnable -- the same defect class #673 fixed for module-internal stocks, on a different leg: there the stock existed but the validator could not see it; here the two surfaces genuinely disagree about whether a PREVIOUS-lagged cycle is a feedback loop at all.

Open design question

PREVIOUS(x) is discrete state -- a one-DT memory -- so arguably it IS a feedback loop under the LTM reference's definition (sec. 2.1) and the pin should accept it, matching the enumerator. Alternatively the enumerator is over-permissive and both surfaces should reject stockless lagged cycles. Either resolution is defensible; the requirement is that the two surfaces agree and the validation comment be truthful about why.

Why it matters

  • Consistency: a loop the discovery/exhaustive paths report and score cannot be pinned-and-tracked, with a rejection message whose rationale does not apply.
  • Severity low: uncommon model shape; silent inconsistency, no wrong simulation numbers.

Components affected

  • src/simlin-engine/src/db/ltm/pinned.rs (model_pinned_loops stock validation, ~line 163)
  • src/simlin-engine/src/db/query.rs (~336-340, dt_deps including lagged refs) and src/simlin-engine/src/variable.rs (~930-932) -- where the enumerator side's inclusion is decided
  • the loop enumeration path (src/simlin-engine/src/db/ltm/loops.rs) if the resolution is to filter there instead

Possible approaches

  1. Accept stockless PREVIOUS-lagged cycles in pin validation (treat PREVIOUS as state), keeping the surfaces consistent with the enumerator. Likely the smaller change: relax the empty-stock rejection when the cycle contains a lagged edge.
  2. Filter stockless cycles out of enumeration too, so both surfaces reject. Requires distinguishing lagged-only cycles on the enumeration path and is a behavior change for discovery output.

Cross-references

How discovered

Identified during adversarial review of the #673 fix on branch ltm-core-batch (commit a98d7106), 2026-06-09.

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