nautechsystems/nautilus_trader · error
Failed to start AX execution session generation: {e}
Error message
Failed to start AX execution session generation: {e} What it means
During AX execution client connect, the adapter must (re)start its background task generations for pending-task and session-task groups. This error wraps a failure from `session_tasks.start_generation()` (the tokio task-group generation starter), raised after `teardown_partial_connect()` ran because a prior group was not open. It indicates the async runtime task set for the execution session could not be spawned.
Source
Thrown at crates/adapters/architect_ax/src/execution.rs:525
}
fn get_account(&self) -> Option<AccountAny> {
self.core.cache().account_owned(&self.core.account_id)
}
async fn connect(&mut self) -> anyhow::Result<()> {
if self.core.is_connected() && self.pending_tasks.is_open() && self.session_tasks.is_open()
{
return Ok(());
}
if !self.pending_tasks.is_open() || !self.session_tasks.is_open() {
self.teardown_partial_connect().await?;
self.pending_tasks.start_generation().map_err(|e| {
anyhow::anyhow!("Failed to start AX execution task generation: {e}")
})?;
self.session_tasks.start_generation().map_err(|e| {
anyhow::anyhow!("Failed to start AX execution session generation: {e}")
})?;
}
let http_client = self.http_client.clone();
let ws_orders = self.ws_orders.clone();
let setup_guard =
TaskGroupGuard::new(&[&self.session_tasks, &self.pending_tasks], move || {
http_client.cancel_all_requests();
ws_orders.begin_shutdown();
});
// Reset so requests work after a previous disconnect
self.http_client.reset_cancellation_token();
let credential = Credential::resolve(
self.config.api_key.clone().map(|value| value.into_inner()),
self.config
.api_secret
.clone()View on GitHub (pinned to 18893faf8b)
Solutions
- Ensure `connect` is not called after the client has been shut down; create a fresh client instance instead of reconnecting a torn-down one.
- Avoid concurrent/duplicate `connect` calls; serialize connection attempts behind a lock or once-guard.
- Check the wrapped source error (`: {e}`) from `start_generation` — it usually names the actual task-group failure (channel closed, runtime gone).
- Verify the client lives inside an active tokio runtime for the whole session, including reconnects.
Example fix
// before
let client = AxExecutionClient::new(...);
client.connect().await?; // after a prior shutdown this can fail
// after
let client = if client.is_connected() {
client
} else {
AxExecutionClient::new(...)? // fresh client for a fresh connect
};
client.connect().await?; Defensive patterns
Strategy: try-catch
Validate before calling
// before connect
if client_was_previously_shutdown { /* build a new client instead */ }
assert!(connect_once_flag.compare_exchange(false, true).is_ok(), "connect already in progress"); Try / catch
match client.connect().await {
Ok(()) => {},
Err(e) if e.to_string().contains("Failed to start AX execution") => {
log::error("task-group generation failed: {e:#}; rebuild client");
client = rebuild_client()?;
client.connect().await?;
}
Err(e) => return Err(e),
} Prevention
- Never reconnect a client after shutdown; construct a new one.
- Serialize connect calls with a mutex/once flag.
- Keep the tokio runtime alive for the client's entire lifetime.
- Always log the wrapped source error chain (`{e:#}`) for diagnosis.
When it happens
Trigger: Calling `connect` on the AX execution client when `pending_tasks` or `session_tasks` is not open, and the subsequent `start_generation()` call on the session task group fails (e.g. the task group's internal channel/generation handle is already shut down or the runtime cannot spawn the task).
Common situations: Reconnecting after a disconnect where the task groups were torn down mid-flight; calling connect concurrently from two places; a shutdown runtime or reactor context when the client is dropped while connecting; a prior connect failure leaving the group in a closed state.
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
- Failed to start Betfair data session tasks: {e}
- Failed to start Betfair data command tasks: {e}
- Failed to start Lighter task generation: {e}
- Failed to start Polymarket task generation: {e}
- Failed to start Polymarket session generation: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/ef83331d5147532b.
Report an issue: GitHub.