{"record":{"id":"c516580c885a469a","repo":"nautechsystems/nautilus_trader","slug":"failed-to-restore-strategy-strategy-id-state-e","errorCode":null,"errorMessage":"Failed to restore strategy {strategy_id} state: {e:#}","messagePattern":"Failed to restore strategy (.+?) state: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/system/src/trader.rs","lineNumber":1606,"sourceCode":"            };\n\n            (callbacks.load)(actor_id.inner(), state)\n                .map_err(|e| anyhow::anyhow!(\"Failed to restore actor {actor_id} state: {e:#}\"))?;\n        }\n\n        for (strategy_id, callbacks) in strategy_callbacks {\n            let state = cache\n                .borrow()\n                .load_strategy_state(&strategy_id)\n                .map_err(|e| {\n                    anyhow::anyhow!(\"Failed to load strategy {strategy_id} state: {e:#}\")\n                })?;\n            let Some(state) = state.filter(|state| !state.is_empty()) else {\n                continue;\n            };\n\n            (callbacks.load)(strategy_id.inner(), state).map_err(|e| {\n                anyhow::anyhow!(\"Failed to restore strategy {strategy_id} state: {e:#}\")\n            })?;\n        }\n\n        Ok(())\n    }\n\n    /// Saves actor and strategy state in registration order.\n    ///\n    /// Empty state is persisted, while a cache without database backing does not invoke\n    /// component callbacks. All callbacks and updates receive an attempt before errors return.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error containing every component callback or persistence failure.\n    pub(crate) fn save_state(trader: &Rc<RefCell<Self>>) -> anyhow::Result<()> {\n        let (cache, actor_callbacks, strategy_callbacks) = {\n            let trader = trader.borrow();\n            let actor_callbacks = trader.actor_state_callbacks()?;","sourceCodeStart":1588,"sourceCodeEnd":1624,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/system/src/trader.rs#L1588-L1624","documentation":"Raised in `Trader::load_state` when a strategy's registered `on_load` state-restoration callback returns an error. The persisted state was read from the cache successfully, but the strategy could not restore it, so recovery aborts with this message.","triggerScenarios":"Trader start with state recovery enabled; the cache returns non-empty state for the strategy and the strategy's `load` callback errors — typically because the saved payload does not match the strategy's current state schema (version upgrade, changed fields, wrong strategy type).","commonSituations":"Restarting after a nautilus upgrade with state saved by the older version; refactoring a strategy's saved-state struct without a migration; a cache shared between configurations containing state for a different strategy instance.","solutions":["Inspect the wrapped `{e:#}` for the exact restore failure and align the load callback with the persisted schema","Ensure the strategy implementation/version that saved the state matches the one restoring it; add migration logic to the load callback if needed","Delete the strategy's stale persisted key so it starts with empty state, then let it re-save","Keep library versions consistent between state-saving and state-restoring runs"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// round-trip check the strategy state before relying on recovery\nlet state = cache.load_strategy_state(&strategy_id)?;\nstrategy.test_restore(state.clone())?;","typeGuard":null,"tryCatchPattern":"do {\n    system.start_with_recovery()\n} catch e if e.contains(\"Failed to restore strategy\") => {\n    // migrate the schema or delete the stale key, then restart\n}","preventionTips":["Version and migration-test strategy state schemas across releases","Save/restore with the identical strategy type and library version","Round-trip test save/load in CI for every strategy","Delete stale keys intentionally when a strategy's state layout changes"],"tags":["state","strategy","restore","persistence"],"backgroundTag":"state-restore-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}