{"record":{"id":"49d847fffaca37bf","repo":"nautechsystems/nautilus_trader","slug":"actor-type-mismatch-for-id-expected-expected","errorCode":null,"errorMessage":"Actor type mismatch for '{id}': expected {expected_type:?}, found {actual_type:?}","messagePattern":"Actor type mismatch for '(.+?)': expected (.+?), found (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/actor/registry.rs","lineNumber":217,"sourceCode":"/// The returned [`ActorRef`] holds an `Rc` to keep the actor alive, preventing\n/// use-after-free if the actor is removed from the registry.\n///\n/// # Panics\n///\n/// - Panics if no actor with the specified `id` is found in the registry.\n/// - Panics if the stored actor is not of type `T`.\n#[must_use]\npub fn get_actor_unchecked<T: Actor>(id: &Ustr) -> ActorRef<T> {\n    let actor_rc = with_actor_registry(|registry| registry.get(id))\n        .unwrap_or_else(|| panic!(\"Actor for {id} not found\"));\n\n    match actor_ref_from_rc(actor_rc) {\n        Ok(actor_ref) => actor_ref,\n        Err(ActorRefError {\n            expected_type,\n            actual_type,\n        }) => {\n            panic!(\n                \"Actor type mismatch for '{id}': expected {expected_type:?}, found {actual_type:?}\"\n            )\n        }\n    }\n}\n\n/// Attempts to get a guard providing mutable access to the registered actor.\n///\n/// Returns `None` if the actor is not found or the type doesn't match.\n#[must_use]\npub fn try_get_actor_unchecked<T: Actor>(id: &Ustr) -> Option<ActorRef<T>> {\n    let actor_rc = with_actor_registry(|registry| registry.get(id))?;\n    actor_ref_from_rc(actor_rc).ok()\n}\n\n#[derive(Debug)]\nstruct ActorRefError {\n    expected_type: TypeId,","sourceCodeStart":199,"sourceCodeEnd":235,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/actor/registry.rs#L199-L235","documentation":"get_actor_unchecked first finds an actor by id, then downcasts its ActorRef to the requested type T. If an actor with the id exists but its concrete type differs from T, the function panics with the expected vs actual type names. 'Unchecked' refers to both existence and type assumptions being unchecked by the caller.","triggerScenarios":"Calling get_actor_unchecked::<SomeActor>(id) where the id maps to an actor of a different concrete type, e.g. two actor kinds registered under the same id, or the actor's type changed after a refactor.","commonSituations":"Registering a test double/mock under the same id as the production actor type; refactoring an actor's type without updating callers of get_actor_unchecked; generic code parameterized with the wrong Actor type argument.","solutions":["Check the actual type in the panic message and request that type (or a compatible one) in get_actor_unchecked::<T>","Ensure only one actor kind is registered under each id","Use the checked API that returns Result<ActorRef<T>, ActorRefError> to handle mismatches gracefully","Update call sites after refactoring an actor's concrete type"],"exampleFix":"// before\nlet actor = get_actor_unchecked::<DataActor>(&ustr(\"quotes\"));\n// after\nlet actor = get_actor_unchecked::<RiskActor>(&ustr(\"quotes\")); // request actual type per panic message","handlingStrategy":"validation","validationCode":"let actor = registry.get(&id).expect(\"actor registered\");\n// confirm concrete type before unchecked downcast via a checked API returning Result","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Avoid reusing the same id for different actor types","Centralize actor type bindings (id -> type) in one module","After refactoring an actor type, grep all get_actor_unchecked::<OldType> call sites"],"tags":["rust","actor-registry","type-mismatch","panic","downcast"],"backgroundTag":"type-mismatch","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"}