Repository navigation
engine: move compat fields into Compat struct - #319
Conversation
Code Review: engine: move compat fields into Compat structReviewed the full diff across all 38 changed files. This is a clean structural refactoring that moves FindingsNo bugs found. Key observationsProtobuf backward compatibility is correctly handled: old protos (without the new compat fields) are read by falling back to the top-level fields ( JSON serialization correctly moves the fields into the JSON schema is consistent: the TypeScript changes are aligned: XMILE conversion uses the updated Salsa DB layer ( Overall correctness verdictCorrect. The patch is free of bugs. The field migration is consistent across all serialization formats and code layers, with proper backward compatibility for protobufs. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dbee259340
ℹ️ 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".
| non_negative: false, | ||
| can_be_module_input: false, | ||
| visibility: 0, |
There was a problem hiding this comment.
Preserve legacy proto flags when writing variables
This serializer now zeroes the legacy protobuf fields (non_negative, can_be_module_input, visibility) and only writes the real values into compat. Because project_io.proto still carries those legacy fields for compatibility, any reader on the previous schema/version (or a rollback) will ignore compat and deserialize changed variables as defaults (negative-allowed, not module-input, private), which changes model semantics after a save. Keep emitting the legacy fields in parallel with compat until old readers are no longer possible.
Useful? React with 👍 / 👎.
PR Review: engine: move compat fields into Compat structSummaryThis PR consolidates FindingsNo bugs found. AnalysisBackward compatibility (JSON): Handled correctly. The Rust Backward compatibility (protobuf): Handled correctly. The protobuf schema adds new optional fields to the TypeScript consistency: The engine types ( Python bindings: The Schema: The Overall Correctness VerdictCorrect. The patch is thorough and consistent across all layers (Rust, TypeScript, Python). Backward compatibility is maintained for both JSON and protobuf serialization formats. Tests cover legacy deserialization, precedence rules, and roundtrip behavior. |
These fields are Vensim compatibility options that belong together in the Compat sub-struct rather than cluttering the top-level variable types. The Compat struct now holds active_initial, non_negative, can_be_module_input, and visibility (previously it only had active_initial). This consolidation applies across the full stack: Rust datamodel, JSON serialization, protobuf schema, TypeScript types, and TypeScript converters. Module gains a compat field matching the pattern already used by Stock, Flow, and Aux.
…ypes.ts The prior commit moved these fields on the Rust and JSON serialization side but missed the public TypeScript API types in types.ts. This completes the migration so the types match the actual serialization format.
Add legacy field reading for JSON (skip_serializing + default) so old .simlin files with top-level non_negative/can_be_module_input/is_public still deserialize correctly. Proto serializer now populates legacy fields with actual values so old code reading from Firestore sees correct data. Extract Compat::is_empty() to DRY up duplicated emptiness checks. Update pysimlin json_types/json_converter/model to match the new nested compat structure with fallback to legacy top-level fields.
Legacy JSON files can have compat only for activeInitial while boolean flags (nonNegative, canBeModuleInput, isPublic) remain top-level. The previous fallback logic only checked legacy fields when compat was absent; when compat existed (even just for activeInitial), the defaulted false booleans in compat silently overrode top-level true values. Fix by OR-merging: the result is true if either compat or the legacy field says true. This is safe because old files never write compat booleans and new files never write top-level booleans, so the contradictory case cannot arise in practice.
fba88b7 to
3e59757
Compare
Code Review: engine: move compat fields into Compat structI reviewed all 42 changed files in this PR, focusing on:
SummaryThis is a well-implemented migration that consolidates Backward Compatibility AnalysisRust JSON ( Protobuf ( Python ( TypeScript ( FindingsNo bugs found. The migration is thorough and handles all backward compatibility paths correctly across JSON, protobuf, and XMILE serialization formats. Overall Correctness VerdictCorrect. The patch properly migrates compat fields into a dedicated struct with full backward compatibility for all serialization formats. Existing tests and code will not break. |
Code ReviewSummaryThis PR consolidates AnalysisThe refactoring is well-executed. Key observations:
FindingsNo bugs found. The migration is mechanically correct across all layers, backward compatibility is properly maintained, and the test coverage is comprehensive. Verdict: CorrectThe patch is free of bugs and blocking issues. Existing code and tests should not break. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #319 +/- ##
==========================================
+ Coverage 79.16% 79.24% +0.07%
==========================================
Files 121 121
Lines 30832 30954 +122
==========================================
+ Hits 24409 24528 +119
- Misses 6423 6426 +3 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The aux case manually reconstructed compat from only activeInitial, dropping canBeModuleInput, isPublic, and nonNegative. This could cause callers to lose access metadata and unintentionally clear those flags when writing updates. Fix by passing through v.compat directly, matching the behavior of the Stock, Flow, and Module cases.
Code ReviewReviewed the full diff (~6600 lines across 42 files) covering Rust engine, TypeScript, Python, protobuf schema, JSON schema, XMILE/MDL conversion, and test updates. SummaryThis PR consolidates Key Design Decisions (all look correct)
Verification Points
FindingsNo bugs found. The migration is correct across all serialization formats (JSON, protobuf, XMILE) and all three language implementations (Rust, TypeScript, Python). Backward compatibility is properly maintained for both protobuf (DB records) and JSON (project files). Overall correctness: correct — existing code and tests will not break, and the patch is free of blocking issues. |
…Json The TypeScript core stockFromJson and flowFromJson read nonNegative only from json.compat, but legacy JSON still has it at top level. This caused silent data loss when loading older project files. Add legacy nonNegative field back to JsonStock/JsonFlow types and OR-merge like the Rust side.
Code ReviewI reviewed the full diff for PR #319 which consolidates Findings[P3] JSON schema inconsistency: Stock retains legacy fields but Flow/Aux do not
The Stock schema definition retains legacy top-level Overall Correctness VerdictCorrect. The patch correctly handles backward compatibility across all serialization boundaries (JSON, protobuf, XMILE). Legacy fields are properly OR-merged with the new |
Document why OR-merging compat booleans with legacy top-level fields is safe: old code never writes compat booleans and new code uses skip_serializing on legacy fields, so both cannot be meaningfully set at once. The contradictory case (compat false + legacy true) cannot arise through normal serialization paths.
Code ReviewThis PR consolidates
FindingsNo bugs found. The migration is well-structured:
Verdict: CorrectThe patch is free of bugs and handles backward compatibility thoroughly across all serialization formats (JSON, protobuf) and all language layers (Rust, TypeScript, Python). |
The generic rule that dropped optional fields unstructuring to {} was
too broad -- it could also drop GraphicalFunction() or other optional
objects that legitimately serialize as empty dicts. Restrict the check
to only the 'compat' field where empty means semantically None.
Code Review: engine: move compat fields into Compat structI reviewed the full diff across all 42 changed files, focusing on data integrity during serialization/deserialization roundtrips, backward compatibility with legacy field formats, and consistency across the Rust, TypeScript, and Python codebases. SummaryThis PR consolidates FindingsNo blocking bugs found. The key correctness properties I verified:
Observations (non-blocking)
VerdictOverall correctness: Correct. The patch maintains full backward compatibility, roundtrip integrity is preserved across all serialization formats, and the consolidation is applied consistently across all three language implementations. The property-based tests provide good coverage for the new structure. |
Review cycle summaryThis PR went through 7 automated review iterations (codex + claude) that drove several backward-compatibility improvements beyond the original structural migration. The key improvements made during review were: adding OR-merge semantics so that legacy top-level boolean fields ( A pre-existing issue with Module visibility being lost during Salsa DB synchronization was identified and tracked separately as #320. |
Summary
non_negative,can_be_module_input, andvisibilityfields into aCompatstruct in the Rust enginenonNegative,canBeModuleInput, andisPublicinto aCompattype intypes.tsTest plan