Skip to content

ltm: synthetic-fragment compilation uses an empty tables map, so link scores into graphical-function targets stub to 0 #546

Closed

Description

@bpowers

Summary

compile_ltm_equation_fragment in src/simlin-engine/src/db_ltm.rs builds its compilation context with an empty tables map. Any LTM synthetic link-score fragment whose equation references a graphical-function (lookup table) target variable cannot resolve that variable's lookup table, so the fragment fails to compile. The synthetic variable then keeps its layout slot but no bytecode writes it, and it reads a constant 0 -- a wrong link score.

This means LTM link scores into graphical-function targets are wrong (0) for essentially any real model that uses lookup tables inside a feedback loop -- a significant LTM correctness gap.

The bug

db_ltm.rs has two sibling LTM fragment-compile sites, and both hardcode an empty tables map:

  • compile_ltm_equation_fragment around line 1171:
    // LTM vars don't have graphical functions or lookup tables
    let tables: HashMap<Ident<Canonical>, Vec<crate::compiler::Table>> = HashMap::new();
  • the implicit-var fragment compile path around line 1946:
    let tables: HashMap<Ident<Canonical>, Vec<crate::compiler::Table>> = HashMap::new();

The comment ("LTM vars don't have graphical functions or lookup tables") is correct about the LTM synthetic variable itself -- a link/loop/path score is never a graphical function. But it overlooks the fact that an LTM synthetic fragment's equation can reference a model variable that is a graphical function. A ceteris-paribus link-score partial for an edge ... -> gf_target substitutes/holds references to gf_target, and gf_target's equation applies a lookup table. With an empty tables map the compiler cannot resolve that table and the whole fragment fails to compile.

tables.clone() is then handed straight to the crate::compiler::Module that gets compiled (line 1230), so the module is built without any lookup-table definitions.

Why it matters

  • Correctness. Graphical functions inside feedback loops are extremely common in real SD models (the entire WRLD3 / World3 family is built on them). For every such loop, the LTM link score into the graphical-function target silently degrades to 0, which corrupts the loop score and the relative loop score for that loop.
  • Silent until very recently. Before commit dbc0844e ("engine: surface LTM synthetic-fragment compile failures") this failure was completely silent. After dbc0844e it surfaces as a Warning via model_ltm_fragment_diagnostics -- but the warning only reports the failure; the underlying compile failure and the wrong 0 link score remain. On the WRLD3 model with ltm_enabled = true this produces a large batch of fragment-failure warnings whose names confirm the graphical-function pattern (e.g. ...assimilation_half_life_mult_table -> assimilation_half_life_multiplier, ...capacity_utilization_fraction_table -> capacity_utilization_fraction), alongside some SMOOTH-macro-internal ones.

Component(s) affected

  • src/simlin-engine/src/db_ltm.rs -- compile_ltm_equation_fragment (~line 1171) and the implicit-var fragment-compile path (~line 1946)
  • Downstream: every LTM link/loop/relative-loop score for a loop that passes through a graphical-function variable

Suggested fix direction

Thread the model's real tables map into the fragment compile context instead of HashMap::new(). The non-LTM compilation path already builds a tables map for the model's graphical-function variables; the fragment-compile path needs to populate tables with (at minimum) the lookup tables of the variables the fragment references, so the compiler can resolve them. The empty map is only correct for the LTM synthetic variable's own slot, not for its dependencies. Both fragment-compile sites in db_ltm.rs need the same treatment. Replace the misleading comment with one that explains why the dependencies' tables must be present.

How it was discovered

Identified during a deep review of the current LTM-hardening effort, while triaging the fragment-failure warnings that commit dbc0844e newly surfaces on WRLD3.

Part of the LTM epic #488.

Activity

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

    @bpowers
    OwnerAuthor

    Fixed by 94f9c07 ("engine: fix LTM link scores through lookup tables silently zeroing"). Both fragment compilers (compile_ltm_equation_fragment, compile_ltm_implicit_var_fragment, now in src/simlin-engine/src/db/ltm/compile.rs) thread the model's referenced lookup tables into the mini-Module's tables map instead of an empty map, and the ceteris-paribus partial no longer PREVIOUS-wraps a LOOKUP table argument.

    Verified empirically on main (521fc37): the regression test test_lookup_table_link_score_is_nonzero passes, and WRLD3 discovery now surfaces 200 loops (was 16).

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