{"record":{"id":"c31ef6836cf48143","repo":"nautechsystems/nautilus_trader","slug":"failed-to-lock-intent-for-verified-finality-e","errorCode":null,"errorMessage":"Failed to lock intent for verified finality: {e}","messagePattern":"Failed to lock intent for verified finality: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":7056,"sourceCode":"                header.number\n            );\n        }\n\n        let (current_status, intent_nonce, fill_emitted, terminal_emitted) =\n            sqlx::query_as::<_, (String, Option<i64>, bool, bool)>(\n                \"\n                SELECT status, nonce, fill_emitted, terminal_emitted\n                FROM execution_intent\n                WHERE id = $1 AND chain_id = $2 AND wallet_address = $3 AND active\n                FOR UPDATE\n                \",\n            )\n            .bind(finality.intent_id)\n            .bind(chain_id)\n            .bind(finality.wallet_address)\n            .fetch_optional(&mut *transaction)\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to lock intent for verified finality: {e}\"))?\n            .ok_or_else(|| anyhow::anyhow!(\"Active finality intent was not found\"))?;\n        anyhow::ensure!(\n            intent_nonce == Some(nonce)\n                && execution_transition_allowed(&current_status, finality.status),\n            \"Intent cannot make the verified finality transition\"\n        );\n\n        for (index, decision) in finality.decisions.iter().enumerate() {\n            let height_start = decision\n                .height_start\n                .map(i64::try_from)\n                .transpose()\n                .context(\"Verification height exceeds PostgreSQL BIGINT\")?;\n            let height_end = decision\n                .height_end\n                .map(i64::try_from)\n                .transpose()\n                .context(\"Verification height exceeds PostgreSQL BIGINT\")?;","sourceCodeStart":7038,"sourceCodeEnd":7074,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L7038-L7074","documentation":"This error wraps a sqlx failure on the `fetch_optional` SELECT that locks (SELECT ... FOR UPDATE semantics via the transaction) the active intent row before applying verified finality. It means the locking query itself errored — not that the intent is missing (that is error 2334). The transaction is aborted so no finality state changes are applied.","triggerScenarios":"The intent-lock SELECT for (intent_id, chain_id, wallet_address) fails: connection loss, permission error on the table, schema mismatch, or a lock-wait/statement timeout while another transaction holds the intent row.","commonSituations":"Concurrent finality processors contending on the same intent row causing lock timeouts; the cache DB user lacking SELECT grants after a permissions change; long transactions blocking on the intent row until the statement timeout fires.","solutions":["Read the interpolated `{e}` to get the underlying sqlx/Postgres error","If it is a lock timeout, reduce contention: shorten surrounding transactions or retry the finality application with backoff","Verify the DB role has SELECT (and FOR UPDATE) privileges on the intent table","Check schema/columns used by the intent SELECT match current migrations"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Verify table access and grants before finality runs\nsqlx::query(\"SELECT 1 FROM execution_intent LIMIT 1\")\n    .fetch_optional(&mut *conn).await\n    .map_err(|e| anyhow!(\"intent table unavailable: {e}\"))?;","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if is_lock_timeout(&e) || is_transient_db_error(&e) => {\n        retry_with_backoff(3, || apply_verified_finality(...)).await\n    }\n    Err(e) => Err(e),\n    Ok(v) => Ok(v),\n}","preventionTips":["Keep the intent-lock transaction short to reduce lock contention","Serialize finality application per intent (single worker or advisory lock)","Grant the cache DB role SELECT/UPDATE on intent tables before rollout","Set explicit, generous statement_timeout for finality transactions"],"tags":["database","locking","sqlx","concurrency"],"backgroundTag":"database-query-failed","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"}