{"record":{"id":"614fccef1cf060e3","repo":"nautechsystems/nautilus_trader","slug":"persisted-swap-instrument-instrument-id-does-not","errorCode":null,"errorMessage":"Persisted swap instrument {instrument_id} does not match restored order instrument {}","messagePattern":"Persisted swap instrument (.+?) does not match restored order instrument (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/blockchain/src/execution/client.rs","lineNumber":1044,"sourceCode":"                .ok_or_else(|| anyhow::anyhow!(\"Persisted swap intent has no client order ID\"))?,\n        )?;\n        let order = self\n            .core\n            .cache()\n            .try_order_owned(&client_order_id)\n            .with_context(|| {\n                format!(\n                    \"Cannot reconcile swap intent {} because order {client_order_id} is not restored\",\n                    intent.id\n                )\n            })?;\n        let instrument_id = InstrumentId::from_str(\n            intent\n                .instrument_id\n                .as_deref()\n                .ok_or_else(|| anyhow::anyhow!(\"Persisted swap intent has no instrument ID\"))?,\n        )?;\n        anyhow::ensure!(\n            order.instrument_id() == instrument_id,\n            \"Persisted swap instrument {instrument_id} does not match restored order instrument {}\",\n            order.instrument_id()\n        );\n        anyhow::ensure!(\n            intent.trader_id.as_deref() == Some(order.trader_id().as_str()),\n            \"Persisted swap trader does not match restored order\"\n        );\n        anyhow::ensure!(\n            intent.strategy_id.as_deref() == Some(order.strategy_id().as_str()),\n            \"Persisted swap strategy does not match restored order\"\n        );\n        anyhow::ensure!(\n            intent.account_id.as_deref() == Some(self.core.account_id.as_str()),\n            \"Persisted swap account does not match execution client account\"\n        );\n\n        let pool = self.resolve_pool(&instrument_id)?;","sourceCodeStart":1026,"sourceCodeEnd":1062,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/blockchain/src/execution/client.rs#L1026-L1062","documentation":"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.","triggerScenarios":"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().","commonSituations":"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.","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."],"exampleFix":"// before\n-- one shared DB for testnet and mainnet\nDATABASE_URL=postgres://host/nautilus_shared\n// after\n-- per-environment databases\nDATABASE_URL=postgres://host/nautilus_mainnet","handlingStrategy":"validation","validationCode":"-- detect mismatches before reconcile\nSELECT i.client_order_id, i.instrument_id, o.instrument_id\nFROM execution_intents i\nJOIN cached_orders o ON o.client_order_id = i.client_order_id\nWHERE i.instrument_id <> o.instrument_id;\n-- must return zero rows","typeGuard":null,"tryCatchPattern":"match client.reconcile_unresolved_execution().await {\n    Err(e) if e.to_string().contains(\"does not match restored order instrument\") => {\n        // isolate the environment: verify no shared cache DB, purge stale intents, retry\n        client.reconcile_unresolved_execution().await?\n    }\n    other => other,\n}","preventionTips":["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."],"tags":["rust","postgres","data-integrity","instrument"],"backgroundTag":"schema-validation-failed","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}