nautechsystems/nautilus_trader · error · anyhow::Error

Failed to load active execution intent: {e}

Error message

Failed to load active execution intent: {e}

What it means

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.

Source

Thrown at crates/adapters/blockchain/src/cache/database.rs:3745

        let chain_id_db = i32::try_from(chain_id)
            .with_context(|| format!("Chain ID {chain_id} exceeds PostgreSQL INTEGER"))?;
        sqlx::query_as::<_, ExecutionIntentRow>(
            "
            SELECT
                id, schema_version, chain_id, wallet_address, nonce, purpose, status,
                client_order_id, trader_id, strategy_id, account_id, instrument_id,
                pool_address, transaction_to, transaction_input, transaction_value,
                amount_in, created_block, acknowledgement_emitted, fill_emitted,
                terminal_emitted, active
            FROM execution_intent
            WHERE chain_id = $1 AND wallet_address = $2 AND active
            ",
        )
        .bind(chain_id_db)
        .bind(wallet_address)
        .fetch_optional(&self.pool)
        .await
        .map_err(|e| anyhow::anyhow!("Failed to load active execution intent: {e}"))
    }

    /// Loads all transaction hashes for an intent in insertion order.
    ///
    /// # Errors
    ///
    /// Returns an error if the query fails.
    pub async fn get_execution_transaction_hashes(
        &self,
        intent_id: i64,
    ) -> anyhow::Result<Vec<ExecutionTransactionHashRow>> {
        sqlx::query_as::<_, ExecutionTransactionHashRow>(
            "
            SELECT
                id, intent_id, chain_id, transaction_hash, raw_transaction, status,
                block_number, block_hash, receipt_success, gas_used,
                effective_gas_price, current
            FROM execution_transaction_hash

View on GitHub (pinned to 2114cf6f76)

Solutions

  1. Downcast the error: a decode fault (sqlx::Error::ColumnNotFound/Decode) points to schema drift, a PoolTimedOut/Io fault to connectivity
  2. Run the project migrations so execution_intent exposes every column ExecutionIntentRow expects
  3. For connectivity faults, verify the DATABASE_URL/Postgres endpoint and increase pool acquire_timeout or max_connections if contention is the cause
  4. Distinguish this query failure from a legitimate None (no active intent) in caller handling - only the former is retryable
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight: confirm the pool can serve a query before polling intents
sqlx::query("SELECT 1").execute(&pool).await?;

Type guard

fn is_decode_error(err: &anyhow::Error) -> bool {
    matches!(
        err.downcast_ref::<sqlx::Error>(),
        Some(sqlx::Error::ColumnNotFound(_)) | Some(sqlx::Error::Decode(_))
    )
}

Try / catch

match db.get_active_execution_intent(chain_id, wallet).await {
    Ok(Some(intent)) => handle(intent),
    Ok(None) => {} // valid: no active intent
    Err(e) if is_decode_error(&e) => fatal_schema_drift(e), // fix migrations, do not retry
    Err(e) => transient_or_propagate(e),
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Understand the failure class

Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@2114cf6f76 (2026-08-21). Data as JSON: /api/errors/9a85565ef2cf71a8. Report an issue: GitHub.