{"record":{"id":"9a85565ef2cf71a8","repo":"nautechsystems/nautilus_trader","slug":"failed-to-load-active-execution-intent-e","errorCode":null,"errorMessage":"Failed to load active execution intent: {e}","messagePattern":"Failed to load active execution intent: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":3745,"sourceCode":"        let chain_id_db = i32::try_from(chain_id)\n            .with_context(|| format!(\"Chain ID {chain_id} exceeds PostgreSQL INTEGER\"))?;\n        sqlx::query_as::<_, ExecutionIntentRow>(\n            \"\n            SELECT\n                id, schema_version, chain_id, wallet_address, nonce, purpose, status,\n                client_order_id, trader_id, strategy_id, account_id, instrument_id,\n                pool_address, transaction_to, transaction_input, transaction_value,\n                amount_in, created_block, acknowledgement_emitted, fill_emitted,\n                terminal_emitted, active\n            FROM execution_intent\n            WHERE chain_id = $1 AND wallet_address = $2 AND active\n            \",\n        )\n        .bind(chain_id_db)\n        .bind(wallet_address)\n        .fetch_optional(&self.pool)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to load active execution intent: {e}\"))\n    }\n\n    /// Loads all transaction hashes for an intent in insertion order.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the query fails.\n    pub async fn get_execution_transaction_hashes(\n        &self,\n        intent_id: i64,\n    ) -> anyhow::Result<Vec<ExecutionTransactionHashRow>> {\n        sqlx::query_as::<_, ExecutionTransactionHashRow>(\n            \"\n            SELECT\n                id, intent_id, chain_id, transaction_hash, raw_transaction, status,\n                block_number, block_hash, receipt_success, gas_used,\n                effective_gas_price, current\n            FROM execution_transaction_hash","sourceCodeStart":3727,"sourceCodeEnd":3763,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/2114cf6f761429e0adb5ca9596fcd7b895b16011/crates/adapters/blockchain/src/cache/database.rs#L3727-L3763","documentation":"Wrapped sqlx error from get_active_execution_intent (database.rs:3722-3745), the SELECT ... FROM execution_intent WHERE chain_id = $1 AND wallet_address = $2 AND active query decoded into ExecutionIntentRow. A None result is a valid 'no active intent' answer; this error means the query itself failed or the row could not be decoded into the 21-column struct.","triggerScenarios":"fetch_optional failing on pool acquisition timeout, a dead connection, or a ColumnNotFound/TypeMismatch decode error when the database schema does not match ExecutionIntentRow (missing or renamed columns such as acknowledgement_emitted, terminal_emitted, active after schema drift).","commonSituations":"Calling the recovery/reconnect path after the cache process restarts while Postgres is still starting; pointing the cache at a database migrated by an older adapter version; pool exhaustion when many intents are polled concurrently.","solutions":["Downcast the error: a decode fault (sqlx::Error::ColumnNotFound/Decode) points to schema drift, a PoolTimedOut/Io fault to connectivity","Run the project migrations so execution_intent exposes every column ExecutionIntentRow expects","For connectivity faults, verify the DATABASE_URL/Postgres endpoint and increase pool acquire_timeout or max_connections if contention is the cause","Distinguish this query failure from a legitimate None (no active intent) in caller handling - only the former is retryable"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-flight: confirm the pool can serve a query before polling intents\nsqlx::query(\"SELECT 1\").execute(&pool).await?;","typeGuard":"fn is_decode_error(err: &anyhow::Error) -> bool {\n    matches!(\n        err.downcast_ref::<sqlx::Error>(),\n        Some(sqlx::Error::ColumnNotFound(_)) | Some(sqlx::Error::Decode(_))\n    )\n}","tryCatchPattern":"match db.get_active_execution_intent(chain_id, wallet).await {\n    Ok(Some(intent)) => handle(intent),\n    Ok(None) => {} // valid: no active intent\n    Err(e) if is_decode_error(&e) => fatal_schema_drift(e), // fix migrations, do not retry\n    Err(e) => transient_or_propagate(e),\n}","preventionTips":["Treat Ok(None) and Err distinctly: only Err is retryable","Pin the cache schema and adapter version together; run migrations on deploy, not lazily","After changing ExecutionIntentRow columns, exercise this query in CI against a migrated test database"],"tags":["rust","sqlx","postgres","blockchain","query","decode-error"],"backgroundTag":"database-query-failed","analyzedSha":"2114cf6f761429e0adb5ca9596fcd7b895b16011","analyzedAt":"2026-08-21T11:28:30.864Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}