{"record":{"id":"305c04400c3b1593","repo":"nautechsystems/nautilus_trader","slug":"failed-to-lock-intent-for-verified-action-e","errorCode":null,"errorMessage":"Failed to lock intent for verified action: {e}","messagePattern":"Failed to lock intent for verified action: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":6099,"sourceCode":"            .ok_or_else(|| anyhow::anyhow!(\"Canonical nonce ledger is not initialized\"))?;\n        anyhow::ensure!(\n            manifest_version == batch.manifest_version && manifest_digest == batch.manifest_digest,\n            \"Verified action manifest identity changed\"\n        );\n        let intent_nonce = sqlx::query_scalar::<_, Option<i64>>(\n            \"\n            SELECT nonce\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(batch.intent_id)\n        .bind(chain_id)\n        .bind(batch.wallet_address)\n        .fetch_optional(&mut *transaction)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to lock intent for verified action: {e}\"))?\n        .ok_or_else(|| anyhow::anyhow!(\"Active verified-action intent was not found\"))?;\n        anyhow::ensure!(\n            intent_nonce == Some(nonce),\n            \"Verified action nonce does not match the active intent\"\n        );\n        let attempt = sqlx::query_scalar::<_, i64>(\n            \"\n            SELECT COUNT(*)\n            FROM execution_verification_decision\n            WHERE intent_id = $1 AND decision_class = $2\n            \",\n        )\n        .bind(batch.intent_id)\n        .bind(batch.decision_class)\n        .fetch_one(&mut *transaction)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to number verified action evidence: {e}\"))?;\n","sourceCodeStart":6081,"sourceCodeEnd":6117,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L6081-L6117","documentation":"Thrown when the SELECT that locks the active execution intent for a verified action (by intent_id, chain_id, wallet_address) fails with a database error. This is a query failure rather than a missing row; the transaction is aborted and no nonce or attempt state is read.","triggerScenarios":"fetch_optional on the intent-locking SELECT returns Err — connection loss, statement timeout, permission error, or deadlock while the row lock is being acquired.","commonSituations":"Long-held locks by another transaction causing statement_timeout; database failover mid-query; missing SELECT grants on the intent table; proxy killing idle connections.","solutions":["Retry the operation; the transaction rolls back cleanly and re-acquires the lock.","Check Postgres logs for the underlying error (lock timeout, permission, connection drop).","Reduce lock contention by shortening transactions that hold the intent row lock.","Verify the database role can SELECT from the execution intent table."],"exampleFix":"// before: no retry around lock acquisition\nrecord_execution_verification_batch(&db, &batch).await?;\n// after: retry on lock-related failures\nmatch record_execution_verification_batch(&db, &batch).await {\n    Err(e) if is_lock_timeout(&e) => { tokio::time::sleep(Duration::from_millis(200)).await; record_execution_verification_batch(&db, &batch).await?; }\n    res => res?,\n}","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Rust\nmatch record_batch().await {\n    Err(e) if e.to_string().contains(\"Failed to lock intent for verified action\")\n        && (is_lock_timeout(&e) || is_transient(&e)) => retry_with_backoff(record_batch),\n    res => res,\n}","preventionTips":["Keep transactions that lock the intent row short.","Set a modest lock_timeout so failures are fast and retryable.","Serialize actions per intent (queue per intent_id) to avoid contention."],"tags":["database","locking","sql","rust"],"backgroundTag":"sql-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"}