nautechsystems/nautilus_trader · error · anyhow::Error
Cannot send account state: sender not initialized
Error message
Cannot send account state: sender not initialized
What it means
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.
Source
Thrown at crates/live/src/execution/emitter.rs:499
}
/// Emits an account state event.
pub fn send_account_state(&self, state: AccountState) {
if let Err(e) = self.try_send_account_state(state) {
log::warn!("{e}");
}
}
/// Emits an account state event and returns any channel error to the caller.
///
/// # Errors
///
/// Returns an error if the sender is uninitialized or its receiver is closed.
pub fn try_send_account_state(&self, state: AccountState) -> anyhow::Result<()> {
let sender = self.sender.load();
let sender = sender
.as_ref()
.ok_or_else(|| anyhow::anyhow!("Cannot send account state: sender not initialized"))?;
sender
.send(ExecutionEvent::Account(state))
.map_err(|e| anyhow::anyhow!("Failed to send account state: {e}"))
}
/// Emits an execution report.
pub fn send_execution_report(&self, report: ExecutionReport) {
if let Err(e) = self.try_send_execution_report(report) {
log::warn!("{e}");
}
}
/// Emits an execution report and returns any channel error to the caller.
///
/// # Errors
///
/// Returns an error if the sender is not initialized or the receiving channel is closed.
pub fn try_send_execution_report(&self, report: ExecutionReport) -> anyhow::Result<()> {View on GitHub (pinned to 18893faf8b)
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.
Example fix
// before
emitter.try_emit_account_state(state);
// after
if emitter.is_initialized() {
emitter.try_emit_account_state(state);
} else {
log::warn!("skipping account state emit: emitter not initialized");
} Defensive patterns
Strategy: try-catch
Validate before calling
if !emitter.is_initialized() { log::warn!("emitter not ready for account state"); return; } Type guard
fn can_emit(emitter: &ExecutionEmitter) -> bool { emitter.is_initialized() } Try / catch
match emitter.try_send_account_state(state) { Err(e) => log::warn!("account state emit failed: {e}"), Ok(()) => {} } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.
Related errors
- Cannot send order event: sender not initialized
- Failed to send account state: {e}
- Cannot send execution report: sender not initialized
- Active execution intent {intent_id} was not found
- DataActor {} must be registered before calling `clock_mut()`
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/f1e8906ba6649eb0.
Report an issue: GitHub.