{"record":{"id":"971e26fefe107eef","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-ax-execution-task-generation-e","errorCode":null,"errorMessage":"Failed to start AX execution task generation: {e}","messagePattern":"Failed to start AX execution task generation: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/architect_ax/src/execution.rs","lineNumber":522,"sourceCode":"\n    fn oms_type(&self) -> OmsType {\n        self.core.oms_type\n    }\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()),","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/architect_ax/src/execution.rs#L504-L540","documentation":"Raised in `connect` on the AX execution client when `pending_tasks.start_generation()` fails after a partial-connect teardown. Task generations group per-connection background workers; failing to open a new generation means the execution client cannot start its background task infrastructure and the connect cannot proceed.","triggerScenarios":"Calling `connect()` when either task supervisor was found closed (`!is_open()`), partial teardown ran, and then `start_generation()` on the pending-task supervisor fails — e.g., the supervisor was already started, aborted mid-start, or is in an invalid lifecycle state.","commonSituations":"Rapid disconnect/reconnect cycles racing the task supervisors' lifecycle; previous shutdown left the supervisor in a closed state that cannot be reopened; concurrent connect attempts on the same client instance.","solutions":["Read the wrapped inner error for the supervisor's specific lifecycle complaint (e.g., already started vs closed).","Avoid concurrent connect() calls on the same client; serialize connection lifecycle calls.","Fully tear down (both `teardown_partial_connect` and prior generation completion) before attempting reconnect.","If the supervisor is irrecoverably closed, recreate the execution client instance instead of reconnecting.","Check for bugs where disconnect marked the supervisor closed without allowing a new generation."],"exampleFix":"// before\n// concurrent reconnect from two code paths\nclient.connect().await?;\n// after\n// guard with a single-flight connect\nif client.connect_lock.compare_exchange(false, true, ...).is_ok() {\n    let res = client.connect().await;\n    client.connect_lock.store(false, Ordering::SeqCst);\n    res?;\n}","handlingStrategy":"try-catch","validationCode":"if !client.is_connected() && connect_in_progress.load(Ordering::SeqCst) {\n    anyhow::bail!(\"connect already in progress; skip duplicate attempt\");\n}","typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Err(e) if e.to_string().contains(\"task generation\") => {\n        log::error!(\"task supervisor in bad state ({e:#}); recreate the client instance\");\n    }\n    other => other?,\n}","preventionTips":["Single-flight guard connect()/disconnect() so lifecycle calls never race.","Ensure teardown completes fully before starting new task generations on reconnect.","Recreate the client if a supervisor is left permanently closed after repeated cycles.","Test rapid reconnect scenarios in CI to surface generation lifecycle races."],"tags":["lifecycle","tasks","connect","state"],"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-14T05:17:10.506Z"}