{"record":{"id":"9c9c5ff8afaf8530","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-ax-data-session-generation-e","errorCode":null,"errorMessage":"Failed to start AX data session generation: {e}","messagePattern":"Failed to start AX data session generation: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/architect_ax/src/data.rs","lineNumber":457,"sourceCode":"            && !self.cancellation_token.is_cancelled()\n            && self.pending_tasks.is_open()\n            && self.session_tasks.is_open()\n        {\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","sourceCodeStart":439,"sourceCodeEnd":475,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/architect_ax/src/data.rs#L439-L475","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\nclient.connect().await?;\n// after\ndrop(client); // or ensure previous disconnect completed\nlet client = AXDataClient::new(...); // fresh client on repeated start_generation failures\nclient.connect().await?;","handlingStrategy":"retry","validationCode":"// Rust\n// single-owner pattern: never call connect concurrently\n// if reconnecting, await previous disconnect() fully first","typeGuard":null,"tryCatchPattern":"// Rust\nloop {\n    match client.connect().await {\n        Ok(()) => break,\n        Err(e) if e.to_string().contains(\"session generation\") && retries < 3 => {\n            client.disconnect().await.ok();\n            retries += 1;\n        }\n        Err(e) => return Err(e),\n    }\n}","preventionTips":["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"],"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-14T05:17:10.506Z"}