{"record":{"id":"0c6c1e1af3b21ba8","repo":"nautechsystems/nautilus_trader","slug":"failed-to-record-prepared-execution-intent","errorCode":null,"errorMessage":"failed to record prepared execution intent","messagePattern":"failed to record prepared execution intent","errorType":"exception","errorClass":"ExecutionIntentReservationError","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":5831,"sourceCode":"\n            sqlx::query(\n                \"\n                INSERT INTO execution_transaction_transition (\n                    intent_id, transition_key, to_status, block_number\n                ) VALUES ($1, 'prepared', 'prepared', $2)\n                \",\n            )\n            .bind(row.id)\n            .bind(created_block)\n            .execute(&mut *transaction)\n            .await\n            .context(\"failed to record prepared execution intent\")?;\n\n            Ok::<_, anyhow::Error>((transaction, row))\n        }\n        .await\n        .map_err(|source| {\n            anyhow::Error::new(ExecutionIntentReservationError {\n                stage: ExecutionIntentReservationStage::BeforeCommit,\n                source,\n            })\n        })?;\n        transaction.commit().await.map_err(|e| {\n            anyhow::Error::new(ExecutionIntentReservationError {\n                stage: ExecutionIntentReservationStage::Commit,\n                source: anyhow::Error::new(e)\n                    .context(\"failed to commit execution intent reservation\"),\n            })\n        })?;\n        Ok(row)\n    }\n\n    /// Assigns the signer nonce to a prepared execution intent.\n    ///\n    /// Repeating the same assignment is idempotent. A different nonce or non-prepared state\n    /// fails closed.","sourceCodeStart":5813,"sourceCodeEnd":5849,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L5813-L5849","documentation":"This error is raised when the database insert/update that records a prepared blockchain execution intent (the pre-commit step of reserving an execution intent row) fails. The adapter wraps the underlying sqlx/DB failure in ExecutionIntentReservationError with stage BeforeCommit so callers know the reservation was never committed and the transaction can be safely retried or rolled back.","triggerScenarios":"Calling the database's execution-intent reservation routine when the INSERT/UPDATE of the prepared intent row fails inside the open transaction — e.g. constraint violation, connection loss, or lock timeout before transaction.commit() is reached.","commonSituations":"Postgres restarted or connection pool exhausted mid-transaction; unique/duplicate key conflict on the intent row; schema migration drift between adapter versions; disk-full or permission errors on the database host.","solutions":["Check the wrapped source error (ExecutionIntentReservationError.source) for the actual DB failure cause","Verify database connectivity, credentials, and pool health","Inspect the execution intents table schema/constraints for conflicts (duplicate reservation keys)","Retry the reservation — the BeforeCommit stage means no partial commit occurred","Ensure schema migrations are up to date with the adapter version"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Verify DB reachability before attempting a reservation\nsqlx::query(\"SELECT 1\").execute(&pool).await\n    .map_err(|e| anyhow!(\"database unreachable: {e}\"))?;","typeGuard":"fn is_before_commit_stage(err: &ExecutionIntentReservationError) -> bool {\n    matches!(err.stage, ExecutionIntentReservationStage::BeforeCommit)\n}","tryCatchPattern":"match reserve_intent(&pool, intent).await {\n    Err(e) if is_before_commit_stage(&e) => retry_with_backoff(|| reserve_intent(&pool, intent)),\n    other => other,\n}","preventionTips":["Keep DB connection pool healthy and sized for the workload","Apply schema migrations before deploying adapter updates","Make intent reservations idempotent so retries are safe","Monitor DB health and connection errors"],"tags":["database","blockchain","transaction","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-14T05:17:10.506Z"}