{"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":2750,"sourceCode":"        Ok(())\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":2732,"sourceCodeEnd":2768,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/2114cf6f761429e0adb5ca9596fcd7b895b16011/crates/live/src/node/mod.rs#L2732-L2768","documentation":"add_exec_algorithm (crates/live/src/node/mod.rs:2739) registers an execution algorithm (e.g. TWAP) with the trader so orders tagged with that algorithm are routed to it. Registration must occur before the node runs; the guard requires NodeState::Idle and bails otherwise, because order routing to the algorithm is established at startup.","triggerScenarios":"Calling node.add_exec_algorithm(algo) once the node state is not Idle, e.g. after run() has begun, during shutdown, or on an already-run node instance.","commonSituations":"Installing an exec algorithm in response to runtime conditions; adding TWAP after noticing it was forgotten only once the node is live; hosted launchers attaching algorithms lazily.","solutions":["Register exec algorithms during node construction, before run().","Add a startup checklist (actors, strategies, exec algorithms, cache database) that completes before run() is called.","Build a new node if an algorithm must be added after a session.","Verify with node.state() checks in generic launchers before calling registration APIs."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if node.state() != NodeState::Idle {\n    anyhow::bail!(\"cannot register exec algorithms now; add them before running the node\");\n}\nnode.add_exec_algorithm(TwapAlgorithm::new())?;","typeGuard":null,"tryCatchPattern":"if let Err(e) = node.add_exec_algorithm(algo) {\n    if e.to_string().contains(\"while node is running\") {\n        log::error!(\"exec algorithm registration must happen before run()\");\n    }\n    return Err(e);\n}","preventionTips":["Register exec algorithms (TWAP etc.) at node construction time.","Verify the algorithm set before run() if orders will be tagged with an exec_algorithm_id.","Build a fresh node when the algorithm set must change."],"tags":["live-node","exec-algorithm","registration","lifecycle"],"backgroundTag":"invalid-lifecycle-state","analyzedSha":"2114cf6f761429e0adb5ca9596fcd7b895b16011","analyzedAt":"2026-08-21T11:28:30.864Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}