{"record":{"id":"560f5610b992463c","repo":"nautechsystems/nautilus_trader","slug":"client-order-id-not-found-in-cache","errorCode":null,"errorMessage":"Client order ID not found in cache","messagePattern":"Client order ID not found in cache","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/adapters/dydx/src/execution/mod.rs","lineNumber":1956,"sourceCode":"        }; // Cache borrow released here\n\n        log::debug!(\"Cancelling order {client_order_id} for instrument {instrument_id}\");\n\n        let (tx_manager, broadcaster, order_builder) = match self.get_execution_components() {\n            Ok(components) => components,\n            Err(e) => {\n                log::error!(\"Failed to get execution components for cancel: {e}\");\n                return Ok(());\n            }\n        };\n\n        let block_height = self.block_time_monitor.current_block_height() as u32;\n\n        let encoded = match self.encoder.get(&client_order_id) {\n            Some(enc) => enc,\n            None => {\n                log::error!(\"Client order ID {client_order_id} not found in cache\");\n                anyhow::bail!(\"Client order ID not found in cache\")\n            }\n        };\n        let client_id_u32 = encoded.client_id;\n\n        log::debug!(\n            \"[CANCEL_ORDER] Nautilus '{client_order_id}' -> dYdX u32={client_id_u32} | instrument={instrument_id}\"\n        );\n\n        // Stored flags remain authoritative after the order expires\n        let order_flags = self.get_order_context(client_id_u32).map_or_else(\n            || {\n                log::warn!(\n                    \"Order context not found for {client_order_id}, deriving flags from order\"\n                );\n                types::OrderLifetime::from_time_in_force(\n                    order_time_in_force, // Using extracted value\n                    order_expire_time,   // Using extracted value\n                    false,","sourceCodeStart":1938,"sourceCodeEnd":1974,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/dydx/src/execution/mod.rs#L1938-L1974","documentation":"`cancel_order` looks up the dYdX u32 client ID encoded for the Nautilus client_order_id via `self.encoder.get(...)`. If no encoding exists in the local cache, cancellation cannot build the on-chain cancel message and bails.","triggerScenarios":"Canceling an order whose client_order_id was never submitted through this client instance (e.g. after a process restart with a cold cache, or an order placed by another client/session).","commonSituations":"Adapter restart with an empty encoder cache while the strategy still holds references to prior-session orders; reconciled venue orders not originated locally; submitting orders with a different adapter instance than the one canceling.","solutions":["Only cancel orders submitted through the same client instance/session","Persist and reload the client-ID encoder cache across restarts if supported","Reconcile open orders on connect and re-register their IDs before canceling","If the order is foreign, cancel it via venue_order_id-based paths or the dYdX API directly"],"exampleFix":"// before: cancel regardless of origin\nclient.cancel_order(cmd)?;\n// after: skip orders not submitted this session\nif encoder.contains(cmd.client_order_id) {\n    client.cancel_order(cmd)?;\n} else {\n    log::warn!(\"{} not owned by this session; skipping\", cmd.client_order_id);\n}","handlingStrategy":"validation","validationCode":"if !encoder.contains(client_order_id) { return Err(anyhow!(\"order not owned by this session\")); }","typeGuard":"fn is_session_order(encoder: &Encoder, id: &ClientOrderId) -> bool { encoder.get(id).is_some() }","tryCatchPattern":"match client.cancel_order(cmd) {\n    Err(e) if e.to_string().contains(\"not found in cache\") => log::warn!(\"foreign/unknown order, skipping cancel\"),\n    r => r?,\n}","preventionTips":["Only cancel orders submitted by the same client session","Persist encoder state across restarts if order continuity is required","Reconcile and re-register open orders on startup before canceling"],"tags":["dydx","order-cancellation","cache-miss","state"],"backgroundTag":"record-not-found","analyzedSha":"18893faf8b356be3320add8de2f861b0b647cf06","analyzedAt":"2026-09-08T20:49:34.690Z","contentChangedAt":"2026-09-08T20:49:34.690Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}