{"record":{"id":"70822522b3c9caf0","repo":"nautechsystems/nautilus_trader","slug":"failed-to-start-execution-status-transition-e","errorCode":null,"errorMessage":"Failed to start execution status transition: {e}","messagePattern":"Failed to start execution status transition: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":6783,"sourceCode":"            .map(i64::try_from)\n            .transpose()\n            .with_context(|| {\n                format!(\n                    \"Execution block number {} exceeds PostgreSQL BIGINT\",\n                    block_number.unwrap_or_default()\n                )\n            })?;\n        let gas_used_db = gas_used.map(i64::try_from).transpose().with_context(|| {\n            format!(\n                \"Execution gas used {} exceeds PostgreSQL BIGINT\",\n                gas_used.unwrap_or_default()\n            )\n        })?;\n        let mut transaction = self\n            .pool\n            .begin()\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to start execution status transition: {e}\"))?;\n        let (current_status, fill_emitted, terminal_emitted) =\n            sqlx::query_as::<_, (String, bool, bool)>(\n            \"SELECT status, fill_emitted, terminal_emitted FROM execution_intent WHERE id = $1 FOR UPDATE\",\n        )\n        .bind(intent_id)\n        .fetch_optional(&mut *transaction)\n        .await\n        .map_err(|e| anyhow::anyhow!(\"Failed to lock execution intent {intent_id}: {e}\"))?\n        .ok_or_else(|| anyhow::anyhow!(\"Execution intent {intent_id} was not found\"))?;\n        anyhow::ensure!(\n            execution_transition_allowed(&current_status, status),\n            \"Invalid execution transition for intent {intent_id}: {current_status} -> {}\",\n            status.as_str()\n        );\n\n        let active = match status {\n            TransactionStatus::Finalized | TransactionStatus::Reverted => {\n                !fill_emitted && !terminal_emitted","sourceCodeStart":6765,"sourceCodeEnd":6801,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L6765-L6801","documentation":"This error wraps a failure to BEGIN a SQL transaction via sqlx's pool when starting an execution-status transition in the blockchain cache database. The transaction is needed to row-lock (SELECT ... FOR UPDATE) the execution_intent row and apply the state change atomically. If the pool cannot start a transaction (connection unavailable, pool exhausted, database down), the transition is aborted with this message.","triggerScenarios":"Calling the execution-status transition method (e.g. record_execution_status/transition) when DatabasePool::begin() fails: connection pool exhausted (max_connections in use), database unreachable, connection dropped mid-handshake, or TLS/auth failure at connect time.","commonSituations":"Database restarted or failover in progress while the adapter processes receipts; pool saturation under high event throughput; wrong DATABASE_URL / credentials after a config change; network partition between the adapter and Postgres; idle connections reaped by a firewall/load balancer.","solutions":["Verify the database is reachable and credentials are correct (psql with the same DATABASE_URL).","Check pool sizing (max_connections, acquire_timeout) versus concurrent load; increase limits or reduce concurrency.","Retry the operation with backoff — sqlx pool acquisition failures are often transient.","Inspect the inner `{e}` message for the root sqlx error (connection refused vs timeout vs auth)."],"exampleFix":"// before\nlet mut transaction = self.pool.begin().await.map_err(|e| anyhow::anyhow!(\"Failed to start execution status transition: {e}\"))?;\n// after\nlet mut transaction = self.pool\n    .begin()\n    .await\n    .with_context(|| format!(\"Failed to start execution status transition (db={})\", self.pool.size()))?;","handlingStrategy":"retry","validationCode":"// Rust: check pool health before attempting the transition\nif self.pool.is_closed() {\n    anyhow::bail!(\"database pool closed\");\n}\n// optionally: let _ = sqlx::query(\"SELECT 1\").execute(&self.pool).await?;","typeGuard":null,"tryCatchPattern":"match db.record_execution_status(&intent_id, status, ...).await {\n    Ok(()) => {},\n    Err(e) if e.to_string().contains(\"Failed to start execution status transition\") => {\n        tracing::warn!(error = %e, \"transient db error; retrying with backoff\");\n        tokio::time::sleep(backoff.next()).await;\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Size the connection pool for peak concurrency and set a sane acquire_timeout.","Run periodic SELECT 1 health checks to recycle stale pool connections.","Alert on database reachability so transitions fail fast during outages."],"tags":["database","transaction","sqlx","connection"],"backgroundTag":"database-query-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}