{"record":{"id":"5773682cf6737fb0","repo":"nautechsystems/nautilus_trader","slug":"failed-to-record-verified-finality-intent-e","errorCode":null,"errorMessage":"Failed to record verified finality intent: {e}","messagePattern":"Failed to record verified finality intent: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":7145,"sourceCode":"        .bind(finality.effective_gas_price)\n        .execute(&mut *transaction)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to record verified finality receipt: {e}\"))?;\n        anyhow::ensure!(\n            hash_result.rows_affected() == 1,\n            \"Finality transaction hash was not found\"\n        );\n\n        let active = !fill_emitted && !terminal_emitted;\n        sqlx::query(\n            \"UPDATE execution_intent SET status = $2, active = $3, updated_at = NOW() WHERE id = $1\",\n        )\n        .bind(finality.intent_id)\n        .bind(finality.status.as_str())\n        .bind(active)\n        .execute(&mut *transaction)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to record verified finality intent: {e}\"))?;\n\n        let transition_key = format!(\n            \"{}:{}:{}:{}\",\n            finality.status.as_str(),\n            finality.transaction_hash,\n            finality.block_number,\n            finality.block_hash\n        );\n        sqlx::query(\n            \"\n            INSERT INTO execution_transaction_transition (\n                intent_id, transaction_hash_id, transition_key, from_status, to_status,\n                block_number, block_hash\n            )\n            SELECT $1, id, $3, $4, $5, $6, $7\n            FROM execution_transaction_hash\n            WHERE intent_id = $1 AND transaction_hash = $2\n            \",","sourceCodeStart":7127,"sourceCodeEnd":7163,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L7127-L7163","documentation":"Wraps a sqlx failure on the final UPDATE that records the verified finality state on the intent row (status = finality.status, active flag). This is the last state write of the finality commit; failing it rolls back the entire transaction so headers, verifications, receipt, and hash updates are all discarded. The database error text is embedded via `{e}`.","triggerScenarios":"The intent-status UPDATE fails: connection loss at the end of a long transaction, lock contention on the intent row, schema drift on status/active columns, or an invalid value for the status enum/text column.","commonSituations":"Long finality transactions hitting idle-in-transaction timeouts right at the final write; concurrent processors holding a lock on the same intent row; an adapter upgrade adding new status values not accepted by a DB CHECK constraint; pool exhaustion during batch finalization.","solutions":["Read the embedded `{e}` for the exact Postgres error","If it is a lock timeout, reduce transaction duration or retry finality application with backoff","Check any CHECK/enum constraints on the status column accept the new status value","Apply pending migrations so status/active columns match the adapter's expectations","Verify pool/connectivity health if failures cluster at the end of long transactions"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Confirm the status value is acceptable before the final write\nlet valid = allowed_statuses().contains(&finality.status.as_str().to_string());\nif !valid { /* reject earlier, before the transaction begins */ }","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if is_transient_db_error(&e) || is_lock_timeout(&e) => {\n        retry_with_backoff(3, || apply_verified_finality(...)).await\n    }\n    Err(e) => Err(e),\n    Ok(v) => Ok(v),\n}","preventionTips":["Keep finality transactions short; do the status UPDATE promptly after the checks","Align DB CHECK constraints on status with every adapter status change","Serialize finality per intent to avoid lock contention on the intent row","Alert on retries clustering at transaction end — a sign of idle-in-transaction timeouts"],"tags":["database","sqlx","intents","finality"],"backgroundTag":"database-write-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"}