Summary
The generate_best_layout function in src/simlin-engine/src/layout/mod.rs explicitly skips Variable::Module elements (lines 1768, 2144, 2153-2158). When sync_diagram regenerates the diagram layout (e.g., after MCP edits via EditModel), any module view elements in the original diagram are silently dropped from the output.
Impact
A user could open an existing XMILE or Vensim file containing modules, edit a variable via the MCP EditModel tool (in src/simlin-mcp), and the subsequent diagram regeneration would permanently remove module view elements from the persisted file. This is silent data loss -- the model equations remain intact, but the visual representation of modules in the diagram is destroyed.
Currently the MCP server does not expose module creation/editing operations, so the scope is limited to models that already contain modules being edited through non-module operations. However, as MCP functionality expands, this gap becomes more significant.
Components affected
src/simlin-engine/src/layout/mod.rs -- generate_best_layout function
src/simlin-mcp -- sync_diagram calls generate_best_layout after model edits
Possible approaches
- Preserve existing module view elements: During layout regeneration, carry forward any
ViewElement::Module entries from the original view that correspond to module variables still present in the model. This is the simpler fix and avoids needing full module layout support.
- Add module support to the layout engine: Teach
generate_best_layout to position module elements alongside stocks, flows, and auxiliaries. This is the more complete fix but requires more work.
Approach (1) is likely sufficient for now and avoids introducing layout heuristics for modules.
Context
Identified during review of the layout engine's interaction with the MCP server's sync_diagram path.
Summary
The
generate_best_layoutfunction insrc/simlin-engine/src/layout/mod.rsexplicitly skipsVariable::Moduleelements (lines 1768, 2144, 2153-2158). Whensync_diagramregenerates the diagram layout (e.g., after MCP edits viaEditModel), any module view elements in the original diagram are silently dropped from the output.Impact
A user could open an existing XMILE or Vensim file containing modules, edit a variable via the MCP
EditModeltool (insrc/simlin-mcp), and the subsequent diagram regeneration would permanently remove module view elements from the persisted file. This is silent data loss -- the model equations remain intact, but the visual representation of modules in the diagram is destroyed.Currently the MCP server does not expose module creation/editing operations, so the scope is limited to models that already contain modules being edited through non-module operations. However, as MCP functionality expands, this gap becomes more significant.
Components affected
src/simlin-engine/src/layout/mod.rs--generate_best_layoutfunctionsrc/simlin-mcp--sync_diagramcallsgenerate_best_layoutafter model editsPossible approaches
ViewElement::Moduleentries from the original view that correspond to module variables still present in the model. This is the simpler fix and avoids needing full module layout support.generate_best_layoutto position module elements alongside stocks, flows, and auxiliaries. This is the more complete fix but requires more work.Approach (1) is likely sufficient for now and avoids introducing layout heuristics for modules.
Context
Identified during review of the layout engine's interaction with the MCP server's
sync_diagrampath.