{"record":{"id":"177235cf37ac24c2","repo":"nautechsystems/nautilus_trader","slug":"ax-execution-startup-teardown-failed-teardown-er","errorCode":null,"errorMessage":"AX execution startup teardown failed: {teardown_error}","messagePattern":"AX execution startup teardown failed: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/architect_ax/src/execution.rs","lineNumber":598,"sourceCode":"        let account_id = self.core.account_id;\n        let instruments_cache = self.ws_orders.instruments_cache();\n        let clock = self.clock;\n\n        if let Err(e) = self.session_tasks.spawn(async move {\n            pin_mut!(stream);\n            while let Some(message) = stream.next().await {\n                dispatch_ws_message(\n                    message,\n                    &emitter,\n                    &caches,\n                    account_id,\n                    &instruments_cache,\n                    clock,\n                );\n            }\n        }) {\n            if let Err(teardown_error) = self.teardown_partial_connect().await {\n                return Err(anyhow::Error::new(e).context(format!(\n                    \"AX execution startup teardown failed: {teardown_error}\"\n                )));\n            }\n            return Err(e.into());\n        }\n\n        let session_result = async {\n            let account_state = self\n                .http_client\n                .request_account_state(self.core.account_id)\n                .await\n                .context(\"failed to request AX account state\")?;\n\n            if !account_state.balances.is_empty() {\n                log::debug!(\n                    \"Received account state with {} balance(s)\",\n                    account_state.balances.len()\n                );","sourceCodeStart":580,"sourceCodeEnd":616,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/architect_ax/src/execution.rs#L580-L616","documentation":"Raised in the AX (Architect) execution client's `connect` when the startup sequence (instruments/stream/venue clients) fails, and the subsequent `teardown_partial_connect` also errors. The teardown failure is attached as `context` to the original error, so the root cause is preserved and the cleanup failure is reported alongside it.","triggerScenarios":"Any failure during AX execution connect (e.g. the `?` inside the block returning Err) combined with teardown_partial_connect failing (network already broken, task cancellation, partial state that cannot be unwound).","commonSituations":"Credentials/network down at startup while cached instrument loaders or background tasks hang or refuse to shut down; node startup racing shutdown; misconfigured AX gateway endpoint.","solutions":["Read the full anyhow error chain: the outermost message is teardown; the root source is the original connect failure — fix that first.","Verify AX gateway URL, credentials, and network reachability.","Check logs for the teardown_partial_connect error to find which resource failed to unwind.","Retry connect after transient network recovery; investigate leaked tasks if teardown consistently fails."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Pre-flight: verify gateway reachability before connect\n// e.g. TCP/DNS check of the AX gateway endpoint from config","typeGuard":null,"tryCatchPattern":"match exec_client.connect().await {\n    Err(e) => {\n        // root cause is the innermost source; teardown context is ancillary\n        log::error!(\"AX connect failed: {e:#}\");\n        tokio::time::sleep(backoff).await;\n        retry_connect().await;\n    }\n    Ok(_) => {},\n}","preventionTips":["Validate AX gateway URL and credentials in config before startup","Monitor network/gateway health before connecting","Inspect full error chain to separate root cause from teardown failure"],"tags":["rust","adapter","connect","teardown"],"backgroundTag":"connection-refused","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"}