{"record":{"id":"0a6ee7a60be589cf","repo":"nautechsystems/nautilus_trader","slug":"cached-lighter-order-cloid-does-not-match-venue","errorCode":null,"errorMessage":"cached Lighter order {cloid} does not match venue order ID {venue_order_id}","messagePattern":"cached Lighter order (.+?) does not match venue order ID (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/websocket/dispatch.rs","lineNumber":1301,"sourceCode":"\n    /// Restore an exact order identity observed during reconciliation.\n    ///\n    /// `terminal` reflects the current venue report because the cached order can be stale after a\n    /// restart.\n    ///\n    /// # Errors\n    ///\n    /// Returns an error when the cached order does not carry the same venue order ID, the client\n    /// index is outside the venue-safe range, or the binding conflicts with existing local state.\n    pub(crate) fn restore_reconciled_order(\n        &self,\n        order: &OrderAny,\n        client_order_index: i64,\n        venue_order_id: VenueOrderId,\n        terminal: bool,\n    ) -> anyhow::Result<()> {\n        let cloid = order.client_order_id();\n        anyhow::ensure!(\n            order.venue_order_id() == Some(venue_order_id),\n            \"cached Lighter order {cloid} does not match venue order ID {venue_order_id}\",\n        );\n        anyhow::ensure!(\n            (0..=i64::from(CLOID_INDEX_MAX)).contains(&client_order_index),\n            \"Lighter client_order_index {client_order_index} is outside the venue-safe range\",\n        );\n\n        if let Some(existing) = self\n            .order_identities\n            .get(&cloid)\n            .map(|entry| entry.value().clone())\n        {\n            anyhow::ensure!(\n                existing.client_order_index == client_order_index\n                    && existing.matches_venue_order_id(venue_order_id),\n                \"active Lighter order {cloid} conflicts with reconciliation binding\",\n            );","sourceCodeStart":1283,"sourceCodeEnd":1319,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/websocket/dispatch.rs#L1283-L1319","documentation":"During order reconciliation binding, the cached OrderAny for a client_order_id must already carry the same venue order ID that the venue reports. ensure! rejects the call when order.venue_order_id() != Some(venue_order_id), catching an identity mismatch between local cache and venue state.","triggerScenarios":"Calling the reconciliation bind helper with an order whose cached venue_order_id is None or differs from the venue_order_id argument — e.g. dispatching a venue event to the wrong cached order, or a stale cache entry.","commonSituations":"Client order ID collisions after restart, orders restored from cache before venue ID assignment, events from one venue instrument applied to another's cached order.","solutions":["Clear/rebuild the local order cache and re-reconcile against venue state","Verify the event's client_order_id maps to the correct cached order","Ensure venue_order_id assignment happens before this binding is invoked"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if order.venue_order_id() != Some(venue_order_id) {\n    tracing::warn!(\"identity mismatch for {cloid}; forcing re-reconcile\");\n    rebuild_cache_from_venue().await?;\n}","typeGuard":"fn binding_consistent(o: &OrderAny, vid: VenueOrderId) -> bool {\n    o.venue_order_id() == Some(vid)\n}","tryCatchPattern":"if let Err(e) = bind_reconciliation(order, idx, vid, terminal).await {\n    tracing::error!(\"bind failed, re-reconciling: {e}\");\n    full_reconcile_from_venue().await?;\n}","preventionTips":["Keep a 1:1 cloid→order mapping; never reuse client order IDs","Reconcile cache against venue state after every reconnect","Route venue events only to orders from the matching instrument/account"],"tags":["rust","websocket","reconciliation","state-mismatch"],"backgroundTag":"internal-invariant-violation","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}