nautechsystems/nautilus_trader · error
Failed to start AX data session generation: {e}
Error message
Failed to start AX data session generation: {e} What it means
On connect, if the client detects stale state (existing session/pending tasks or funding-rate cancellations), it tears down the partial connection and starts a fresh session-task generation. If start_generation fails, connect aborts with "Failed to start AX data session generation". This means the task group could not be reset for a clean session.
Source
Thrown at crates/adapters/architect_ax/src/data.rs:457
&& !self.cancellation_token.is_cancelled()
&& self.pending_tasks.is_open()
&& self.session_tasks.is_open()
{
log::debug!("Already connected {}", self.client_id);
return Ok(());
}
log::info!("Connecting {}", self.client_id);
if self.cancellation_token.is_cancelled()
|| !self.pending_tasks.is_open()
|| !self.session_tasks.is_open()
|| !self.funding_rate_cancellations.is_empty()
{
self.teardown_partial_connect().await?;
self.session_tasks
.start_generation()
.map_err(|e| anyhow::anyhow!("Failed to start AX data session generation: {e}"))?;
self.pending_tasks
.start_generation()
.map_err(|e| anyhow::anyhow!("Failed to start AX data task generation: {e}"))?;
self.cancellation_token = CancellationToken::new();
}
let cancellation_token = self.cancellation_token.clone();
let ws_client = self.ws_client.clone();
let setup_guard =
TaskGroupGuard::new(&[&self.session_tasks, &self.pending_tasks], move || {
cancellation_token.cancel();
ws_client.begin_shutdown();
});
let credential = if self.config.has_api_credentials() {
let credential = Credential::resolve(
self.config.api_key.clone().map(|value| value.into_inner()),
self.config
.api_secretView on GitHub (pinned to 18893faf8b)
Solutions
- Ensure disconnect/teardown_partial_connect completed before reconnecting; await it fully
- Avoid calling connect concurrently from multiple tasks (serialize with a lock/flag)
- Retry connect after inspecting task group state; recreate the client if state is corrupted
- Check the inner error text for the specific start_generation failure
Example fix
// before client.connect().await?; // after drop(client); // or ensure previous disconnect completed let client = AXDataClient::new(...); // fresh client on repeated start_generation failures client.connect().await?;
Defensive patterns
Strategy: retry
Validate before calling
// Rust // single-owner pattern: never call connect concurrently // if reconnecting, await previous disconnect() fully first
Try / catch
// Rust
loop {
match client.connect().await {
Ok(()) => break,
Err(e) if e.to_string().contains("session generation") && retries < 3 => {
client.disconnect().await.ok();
retries += 1;
}
Err(e) => return Err(e),
}
} Prevention
- Serialize connect/disconnect with a mutex or single owning task
- Fully await teardown before reconnecting; do not fire-and-forget disconnects
- On repeated failures, recreate the client rather than retrying on corrupt state
- Check the inner error message to distinguish generation conflicts from real failures
When it happens
Trigger: Calling connect when prior session_tasks are still open/registered and the session task group's start_generation returns an error (e.g. generation already in progress or group in an inconsistent state).
Common situations: Reconnecting after a previous disconnect that left tasks behind; concurrent connect calls racing on the same client; a previous teardown that did not fully complete.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- Failed to start AX data task generation: {e}
- std::mem::take(&mut self.shutdown_errors).join("; ")
- std::mem::take(&mut self.shutdown_errors).join("; ")
- Blockchain execution client is not connected
- WebSocket output receiver not available
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/9c9c5ff8afaf8530.
Report an issue: GitHub.