{"record":{"id":"8206f51446285761","repo":"nautechsystems/nautilus_trader","slug":"failed-to-reconstruct-migrated-intent-e","errorCode":null,"errorMessage":"Failed to reconstruct migrated intent: {e}","messagePattern":"Failed to reconstruct migrated intent: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":4285,"sourceCode":"                        .bind(block_hash)\n                        .bind(receipt_success)\n                        .bind(gas_used)\n                        .bind(record.effective_gas_price.as_deref())\n                        .execute(&mut *transaction)\n                        .await\n                        .map_err(|e| anyhow::anyhow!(\"Failed to reconstruct migrated hash: {e}\"))?;\n                        anyhow::ensure!(\n                            hash_result.rows_affected() == 1,\n                            \"Migrated terminal transaction hash was not found\"\n                        );\n                        sqlx::query(\n                            \"UPDATE execution_intent SET status = $2, updated_at = NOW() WHERE id = $1\",\n                        )\n                        .bind(record.intent_id)\n                        .bind(status.as_str())\n                        .execute(&mut *transaction)\n                        .await\n                        .map_err(|e| anyhow::anyhow!(\"Failed to reconstruct migrated intent: {e}\"))?;\n                        if current_status != status.as_str() {\n                            sqlx::query(\n                                \"\n                                INSERT INTO execution_transaction_transition (\n                                    intent_id, transaction_hash_id, transition_key,\n                                    from_status, to_status, 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                                \",\n                            )\n                            .bind(record.intent_id)\n                            .bind(transaction_hash)\n                            .bind(format!(\"migration:{}:{transaction_hash}\", status.as_str()))\n                            .bind(current_status)\n                            .bind(status.as_str())\n                            .bind(block_number)","sourceCodeStart":4267,"sourceCodeEnd":4303,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L4267-L4303","documentation":"This error wraps sqlx failures from `UPDATE execution_intent SET status = $2, updated_at = NOW() WHERE id = $1`, the step that moves the locked migrated intent to its terminal status (finalized/reverted) after the hash row was reconstructed. It fires only when the UPDATE errors at the database level — not when it affects zero rows, since the intent row was already locked and verified earlier in the same transaction. The driver error is interpolated as {e}.","triggerScenarios":"The UPDATE fails due to: a CHECK constraint or enum on the status column rejecting the terminal status string, the transaction already being aborted by a prior failed statement, a connection loss mid-transaction, or conflicting locks from concurrent DDL.","commonSituations":"Schema drift where execution_intent.status allows different values than TransactionStatus::as_str() produces; DB connection timeout during a long migration batch; migration running while another deployment applies schema changes.","solutions":["Read the interpolated {e}; constraint violations name the offending column/constraint directly.","Verify execution_intent.status accepts TransactionStatus::Finalized/Reverted as_str() values; align enum strings or schema.","Check for transaction-aborted cascade: an earlier statement in this transaction failed; fix that first error in the logs.","Retry the migration if the cause was a transient connection failure; the rollback keeps state consistent.","Ensure no concurrent schema changes run during the migration window."],"exampleFix":"// before: status passed straight through\n.bind(status.as_str())\n\n// after: guard against schema drift first\nlet s = status.as_str();\nanyhow::ensure!(matches!(s, \"finalized\" | \"reverted\"), \"unexpected terminal status {s}\");\n.bind(s)","handlingStrategy":"try-catch","validationCode":"// confirm the terminal status strings are accepted by the schema\nlet allowed: Vec<String> = sqlx::query_scalar(\n    \"SELECT unnest(enum_range(NULL::execution_intent_status))::text\",\n).fetch_all(&pool).await?;\nanyhow::ensure!(allowed.contains(&\"finalized\".to_string()) && allowed.contains(&\"reverted\".to_string()),\n    \"schema does not accept terminal statuses: {allowed:?}\");","typeGuard":"fn is_terminal_status(status: &TransactionStatus) -> bool {\n    matches!(status, TransactionStatus::Finalized | TransactionStatus::Reverted)\n}","tryCatchPattern":"if let Err(e) = run_migration(&pool, records).await {\n    let msg = format!(\"{e:#}\");\n    if msg.contains(\"Failed to reconstruct migrated intent\") {\n        // usually schema drift on execution_intent.status or an aborted transaction\n        tracing::error!(\"intent UPDATE failed: {msg}\");\n    }\n    return Err(e); // rolled back; safe to fix and re-run\n}","preventionTips":["Keep TransactionStatus::as_str() strings aligned with the DB enum/CHECK constraint on execution_intent.status.","Apply schema migrations before data migrations in every environment.","Retry only after diagnosing: transient connection errors are safe to retry (transaction rolls back).","Watch for 'current transaction is aborted' — the real failure is an earlier statement."],"tags":["database","postgres","sqlx","migration","update-failed"],"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"}