Skip to content

engine: MDL export has no lossiness contract -- callers can't learn an export was degraded #856

Closed

Description

@bpowers

Problem

project_to_mdl in src/simlin-engine/src/mdl/writer.rs mixes three incompatible failure modes with no unifying contract and no channel to surface degradation to callers:

  • hard error for some unsupported constructs (e.g. Variable::Module, mod.rs:88-94)
  • silent drop for many fidelity/semantic fields (see inventory below)
  • best-effort garbling for others (an unparseable equation falls through equation_to_mdl, printing the XMILE text with underscores converted to spaces, writer.rs:758)

A caller such as simlin-cli gets back a String and cannot tell whether the export was faithful, silently lossy, or actively corrupted. There is no documentation of which category each field falls into.

Inventory of silent drops (field-by-field audit, 2026-07)

Semantic (changes simulation results):

Fidelity (structure/metadata loss):

  • Model.loop_metadata (LOOPSCORE pins)
  • ModelGroup.parent sector nesting (importer populates it, convert/variables.rs:206) and run_enabled
  • per-element comments in arrayed equations (writer.rs:1078, 1317)
  • one-to-many element-level dimension mappings (writer.rs:1658-1683 falls back to plain name mapping; documented in-code)
  • StockFlow.zoom / view_box
  • compat.visibility
  • ai_state, Project.ai_information
  • Dimension.parent indexed subdimensions (XMILE-only)

Why it matters

Correctness (non_negative changes results), data loss (fidelity fields vanish on round-trip), and developer experience (no signal that an export degraded). This is the design umbrella above the individual per-field bugs.

Proposal

  1. Document the contract: for each field/construct, specify whether export errors, warns, or silently drops -- and why.
  2. Add a warnings channel: change project_to_mdl to return (String, Vec<ExportWarning>) (or add a warnings out-param) so callers like simlin-cli can print "exported with N fidelity warnings" and enumerate them.
  3. Escalate non_negative: hard-error or MAX(0, ...)-wrap on export, since silently dropping it changes simulation semantics.

Scope / relationship to other issues

This is the design/tech-debt umbrella. Individual semantic items are tracked separately: GraphicalFunction.kind #854, free-text sanitization #849, quoted-underscore idents #846, Module-in-macro drop #566, EXCEPT defaults, stock compat, non_negative enforcement #545, view-element fidelity #811. This issue tracks the missing contract + warnings mechanism itself, not any single field.

Discovery

Identified during a field-by-field audit of src/simlin-engine/src/mdl/writer.rs (2026-07).

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