{"record":{"id":"cd41a533460d2415","repo":"nautechsystems/nautilus_trader","slug":"cannot-add-exec-algorithm-while-node-is-running-a","errorCode":null,"errorMessage":"Cannot add exec algorithm while node is running, add exec algorithms before running the node","messagePattern":"Cannot add exec algorithm while node is running, add exec algorithms before running the node","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/live/src/node/mod.rs","lineNumber":2843,"sourceCode":"        cache.set_external_order_claims(strategy_id, &retained)\n    }\n\n    /// Adds an execution algorithm to the trader.\n    ///\n    /// Execution algorithms are registered in both the component registry (for lifecycle\n    /// management) and the actor registry (for data callbacks via msgbus).\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if:\n    /// - The node is currently running.\n    /// - An execution algorithm with the same ID is already registered.\n    pub fn add_exec_algorithm<T>(&mut self, exec_algorithm: T) -> anyhow::Result<()>\n    where\n        T: ExecutionAlgorithm + ExecutionAlgorithmNative + Component + Debug + 'static,\n    {\n        if self.state() != NodeState::Idle {\n            anyhow::bail!(\n                \"Cannot add exec algorithm while node is running, add exec algorithms before running the node\"\n            );\n        }\n\n        self.kernel\n            .trader\n            .borrow_mut()\n            .add_exec_algorithm(exec_algorithm)\n    }\n\n    // Runs reconciliation sub-checks, each gated by its own interval.\n    // Continuous checks only schedule venue work; they do not await venue I/O\n    // in the event loop.\n    fn run_reconciliation_checks(\n        &mut self,\n        now: dst::time::Instant,\n        intervals: ReconciliationCheckIntervals,\n        state: &mut ReconciliationCheckState<'_>,","sourceCodeStart":2825,"sourceCodeEnd":2861,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/live/src/node/mod.rs#L2825-L2861","documentation":"`add_exec_algorithm` only permits registering execution algorithms while the node is in `NodeState::Idle`. Calling it after the node has started (state != Idle) is rejected because the execution engine is already running and cannot safely incorporate new algorithms. Register all exec algorithms during setup, before calling run.","triggerScenarios":"Calling `node.add_exec_algorithm(algo)` after `node.run()` / `node.run_async()` has transitioned the node out of Idle; e.g. adding algorithms dynamically from a callback or after start.","commonSituations":"Trying to hot-swap or add a strategy's exec algorithm at runtime, or calling add_exec_algorithm after a first run in a long-lived process.","solutions":["Move all `add_exec_algorithm` calls before the node run call.","Check `node.state() == NodeState::Idle` before calling add_exec_algorithm.","If dynamic behavior is needed, configure the algorithm with internal logic that adapts at runtime instead of registering new ones.","Restart the node with the full set of exec algorithms configured up front."],"exampleFix":"// before\nnode.run()?;\nnode.add_exec_algorithm(MyAlgo::default())?;\n// after\nnode.add_exec_algorithm(MyAlgo::default())?;\nnode.run()?;","handlingStrategy":"type-guard","validationCode":"if node.state() != NodeState::Idle {\n    panic!(\"register exec algorithms before running the node\");\n}\nnode.add_exec_algorithm(algo)?;","typeGuard":"fn can_register_exec_algo(node: &LiveNode) -> bool { node.state() == NodeState::Idle }","tryCatchPattern":"match node.add_exec_algorithm(algo) {\n    Err(e) if e.to_string().contains(\"while node is running\") => {\n        eprintln!(\"defer registration: collect algos and register pre-run\");\n    }\n    r => r?,\n}","preventionTips":["Register all exec algorithms in the setup phase, before run().","Never mutate node composition from runtime callbacks.","Assert node state in tests that exercise node wiring."],"tags":["lifecycle","node-state","exec-algorithm","rust"],"backgroundTag":"invalid-state-transition","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}