{"record":{"id":"00099068c354a40e","repo":"nautechsystems/nautilus_trader","slug":"actor-actor-id-is-already-tracked-by-trader","errorCode":null,"errorMessage":"Actor '{actor_id}' is already tracked by trader","messagePattern":"Actor '(.+?)' is already tracked by trader","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/system/src/trader.rs","lineNumber":387,"sourceCode":"        Ok(())\n    }\n\n    /// Adds an actor ID to the trader's lifecycle management without consuming the actor.\n    ///\n    /// This is useful when the actor is already registered in the global component registry\n    /// but the trader needs to track it for lifecycle management. The caller is responsible\n    /// for ensuring the actor is properly registered in the global registries.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the actor ID is already tracked by this trader.\n    pub fn add_actor_id_for_lifecycle<T>(&mut self, actor_id: ActorId) -> anyhow::Result<()>\n    where\n        T: DataActor + DataActorNative + Debug + 'static,\n    {\n        // Check for duplicate registration\n        if self.actor_ids.contains(&actor_id) {\n            anyhow::bail!(\"Actor '{actor_id}' is already tracked by trader\");\n        }\n\n        // Store actor ID for lifecycle management\n        self.actor_ids.push(actor_id);\n        self.actor_state_callbacks.insert(\n            actor_id,\n            ComponentStateCallbacks {\n                load: Self::load_component_state::<T>,\n                save: Self::save_component_state::<T>,\n            },\n        );\n\n        log::debug!(\n            \"Added actor ID '{actor_id}' to trader {} for lifecycle management\",\n            self.trader_id\n        );\n\n        Ok(())","sourceCodeStart":369,"sourceCodeEnd":405,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/system/src/trader.rs#L369-L405","documentation":"add_actor_id_for_lifecycle registers just an ActorId (for a native DataActor type) with the trader for lifecycle management. If the ID is already in actor_ids the call bails, since two lifecycle-tracked components cannot share one ID.","triggerScenarios":"Calling the public add_actor_id_for_lifecycle twice with the same ActorId, or after that ID was already registered through add_actor (which also pushes into actor_ids).","commonSituations":"Double registration during node/kernel setup, registering the same actor both as a full component and as an ID for lifecycle, test code re-invoking setup per case without a fresh trader.","solutions":["Register each actor ID exactly once per trader.","Don't mix add_actor and add_actor_id_for_lifecycle for the same ID.","Create a fresh Trader per run/test instead of reusing a populated one."],"exampleFix":"// before\ntrader.add_actor_id_for_lifecycle::<MyActor>(actor_id)?;\ntrader.add_actor_id_for_lifecycle::<MyActor>(actor_id)?; // duplicate\n// after\nif !trader.actor_ids.contains(&actor_id) {\n    trader.add_actor_id_for_lifecycle::<MyActor>(actor_id)?;\n}","handlingStrategy":"validation","validationCode":"if trader.actor_ids().contains(&actor_id) {\n    return Ok(()); // or skip\n}\ntrader.add_actor_id_for_lifecycle::<T>(actor_id)?;","typeGuard":"fn lifecycle_id_registered(trader: &Trader, id: &ActorId) -> bool {\n    trader.actor_ids().contains(id)\n}","tryCatchPattern":"match trader.add_actor_id_for_lifecycle::<T>(actor_id) {\n    Err(e) if e.to_string().contains(\"already tracked by trader\") => Ok(()),\n    other => other,\n}","preventionTips":["Register each actor ID through exactly one path (add_actor OR id-for-lifecycle)","Check actor_ids before adding lifecycle-only registrations","Avoid re-running registration setup on the same trader instance"],"tags":["actor","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-14T00:17:10.932Z"}