Repository navigation
engine: fix mdl roundtrip edge cases - #332
Conversation
Code ReviewI reviewed all 15 changed files in this PR. The changes cover five distinct areas:
Areas examined closely:
FindingsNo bugs found. The changes are well-structured, properly wired through all conversion paths, and covered by targeted regression tests. The protobuf versioning is correct (additive field with unused tag). Overall CorrectnessCorrect. The patch should not break existing code or tests, and is free of bugs. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 762d9ff52f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| *next_connector_uid, | ||
| valve_uid, | ||
| valve_uid, |
There was a problem hiding this comment.
Avoid emitting valve-to-valve flow connectors
For flows with intermediate waypoints (flow.points.len() > 2), this loop writes type-1 connectors with both endpoints set to the valve UID. On MDL import, mdl/view/convert.rs::convert_connector applies valve indirection on both sides and turns those lines into variable-to-variable links (often a flow linking to itself), so exporting then re-importing mutates the diagram by adding bogus causal links. This regression is triggered specifically by bent flow pipes with interior points.
Useful? React with 👍 / 👎.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #332 +/- ##
==========================================
+ Coverage 79.61% 79.69% +0.08%
==========================================
Files 134 134
Lines 32650 32820 +170
==========================================
+ Hits 25993 26157 +164
- Misses 6657 6663 +6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
@codex review |
Code ReviewI reviewed all 15 changed files in this PR covering five distinct improvements: view title preservation, infinity formatting, arrayed stock INTEG roundtrip, flow pipe connector emission, and self-connector filtering. AnalysisView
Arrayed stock INTEG — The refactored Flow pipe connectors — The Self-connector filtering — The early-return in FindingsNo bugs found. The changes are well-structured, backward compatible, and thoroughly tested with targeted regression tests for each fix. Overall CorrectnessCorrect. The patch is free of bugs and blocking issues. All conversion paths are properly handled, protobuf compatibility is maintained, and edge cases are addressed. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: aecfb85150
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let view_title = sf.name.as_deref().unwrap_or("View 1"); | ||
| writeln!(self.buf, "*{}", view_title).unwrap(); |
There was a problem hiding this comment.
Sanitize stock-flow view titles before MDL emission
write_stock_flow_view now writes sf.name directly into the *<title> line, but this field is accepted verbatim from JSON/protobuf/XMILE without validation. If a title contains a newline ("\n"/"\r"), the generated sketch header is split across lines and parse_views (in mdl/view/mod.rs) can no longer interpret the next line as the expected font/element content, breaking MDL round-trip parsing for that project. Replacing line breaks with spaces (or otherwise escaping them) before writing the title avoids producing malformed MDL.
Useful? React with 👍 / 👎.
|
@codex review |
Code ReviewReviewed the full diff across all 15 changed files. The PR fixes MDL roundtrip edge cases: view title preservation, infinity formatting, arrayed stock INTEG emission, and flow pipe connector geometry. AnalysisProtobuf backward compatibility (serde.rs, project_io.proto): Tag 7 is new and unused by existing data. Proto3
Stock equation refactor (writer.rs:710-802): All three Flow pipe connectors (writer.rs:1064-1125): The iterator logic Self-connector filtering (view/convert.rs:571-576): Correctly skips attached-valve self-connectors during MDL→datamodel conversion, preventing spurious causal links from flow pipe geometry.
View title sanitization (writer.rs:1007-1025): Collapses CR/LF runs into a single space, preventing untrusted titles from breaking MDL sketch structure. XMILE wiring (xmile/views.rs): Name attribute correctly serialized/deserialized via FindingsNo bugs found. The changes are well-structured with targeted regression tests for each fix. Protobuf versioning is backward compatible, MDL format output is correct, and edge cases are handled properly. Verdict: CorrectThe patch introduces no regressions. Existing code and tests will not break. All conversion paths (MDL, XMILE, JSON, protobuf) correctly wire the new |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bd1297c867
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } | ||
|
|
||
| Some(View::StockFlow(datamodel::StockFlow { | ||
| name: Some(view.title().to_string()), |
There was a problem hiding this comment.
Use unnormalized title when persisting MDL view names
build_views normalizes and deduplicates view titles via make_view_names_unique before convert_view, so storing view.title() here persists the rewritten value rather than the original MDL title. That means titles containing normalized punctuation (like /, -, *) or colliding names still change on MDL roundtrip, which breaks the new title-preservation behavior for those models.
Useful? React with 👍 / 👎.
| elements: view.elements.into_iter().map(ViewElement::from).collect(), | ||
| view_box: view.view_box.map(Rect::from).unwrap_or_default(), | ||
| zoom: if approx_eq!(f64, view.zoom, 0.0) { | ||
| name: if name.is_empty() { None } else { Some(name) }, |
There was a problem hiding this comment.
Preserve empty view titles during protobuf decode
This conversion maps an empty protobuf name to None, which collapses an explicit blank title into “no title.” For MDL inputs that intentionally use * with an empty title, a protobuf roundtrip will later re-emit the default View 1 instead of the blank title, so title fidelity is lost.
Useful? React with 👍 / 👎.
Code ReviewI've reviewed the full diff for this PR covering view title preservation, infinity formatting, arrayed stock INTEG emission, flow pipe connector geometry, and the supporting protobuf/JSON/XMILE wiring. AnalysisView title (
Arrayed stock INTEG emission: The old code dropped initial values for Flow pipe connectors in UTF-8 marker: Adding FindingsNo bugs found. VerdictCorrect. The patch is well-structured with targeted regression tests for each fix. Serialization roundtrips are properly covered, edge cases are handled, and backward compatibility with existing protobuf data is maintained. |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: a9911cb85d
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| *next_connector_uid, | ||
| valve_uid, | ||
| endpoint_uid, |
There was a problem hiding this comment.
Emit flow pipe connectors with parser-compatible valve IDs
The new flow-pipe connector serialization uses valve_uid as the connector source, but the MDL import path still derives attached-flow relationships from the assumption that the valve is adjacent to the flow (valve_uid == flow_uid - 1 in compute_flow_data, and cloud mapping uses conn.from_uid + 1 in is_cloud_endpoint). Because allocate_valve_uids can remap valves far away from flow.uid (for example, the new test case uses valve 100 for flow 6), reparsing writer output can no longer recover endpoint attachments or bend geometry, so the advertised flow-connector roundtrip is not preserved.
Useful? React with 👍 / 👎.
Address four MDL writer regressions from PR 324 by handling non-finite numeric formatting, preserving stock initial values across all equation variants, emitting flow pipe connector geometry, and carrying stock-flow view titles through conversion and serialization. The changes keep behavior deterministic and backwards-safe by defaulting missing titles to View 1, using finite sentinels for infinities, and preserving existing output structure while extending the writer to handle previously dropped metadata.
Flow pipe interior bend points are encoded in MDL as type-1 connectors\nfrom an attached valve back to the same valve. Our connector converter\nwas applying valve indirection on both ends and incorrectly materializing\nthese geometry records as flow self-links during import.\n\nTreating attached-valve self-connectors as geometry preserves flow pipe\nserialization without introducing bogus causal links on re-import. Tests\nnow cover both convert_connector directly and the full build_views path.
StockFlow names are user-provided data and were written directly into the title sketch header line. Embedded CR/LF characters split the header across lines and made generated MDL sketch sections unparsable. Normalize view titles to a single line at emission time by collapsing line-break runs to a single space. Add a regression test that writes a multiline title, verifies single-line emission, and roundtrips through parse_mdl with the sanitized title.
Fix two remaining title roundtrip regressions and align MDL output encoding.
First, build_views now preserves the original MDL view title for persisted StockFlow names instead of the normalized/deduplicated internal title used for composition. This keeps punctuation and collision-prone titles stable across MDL roundtrips.
Second, protobuf view serialization now carries an explicit title-presence bit so an intentionally blank title can roundtrip as Some() while still decoding legacy missing-name payloads to None. MDL writing now always starts with {UTF-8} on the first line, with regression coverage for all changes.
MDL import assumed attached valves always used , but the writer can allocate non-adjacent valve UIDs to avoid collisions. That caused flow endpoint/cloud connectors to lose their flow association on roundtrip and produced detached flow endpoints. Build a per-view attached valve<->flow mapping once and reuse it for cloud detection, connector valve indirection, and flow endpoint resolution. Keep legacy +1 adjacency as a fallback for compatibility, and add regressions that cover non-adjacent valve IDs in both conversion and full MDL roundtrip paths.
ba3dcf5 to
ff9aaf9
Compare
Code ReviewI reviewed all 16 changed files in this PR covering: view title preservation, infinity formatting, arrayed stock INTEG reconstruction, flow pipe connector serialization, and the supporting protobuf/JSON/XMILE plumbing. FindingsNo bugs found. The implementation is well-constructed:
Test coverage is comprehensive — the new tests cover infinity formatting, view title roundtrip (including sanitization), arrayed stock INTEG for both Overall Correctness VerdictCorrect. The patch is free of bugs and blocking issues. Existing code and tests will not break. |
Code ReviewI reviewed all 16 changed files in this PR covering: view title preservation, infinity formatting, arrayed stock INTEG handling, flow pipe connector emission, robust valve-flow UID mapping, UTF-8 marker, and protobuf/JSON/XMILE wiring. FindingsNo bugs found. Analysis of Key ChangesArrayed stock handling ( Valve-flow mapping ( Flow pipe connectors ( Protobuf Self-connector filtering ( View title sanitization ( Overall Correctness VerdictCorrect. The patch is free of bugs and blocking issues. All changes are well-tested with targeted regression tests, the MDL format output is consistent with Vensim conventions, and the protobuf schema change is backward-compatible. |
|
Addressed the latest Codex feedback around MDL valve/flow roundtripping by removing the strict I also added regression coverage at two levels: an end-to-end |
Summary
name: Option<String>todatamodel::StockFlowand wiring it through MDL/XMILE/JSON/protobuf conversion pathsformat_f64to emit finite MDL-compatible sentinels for+/-infinityinstead of Rust'sinf/-infEquation::Scalar,Equation::ApplyToAll, andEquation::Arrayedso INTEG initial values are never dropped for arrayed stocksflow.points, including endpoint attachment connectors and intermediate waypointsTesting
cargo test -p simlin-engine mdl::writer::tests::cargo test -p simlin-engine mdl::view::convert::tests::test_build_single_viewcargo test -p simlin-engine json_proptest::cargo test -p simlin-engine --features file_io --test simulate simulates_models_correctlygit commitFixes #325
Fixes #326
Fixes #328
Fixes #329