Repository navigation
Description
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):
compat.non_negative-- never referenced by the writer; the exported model can go negative in Vensim where the XMILE source clamps. (Enforcement in the compiler/VM is separately tracked in engine: non-negative stocks and flows are not enforced #545; this is the export-side drop.)
Fidelity (structure/metadata loss):
Model.loop_metadata(LOOPSCORE pins)ModelGroup.parentsector nesting (importer populates it, convert/variables.rs:206) andrun_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_boxcompat.visibilityai_state,Project.ai_informationDimension.parentindexed 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
- Document the contract: for each field/construct, specify whether export errors, warns, or silently drops -- and why.
- Add a warnings channel: change
project_to_mdlto return(String, Vec<ExportWarning>)(or add a warnings out-param) so callers likesimlin-clican print "exported with N fidelity warnings" and enumerate them. - Escalate
non_negative: hard-error orMAX(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).
Activity
engine: warn on unreferenced extrapolating lookup export
engine: warn when MDL export drops conveyor/queue markers
engine: warn when MDL export drops conveyor/queue markers