{"record":{"id":"4c6750e0f86202b6","repo":"nautechsystems/nautilus_trader","slug":"lighter-client-order-index-client-order-index-is","errorCode":null,"errorMessage":"Lighter client_order_index {client_order_index} is outside the venue-safe range","messagePattern":"Lighter client_order_index (.+?) is outside the venue-safe range","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/lighter/src/websocket/dispatch.rs","lineNumber":1305,"sourceCode":"    /// 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            );\n\n            if terminal {\n                self.retire_order_identity(&cloid);\n            } else if order.is_triggered() == Some(true) {","sourceCodeStart":1287,"sourceCodeEnd":1323,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/lighter/src/websocket/dispatch.rs#L1287-L1323","documentation":"The venue only accepts client_order_index values in [0, CLOID_INDEX_MAX]; this ensure! rejects any reconciliation bind where the index from the venue event falls outside that range, protecting against malformed or hostile venue payloads.","triggerScenarios":"A venue order-status event carries a client_order_index that is negative or exceeds CLOID_INDEX_MAX while reconciling/binding an order.","commonSituations":"Unexpected venue API payload shape changes, i64 overflow of a parsed field, decoding bug producing garbage indices.","solutions":["Log the offending event payload and check the venue API schema version","Validate/clamp client_order_index at the parse boundary before dispatch","Update the adapter if Lighter widened or changed the index range"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"if !(0..=i64::from(CLOID_INDEX_MAX)).contains(&client_order_index) {\n    tracing::error!(\"dropping malformed event, client_order_index={client_order_index}\");\n    return Ok(());\n}","typeGuard":"fn valid_cloid_index(i: i64) -> bool { (0..=i64::from(CLOID_INDEX_MAX)).contains(&i) }","tryCatchPattern":"if let Err(e) = bind_reconciliation(order, idx, vid, terminal).await {\n    if e.to_string().contains(\"outside the venue-safe range\") {\n        tracing::error!(\"malformed venue payload: {e}; skipping event\");\n        return Ok(());\n    }\n    return Err(e);\n}","preventionTips":["Validate parsed integers at the WebSocket decode boundary","Pin and monitor the venue API schema/version for payload changes","Alert on out-of-range indices — they usually indicate upstream anomalies"],"tags":["rust","validation","range-check","venue"],"backgroundTag":"value-out-of-range","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"}