Skip to content

Serialization silently drops multi-target positional dimension mappings #344

Closed

Description

@bpowers

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() returns None for multi-target cases, and the mappings filter only includes entries with non-empty element_map, so all positional mappings are dropped.
  • Protobuf (serde.rs:2260-2263): Only validates that element_map is empty, so multi-target positional mappings pass validation but maps_to() writes None, 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() method
  • src/simlin-engine/src/json.rs -- JSON serialization
  • src/simlin-engine/src/serde.rs -- Protobuf serialization
  • src/simlin-engine/src/xmile/mod.rs -- XMILE serialization

Suggested fix

Either:

  1. Validate at serialization time that at most one positional mapping exists, returning an error if not (fail loudly rather than silently dropping data), or
  2. 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.

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