{"record":{"id":"50c001ee58860f88","repo":"nautechsystems/nautilus_trader","slug":"failed-to-mark-execution-event-emitted-e","errorCode":null,"errorMessage":"Failed to mark execution {event} emitted: {e}","messagePattern":"Failed to mark execution (.+?) emitted: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":7378,"sourceCode":"        event: &str,\n    ) -> anyhow::Result<()> {\n        let statement = match event {\n            \"acknowledgement\" => {\n                \"UPDATE execution_intent SET acknowledgement_emitted = TRUE, updated_at = NOW() WHERE id = $1\"\n            }\n            \"fill\" => {\n                \"UPDATE execution_intent SET fill_emitted = TRUE, active = CASE WHEN status = 'finalized' THEN FALSE ELSE active END, updated_at = NOW() WHERE id = $1 AND NOT terminal_emitted\"\n            }\n            \"terminal\" => {\n                \"UPDATE execution_intent SET terminal_emitted = TRUE, active = CASE WHEN status IN ('finalized', 'reverted') THEN FALSE ELSE active END, updated_at = NOW() WHERE id = $1 AND NOT fill_emitted\"\n            }\n            _ => anyhow::bail!(\"Unknown execution event marker {event}\"),\n        };\n        let result = sqlx::query(statement)\n            .bind(intent_id)\n            .execute(&self.pool)\n            .await\n            .map_err(|e| anyhow::anyhow!(\"Failed to mark execution {event} emitted: {e}\"))?;\n        anyhow::ensure!(\n            result.rows_affected() == 1,\n            \"Execution intent {intent_id} cannot mark {event} emitted\"\n        );\n        Ok(())\n    }\n\n    /// Updates the status of a persisted execution transaction record.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error if the database operation fails.\n    pub async fn update_execution_transaction_status(\n        &self,\n        chain_id: u32,\n        transaction_hash: &str,\n        status: &str,\n    ) -> anyhow::Result<()> {","sourceCodeStart":7360,"sourceCodeEnd":7396,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L7360-L7396","documentation":"This wraps a SQLx failure while marking one of an intent's event flags (acknowledgement/fill/terminal) as emitted (database.rs:7378). Before the query runs, an unrecognized event name bails with 'Unknown execution event marker'; this specific error means the chosen UPDATE statement itself failed at the database level, aborting the emit bookkeeping.","triggerScenarios":"The UPDATE on execution_intent (setting acknowledgement_emitted/fill_emitted/terminal_emitted) fails: connection loss or statement timeout, the flag column is missing due to migration drift, a parameter/type mismatch, or the row is locked by another writer until timeout.","commonSituations":"Dispatching events while a migration is in progress or columns were renamed; Postgres connectivity loss during event dispatch; long-held row locks from concurrent finality transactions causing lock_timeout; adapter pointed at a stale schema.","solutions":["Read the wrapped {e} for the underlying cause (lock timeout, undefined column, connection).","Apply pending migrations so the emitted-flag columns exist with expected names.","Retry the mark-emitted call on transient errors; then confirm the flag state before re-dispatching the event to avoid duplicates.","Check for concurrent transactions holding locks on the execution_intent row and reduce lock contention.","Verify the event name is one of the recognized markers, since unknown names fail earlier with a different message."],"exampleFix":"// before: ignoring the failure and re-emitting the event\nif let Err(e) = db.mark_event_emitted(intent_id, \"fill\") { log::warn!(\"{e}\"); }\nemit_fill_event();\n// after: mark first, only emit on success\nlet _ = db.mark_execution_event_emitted(intent_id, \"fill\").await.context(\"mark fill emitted\")?;\nemit_fill_event();","handlingStrategy":"try-catch","validationCode":"let cols: Vec<String> = sqlx::query_scalar(\n    \"SELECT column_name FROM information_schema.columns WHERE table_name = 'execution_intent' AND column_name LIKE '%_emitted'\")\n    .fetch_all(&pool).await?;\nanyhow::ensure!(cols.contains(&\"fill_emitted\".to_string()), \"emitted-flag columns missing; run migrations\");","typeGuard":"fn is_lock_timeout(e: &anyhow::Error) -> bool {\n    e.to_string().contains(\"lock timeout\") || e.to_string().contains(\"canceling statement\")\n}","tryCatchPattern":"match mark_result {\n    Err(e) if is_lock_timeout(&e) => retry_with_backoff(|| db.mark_execution_event_emitted(intent_id, event)).await?,\n    Err(e) => return Err(e.context(\"mark emitted\")),\n    Ok(()) => emit_event(), // emit only after durable bookkeeping\n}","preventionTips":["Mark the event emitted before dispatching it; never the other way around.","Keep migrations applied before the worker starts dispatching events.","Minimize concurrent writers to the same execution_intent row.","Set explicit lock_timeout/statement_timeout and retry rather than hanging."],"tags":["database","sqlx","event-dispatch"],"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-23T08:17:48.524Z"}