Repository navigation
Description
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_stockvalidation)
Test gap
There are currently no tests covering a pin through a module at all.
Possible approaches
- Treat a
DynamicModulenode in the cycle as stock-bearing for thehas_stockcheck (classify_module_for_ltmalready knows which modules carry internal state), or - Run module stock enrichment (
enrich_with_module_stocks) before thehas_stockcheck 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