Skip to content

model_causal_edges does not normalize module refs for inter-module edges #293

Closed

Description

@bpowers

Summary

In src/simlin-engine/src/db.rs, the model_causal_edges function inserts edges from canonicalize(&mr.src) for module variables without passing through normalize_module_ref_str. When a module input is fed by another module's output (e.g., foo.bar canonicalized with the middle-dot separator), this creates an edge from a phantom module.output node instead of the module node itself.

Other code paths in the same function correctly use normalize_module_ref_str to strip the output qualifier (around lines 1187 and 1227), but the initial module-ref edge insertion at lines 1176-1177 does not.

Why it matters

Cycle/loop analysis could miss real feedback paths when models chain module outputs through other modules. The causal edge graph would contain phantom nodes that don't correspond to actual model variables, breaking graph connectivity for inter-module dependency chains.

Correctness: Feedback loop detection (used by LTM and loop analysis) may produce incorrect results for models with module-to-module connections.

Affected component: simlin-engine, specifically model_causal_edges in src/simlin-engine/src/db.rs.

Concrete example

Given two modules A and B where B's input is wired to A's output:

  • Current behavior: inserts edge from A·output_var (a phantom composite node) instead of A
  • Expected behavior: inserts edge from A (the module node), matching what normalize_module_ref_str would produce

Possible fix

Apply normalize_module_ref_str to canonical_src at lines 1176-1177, and apply the same normalization to the corresponding implicit module ref handling at lines 1211-1215. This would make the behavior consistent with the other code paths in the same function that already normalize correctly.

Context

Identified during code review of PR #289 (incremental compilation refactor). This is a pre-existing pattern that was moved into a salsa tracked function during the refactor, not a regression introduced by the PR.

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions