{"record":{"id":"063f69a5c7d8943c","repo":"nautechsystems/nautilus_trader","slug":"account-event-had-a-different-account-id-expected","errorCode":null,"errorMessage":"Account event had a different account ID: expected {}, received {}","messagePattern":"Account event had a different account ID: expected (.+?), received (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/model/src/accounts/base.rs","lineNumber":242,"sourceCode":"        self.commissions.get(currency).copied()\n    }\n\n    /// Returns a map of all commissions by currency.\n    #[must_use]\n    pub fn commissions(&self) -> AHashMap<Currency, Money> {\n        self.commissions.clone()\n    }\n\n    /// Checks the event belongs to this account.\n    ///\n    /// Concrete accounts call this before mutating any state, so a foreign event is rejected\n    /// rather than partially applied.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if `event.account_id` does not match this account's ID.\n    pub(crate) fn check_event_account_id(&self, event: &AccountState) -> anyhow::Result<()> {\n        anyhow::ensure!(\n            event.account_id == self.id,\n            \"Account event had a different account ID: expected {}, received {}\",\n            self.id,\n            event.account_id\n        );\n        Ok(())\n    }\n\n    /// Applies an [`AccountState`] event, updating balances.\n    ///\n    /// # Panics\n    ///\n    /// Panics if `event.account_id` does not match this account's ID. Every account rejects a\n    /// foreign event before reaching here, so this remains an internal invariant.\n    pub fn base_apply(&mut self, event: AccountState) {\n        check_equal(&event.account_id, &self.id, \"event.account_id\", \"self.id\").expect(FAILED);\n        self.update_balances(&event.balances);\n        self.events.push(event);","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/model/src/accounts/base.rs#L224-L260","documentation":"An AccountState event was applied to an Account whose account_id does not match the event's account_id. The library guards against applying another account's state to this account, ensuring events are never partially or incorrectly applied. Raised by the internal `check_event_account_id` check.","triggerScenarios":"Routing an AccountState event for account X to the Account object for account Y — typically when an adapter emits events with a mismatched or reformatted account ID, or when events are dispatched to the wrong registered account.","commonSituations":"Broker adapter generating account IDs that change format across sessions, multiple accounts configured and events mixed up during replay, or event cache/actor wiring sending events to the wrong account handler.","solutions":["Check the adapter's account ID generation to confirm the event's account_id matches the account it is dispatched to","Verify only one account instance is registered per account_id in the cache","Re-run/reconcile with events from the correct account source"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if event.account_id != account.id:\n    log.error(f\"event for {event.account_id} routed to {account.id}; dropping\")\n    return","typeGuard":null,"tryCatchPattern":"try:\n    account.apply(event)\nexcept Exception as e:\n    log.error(f\"account event rejected: {e}\")","preventionTips":["Register exactly one account per account_id in the cache","Verify adapter account ID format is stable across sessions","Reconcile event account_id before dispatch in custom actors"],"tags":["rust","account-id","event-consistency"],"backgroundTag":"invalid-state-transition","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"}