Repository navigation
Description
Problem
When a Dimension has multiple positional mappings (mappings with empty element_map), the serialization paths silently lose data:
- JSON (
json.rs:1808-1812):maps_to()returnsNonefor multi-target cases, and the mappings filter only includes entries with non-emptyelement_map, so all positional mappings are dropped. - Protobuf (
serde.rs:2260-2263): Only validates thatelement_mapis empty, so multi-target positional mappings pass validation butmaps_to()writesNone, silently stripping all targets. - XMILE (
xmile/mod.rs:813-816): Same gap as protobuf.
The root cause is the maps_to() helper on Dimension, which returns Option<&str> -- it can only represent zero or one positional mapping targets. When there are multiple positional mappings, it returns None, and the serialization code interprets that as "no positional mapping."
Why it matters
This is a silent data-loss bug. Although currently not reachable in practice (only single positional mappings are generated by the MDL parser and other loaders), the data model (Vec<DimensionMapping>) explicitly allows multiple positional mappings. Any future code path that produces multi-target positional mappings would hit this and lose data without any error or warning.
Components affected
src/simlin-engine/src/datamodel.rs--Dimension::maps_to()methodsrc/simlin-engine/src/json.rs-- JSON serializationsrc/simlin-engine/src/serde.rs-- Protobuf serializationsrc/simlin-engine/src/xmile/mod.rs-- XMILE serialization
Suggested fix
Either:
- Validate at serialization time that at most one positional mapping exists, returning an error if not (fail loudly rather than silently dropping data), or
- Extend the serialization formats to support multiple positional targets (updating JSON, protobuf, and XMILE writers/readers accordingly).
Option 1 is simpler and sufficient until a real use case for multi-target positional mappings arises.
Relationship to other issues
This is distinct from #341 and #342, which track adding serialization support for element_map-based (non-empty) dimension mappings. This issue is about the positional (empty element_map) case specifically when there are multiple targets.
Context
Identified during code review of MDL full compatibility changes on branch mdl-full-compat.
Activity
engine: add why-comments for VectorElmMap/VectorSortOrder indexing as…
engine: add why-comments for VectorElmMap/VectorSortOrder indexing as…