Skip to content

ltm: pin whose only stock is module-internal is wrongly rejected as 'contains no stock' #673

Closed

Description

@bpowers

Problem

model_pinned_loops (src/simlin-engine/src/db/ltm/pinned.rs, the has_stock validation around line 156) checks the pin's raw, pre-enrichment cycle against the parent-level model_causal_edges.stocks set:

let has_stock = cycle.iter().any(|n| edges.stocks.contains(n.as_str()));
if !has_stock {
    // reject: "pinned loop '...' contains no stock"
}

edges.stocks contains only parent-level stocks. A DynamicModule node (e.g. a SMOOTH instance whose internal stock is the loop's only state) is not in that set. So a valid feedback loop such as aux1 -> smooth -> aux2 -> aux1, whose only stock lives inside the SMOOTH module, fails the check and the pin is rejected with "contains no stock".

Inconsistency

The same variable set is happily found and scored by the loop enumerator, which applies no has_stock filter and enriches module-internal stocks via enrich_with_module_stocks. The result is that the exact same cycle is enumerable but unpinnable -- the discovery path accepts it, the pin path rejects it. That divergence is the core defect.

Why it matters

  • Correctness / consistency: a loop that discovery treats as a real feedback loop cannot be pinned, so users (or agents) cannot pin-and-track a loop the enumerator already recognizes.
  • Module support: this is a concrete gap in pinning loops that route through stdlib modules (SMOOTH/DELAY), which is exactly the case where state hides inside a module.

Component(s) affected

  • src/simlin-engine/src/db/ltm/pinned.rs (model_pinned_loops, has_stock validation)

Test gap

There are currently no tests covering a pin through a module at all.

Possible approaches

  • Treat a DynamicModule node in the cycle as stock-bearing for the has_stock check (classify_module_for_ltm already knows which modules carry internal state), or
  • Run module stock enrichment (enrich_with_module_stocks) before the has_stock check so module-internal stocks are visible to the validation.

Either way, add a regression test that pins a loop whose only stock is inside a SMOOTH/DELAY module.

Discovery context

Found during a design review on 2026-06-02; documented in docs/design/ltm--loops-that-matter.md (Pinned Loops section) as of commit cc072973.

Severity: minor.

Related but distinct: #282 (enrichment misses cycle-only internal stocks -- opposite failure mode, different code site) and #274 (umbrella "improve/generalize module support").

Activity

  1. added
    ltm
    on Jun 2, 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