Store history restore for state transition
What does this MR do and why?
Store history restore for state transition
Implementation Changes:
- Updated JSON Schema - Added
state_historyarray field (max 5 items) tonamespace_detail_state_metadata.json - State History Tracking - Modified Stateful concern to:
- Track previous states in state_history (keeps last 5 states)
- Automatically record state before each transition
- Prevent duplicate consecutive states
- Restore Functionality - Added public restore(options = {}) method that:
- Restores namespace to its previous state from history
- Supports step-by-step restoration through state chain
- Updates metadata and logs restoration events
- Works with user attribution and correlation IDs
Implementation
Problems with transition :restore approach:
- The state machine can't dynamically determine where to restore to; it would need every possible combination hardcoded
- The destination state comes from
state_history.last, which the state machine can't access during event definition -
before_transitionguards (like validate_ancestors_state) would run and might block legitimate restores - Every time you add a new state, you'd need to update the restore event transitions
The current approach is better because:
-
restorebypasses the state machine intentionally - It's essentially a
manual overridethat directly manipulates the state - It has its own logging and metadata handling
- It's more flexible - it can restore to any previous state without declaring all combinations
References
Closes #583196
Screenshots or screen recordings
| Before | After |
|---|---|
How to set up and validate locally
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Shubham Kumar