nautechsystems/nautilus_trader · error · anyhow::Error
Persisted swap instrument
Error message
Persisted swap instrument {instrument_id} does not match restored order instrument {} What it means
After parsing the intent row's instrument_id and loading the cached order, restore_swap_plan() ensures the two instruments agree via anyhow::ensure!. A mismatch means the persisted intent points at a different instrument than the order actually stored under that client_order_id — an integrity violation that would mis-route a swap if allowed.
Solutions
- Verify you are not sharing one cache database across deployments/clients (each environment needs its own database).
- Inspect the intent row and the cached order; delete the conflicting intent or cache entry and re-run reconciliation.
- Ensure order client_order_ids are unique per instrument in your order generation.
- Purge stale cache data after changing venue/instrument definitions.
Example fix
// before -- one shared DB for testnet and mainnet DATABASE_URL=postgres://host/nautilus_shared // after -- per-environment databases DATABASE_URL=postgres://host/nautilus_mainnet
Defensive patterns
Strategy: validation
Validate before calling
-- detect mismatches before reconcile SELECT i.client_order_id, i.instrument_id, o.instrument_id FROM execution_intents i JOIN cached_orders o ON o.client_order_id = i.client_order_id WHERE i.instrument_id <> o.instrument_id; -- must return zero rows
Try / catch
match client.reconcile_unresolved_execution().await {
Err(e) if e.to_string().contains("does not match restored order instrument") => {
// isolate the environment: verify no shared cache DB, purge stale intents, retry
client.reconcile_unresolved_execution().await?
}
other => other,
} Prevention
- Use one cache database per environment/venue; never share across deployments.
- Guarantee client_order_id uniqueness per instrument in order generation.
- Purge stale cache entries after changing instrument definitions.
When it happens
Trigger: An ExecutionIntentRow whose instrument_id differs from order.instrument_id() of the cached order with the same client_order_id, discovered during reconcile_unresolved_execution() or build_execution_verification_migration().
Common situations: Order ID reuse across different instruments; two environments sharing one Postgres cache database; stale cache entries from a previous deployment mixed with new intents; manual cache manipulation.
Understand the failure class
Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.
Related errors
- Execution payload rewrap left
- Persisted swap intent has no instrument ID
- Replacement hash conflicts with another intent
- Active execution intent
- AX dated contract has different quote and settlement…
AI-assisted analysis of nautechsystems/nautilus_trader@18893faf8b (2026-09-08).
Data as JSON: /api/errors/614fccef1cf060e3.
Report an issue: GitHub.
Appendix: source
Thrown at crates/adapters/blockchain/src/execution/client.rs:1044
.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 18893faf8b)