{"record":{"id":"ef83331d5147532b","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-ax-execution-session-generation","errorCode":null,"errorMessage":"Failed to start AX execution session generation: {e}","messagePattern":"Failed to start AX execution session generation: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/architect_ax/src/execution.rs","lineNumber":525,"sourceCode":"    }\n\n    fn get_account(&self) -> Option<AccountAny> {\n        self.core.cache().account_owned(&self.core.account_id)\n    }\n\n    async fn connect(&mut self) -> anyhow::Result<()> {\n        if self.core.is_connected() && self.pending_tasks.is_open() && self.session_tasks.is_open()\n        {\n            return Ok(());\n        }\n\n        if !self.pending_tasks.is_open() || !self.session_tasks.is_open() {\n            self.teardown_partial_connect().await?;\n            self.pending_tasks.start_generation().map_err(|e| {\n                anyhow::anyhow!(\"Failed to start AX execution task generation: {e}\")\n            })?;\n            self.session_tasks.start_generation().map_err(|e| {\n                anyhow::anyhow!(\"Failed to start AX execution session generation: {e}\")\n            })?;\n        }\n        let http_client = self.http_client.clone();\n        let ws_orders = self.ws_orders.clone();\n        let setup_guard =\n            TaskGroupGuard::new(&[&self.session_tasks, &self.pending_tasks], move || {\n                http_client.cancel_all_requests();\n                ws_orders.begin_shutdown();\n            });\n\n        // Reset so requests work after a previous disconnect\n        self.http_client.reset_cancellation_token();\n\n        let credential = Credential::resolve(\n            self.config.api_key.clone().map(|value| value.into_inner()),\n            self.config\n                .api_secret\n                .clone()","sourceCodeStart":507,"sourceCodeEnd":543,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/architect_ax/src/execution.rs#L507-L543","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before\nlet client = AxExecutionClient::new(...);\nclient.connect().await?; // after a prior shutdown this can fail\n\n// after\nlet client = if client.is_connected() {\n    client\n} else {\n    AxExecutionClient::new(...)? // fresh client for a fresh connect\n};\nclient.connect().await?;","handlingStrategy":"try-catch","validationCode":"// before connect\nif client_was_previously_shutdown { /* build a new client instead */ }\nassert!(connect_once_flag.compare_exchange(false, true).is_ok(), \"connect already in progress\");","typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"Failed to start AX execution\") => {\n        log::error(\"task-group generation failed: {e:#}; rebuild client\");\n        client = rebuild_client()?;\n        client.connect().await?;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["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."],"tags":["async","connection","task-group","rust"],"backgroundTag":"invalid-state-transition","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}