Skip to content

web editor round-trips canonical idents through patch upserts/renames, eroding display names of imported models #906

Closed

Description

@bpowers

Problem

The engine-side fix for #890 makes the Rust patch path (src/simlin-engine/src/patch.rs) preserve the caller's display spelling verbatim: upserts store the payload's name as-is, renames store the raw to string, and all lookup/matching remains canonicalization-based. But the patch payload is now authoritative for the display spelling -- and the TypeScript layer sends canonical idents in those payloads, so web-editor edits still erode display names.

Two mechanisms in the TS layer:

  1. Deserializers discard the display spelling on read. src/core/datamodel.ts stockFromJson / flowFromJson / auxFromJson / moduleFromJson (around lines 707 / 809 / 919 / 993) do ident: canonicalize(json.name). The corresponding *ToJson functions then serialize that canonical ident back as name (lines 736 / 840 / 943 / 1013). src/diagram/Editor.tsx handleEquationChange builds upsert payloads via stockToJson etc. (lines ~1700-1744), so every equation/documentation/units edit sends the canonical form as the variable's name.

  2. Renames canonicalize the target. src/diagram/Editor.tsx line ~790 sends payload: { from: oldIdent, to: canonicalize(newName) }, so even an explicit rename to "New Students" stores new_students.

Net effect

For a model imported from Stella/XMILE, where the datamodel idents carry display names like Students or testing\nassymptomatic, any web-editor edit of a variable downgrades the stored ident to its canonical form (students, testing_assymptomatic). The web editor gets away with it visually because the diagram renders the VIEW element's name (src/diagram/drawing/common.ts displayName), but the <variables> block in exported XMILE degrades -- exactly the 2021 report in #82.

Why it matters

Components affected

  • src/core/datamodel.ts (*FromJson / *ToJson)
  • src/diagram/Editor.tsx (handleEquationChange, handleRename)

Possible approaches

  • Preserve the raw name in the TS Variable model: store name (display spelling) alongside ident (canonical), have *FromJson keep json.name verbatim, *ToJson emit the preserved name, and handleRename send the raw newName. Lookups/comparisons keep using the canonical ident.
  • Longer term: the dual-name datamodel design discussed in XMILE export from simlin: variable name to lowercase but not in equations #82, separating display name from canonical ident end-to-end so canonicalization can never be lossy.

Related

Discovery context

Identified while fixing #890 on branch conveyor-engine: after making the engine preserve payload spelling verbatim, the TS client remains a source of canonical-only payloads.

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