{"record":{"id":"1193ace80d1df0ca","repo":"nautechsystems/nautilus_trader","slug":"failed-to-commit-verified-finality-transition-e","errorCode":null,"errorMessage":"Failed to commit verified finality transition: {e}","messagePattern":"Failed to commit verified finality transition: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":7199,"sourceCode":"              AND next_canonical_nonce = $4 AND revision = $5\n            \",\n        )\n        .bind(chain_id)\n        .bind(finality.wallet_address)\n        .bind(next_nonce)\n        .bind(nonce)\n        .bind(revision)\n        .execute(&mut *transaction)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to advance canonical nonce ledger: {e}\"))?;\n        anyhow::ensure!(\n            nonce_result.rows_affected() == 1,\n            \"Canonical nonce ledger changed during finality transition\"\n        );\n        transaction\n            .commit()\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to commit verified finality transition: {e}\"))?;\n        Ok(())\n    }\n\n    /// Loads one durable execution intent by ID.\n    pub(crate) async fn get_execution_intent(\n        &self,\n        intent_id: i64,\n    ) -> anyhow::Result<ExecutionIntentRow> {\n        sqlx::query_as::<_, ExecutionIntentRow>(\n            \"\n            SELECT\n                id, schema_version, chain_id, wallet_address, nonce, purpose, status,\n                client_order_id, trader_id, strategy_id, account_id, instrument_id,\n                pool_address, transaction_to, transaction_input, transaction_value,\n                amount_in, created_block, acknowledgement_emitted, fill_emitted,\n                terminal_emitted, active\n            FROM execution_intent\n            WHERE id = $1","sourceCodeStart":7181,"sourceCodeEnd":7217,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L7181-L7217","documentation":"This error wraps a failure of transaction.commit() at the end of the verified-finality flow (database.rs:7199). All statements succeeded but the atomic commit to PostgreSQL failed, so the entire transition (finality receipt, intent status, transition row, nonce advance) rolls back and nothing is persisted.","triggerScenarios":"The COMMIT statement fails: the database connection was lost or restarted between the last statement and commit, a serialization/deadlock error was raised at commit time, the statement/idle-in-transaction timeout expired during a long transaction, or the pool forcibly closed the connection.","commonSituations":"Long-running finality transactions hitting idle_in_transaction_session_timeout on managed Postgres (RDS/Cloud SQL); network partition or failover mid-transaction; connection pool recycling while a transaction is open; Postgres under heavy lock contention deadlocking with another writer.","solutions":["Retry the entire finality transition with a fresh transaction — commit failure is atomic, so state is unchanged and a retry is safe.","Reduce transaction duration (check network latency, move non-DB work outside the transaction) to avoid idle-in-transaction timeouts.","Verify database health/uptime at the failure timestamp; check for failover or restarts in Postgres logs.","Tune pool settings (acquire timeout, max lifetime) so connections are not closed mid-transaction.","Inspect Postgres logs for deadlock or serialization-failure SQLSTATEs and coordinate lock ordering with other writers."],"exampleFix":"// before: treating commit failure as partial success\nif let Err(e) = res { log::warn!(\"finality commit: {e}\"); }\n// after: retry the whole transactional operation\nlet res = db.record_verified_finality(&finality).await;\nmatch res {\n    Err(e) if is_transient(&e) => db.record_verified_finality(&finality).await.context(\"finality retry\")?,\n    other => other?,\n}","handlingStrategy":"retry","validationCode":"let healthy: bool = sqlx::query_scalar(\"SELECT 1 = 1\").fetch_one(&pool).await.is_ok();\nif !healthy { return Err(anyhow!(\"database unreachable; defer finality commit\")); }","typeGuard":"fn is_commit_failure(e: &anyhow::Error) -> bool {\n    e.to_string().contains(\"Failed to commit verified finality transition\")\n}","tryCatchPattern":"match res {\n    Err(e) if is_commit_failure(&e) && attempt < MAX_RETRIES => {\n        warn!(\"commit failed, retrying atomically: {e}\");\n        return retry_whole_transition().await;\n    }\n    other => other,\n}","preventionTips":["Keep finality transactions short; do no external I/O inside the transaction.","Set idle_in_transaction_session_timeout above your worst-case transaction duration.","Retry the entire operation on commit failure — the rollback leaves state consistent.","Monitor Postgres restarts/failovers and alert on connection churn in pool metrics."],"tags":["database","transaction","commit","sqlx"],"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-14T00:17:10.932Z"}