{"record":{"id":"b10114b14c4c6a82","repo":"nautechsystems/nautilus_trader","slug":"actor-actor-id-is-already-registered","errorCode":null,"errorMessage":"Actor {actor_id} is already registered","messagePattern":"Actor (.+?) is already registered","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/system/src/python/registration.rs","lineNumber":68,"sourceCode":"};\n\nuse crate::{registration::ensure_unique_order_id_tag, trader::Trader};\n\nimpl Trader {\n    /// Adds an importable Python actor to the trader.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the actor cannot be imported, configured, registered, or tracked.\n    pub fn add_actor_from_importable_config(\n        &mut self,\n        config: &ImportableActorConfig,\n    ) -> anyhow::Result<ActorId> {\n        self.validate_actor_or_strategy_registration()?;\n\n        let (python_actor, actor_id) = create_python_actor(config)?;\n        if self.actor_ids.contains(&actor_id) {\n            anyhow::bail!(\"Actor {actor_id} is already registered\");\n        }\n\n        self.add_python_actor_instance(&python_actor, actor_id)?;\n\n        log::info!(\n            \"Registered Python actor {actor_id} with trader {}\",\n            self.trader_id\n        );\n        Ok(actor_id)\n    }\n\n    /// Adds a constructed Python actor instance to the trader under `actor_id`.\n    ///\n    /// The actor must already be configured; this runs the registration sequence every Python\n    /// actor needs and rolls back everything the attempt created if any step fails.\n    ///\n    /// # Errors\n    ///","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/system/src/python/registration.rs#L50-L86","documentation":"The Python-registration path (add_actor_from_importable_config) creates the Python actor instance and then checks whether an actor with the same ActorId is already registered with the trader. Duplicate ActorIds are not allowed — the trader would otherwise own two components with the same identity — so it bails before adding. Registration must use unique actor IDs per trader.","triggerScenarios":"Calling add_actor_from_importable_config (or trader.add_actor with a Python actor) with a config whose factory/actor_id resolves to an ActorId already present in self.actor_ids — e.g. registering the same importable actor config twice.","commonSituations":"Applying a config twice (double registration on reconnect or restart); configs for multiple actors that produce identical IDs because their override/instance IDs collide; adding an actor to both the trader and another owner then retrying.","solutions":["Ensure each actor config has a unique actor_id / instance_id override","Check before adding whether the actor ID is already registered and skip or error in caller code","Remove the duplicate registration attempt or de-duplicate config entries before applying","If re-registering intentionally, remove the existing actor first"],"exampleFix":"// before\nlet id = create_python_actor(&config)?.1;\ntrader.add_actor_from_importable_config(&config)?; // bails if duplicate\n// after\nlet id = create_python_actor(&config)?.1;\nif !trader.actor_ids().contains(&id) {\n    trader.add_actor_from_importable_config(&config)?;\n}","handlingStrategy":"validation","validationCode":"// Check for duplicate registration before adding\nlet actor_id = expected_actor_id(&config); // deterministic ID from config\nanyhow::ensure!(\n    !trader.actor_ids().contains(&actor_id),\n    \"actor {actor_id} already registered; skip or remove first\"\n);","typeGuard":null,"tryCatchPattern":"match trader.add_actor_from_importable_config(&config) {\n    Err(e) if e.to_string().contains(\"is already registered\") => {\n        log::debug!(\"actor already registered; skipping duplicate\");\n    }\n    other => other?,\n}","preventionTips":["Assign unique actor_id/instance_id overrides in every actor config","De-duplicate config lists before applying them to a trader","Avoid double-invoking registration on reconnect/restart paths"],"tags":["rust","python","trader","registration","duplicate-id"],"backgroundTag":"entity-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"}