{"record":{"id":"f37da087a3ced676","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-derive-task-generation-e","errorCode":null,"errorMessage":"Failed to start Derive task generation: {e}","messagePattern":"Failed to start Derive task generation: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/derive/src/execution.rs","lineNumber":608,"sourceCode":"            && self.session_tasks.is_open()\n            && self.pending_tasks.is_open()\n        {\n            return Ok(());\n        }\n\n        log::info!(\"Connecting Derive execution client\");\n\n        if self.cancellation_token.is_cancelled()\n            || !self.session_tasks.is_open()\n            || !self.pending_tasks.is_open()\n        {\n            self.teardown_partial_connect().await?;\n            self.session_tasks\n                .start_generation()\n                .map_err(|e| anyhow::anyhow!(\"Failed to start Derive session generation: {e}\"))?;\n            self.pending_tasks\n                .start_generation()\n                .map_err(|e| anyhow::anyhow!(\"Failed to start Derive task generation: {e}\"))?;\n            self.cancellation_token = CancellationToken::new();\n        }\n        let cancellation_token = self.cancellation_token.clone();\n        let ws_shutdown = self.ws_client.shutdown_handle();\n        let setup_guard =\n            TaskGroupGuard::new(&[&self.session_tasks, &self.pending_tasks], move || {\n                cancellation_token.cancel();\n                ws_shutdown.begin_shutdown();\n            });\n\n        self.ensure_instruments_initialized()\n            .await\n            .context(\"failed to initialize Derive instruments\")?;\n\n        self.ws_client\n            .connect()\n            .await\n            .context(\"failed to connect Derive WebSocket\")?;","sourceCodeStart":590,"sourceCodeEnd":626,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/derive/src/execution.rs#L590-L626","documentation":"Right after starting the session task generation, connect also calls pending_tasks.start_generation(). If the pending-task group cannot start a new generation, connect raises this message (after tearing down the partial connect). Note the session generation already succeeded at this point, so the client is half-initialized before teardown.","triggerScenarios":"connect called when the pending_tasks TaskGroup is already open or mid-shutdown; concurrent connect attempts; a prior failed connect that left pending_tasks open.","commonSituations":"Double-connect on the same instance; reconnect attempts without a full teardown; task group state carried over from a previously failed connection cycle.","solutions":["Recreate the client or ensure a clean disconnect before calling connect again.","Avoid concurrent connect invocations; serialize lifecycle transitions.","Check that prior connect failures fully tore down both task groups (teardown_partial_connect) before retrying.","Inspect the wrapped TaskGroup error for the exact pending_tasks state violation."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if client.is_connected() || client.is_shutting_down() {\n    return Err(\"connect not allowed in current state\".into());\n}","typeGuard":null,"tryCatchPattern":"if let Err(e) = exec_client.connect().await {\n    if e.to_string().contains(\"start Derive task generation\") {\n        // pending task group in bad state; teardown ran — recreate the client\n    }\n    return Err(e);\n}","preventionTips":["Ensure prior failed connects fully tear down both task groups before retry","Never share one execution client across concurrent connect attempts","Prefer recreating the client over retrying connect after generation-start failures"],"tags":["derive","connect","task-group","lifecycle","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"}