{"record":{"id":"f1e8906ba6649eb0","repo":"nautechsystems/nautilus_trader","slug":"cannot-send-account-state-sender-not-initialized","errorCode":null,"errorMessage":"Cannot send account state: sender not initialized","messagePattern":"Cannot send account state: sender not initialized","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/live/src/execution/emitter.rs","lineNumber":499,"sourceCode":"    }\n\n    /// Emits an account state event.\n    pub fn send_account_state(&self, state: AccountState) {\n        if let Err(e) = self.try_send_account_state(state) {\n            log::warn!(\"{e}\");\n        }\n    }\n\n    /// Emits an account state event and returns any channel error to the caller.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the sender is uninitialized or its receiver is closed.\n    pub fn try_send_account_state(&self, state: AccountState) -> anyhow::Result<()> {\n        let sender = self.sender.load();\n        let sender = sender\n            .as_ref()\n            .ok_or_else(|| anyhow::anyhow!(\"Cannot send account state: sender not initialized\"))?;\n        sender\n            .send(ExecutionEvent::Account(state))\n            .map_err(|e| anyhow::anyhow!(\"Failed to send account state: {e}\"))\n    }\n\n    /// Emits an execution report.\n    pub fn send_execution_report(&self, report: ExecutionReport) {\n        if let Err(e) = self.try_send_execution_report(report) {\n            log::warn!(\"{e}\");\n        }\n    }\n\n    /// Emits an execution report and returns any channel error to the caller.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the sender is not initialized or the receiving channel is closed.\n    pub fn try_send_execution_report(&self, report: ExecutionReport) -> anyhow::Result<()> {","sourceCodeStart":481,"sourceCodeEnd":517,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/live/src/execution/emitter.rs#L481-L517","documentation":"Same uninitialized-sender condition as the order-event variant, raised by try_send_account_state: the emitter's sender slot is None when an AccountState is about to be routed onto the execution event channel. The emitter cannot deliver account state updates before it is initialized.","triggerScenarios":"Calling try_send_account_state (via try_emit_account_state or send_account_state) before the emitter's sender is wired — typically during early live-node startup or before account initialization completes.","commonSituations":"Venue adapters generating an account state immediately on connect while the execution engine start sequence hasn't registered the channel; reconnect flows re-emitting account states prematurely.","solutions":["Initialize the emitter/engine before emitting account states.","Gate account-state emission on the live execution engine being started.","Queue or retry the account state emission until the emitter is ready.","If reproducible in a normal startup, verify adapter integration follows the engine's start order."],"exampleFix":"// before\nemitter.try_emit_account_state(state);\n// after\nif emitter.is_initialized() {\n    emitter.try_emit_account_state(state);\n} else {\n    log::warn!(\"skipping account state emit: emitter not initialized\");\n}","handlingStrategy":"try-catch","validationCode":"if !emitter.is_initialized() { log::warn!(\"emitter not ready for account state\"); return; }","typeGuard":"fn can_emit(emitter: &ExecutionEmitter) -> bool { emitter.is_initialized() }","tryCatchPattern":"match emitter.try_send_account_state(state) { Err(e) => log::warn!(\"account state emit failed: {e}\"), Ok(()) => {} }","preventionTips":["Emit account states only after engine start completes","Queue early account states and flush post-init","Keep adapter on_connect handlers from emitting synchronously before wiring is done"],"tags":["rust","lifecycle","account","channel"],"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-14T00:17:10.932Z"}