Skip to content

ltm: LTM variable dropped at assembly silently reads 0 #683

Open

Description

@bpowers

When an LTM equation compiles but refers to a variable that has no slot in the model's layout, assembly drops it silently: the variable keeps its slot and reads 0 every step, and every loop score through it reads 0.
No diagnostic says so.
That is intended for one case (a sub-model's LTM equation the parent model re-emits under qualified names), but nothing distinguishes that case from a real omission.

No current path is known to produce a real omission.
One did: link scores into a pass-through user module referenced a composite score the module never had, and every loop through such a module read 0.
That emitter now checks that the composite exists first (module_composite_ports), which fixes that path but not the class.

Why it matters

A loop score of 0 tells the modeler the loop does not matter, which is worse than an error.
The next emitter that names a missing variable will fail the same way.

Fix

In assemble_module, warn when an LTM variable or LTM helper is dropped for having no layout slot in the root model.
The drop is documented as the sub-model stdlib-instance case and never fires on single-model test fixtures; that it cannot fire legitimately in the root is likely but unverified.
Small.
Alternative: also detect the sub-model case precisely by checking that the root emits the qualified equivalent; more work for a case with no known bug.
Reasonable to close instead if the owner prefers to rely on per-emitter checks.

Pointers

  • src/simlin-engine/src/db/assemble.rs: the two fragment_vars_in_layout drops (LTM variables and LTM helpers)
  • src/simlin-engine/src/db/ltm/compile.rs: model_ltm_fragment_diagnostics (reports compile failures only; its rustdoc describes the silent drop)
  • src/simlin-engine/src/db.rs: module_composite_ports
  • Related: ltm: module pathway scores read 0 through reducer or declined links #768 (module pathway scores reading 0)

Activity

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

    @bpowers
    OwnerAuthor

    Helper-leg instance of this class, post-cd96ffcf (the GH #741 diagnostics leg on branch ltm-fix-batch-2):

    A successfully-COMPILED LTM implicit helper dropped by assembly's layout-presence check is still silent. src/simlin-engine/src/db/assemble.rs:1413-1418 drops a helper fragment when fragment_vars_in_layout fails -- even though the fragment compiled fine -- so the helper keeps its layout slot and reads a constant 0 at runtime. The new #741 helper probe in model_ltm_fragment_diagnostics (src/simlin-engine/src/db/ltm/compile.rs, commit cd96ffcf) deems such a helper "compiled ok" (it checks only for value-bearing-phase bytecode), so no Warning fires. Its doc comment explicitly carves this out: "A fragment that compiles but whose variable references do not resolve in the model's layout is the documented sub-model dedup case ... that drop is intentionally left silent."

    That carve-out is sound only for the benign sub-model dedup case (the root re-emits an equivalent fragment under qualified names). A layout-absence with NO root-level equivalent is exactly this issue's failure mode -- compiles cleanly, reads silent 0 -- just surfacing on the implicit-HELPER leg rather than a synthetic variable's cross-module reference. Note the synthetic-variable leg has the identical structure at db/assemble.rs:1383 (same fragment_vars_in_layout drop, same dedup rationale).

    When implementing the suggested "warn when a fragment compiled against a stubbed/absent dependency / no laid-out slot" guard, please cover both legs (synthetic vars at assemble.rs:1383, implicit helpers at assemble.rs:1413-1418), and have the guard distinguish the benign dedup drop (root emits a qualified equivalent) from a genuine absence -- a blanket warning on every fragment_vars_in_layout failure would be noisy for the documented dedup case, while the current blanket silence hides the dangerous one.

    Identified during adversarial review of the #741 work (PR branch ltm-fix-batch-2, commit cd96ffcf).

  3. changed the title [-]ltm: a generated reference to an absent cross-module LTM variable compiles cleanly and reads a silent constant 0[/-] [+]ltm: LTM variable dropped at assembly silently reads 0[/+] on Oct 12, 2026
  4. added
    hygiene
    on Oct 12, 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

    hygieneltm

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions