Skip to content

engine: layout loses glyph positions for names containing a period #704

Closed as not planned

Description

@bpowers

For a variable whose name contains a period, the diagram glyph and the variable no longer match by name, so incremental layout probably re-places a glyph that already has a position.
Group membership has the same mismatch, so renaming such a variable probably leaves its group entry stale.
Both are traced from the code and have not been reproduced.

Example

Take a stored project with a variable Goal 1.5 for Temperature that has a glyph on the diagram.
On load, the variable's stored ident is rewritten to use the literal-period marker ‥ (U+2024), so it canonicalizes to goal_1‥5_for_temperature.
The glyph's name is stored as display text with a plain ., which canonicalize reads as a module separator: goal_1·5_for_temperature (U+00B7).
Layout matches glyphs to variables on these keys, misses, and treats the glyph as new.

Expected: running incremental layout with no changes keeps the glyph where it was.

The group-member rename compares canonicalize(member) to the renamed ident in the same way and also misses.

Why it matters

Only names containing a period are affected, as in C-LEARN's "Goal 1.5 for Temperature".
The model simulates; the cost is a moved glyph or a stale group entry.

Fix

This is the diagram side of #702 and should use the same name-context canonicalization (a . in a name is always literal) at each place a stored name is matched to a variable.
Do not rewrite the stored view-element name: it is display text, and display_name does not turn ‥ back into ..

Pointers

Activity

  1. bpowers commented on Jun 3, 2026

    @bpowers
    OwnerAuthor

    Update after the #690 serde.rs fix merged (two findings; raises the severity framing)

    The #690 fix is now merged: migrate_stored_ident (src/simlin-engine/src/serde.rs:47-51, raw . -> U+2024 sentinel) is applied to the stored simulation-ident fields on the protobuf-deserialize path (variable/stock/flow/aux idents and dimension/element names, e.g. serde.rs:471/485/492/699/710/715/854/951). It is deliberately NOT applied to the view-element name fields (this issue) nor to ModelGroup.members/parent. Two findings emerged after it landed (both still code-traced, not yet empirically reproduced -- repro recipes below).

    Finding 1 -- this is now an ACTIVE REGRESSION in incremental_layout, not just a latent hazard

    For a 2022-era model that has BOTH a period-named variable AND a diagram glyph for it, the merged #690 fix actively REGRESSES glyph<->variable association in incremental layout. Mechanism, verified by code-trace on the layout side, in src/simlin-engine/src/layout/mod.rs LayoutState::from_existing_view (~lines 151-227):

    • The uid manager is seeded from the VARIABLE side via canonicalize(var.get_ident()) at mod.rs:163. Post-engine: 2022 projects with a period in a variable name do not simulate #690, var.get_ident() is the migrated ‥/U+2024 form, so the variable registers under the U+2024 key.
    • The uid manager is seeded from the VIEW-ELEMENT side via canonicalize(&view_element.name) on the stored DISPLAY name at mod.rs:180/184/188/192 (Aux/Stock/Flow/Module). The display name still carries a raw ., which canonicalize maps to ·/U+00B7 (the module separator, common.rs:691), so the glyph registers under the U+00B7 key.
    • uid_to_ident (mod.rs:219-227) then rebuilds the map by looking up each variable's canonicalize(var.get_ident()) (the ‥ key) against the uid manager -- but the glyph was registered under the · key -> miss -> the glyph's position is dropped from uid_to_ident, so incremental layout treats the existing glyph as a new/orphaned element and re-places it.

    PRE-#690-fix both sides canonicalized the raw . to · and MATCHED (broken-but-symmetric); POST-fix the variable side moved to ‥ while the view side stayed on ·, so they now diverge. So #704 is a fast-follow to the merged #690 fix, not an indefinite backlog item -- the fix introduced a concrete diagram regression for the exact class of models #690 set out to repair. The severity framing in the original body ("low-stakes latent, diagram-only") should be read with this caveat: simulatability is repaired, but a layout/association regression is the cost.

    The correct fix is NOT to migrate the view-element name. That field is stored DISPLAY form and is rendered directly by diagram::common::display_name (src/simlin-engine/src/diagram/common.rs:29-31), which does only .replace("\\n","\n").replace('_'," ") -- it does NOT reverse the U+2024 sentinel. Migrating the stored name to ‥ would therefore corrupt the rendered label ("Goal 1.5" -> "Goal 1‥5"). The fix belongs in the layout/diagram NAME-MATCHING boundary instead: make the view<->variable uid match literal-period-aware (a . in a view-element name attribute is always literal), or reverse the sentinel only at the match/display boundary, so both sides agree on one key without changing the stored display string. This is coherent with the broader name-context-vs-equation-context canonicalize problem (#702/#565).

    Repro recipe (layout): take a 2022-era stored model (or synthesize the project_io blob) with a quoted-period-named variable (e.g. "Goal 1.5 for Temperature") that has a Stock/Aux/Flow glyph, deserialize it (so #690 migrates the variable ident to ‥), then run incremental_layout with an empty/no-op ModelPatch and assert the existing glyph keeps its stored position (its uid is present in uid_to_ident). Expected at HEAD: the glyph is treated as orphaned and re-placed. A no-period control keeps its position.

    Finding 2 -- related sibling site (same family, metadata layer): ModelGroup.members / parent

    ModelGroup.members and ModelGroup.parent are deserialized holding canonical variable idents and are NOT migrated by the #690 fix (From<project_io::ModelGroup>, serde.rs:2237-2255: members: group.members, parent: ... group.parent). This is correct in the sense that group membership is not on the simulation compile path -- but it creates the same name-context asymmetry against the now-migrated variable idents:

    • Rename propagation (rename_group_members, src/simlin-engine/src/patch.rs:1143-1144) matches a member against the renamed variable via canonicalize(member.as_str()) == old_ident.as_str(). For a period-named member, canonicalize maps the stored member's raw . to ·, while old_ident (a Canonical ident derived through the migrated path) is the ‥ form -> mismatch -> the rename silently fails to update the group membership, orphaning the member entry.
    • Writers / group display consume group.members directly: MDL (src/simlin-engine/src/mdl/writer.rs:2924 and :2943, building grouped_idents and emitting members in group order), XMILE (src/simlin-engine/src/xmile/model.rs:513/:603, members/vars), and JSON (src/simlin-engine/src/json.rs:1308/:1977). A period-named member that no longer matches its migrated variable ident would be grouped/emitted inconsistently (e.g. a member string that doesn't resolve to any current variable).

    This is another metadata-layer asymmetry exposed by the #690 fix -- same root cause (name-context vs equation-context canonicalize), different consumer. Capture it here so the metadata cleanup is tracked in one place; it is a reasonable candidate split-out if #704's fix ends up scoped narrowly to the layout/diagram uid match (the group-member path needs its own match-boundary fix in patch.rs + writer-side consistency).

    Repro recipe (group membership): build a model with a period-named variable that is a member of a non-Control group, round-trip it through the protobuf deserialize (so the variable ident migrates to ‥ but the group member stays raw-.), then (a) rename the variable via a RenameVariable patch and assert the group's members entry updates, and (b) export to MDL/XMILE and assert the member still appears under its group. Expected at HEAD: the rename does not propagate (the member keeps the old name) and the writer's grouped_idents set does not contain the variable's migrated ident. A no-period control propagates and emits correctly.

    Status

    Both findings are code-traced against HEAD and NOT yet empirically reproduced -- they should be confirmed with the recipes above before being treated as closed-loop. No fix implemented. Code refs validated at HEAD: serde.rs:47-51 (migrate_stored_ident) + 2237-2255 (ModelGroup unmigrated); layout/mod.rs:163/180/184/188/192/219-227 (the seed asymmetry); diagram/common.rs:29-31 (display_name does not reverse the sentinel); patch.rs:1143-1144 (group-member rename match); writer consumers mdl/writer.rs:2924/2943, xmile/model.rs:513/603, json.rs:1308/1977.

  2. added
    engine
    bug
    on Jun 8, 2026
  3. changed the title [-]engine: view-element name fields skip literal-period ident handling, so a period-named variable's diagram glyph/label/selection-association can mismatch (·-vs-.-vs-‥)[/-] [+]engine: layout loses glyph positions for names containing a period[/+] on Oct 12, 2026
  4. added
    layout
    duplicate
    on Oct 12, 2026
  5. bpowers commented on Oct 12, 2026

    @bpowers
    OwnerAuthor

    Closing as a duplicate of #702.

    Same root cause and same fix as #702 (one name-context canonicalization used wherever a stored name is matched to a variable). Code sites verified on main; not reproduced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugduplicateenginelayout

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions