Skip to content

mdl: a module inside a macro is silently dropped on MDL save #566

Open

Description

@bpowers

If a macro's body contains a module, saving to MDL drops the module without an error or warning, leaving any variables wired to it pointing at nothing.
It should refuse the save with an error naming the module and the macro, as it already does for a module in the main model.

Example

No imported file produces this: the MDL importer does not put modules inside macro bodies.
It takes an edit after import, for example an agent adding a module to a macro model through MCP, then saving as .mdl.

Why it matters

Silent data loss on save, though only reachable through a programmatic edit.
Every other module the MDL format cannot hold is refused with an error.

Fix

Extend the pre-save check in project_to_mdl_with_warnings to look at the variables of every macro model, not only the main model, and return an error for any module there.
Add a test beside the existing project_to_mdl_rejects_* tests with the module placed inside a macro.

Alternative: write a multi-output macro call inside a macro body the way the main model's are written.
Only worth it once the importer can produce one.

Pointers

  • src/simlin-engine/src/mdl/mod.rs: project_to_mdl_with_warnings, the loop over main_model(project).variables
  • src/simlin-engine/src/mdl/writer.rs: write_macro_blocks; the Variable::Module(_) => return arm in the variable writer is where the module disappears
  • src/simlin-engine/src/mdl/writer_tests.rs: project_to_mdl_rejects_ordinary_module_variable

Activity

  1. added
    engine
    on May 16, 2026
  2. added a commit that references this issue on May 16, 2026
  3. changed the title [-]engine: Variable::Module inside a macro-body model is silently dropped by the MDL writer (project_to_mdl reject gate scans only the main model)[/-] [+]mdl: a module inside a macro is silently dropped on MDL save[/+] on Oct 12, 2026
  4. added
    bug
    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

    bugengine

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions