{"record":{"id":"94595d73e4286e81","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-hyperliquid-task-generation-e","errorCode":null,"errorMessage":"Failed to start Hyperliquid task generation: {e}","messagePattern":"Failed to start Hyperliquid task generation: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/hyperliquid/src/execution.rs","lineNumber":1690,"sourceCode":"            Ok(())\n        });\n\n        Ok(())\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        log::info!(\"Connecting Hyperliquid execution client\");\n\n        if !self.pending_tasks.is_open() || !self.session_tasks.is_open() {\n            self.teardown_partial_connect().await?;\n            self.pending_tasks\n                .start_generation()\n                .map_err(|e| anyhow::anyhow!(\"Failed to start Hyperliquid task generation: {e}\"))?;\n            self.session_tasks.start_generation().map_err(|e| {\n                anyhow::anyhow!(\"Failed to start Hyperliquid execution session generation: {e}\")\n            })?;\n        }\n        let ws_client = self.ws_client.clone();\n        let setup_guard =\n            TaskGroupGuard::new(&[&self.session_tasks, &self.pending_tasks], move || {\n                ws_client.begin_shutdown();\n            });\n\n        self.ensure_instruments_initialized_async().await?;\n        let ready_bracket_parents = self.restore_staged_brackets();\n\n        if let Err(e) = self.start_ws_stream().await {\n            if let Err(teardown_error) = self.teardown_partial_connect().await {\n                return Err(e.context(format!(\n                    \"Hyperliquid execution startup teardown failed: {teardown_error}\"\n                )));","sourceCodeStart":1672,"sourceCodeEnd":1708,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/hyperliquid/src/execution.rs#L1672-L1708","documentation":"Raised in connect() when start_generation() on the pending-tasks TaskGroup fails, meaning a new task generation could not be opened because the group is not in a state admitting new tasks (e.g. it is still shutting down from a previous generation). Before retrying, the client tears down any partial connect.","triggerScenarios":"connect() sees either pending_tasks or session_tasks not open, calls teardown_partial_connect(), then attempts pending_tasks.start_generation(); failure occurs when the prior generation's tasks have not fully terminated, leaving the group closed.","commonSituations":"Rapid reconnect cycles where the previous generation's tasks are still unwinding; a prior teardown that failed with the 'Failed to terminate Hyperliquid execution tasks' error leaving the group in a shutdown state.","solutions":["Wait for the previous generation to fully shut down before reconnecting (add a delay/backoff between connect attempts)","Ensure the prior teardown completes without error and logs are clean before retrying connect","Investigate why previous-generation tasks did not terminate (see 3110)","Inspect the wrapped TaskGroup error for the precise state violation"],"exampleFix":"null","handlingStrategy":"retry","validationCode":"assert!(client.pending_tasks.is_open() || previous_teardown_completed);","typeGuard":null,"tryCatchPattern":"loop { match client.connect().await { Ok(_) => break, Err(e) if e.to_string().contains(\"task generation\") => { sleep(backoff).await; } Err(e) => return Err(e) } }","preventionTips":["Apply backoff between reconnect attempts","Confirm prior teardown completed before reconnecting","Watch for paired 'Failed to terminate ... tasks' errors that leave groups closed","Restart the client if generations remain stuck"],"tags":["rust","reconnect","task-group","lifecycle"],"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"}