{"record":{"id":"627020a6ac88ca73","repo":"nautechsystems/nautilus_trader","slug":"execution-algorithm-exec-algorithm-id-is-alrea-627020","errorCode":null,"errorMessage":"Execution algorithm '{exec_algorithm_id}' is already tracked by trader","messagePattern":"Execution algorithm '(.+?)' is already tracked by trader","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/system/src/trader.rs","lineNumber":422,"sourceCode":"\n        Ok(())\n    }\n\n    /// Adds an externally-registered execution algorithm ID to the trader for lifecycle management.\n    ///\n    /// The execution algorithm must already be registered in the global component and actor\n    /// registries. This method only tracks the ID so the trader can manage the algorithm's\n    /// lifecycle (start/stop/dispose).\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if an execution algorithm with the same ID is already tracked.\n    pub fn add_exec_algorithm_id_for_lifecycle(\n        &mut self,\n        exec_algorithm_id: ExecAlgorithmId,\n    ) -> anyhow::Result<()> {\n        if self.exec_algorithm_ids.contains(&exec_algorithm_id) {\n            anyhow::bail!(\"Execution algorithm '{exec_algorithm_id}' is already tracked by trader\");\n        }\n\n        self.exec_algorithm_ids.push(exec_algorithm_id);\n\n        log::debug!(\n            \"Added exec algorithm ID '{exec_algorithm_id}' to trader {} for lifecycle management\",\n            self.trader_id\n        );\n\n        Ok(())\n    }\n\n    /// Adds an externally-registered strategy to the trader for lifecycle management\n    /// and installs its order/position event subscriptions, stop hook, and control endpoint.\n    ///\n    /// The strategy must already be registered in the global component and actor\n    /// registries. The generic parameter `T` must match the concrete type stored\n    /// in those registries so that the typed event handlers can retrieve it.","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/system/src/trader.rs#L404-L440","documentation":"add_exec_algorithm_id_for_lifecycle tracks an execution algorithm ID with the trader for lifecycle management and refuses IDs already tracked. Exec algorithms are singular per trader; a duplicate would create double lifecycle handling.","triggerScenarios":"Calling the public add_exec_algorithm_id_for_lifecycle twice with the same ExecAlgorithmId, typically from register_python_exec_algorithm_components running more than once (module re-init, repeated node setup).","commonSituations":"Re-running kernel/node setup in the same process, registering the same exec algorithm in both a builder and a manual setup path, notebook cells re-executed.","solutions":["Register each exec algorithm ID once; make registration idempotent.","Ensure only one code path registers exec algorithm components.","Rebuild the trader between runs instead of re-registering into it."],"exampleFix":"// before\nregister_python_exec_algorithm_components(...)\nregister_python_exec_algorithm_components(...)  # second pass: duplicate id\n// after\nif !exec_algorithm_registered {\n    register_python_exec_algorithm_components(...);\n    exec_algorithm_registered = true;\n}","handlingStrategy":"validation","validationCode":"if trader.exec_algorithm_ids().contains(&exec_algorithm_id) {\n    return Ok(()); // idempotent\n}\ntrader.add_exec_algorithm_id_for_lifecycle(exec_algorithm_id)?;","typeGuard":"fn exec_algo_tracked(trader: &Trader, id: &ExecAlgorithmId) -> bool {\n    trader.exec_algorithm_ids().contains(id)\n}","tryCatchPattern":"match trader.add_exec_algorithm_id_for_lifecycle(id) {\n    Err(e) if e.to_string().contains(\"already tracked by trader\") => Ok(()),\n    other => other,\n}","preventionTips":["Have a single code path that registers exec algorithm components","Make component registration idempotent for repeated node setup","Rebuild the trader/system per run rather than re-registering algorithms"],"tags":["exec-algorithm","duplicate","trader","lifecycle"],"backgroundTag":"file-already-exists","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"}