{"record":{"id":"d286642ca509fa7a","repo":"nautechsystems/nautilus_trader","slug":"execution-intent-intent-id-cannot-mark-event-e","errorCode":null,"errorMessage":"Execution intent {intent_id} cannot mark {event} emitted","messagePattern":"Execution intent (.+?) cannot mark (.+?) emitted","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/cache/database.rs","lineNumber":7379,"sourceCode":"    ) -> 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<()> {\n        let result = sqlx::query(","sourceCodeStart":7361,"sourceCodeEnd":7397,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/cache/database.rs#L7361-L7397","documentation":"After the mark-emitted UPDATE runs, the code asserts rows_affected == 1 (database.rs:7379). Zero rows means the execution_intent row for intent_id no longer matched — it was deleted, or the statement's WHERE clause filtered it out — so the emit flag was not recorded and the library fails to prevent dispatching an event without durable bookkeeping.","triggerScenarios":"Calling mark-executed-emitted for an intent_id that was purged from execution_intent; the intent row was deleted between loading it and marking the event; a concurrent finality transition moved the row out of the statement's WHERE conditions; an ID from a different environment/database.","commonSituations":"Retention jobs deleting old intents while a worker still dispatches their events; workers resuming from stale queues referencing removed intents; environments pointing at different databases; race between intent cleanup and event dispatch.","solutions":["Confirm the intent row still exists (SELECT id FROM execution_intent WHERE id = <id>); if it was purged, drop the pending event instead of retrying.","Re-check that the intent_id came from the same database/environment the worker is connected to.","Serialize event dispatch with intent lifecycle operations so the row cannot be deleted mid-dispatch.","Refresh intent state from the database before marking events after long pauses or queue replays.","If this happens after manual data cleanup, restore or re-create the intent record."],"exampleFix":"// before: marking emitted on a possibly-deleted intent\nlet _ = db.mark_execution_event_emitted(intent_id, \"terminal\").await?;\n// after: verify existence first and skip stale events\nif !db.execution_intent_exists(intent_id).await? { log::warn!(\"intent {intent_id} gone; dropping event\"); return Ok(()); }\ndb.mark_execution_event_emitted(intent_id, \"terminal\").await?;","handlingStrategy":"validation","validationCode":"let exists: Option<i64> = sqlx::query_scalar(\n    \"SELECT id FROM execution_intent WHERE id = $1\").bind(intent_id).fetch_optional(&pool).await?;\nif exists.is_none() { return Ok(()); } // intent purged; drop the stale event instead of marking","typeGuard":"fn is_zero_rows_affected(msg: &str) -> bool {\n    msg.contains(\"cannot mark\") && msg.contains(\"emitted\")\n}","tryCatchPattern":"match mark_result {\n    Err(e) if is_zero_rows_affected(&e.to_string()) => {\n        if !intent_exists(intent_id).await? { warn!(\"intent gone; dropping event\"); } else { return Err(e); }\n    }\n    other => other?,\n}","preventionTips":["Serialize intent deletion/retention with event dispatch for the same intent.","Re-verify intent existence after queue replays or long worker pauses.","Don't share intent IDs across environments/databases.","Use a foreign-key from event queues to execution_intent to catch dangling references early."],"tags":["database","concurrency","event-dispatch","not-found"],"backgroundTag":"internal-invariant-violation","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"}