{"record":{"id":"6bfa69202e9ef4b8","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-derive-data-task-generation-e","errorCode":null,"errorMessage":"Failed to start Derive data task generation: {e}","messagePattern":"Failed to start Derive data task generation: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/derive/src/data.rs","lineNumber":749,"sourceCode":"            && self.session_tasks.is_open()\n            && self.pending_tasks.is_open()\n        {\n            return Ok(());\n        }\n\n        // Completes the async teardown deferred by sync reset()/stop().\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.cancellation_token = CancellationToken::new();\n            self.session_tasks.start_generation().map_err(|e| {\n                anyhow::anyhow!(\"Failed to start Derive data session generation: {e}\")\n            })?;\n            self.pending_tasks\n                .start_generation()\n                .map_err(|e| anyhow::anyhow!(\"Failed to start Derive data task generation: {e}\"))?;\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        if !self.config.currencies.is_empty() {\n            self.provider\n                .load_all(None)\n                .await\n                .context(\"failed to load Derive instruments\")?;\n            self.cache_provider_instruments();\n        }\n\n        self.ws_client","sourceCodeStart":731,"sourceCodeEnd":767,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/derive/src/data.rs#L731-L767","documentation":"Right after starting the session task generation, the Derive data client's `connect` also starts a new generation for `pending_tasks`. This error wraps a failure of that second generation start; the client cannot queue pending subscription tasks for the new session.","triggerScenarios":"Calling `connect()` when `pending_tasks` is not open/empty and `start_generation()` returns Err — group closed, invalid generation state, or partial teardown left it unusable.","commonSituations":"Reconnect cycles where a previous pending-task generation never finished; concurrent connect attempts; a failed earlier connect leaving pending_tasks in a bad state.","solutions":["Inspect the wrapped `{e}` for the exact generation-state error.","Ensure the prior connect/disconnect fully completed before retrying.","Serialize lifecycle calls (connect/disconnect) on the data client.","Rebuild the data client if the pending task group is shut down permanently.","Verify teardown_partial_connect ran (or its error was propagated) after any failed connect."],"exampleFix":"// before\nif let Err(e) = client.connect().await { log(e); } // then retry immediately\nclient.connect().await?;\n// after\nif let Err(e) = client.connect().await { client.disconnect().await?; } // clean state\nclient.connect().await?;","handlingStrategy":"retry","validationCode":"// Clean state before connect:\n// data_client.disconnect().await?; // ensures pending/session groups reset","typeGuard":null,"tryCatchPattern":"if let Err(e) = data_client.connect().await {\n    if e.to_string().contains(\"task generation\") {\n        data_client.disconnect().await.ok();\n        tokio::time::sleep(BACKOFF).await;\n        data_client.connect().await?;\n    }\n}","preventionTips":["After any failed connect, run disconnect/teardown before retrying.","Serialize lifecycle calls on the data client.","Avoid rapid reconnect loops that race generation rollovers.","Rebuild the client if errors recur."],"tags":["websocket","task-generation","derive","connection-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-14T00:17:10.932Z"}