Currently, persisting the state of a StateChart (especially complex ones with hierarchy or parallelism) often requires relying on internal implementation details. I am proposing the addition of a formal, public API for serialization and deserialization to ensure robust persistence across different storage backends.
Proposed Requirements
- Standardized Data Format: Define a clear, versioned schema (e.g., JSON Schema) that represents the full configuration of a running state machine.
- Public API: Provide a documented public API for:
- Exporting the current state configuration to the schema format.
- Re-instantiating a
StateChart instance from that format.
- Full Feature Support: The persistence mechanism must accurately capture and restore:
- Compound States: The
StateChart must be re-instantiated in exactly the same inner/nested state it was in before saving.
- Parallel States: All parallel regions must be restored so that every active branch is exactly as it was before the save.
- History States: Snapshots of both deep and shallow history states to ensure transitions back into compounds work correctly after a reload.
- No Side Effects on Re-instantiation: Guards and callbacks should not be re-evaluated during re-instantiation, as they would have already executed prior to the save. Possibly, add a setting to change this behavior.
Use Cases
This is essential for long-running workflows and entities where the state machine instance cannot reside in memory indefinitely, e.g.:
- Web applications saving state to DB between requests
- Distributed systems and serverless environments where a state machine must "sleep" in storage and "wake up" on a different node without losing its position in a complex hierarchy or parallel flow
Considerations
- Re-binding of the custom models
- Delayed events
Currently, persisting the state of a
StateChart(especially complex ones with hierarchy or parallelism) often requires relying on internal implementation details. I am proposing the addition of a formal, public API for serialization and deserialization to ensure robust persistence across different storage backends.Proposed Requirements
StateChartinstance from that format.StateChartmust be re-instantiated in exactly the same inner/nested state it was in before saving.Use Cases
This is essential for long-running workflows and entities where the state machine instance cannot reside in memory indefinitely, e.g.:
Considerations