nautechsystems/nautilus_trader · error · anyhow::Error

Persisted swap instrument {instrument_id} does not match res

Error message

Persisted swap instrument {instrument_id} does not match restored order instrument {}

What it means

restore_swap_plan (crates/adapters/blockchain/src/execution/client.rs:840) cross-checks the persisted intent's instrument_id against the instrument of the order restored from the cache under the intent's client_order_id. A mismatch means the durable intent and the live order disagree about which market the swap targeted - a split-brain state the client refuses to reconcile blindly, because completing the swap would emit fills against the wrong instrument. The mismatch check protects order-event integrity after restarts.

Source

Thrown at crates/adapters/blockchain/src/execution/client.rs:840

                .ok_or_else(|| anyhow::anyhow!("Persisted swap intent has no client order ID"))?,
        )?;
        let order = self
            .core
            .cache()
            .try_order_owned(&client_order_id)
            .with_context(|| {
                format!(
                    "Cannot reconcile swap intent {} because order {client_order_id} is not restored",
                    intent.id
                )
            })?;
        let instrument_id = InstrumentId::from_str(
            intent
                .instrument_id
                .as_deref()
                .ok_or_else(|| anyhow::anyhow!("Persisted swap intent has no instrument ID"))?,
        )?;
        anyhow::ensure!(
            order.instrument_id() == instrument_id,
            "Persisted swap instrument {instrument_id} does not match restored order instrument {}",
            order.instrument_id()
        );
        anyhow::ensure!(
            intent.trader_id.as_deref() == Some(order.trader_id().as_str()),
            "Persisted swap trader does not match restored order"
        );
        anyhow::ensure!(
            intent.strategy_id.as_deref() == Some(order.strategy_id().as_str()),
            "Persisted swap strategy does not match restored order"
        );
        anyhow::ensure!(
            intent.account_id.as_deref() == Some(self.core.account_id.as_str()),
            "Persisted swap account does not match execution client account"
        );

        let pool = self.resolve_pool(&instrument_id)?;

View on GitHub (pinned to 2114cf6f76)

Solutions

  1. Compare both sides: the intent's instrument_id column vs the instrument on the order named by its client_order_id.
  2. Settle the stale intent - verify the on-chain transaction outcome and mark the intent resolved so reconciliation skips it.
  3. Make client order ids unique per instrument and deployment to prevent cross-instrument reuse.
  4. Keep instrument/pool configuration stable across restarts that carry active intents.
Defensive patterns

Strategy: try-catch

Validate before calling

-- Pre-flight: active swap intents whose recorded instrument no longer matches
-- the orders you will restore (compare against your current instrument config)
SELECT id, client_order_id, instrument_id, status
FROM execution_intent
WHERE status IN ('prepared', 'signed', 'submitted')
  AND purpose = 'swap';

Type guard

fn is_instrument_mismatch(e: &anyhow::Error) -> bool {
    e.to_string().contains("does not match restored order instrument")
}

Try / catch

if let Err(e) = client.connect().await {
    if is_instrument_mismatch(&e) {
        // durable intent and restored order disagree: do not trade; reconcile data first
        log::error!("split-brain swap intent (instrument): {e}");
    }
    return Err(e);
}

Prevention

When it happens

Trigger: The same ClientOrderId was reused on a different instrument across runs while an old intent for it was still active; the order cache was restored from a session whose instrument mapping differs from the one recorded in the intent; stale intents surviving a reconfiguration that renamed or remapped instruments/pools.

Common situations: Restarting with changed instrument configuration (different pool set or naming) while intents from the prior configuration remain active; client order id schemes that collide across deployments.

Related errors


AI-assisted analysis of nautechsystems/nautilus_trader@2114cf6f76 (2026-08-21). Data as JSON: /api/errors/614fccef1cf060e3. Report an issue: GitHub.