nautechsystems/nautilus_trader · error · anyhow::Error
Failed to mark execution
Error message
Failed to mark execution {event} emitted: {e} What it means
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.
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.
Example fix
// before: ignoring the failure and re-emitting the event
if let Err(e) = db.mark_event_emitted(intent_id, "fill") { log::warn!("{e}"); }
emit_fill_event();
// after: mark first, only emit on success
let _ = db.mark_execution_event_emitted(intent_id, "fill").await.context("mark fill emitted")?;
emit_fill_event(); Defensive patterns
Strategy: try-catch
Validate before calling
let cols: Vec<String> = sqlx::query_scalar(
"SELECT column_name FROM information_schema.columns WHERE table_name = 'execution_intent' AND column_name LIKE '%_emitted'")
.fetch_all(&pool).await?;
anyhow::ensure!(cols.contains(&"fill_emitted".to_string()), "emitted-flag columns missing; run migrations"); Type guard
fn is_lock_timeout(e: &anyhow::Error) -> bool {
e.to_string().contains("lock timeout") || e.to_string().contains("canceling statement")
} Try / catch
match mark_result {
Err(e) if is_lock_timeout(&e) => retry_with_backoff(|| db.mark_execution_event_emitted(intent_id, event)).await?,
Err(e) => return Err(e.context("mark emitted")),
Ok(()) => emit_event(), // emit only after durable bookkeeping
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Execution intent cannot mark emitted
- Execution transaction
- Failed to advance canonical nonce ledger
- Failed to assign nonce
- Failed to batch insert into block table
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/50c001ee58860f88.
Report an issue: GitHub.
Appendix: source
Thrown at crates/adapters/blockchain/src/cache/database.rs:7378
event: &str,
) -> 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<()> {View on GitHub (pinned to 18893faf8b)