nautechsystems/nautilus_trader · error
Failed to commit order client origins: {e}
Error message
Failed to commit order client origins: {e} What it means
At the end of index_order_clients the database transaction is committed; any sqlx commit failure is wrapped as 'Failed to commit order client origins'. The prior statements succeeded but finalizing them atomically failed — usually a lost connection or serialization/lock conflict at commit time. All changes roll back, so callers can safely retry the whole operation.
Source
Thrown at crates/infrastructure/src/sql/queries.rs:1504
WHERE client_order_id = $1
AND (client_id IS NULL OR client_id = $2)
"#,
)
.bind(client_order_id.to_string())
.bind(client_id.to_string())
.execute(&mut *transaction)
.await
.map_err(|e| anyhow::anyhow!("Failed to index order client origin: {e}"))?;
if result.rows_affected() == 0 {
anyhow::bail!("No persisted order events found for {client_order_id}");
}
}
transaction
.commit()
.await
.map_err(|e| anyhow::anyhow!("Failed to commit order client origins: {e}"))
}
/// Inserts or updates an order ID to position ID index entry via the provided `pool`.
///
/// # Errors
///
/// Returns an error if the SQL INSERT or UPDATE operation fails.
pub async fn index_order_position(
pool: &PgPool,
client_order_id: ClientOrderId,
position_id: PositionId,
) -> anyhow::Result<()> {
sqlx::query(
r#"
INSERT INTO "order_position_index" (
client_order_id, position_id, created_at, updated_at
) VALUES (
$1, $2, CURRENT_TIMESTAMP, CURRENT_TIMESTAMPView on GitHub (pinned to 18893faf8b)
Solutions
- Simply retry index_order_clients — the rolled-back transaction leaves no partial state.
- Check DB server logs for the commit failure cause (connection reset, serialization failure).
- Keep the transaction short; batch large rebuilds into smaller transactions if timeouts occur.
- Ensure pool timeouts and keepalives are configured for long operations.
Example fix
// before
queries::postgres::index_order_clients(&mut tx, &client_order_id, &client_id).await?;
// after
for attempt in 0..3 {
match try_index_clients(&pool, &client_order_id, &client_id).await {
Ok(_) => break,
Err(e) if attempt < 2 && is_transient(&e) => tokio::time::sleep(backoff(attempt)).await,
Err(e) => return Err(e),
}
} Defensive patterns
Strategy: retry
Validate before calling
let healthy = pool.acquire().await.is_ok(); anyhow::ensure!(healthy, "database pool unhealthy before index commit");
Try / catch
for attempt in 0..3 {
match index_clients_in_tx(&pool, &client_order_id, &client_id).await {
Ok(_) => break,
Err(e) if attempt < 2 && e.to_string().contains("commit") => {
tokio::time::sleep(std::time::Duration::from_millis(250 * (attempt + 1))).await;
}
Err(e) => return Err(e),
}
} Prevention
- Retry whole index operations — rollback makes them idempotent
- Keep transactions short; batch large rebuilds
- Configure DB idle/connection timeouts for long-running jobs
- Monitor DB server logs for commit-time connection resets
When it happens
Trigger: Calling index_order_clients when the connection drops between the UPDATEs and commit, the DB is shutting down, or a constraint/concurrency conflict surfaces only at COMMIT.
Common situations: Long-running index rebuild against a remote Postgres with an idle-timeout killing the connection; DB restart; network partition between nautilus and the cache DB.
Related errors
- Failed to commit verified nonce assignment: {e}
- Failed to commit transaction: {e}
- Failed to validate order client origin: {e}
- Unknown execution event marker {event}
- Failed to start verified action evidence: {e}
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/c331881866a3bcad.
Report an issue: GitHub.