{"record":{"id":"0ebdeba8ae9629dc","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-coinbase-task-generation-e","errorCode":null,"errorMessage":"Failed to start Coinbase task generation: {e}","messagePattern":"Failed to start Coinbase task generation: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/coinbase/src/execution.rs","lineNumber":376,"sourceCode":"    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() {\n            self.await_pending_tasks().await?;\n            self.pending_tasks\n                .start_generation()\n                .map_err(|e| anyhow::anyhow!(\"Failed to start Coinbase task generation: {e}\"))?;\n        }\n\n        if !self.session_tasks.is_open() || !self.session_tasks.is_empty() {\n            self.abort_session_tasks();\n            self.ws_user\n                .disconnect()\n                .await\n                .context(\"failed to close stale Coinbase user WebSocket\")?;\n            self.await_session_tasks().await?;\n            self.session_tasks\n                .start_generation()\n                .map_err(|e| anyhow::anyhow!(\"Failed to start Coinbase session generation: {e}\"))?;\n        }\n        let ws_user = self.ws_user.clone();\n        let setup_guard =\n            TaskGroupGuard::new(&[&self.session_tasks, &self.pending_tasks], move || {\n                ws_user.begin_shutdown();\n            });","sourceCodeStart":358,"sourceCodeEnd":394,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/coinbase/src/execution.rs#L358-L394","documentation":"Inside connect(), after awaiting and terminating the previous pending-task generation, the client calls `start_generation` to open a fresh generation of execution tasks. If the task set refuses to start, this error is raised.","triggerScenarios":"connect() invoked when the pending task set is closed but its internal state does not permit starting a new generation — e.g. shutdown not fully observed, or concurrent connect calls racing on the same task set.","commonSituations":"Two components calling connect() on the same execution client simultaneously; reconnect logic that skips proper disconnect/teardown ordering.","solutions":["Serialize connect() calls (single owner task or mutex)","Ensure disconnect/finish_shutdown completed before reconnecting","Read the inner `{e}` from start_generation in logs","Recreate the execution client if the generation state is corrupted","Check for concurrent engine start/stop racing the adapter"],"exampleFix":"// before\nlet c = client.clone();\ntokio::spawn(async move { c.connect().await });\nclient.connect().await?; // duplicate connect\n// after\nclient.connect().await?; // exactly one connect per client","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if let Err(e) = client.connect().await {\n    if e.to_string().contains(\"Failed to start Coinbase task generation\") {\n        // unrecoverable state race: rebuild client\n        client = CoinbaseExecClient::new(...).await?;\n        client.connect().await?;\n    } else { return Err(e); }\n}","preventionTips":["Give exactly one component ownership of connect()/disconnect()","Always disconnect before reconnecting; never skip teardown","Guard against engine restart races on the same adapter instance"],"tags":["rust","async","tasks","lifecycle","execution"],"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"}