{"record":{"id":"77e0a36e510559a2","repo":"nautechsystems/nautilus_trader","slug":"cannot-remove-strategy-strategy-id-not-found","errorCode":null,"errorMessage":"Cannot remove strategy, {strategy_id} not found","messagePattern":"Cannot remove strategy, (.+?) not found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/system/src/trader.rs","lineNumber":1424,"sourceCode":"        };\n\n        Ok(handler)\n    }\n\n    /// Removes the strategy with the given `strategy_id`.\n    ///\n    /// Will stop the strategy first if it is currently running. Disposes the strategy\n    /// and removes it from the trader's tracking along with its event subscriptions.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the strategy is not registered, the cache is already borrowed, or\n    /// disposal fails. A cache borrow failure preserves the strategy registration and its external\n    /// order claims. A failed disposal keeps the strategy registered and tracked, and leaves it\n    /// `Faulted`; see [`Component::dispose`]. Calling this again retires the strategy.\n    pub fn remove_strategy(&mut self, strategy_id: &StrategyId) -> anyhow::Result<()> {\n        if !self.strategy_ids.contains(strategy_id) {\n            anyhow::bail!(\"Cannot remove strategy, {strategy_id} not found\");\n        }\n\n        // Stop if running, then dispose\n        let _ = stop_component(&strategy_id.inner());\n        self.retire_strategy(*strategy_id)?;\n\n        log::info!(\n            \"Removed strategy {strategy_id} from trader {}\",\n            self.trader_id\n        );\n        Ok(())\n    }\n\n    /// Disposes an actor, then releases everything its registration created.\n    ///\n    /// Each component is retired completely before the next one starts, so a failure part way\n    /// through a bulk operation leaves the trader's bookkeeping consistent with the registries.\n    fn retire_actor(&mut self, actor_id: ActorId) -> anyhow::Result<()> {","sourceCodeStart":1406,"sourceCodeEnd":1442,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/system/src/trader.rs#L1406-L1442","documentation":"remove_strategy is a guard-clause in Trader::remove_strategy: it checks strategy_ids membership and bails if the StrategyId was never registered (or was already removed). The trader refuses to remove an unknown strategy rather than silently succeeding.","triggerScenarios":"Calling trader.remove_strategy(&strategy_id) with an ID that was never added, a strategy already removed in a prior call, or an ID from a different trader/config.","commonSituations":"Double teardown during shutdown; config lists a strategy that failed to register at startup; ID constructed manually instead of taken from the trader's registry.","solutions":["Check trader.strategy_ids().contains(strategy_id) before calling remove_strategy","Ensure the strategy was registered via trader.add_strategy before removal","Track removal state so teardown logic doesn't call remove_strategy twice","Log the registered strategy IDs when the removal fails to spot ID mismatches"],"exampleFix":"// before\ntrader.remove_strategy(&strategy_id)?;\n// after\nif trader.strategy_ids().contains(&strategy_id) {\n    trader.remove_strategy(&strategy_id)?;\n}","handlingStrategy":"validation","validationCode":"if trader.strategy_ids().contains(&strategy_id) { trader.remove_strategy(&strategy_id)?; }","typeGuard":null,"tryCatchPattern":"match trader.remove_strategy(&id) { Err(e) if e.to_string().contains(\"not found\") => {/* already removed */}, other => other?, }","preventionTips":["Track removal state to avoid double teardown","Only remove strategies you added and hold IDs for"],"tags":["rust","trader","lifecycle"],"backgroundTag":"entity-not-found","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"}