{"record":{"id":"cef2ae489175bfb0","repo":"nautechsystems/nautilus_trader","slug":"execution-algorithm-exec-algorithm-id-is-alrea","errorCode":null,"errorMessage":"Execution algorithm '{exec_algorithm_id}' is already registered","messagePattern":"Execution algorithm '(.+?)' is already registered","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/system/src/python/registration.rs","lineNumber":346,"sourceCode":"    /// Adds a constructed [`PyExecutionAlgorithm`] instance to the trader.\n    ///\n    /// `wrapper` is the Python object which owns `algorithm`; the trader's registries keep it\n    /// alive for as long as the algorithm stays registered.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the trader already tracks a component under the algorithm's ID, or if\n    /// the algorithm cannot be registered or tracked.\n    pub fn add_py_execution_algorithm_instance(\n        &mut self,\n        algorithm: PyExecutionAlgorithm,\n        wrapper: &Py<PyAny>,\n    ) -> anyhow::Result<ExecAlgorithmId> {\n        let exec_algorithm_id = algorithm.exec_algorithm_id();\n\n        // Checked before the shared guard so a same-kind duplicate keeps its own message\n        if self.exec_algorithm_ids.contains(&exec_algorithm_id) {\n            anyhow::bail!(\"Execution algorithm '{exec_algorithm_id}' is already registered\");\n        }\n\n        let component_id = ComponentId::from(exec_algorithm_id);\n        self.ensure_component_id_available(component_id)?;\n\n        if let Err(e) = self.add_exec_algorithm(algorithm) {\n            // Without this the guard sees the stranded clock and dead-ends this ID until disposal\n            self.release_component(component_id);\n            return Err(e);\n        }\n\n        Python::attach(|py| {\n            retain_python_wrapper(component_id, wrapper.clone_ref(py));\n        });\n\n        Ok(exec_algorithm_id)\n    }\n","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/system/src/python/registration.rs#L328-L364","documentation":"Thrown by `add_py_execution_algorithm_instance` when an ExecAlgorithmId matching `algorithm.exec_algorithm_id()` is already present in the trader's `exec_algorithm_ids`. Exec algorithm IDs must be unique per trader so order routing can dispatch to the right algorithm. The same-ID check deliberately runs before the shared component-ID guard so same-kind duplicates get this specific message.","triggerScenarios":"Calling `add_py_execution_algorithm_instance` with a wrapper whose exec_algorithm_id was already registered — e.g. adding the same exec algorithm class twice, or two wrappers configured with the same name/ID.","commonSituations":"Duplicate exec_algorithm entries in a trader config; re-adding an algorithm after reconfiguration without deregistering; a test that registers the same algorithm twice (the listed caller is a test asserting ID reusability after failed registration).","solutions":["Give each exec algorithm a unique name/ID in its configuration","Remove the duplicate registration call","Check `trader.exec_algorithm_ids` before adding","If re-registering, deregister the existing algorithm first"],"exampleFix":"// before\ntrader.add_exec_algorithm(algo_a);  # id: MyExecAlgorithm\ntrader.add_exec_algorithm(algo_a_clone);  # same id -> error\n// after\nalgo_b = MyExecAlgorithm(config with name='MyExecAlgorithm2')\ntrader.add_exec_algorithm(algo_b);","handlingStrategy":"validation","validationCode":"if exec_algorithm_id in trader.exec_algorithm_ids():\n    raise ValueError(f\"{exec_algorithm_id} already registered\")","typeGuard":"def is_new_exec_algorithm(trader, algo) -> bool:\n    return algo.exec_algorithm_id() not in trader.exec_algorithm_ids()","tryCatchPattern":"try:\n    trader.add_exec_algorithm(algo)\nexcept ValueError as e:\n    if \"already registered\" in str(e):\n        logger.warning(\"skipping duplicate exec algorithm: %s\", e)\n    else:\n        raise","preventionTips":["Give each exec algorithm a unique name in config","Deduplicate exec_algorithm config lists before trader construction","Keep algorithm registration idempotent: check-then-add"],"tags":["rust","registration","duplicate-id","exec-algorithm"],"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-14T00:17:10.932Z"}