{"record":{"id":"b4fc766935cb0971","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-polymarket-session-generation-e","errorCode":null,"errorMessage":"Failed to start Polymarket session generation: {e}","messagePattern":"Failed to start Polymarket session generation: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/polymarket/src/execution/lifecycle.rs","lineNumber":652,"sourceCode":"        }\n\n        log::info!(\"Connecting Polymarket execution client\");\n\n        if !self.pending_tasks.is_open() || !self.session_tasks.is_open() {\n            self.teardown_partial_connect().await?;\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 Polymarket task generation: {e}\"))?;\n        }\n\n        if !self.session_tasks.is_open() {\n            self.await_session_tasks().await?;\n            self.session_tasks.start_generation().map_err(|e| {\n                anyhow::anyhow!(\"Failed to start Polymarket session generation: {e}\")\n            })?;\n        }\n        self.stopping.store(false, Ordering::Release);\n        let ws_shutdown = self.ws_client.shutdown_handle();\n        let stopping = Arc::clone(&self.stopping);\n        let setup_guard =\n            TaskGroupGuard::new(&[&self.session_tasks, &self.pending_tasks], move || {\n                stopping.store(true, Ordering::Release);\n                ws_shutdown.begin_shutdown();\n            });\n\n        let version = self\n            .http_client\n            .get_version()\n            .await\n            .context(\"failed to query Polymarket CLOB protocol version\")?\n            .version;\n","sourceCodeStart":634,"sourceCodeEnd":670,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/polymarket/src/execution/lifecycle.rs#L634-L670","documentation":"`connect_client` similarly restarts the session task group (WebSocket dispatch, polling) via `session_tasks.start_generation()` when it is not open. Failure of that restart — because the previous generation is still terminating or the group rejects a new generation — is wrapped in this error. Note the message says 'session generation' vs 'task generation' for the pending group (error 3554).","triggerScenarios":"connect_client after session_tasks was closed by begin_shutdown, when start_generation fails; await_session_tasks returned but the group has not fully released its previous generation.","commonSituations":"Reconnect during shutdown race; abort timeout still in flight; consecutive connect calls where the second collides with the first's teardown.","solutions":["Ensure await_session_tasks fully completes (including abort) before start_generation; increase TASK_ABORT_TIMEOUT if needed","Check the wrapped `{e}` for the task-group rejection cause","Serialize connection attempts so a second connect cannot race the first teardown","Restart/recreate the client if the session task group cannot accept a new generation"],"exampleFix":"// before: racing teardown and reconnect\ntokio::join!(adapter.disconnect(), adapter.connect());\n// after: sequential lifecycle\ntokio::join!(adapter.disconnect());\nadapter.connect().await?;","handlingStrategy":"retry","validationCode":"// serialize lifecycle transitions\nlet _guard = lifecycle_lock.lock().await;","typeGuard":null,"tryCatchPattern":"match adapter.connect().await {\n    Err(e) if e.to_string().contains(\"session generation\") => {\n        tokio::time::sleep(backoff).await;\n        adapter.connect().await?;\n    }\n    other => other?,\n}","preventionTips":["Serialize connect/disconnect behind a lifecycle lock","Allow the session abort timeout to fully elapse before restart","Avoid rapid connect/disconnect cycles"],"tags":["rust","async","lifecycle","task-group"],"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"}