Skip to content

ltm: enumerate_module_pathways has no cap on the number of pathways (exponential synthetic-var blowup) #649

Closed

Description

@bpowers

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_paths
  • src/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:

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

  1. added
    ltm
    on Jun 1, 2026
  2. bpowers commented on Jun 2, 2026

    @bpowers
    OwnerAuthor

    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.

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