Repository navigation
Description
Problem
CausalGraph::enumerate_module_pathways (src/simlin-engine/src/ltm/graph.rs:550) calls find_all_simple_paths(input_port, output_name, node_count) (line 589) with a depth cap (node_count) but no cap on the number of simple paths returned. The inner DFS dfs_simple_paths (graph.rs:518-546) enforces simple-path semantics via a visited set and bounds recursion depth at max_depth, but pushes every discovered simple path onto the result Vec unconditionally.
The number of simple paths between two nodes can be exponential in graph size. A module body that is a chain of N diamond patterns has 2^N simple paths from input to output, even though every such path is short and the depth cap never trips.
Each returned pathway becomes one LTM synthetic variable: model_ltm_variables emits a $⁚ltm⁚path⁚{input}⁚{idx} var per pathway (src/db/ltm/mod.rs:696-735). So a pathological module body could generate millions of synthetic variables and exhaust memory.
Why it matters
This is a defense-in-depth gap. A related exponential-memory bug (the LTM composite-score equation text generate_max_abs_chain_str building O(2^n)-sized equation text) was discovered and is being fixed on the layout-hill-climb branch by folding the strongest-pathway composite through O(1)-sized accumulator helper variables. That fix stops the per-equation blowup, but the number of pathways feeding it is still unbounded — so a pathological module body could still mint an exponential number of synthetic variables and OOM even after the composite-equation fix lands.
The pathway count is model-controlled and unbounded: it depends entirely on the topology of a user-defined (or stdlib macro) module body. There is no production threshold protecting against an adversarial or accidentally-dense module.
Real-world evidence
covid19-us-homer's SSTATS macro module (test/metasd/covid19-us-homer/homer v8/Covid19US v8.mdl) already produces 270+ pathways per input port. That is manageable today, but it is the same enumeration with no upper bound — a denser module body scales super-linearly.
Component(s) affected
src/simlin-engine/src/ltm/graph.rs—enumerate_module_pathways/find_all_simple_paths/dfs_simple_pathssrc/simlin-engine/src/db/ltm/mod.rs— the$⁚ltm⁚path⁚{input}⁚{idx}synthetic-variable emission that consumes the pathways
Suggested fix
Follow the existing budget pattern already used for an analogous combinatorial enumeration in src/simlin-engine/src/db/ltm/loops.rs (MAX_CROSS_AGG_LOOPS = 256, MAX_AGG_PETALS = 8): deterministic truncation order, a truncation flag on the result, and an accumulated Warning diagnostic.
Concretely: add a MAX_MODULE_PATHWAYS budget (e.g. 256) in enumerate_module_pathways (or its caller), truncating deterministically (shortest paths first, then lexical tiebreak so truncation is reproducible), setting a truncation flag on the result, and accumulating a CompilationDiagnostic Warning naming the module and input port — mirroring the agg_recovery_truncated + Warning plumbing already used for the cross-agg loop-recovery budget.
Relationship to existing tracking
This is distinct from the already-tracked module-pathway items in the #488 LTM epic:
- ltm: fixed max depth 20 truncates module pathway enumeration #312 (closed): capped the depth of
enumerate_module_pathwaysat a hard-coded 20 (nownode_count). The depth cap does not bound the number of paths. - ltm: module stocks reached only through internal feedback are ignored #282 (open):
enrich_with_module_stocks' simple-path DFS misses stocks reachable only through internal feedback cycles — a coverage/correctness gap, not a resource blowup. - LTM: improve/generalize module support #274 (umbrella): LTM module support — lists ltm: fixed max depth 20 truncates module pathway enumeration #312, ltm: module stocks reached only through internal feedback are ignored #282, ltm: composite-reference link score into a stdlib-macro module fails to compile in exhaustive mode, so loops through SMOOTH/DELAY stub to 0 #548 as the remaining module gaps; none covers the pathway-count blowup.
The budget precedent it should follow is #515 (MAX_CROSS_AGG_LOOPS / MAX_AGG_PETALS), but that bounds a different enumeration (cross-agg loop recovery), not module pathway enumeration.
Context: how it was discovered
Identified while fixing the O(2^n) LTM module composite-score equation-text blowup (generate_max_abs_chain_str) on the layout-hill-climb branch. The composite-equation fix folds the strongest-pathway selection through accumulator helpers; this issue tracks the remaining upstream gap that the pathway count itself is unbounded.
Activity
engine: fix exponential LTM module composite-score equation
LTM hardening: close out the top tracked gaps from epic #488 (#668)
bpowers commentedon Jun 2, 2026
Fixed in PR #668 (merged as f9f850d). enumerate_module_pathways is now budgeted (MAX_MODULE_PATHWAYS = 8192, chosen above the measured corpus maximum: covid19-us-homer SSTATS = 303 pathways/port, its root enrich path peaks at 6744) with a real work bound — the DFS stops emitting at the per-port budget AND aborts after a budgetmax_depth expansion allowance, so an exponential dead-end frontier aborts in O(budgetdepth) instead of 2^N (the parent code performed ~262k descents on a 2^16 frontier; the bounded code ~400). Deterministic kept set (sorted neighbor walk), pathways_truncated flag + Warning naming module and ports (the #515 plumbing), enrich_with_module_stocks degrades to its all-internal-stocks fallback on truncation, ModulePathwayBudgetGuard test override. Red-verified truncation tests; SSTATS verified un-truncated at 8192.