nautechsystems/nautilus_trader · error
Cannot add execution algorithms in current state: {}
Error message
Cannot add execution algorithms in current state: {} What it means
validate_exec_algorithm_registration's catch-all arm rejects registration in any state other than PreInitialized, Ready, Stopped, Running, or Disposed, formatting the current ComponentState into the message. This covers states like Degraded or Faulted where the trader cannot safely wire a new exec algorithm.
Source
Thrown at crates/system/src/trader.rs:855
anyhow::bail!("Cannot add components to disposed trader")
}
_ => anyhow::bail!("Cannot add components in current state: {}", self.state),
}
}
/// Validates that the trader is in a valid state for execution algorithm registration.
pub(crate) fn validate_exec_algorithm_registration(&self) -> anyhow::Result<()> {
match self.state {
ComponentState::PreInitialized | ComponentState::Ready | ComponentState::Stopped => {
Ok(())
}
ComponentState::Running => {
anyhow::bail!("Cannot add execution algorithms to running trader")
}
ComponentState::Disposed => {
anyhow::bail!("Cannot add components to disposed trader")
}
_ => anyhow::bail!(
"Cannot add execution algorithms in current state: {}",
self.state
),
}
}
/// Starts all registered components.
///
/// # Errors
///
/// Returns an error if any component fails to start.
pub fn start_components(&mut self) -> anyhow::Result<()> {
let actor_ids = self.actor_ids.clone();
let strategy_ids = self.strategy_ids.clone();
let exec_algorithm_ids = self.exec_algorithm_ids.clone();
for actor_id in actor_ids {
log::debug!("Starting actor {actor_id}");View on GitHub (pinned to 18893faf8b)
Solutions
- Inspect the state printed in the message and recover the trader (reset/restart) before registering.
- Register exec algorithms during initial setup while the trader is PreInitialized or Ready.
- Rebuild the Trader if it is in Degraded/Faulted state rather than registering onto it.
Example fix
// before
trader.add_exec_algorithm(algo)?; // bails: Degraded
// after
if matches!(trader.state, ComponentState::PreInitialized | ComponentState::Ready | ComponentState::Stopped) {
trader.add_exec_algorithm(algo)?;
} else {
trader = rebuild_trader()?;
trader.add_exec_algorithm(algo)?;
} Defensive patterns
Strategy: validation
Validate before calling
let ok = matches!(trader.state, ComponentState::PreInitialized | ComponentState::Ready | ComponentState::Stopped);
if !ok { /* recover or rebuild the trader first */ } Type guard
fn accepts_exec_algorithm(state: &ComponentState) -> bool {
matches!(state, ComponentState::PreInitialized | ComponentState::Ready | ComponentState::Stopped)
} Try / catch
match trader.add_exec_algorithm(algo) {
Err(e) if e.to_string().contains("Cannot add execution algorithms in current state") => {
trader = rebuild_trader()?;
trader.add_exec_algorithm(algo)?;
}
other => other?,
} Prevention
- Recover from Degraded/Faulted states before any registration
- Perform all exec algorithm wiring in the setup phase
- Reset or rebuild the trader after component failures instead of patching state
When it happens
Trigger: Calling add_exec_algorithm while the trader state is an unlisted ComponentState (commonly Degraded/Faulted following a component failure) — add_exec_algorithm calls this validation before doing any work.
Common situations: Attempting to register exec algorithms after a prior strategy or actor faulted the trader; recovering from a crash where the trader was left in a non-ready state and the app resumed registration without a reset.
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 add exec algorithm while node is running, add exec al
- Cannot add components in current state: {}
- Cannot add execution algorithms to running trader
- Command receiver already taken
- Active execution intent {intent_id} was not found
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/2378fc4bd8ae640f.
Report an issue: GitHub.