nautechsystems/nautilus_trader · error · anyhow::Error

Failed to update execution intent

Error message

Failed to update execution intent {intent_id}: {e}

What it means

Raised when the UPDATE of the execution_intent row itself (setting the new status and active flag) fails inside the transition transaction. Locking, validation, and the execution-hash update already succeeded, but this final status write errored, rolling back the entire transaction.

Solutions

  1. Read the inner `{e}` for the precise SQL error and fix the underlying cause (schema, constraint, connection).
  2. Retry the whole transition with backoff — the transaction rolled back cleanly, so state is consistent.
  3. Reduce lock hold time (shorten the transaction) to avoid connection drops under contention.
  4. Run pending migrations if the status column definition changed in a newer adapter version.

Example fix

// before
.map_err(|e| anyhow::anyhow!("Failed to update execution intent {intent_id}: {e}"))?;
// after
.map_err(|e| anyhow::anyhow!("Failed to update execution intent {intent_id} to {}: {e}", status.as_str()))?;
Defensive patterns

Strategy: retry

Validate before calling

// Pre-flight: ensure status column accepts the value
sqlx::query("SELECT status FROM execution_intent LIMIT 1").execute(&pool).await?;

Try / catch

match transition.await {
    Err(e) if e.to_string().contains("Failed to update execution intent") => {
        tracing::error!(error = %e, "intent update failed; transaction rolled back, safe to retry");
        retry_with_backoff();
    }
    other => other?,
}

Prevention

When it happens

Trigger: Calling the transition when the intent UPDATE statement errors: connection dropped mid-transaction, schema/constraint mismatch on status or active columns, deferred constraint violation from earlier statements, or statement timeout.

Common situations: Long-running transactions killed by idle_in_transaction_session_timeout while waiting on row locks under concurrency; migration drift changing the status column type/enum; database failover dropping the session mid-transaction.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/0b078a5c16d42d7a. Report an issue: GitHub.

Appendix: source

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

        .map_err(|e| anyhow::anyhow!("Failed to update execution hash {transaction_hash}: {e}"))?;
        anyhow::ensure!(
            hash_result.rows_affected() == 1,
            "Execution transaction hash {transaction_hash} was not found for intent {intent_id}"
        );

        sqlx::query(
            "
            UPDATE execution_intent
            SET status = $2, active = $3, updated_at = NOW()
            WHERE id = $1
            ",
        )
        .bind(intent_id)
        .bind(status.as_str())
        .bind(active)
        .execute(&mut *transaction)
        .await
        .map_err(|e| anyhow::anyhow!("Failed to update execution intent {intent_id}: {e}"))?;

        let transition_key = format!(
            "{}:{transaction_hash}:{}:{}",
            status.as_str(),
            block_number.map_or_else(|| "none".to_string(), |value| value.to_string()),
            block_hash.unwrap_or("none")
        );
        sqlx::query(
            "
            INSERT INTO execution_transaction_transition (
                intent_id, transaction_hash_id, transition_key, from_status, to_status,
                block_number, block_hash
            )
            SELECT $1, id, $3, $4, $5, $6, $7
            FROM execution_transaction_hash
            WHERE intent_id = $1 AND transaction_hash = $2
            ON CONFLICT (intent_id, transition_key) DO NOTHING
            ",

View on GitHub (pinned to 18893faf8b)