nautechsystems/nautilus_trader · error · anyhow::Error

Execution intent cannot mark emitted

Error message

Execution intent {intent_id} cannot mark {event} emitted

What it means

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.

Solutions

  1. 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.
  2. Re-check that the intent_id came from the same database/environment the worker is connected to.
  3. Serialize event dispatch with intent lifecycle operations so the row cannot be deleted mid-dispatch.
  4. Refresh intent state from the database before marking events after long pauses or queue replays.
  5. If this happens after manual data cleanup, restore or re-create the intent record.

Example fix

// before: marking emitted on a possibly-deleted intent
let _ = db.mark_execution_event_emitted(intent_id, "terminal").await?;
// after: verify existence first and skip stale events
if !db.execution_intent_exists(intent_id).await? { log::warn!("intent {intent_id} gone; dropping event"); return Ok(()); }
db.mark_execution_event_emitted(intent_id, "terminal").await?;
Defensive patterns

Strategy: validation

Validate before calling

let exists: Option<i64> = sqlx::query_scalar(
    "SELECT id FROM execution_intent WHERE id = $1").bind(intent_id).fetch_optional(&pool).await?;
if exists.is_none() { return Ok(()); } // intent purged; drop the stale event instead of marking

Type guard

fn is_zero_rows_affected(msg: &str) -> bool {
    msg.contains("cannot mark") && msg.contains("emitted")
}

Try / catch

match mark_result {
    Err(e) if is_zero_rows_affected(&e.to_string()) => {
        if !intent_exists(intent_id).await? { warn!("intent gone; dropping event"); } else { return Err(e); }
    }
    other => other?,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08). Data as JSON: /api/errors/d286642ca509fa7a. Report an issue: GitHub.

Appendix: source

Thrown at crates/adapters/blockchain/src/cache/database.rs:7379

    ) -> anyhow::Result<()> {
        let statement = match event {
            "acknowledgement" => {
                "UPDATE execution_intent SET acknowledgement_emitted = TRUE, updated_at = NOW() WHERE id = $1"
            }
            "fill" => {
                "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"
            }
            "terminal" => {
                "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"
            }
            _ => anyhow::bail!("Unknown execution event marker {event}"),
        };
        let result = sqlx::query(statement)
            .bind(intent_id)
            .execute(&self.pool)
            .await
            .map_err(|e| anyhow::anyhow!("Failed to mark execution {event} emitted: {e}"))?;
        anyhow::ensure!(
            result.rows_affected() == 1,
            "Execution intent {intent_id} cannot mark {event} emitted"
        );
        Ok(())
    }

    /// Updates the status of a persisted execution transaction record.
    ///
    /// # Errors
    ///
    /// Returns an error if the database operation fails.
    pub async fn update_execution_transaction_status(
        &self,
        chain_id: u32,
        transaction_hash: &str,
        status: &str,
    ) -> anyhow::Result<()> {
        let result = sqlx::query(

View on GitHub (pinned to 18893faf8b)