{"record":{"id":"9e1db877c9563a0f","repo":"nautechsystems/nautilus_trader","slug":"failed-to-set-lighter-execution-context-e","errorCode":null,"errorMessage":"failed to set Lighter execution context: {e}","messagePattern":"failed to set Lighter execution context: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/execution.rs","lineNumber":911,"sourceCode":"        // (which still owns the handler task); mirrors Hyperliquid's\n        // `post_ws` block.\n        let post_connect = async {\n            ws_guard\n                .client_mut()\n                .wait_until_active()\n                .await\n                .context(\"Lighter WebSocket did not reach active state\")?;\n\n            if let Some(credential) = &self.credential {\n                let auth_token = build_auth_token_for(credential)\n                    .context(\"failed to mint Lighter auth token\")?;\n                let account_index = credential.account_index();\n\n                ws_guard\n                    .client_mut()\n                    .set_execution_context(self.core.account_id, account_index)\n                    .await\n                    .map_err(|e| anyhow::anyhow!(\"failed to set Lighter execution context: {e}\"))?;\n\n                // Subscribe to the five account-scoped streams the consumption\n                // loop converts into typed reports. The handler merges\n                // `account_all_assets` and `user_stats` into a single\n                // AccountState (see websocket/account_state.rs).\n                let channels = [\n                    LighterWsChannel::AccountAllOrders(account_index),\n                    LighterWsChannel::AccountAllTrades(account_index),\n                    LighterWsChannel::AccountAllPositions(account_index),\n                    LighterWsChannel::AccountAllAssets(account_index),\n                    LighterWsChannel::UserStats(account_index),\n                ];\n\n                for channel in channels {\n                    ws_guard\n                        .client_mut()\n                        .subscribe_account(channel.clone(), auth_token.clone())\n                        .await","sourceCodeStart":893,"sourceCodeEnd":929,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/execution.rs#L893-L929","documentation":"In spawn_ws_consumer (called during connect), the adapter must set the execution context on the authenticated WebSocket client — binding the account_id and account_index for account-scoped messages. If the underlying client's set_execution_context call fails, the error is wrapped with this message and connect aborts.","triggerScenarios":"connect() -> spawn_ws_consumer where ws_guard.client_mut().set_execution_context(...) returns an error — e.g. the WS connection is not yet established/authenticated, or the account_id/account_index is invalid for the connection.","commonSituations":"Network failures mid-connect; credentials with a wrong account_index; venue rejecting the session setup; WS endpoint temporarily unavailable.","solutions":["Read the wrapped inner error ({e}) for the concrete WS-level cause.","Verify account_id and account_index in your credentials are correct.","Retry connect — transient network/endpoint failures are common.","Check Lighter WS endpoint availability and your network/proxy setup.","Confirm the credential/auth token was obtained before context setup (ordering issue)."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// validate credentials before connect\nassert!(!account_id.to_string().is_empty());\nassert!(account_index > 0 || account_id.indicates_zero_ok());","typeGuard":null,"tryCatchPattern":"match client.connect().await {\n    Err(e) if e.to_string().contains(\"failed to set Lighter execution context\") => {\n        // inspect inner error; retry with backoff for transient WS issues\n    }\n    r => r?,\n}","preventionTips":["Validate account_id/account_index credentials up front.","Use retry with backoff for transient WS failures.","Monitor venue WS endpoint availability."],"tags":["websocket","execution-context","authentication","connect"],"backgroundTag":"connection-refused","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"}