{"record":{"id":"dfa44d1508c21c87","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-ax-data-task-generation-e","errorCode":null,"errorMessage":"Failed to start AX data task generation: {e}","messagePattern":"Failed to start AX data task generation: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/architect_ax/src/data.rs","lineNumber":460,"sourceCode":"        {\n            log::debug!(\"Already connected {}\", self.client_id);\n            return Ok(());\n        }\n\n        log::info!(\"Connecting {}\", self.client_id);\n\n        if self.cancellation_token.is_cancelled()\n            || !self.pending_tasks.is_open()\n            || !self.session_tasks.is_open()\n            || !self.funding_rate_cancellations.is_empty()\n        {\n            self.teardown_partial_connect().await?;\n            self.session_tasks\n                .start_generation()\n                .map_err(|e| anyhow::anyhow!(\"Failed to start AX data session generation: {e}\"))?;\n            self.pending_tasks\n                .start_generation()\n                .map_err(|e| anyhow::anyhow!(\"Failed to start AX data task generation: {e}\"))?;\n            self.cancellation_token = CancellationToken::new();\n        }\n        let cancellation_token = self.cancellation_token.clone();\n        let ws_client = self.ws_client.clone();\n        let setup_guard =\n            TaskGroupGuard::new(&[&self.session_tasks, &self.pending_tasks], move || {\n                cancellation_token.cancel();\n                ws_client.begin_shutdown();\n            });\n\n        let credential = if self.config.has_api_credentials() {\n            let credential = Credential::resolve(\n                self.config.api_key.clone().map(|value| value.into_inner()),\n                self.config\n                    .api_secret\n                    .clone()\n                    .map(|value| value.into_inner()),\n            )","sourceCodeStart":442,"sourceCodeEnd":478,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/architect_ax/src/data.rs#L442-L478","documentation":"Immediately after starting the session task generation on connect, the pending task group's start_generation is called. If that fails, connect aborts with \"Failed to start AX data task generation\". The client then cannot register subscription tasks for the new session.","triggerScenarios":"Calling connect when the pending task group cannot begin a new generation — e.g. group left in an inconsistent state by an earlier partial teardown or a concurrent connect.","commonSituations":"Rapid disconnect/reconnect cycles; concurrent connect invocations; a previous connect that failed between the session and pending start_generation calls, leaving state torn.","solutions":["Serialize connect/disconnect calls (mutex or single owner) to prevent concurrent generation starts","Retry connect; if it persists, recreate the client to reset task group state","Ensure teardown_partial_connect fully clears pending_tasks before the next connect","Inspect the inner start_generation error for the specific cause"],"exampleFix":"// before\nlet (a, b) = tokio::join!(client_a.connect(), client_b.connect()); // same client shared\n// after\nstatic CONNECT: Mutex<()> = Mutex::new(()); // serialize connects\nlet _g = CONNECT.lock().await;\nclient.connect().await?;","handlingStrategy":"retry","validationCode":"// Rust\n// guard: only one connect in flight at a time\nlet _guard = connect_lock.lock().await;","typeGuard":null,"tryCatchPattern":"// Rust\nmatch client.connect().await {\n    Err(e) if e.to_string().contains(\"task generation\") => {\n        client.disconnect().await.ok(); // reset state then retry once\n        client.connect().await?;\n    }\n    other => other?,\n}","preventionTips":["Never share one data client across concurrent connect callers","After a failed connect, run disconnect/teardown before the next attempt","If generation start keeps failing, rebuild the client to reset task groups","Monitor reconnect storms — rapid cycles make these races likely"],"tags":["connection","lifecycle","tasks"],"backgroundTag":"internal-invariant-violation","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"}