nautechsystems/nautilus_trader · error
Cannot add exec algorithm while node is running, add exec al
Error message
Cannot add exec algorithm while node is running, add exec algorithms before running the node
What it means
add_exec_algorithm (crates/live/src/node/mod.rs:2739) registers an execution algorithm (e.g. TWAP) with the trader so orders tagged with that algorithm are routed to it. Registration must occur before the node runs; the guard requires NodeState::Idle and bails otherwise, because order routing to the algorithm is established at startup.
Source
Thrown at crates/live/src/node/mod.rs:2750
Ok(())
}
/// Adds an execution algorithm to the trader.
///
/// Execution algorithms are registered in both the component registry (for lifecycle
/// management) and the actor registry (for data callbacks via msgbus).
///
/// # Errors
///
/// Returns an error if:
/// - The node is currently running.
/// - An execution algorithm with the same ID is already registered.
pub fn add_exec_algorithm<T>(&mut self, exec_algorithm: T) -> anyhow::Result<()>
where
T: ExecutionAlgorithm + ExecutionAlgorithmNative + Component + Debug + 'static,
{
if self.state() != NodeState::Idle {
anyhow::bail!(
"Cannot add exec algorithm while node is running, add exec algorithms before running the node"
);
}
self.kernel
.trader
.borrow_mut()
.add_exec_algorithm(exec_algorithm)
}
// Runs reconciliation sub-checks, each gated by its own interval.
// Continuous checks only schedule venue work; they do not await venue I/O
// in the event loop.
fn run_reconciliation_checks(
&mut self,
now: dst::time::Instant,
intervals: ReconciliationCheckIntervals,
state: &mut ReconciliationCheckState<'_>,View on GitHub (pinned to 2114cf6f76)
Solutions
- Register exec algorithms during node construction, before run().
- Add a startup checklist (actors, strategies, exec algorithms, cache database) that completes before run() is called.
- Build a new node if an algorithm must be added after a session.
- Verify with node.state() checks in generic launchers before calling registration APIs.
Defensive patterns
Strategy: validation
Validate before calling
if node.state() != NodeState::Idle {
anyhow::bail!("cannot register exec algorithms now; add them before running the node");
}
node.add_exec_algorithm(TwapAlgorithm::new())?; Try / catch
if let Err(e) = node.add_exec_algorithm(algo) {
if e.to_string().contains("while node is running") {
log::error!("exec algorithm registration must happen before run()");
}
return Err(e);
} Prevention
- Register exec algorithms (TWAP etc.) at node construction time.
- Verify the algorithm set before run() if orders will be tagged with an exec_algorithm_id.
- Build a fresh node when the algorithm set must change.
When it happens
Trigger: Calling node.add_exec_algorithm(algo) once the node state is not Idle, e.g. after run() has begun, during shutdown, or on an already-run node instance.
Common situations: Installing an exec algorithm in response to runtime conditions; adding TWAP after noticing it was forgotten only once the node is live; hosted launchers attaching algorithms lazily.
Related errors
- Cannot add actor while node is running, add actors before ru
- Cannot add strategy while node is running, add strategies be
- Already running
- Cannot set cache database while node is running, set it befo
- Binance Spot user data stream is not active
AI-assisted analysis of nautechsystems/nautilus_trader@2114cf6f76 (2026-08-21).
Data as JSON: /api/errors/cd41a533460d2415.
Report an issue: GitHub.