{"record":{"id":"792b30b4868b97f1","repo":"nautechsystems/nautilus_trader","slug":"cannot-find-contingent-order-for-client-order-id","errorCode":null,"errorMessage":"Cannot find contingent order for {client_order_id}","messagePattern":"Cannot find contingent order for (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/execution/src/matching_engine/mod.rs","lineNumber":2876,"sourceCode":"                }\n\n                if let Some(linked_order_ids) = order.linked_order_ids() {\n                    let contingency_type = order.contingency_type();\n                    for client_order_id in linked_order_ids {\n                        match cache_borrow.order(client_order_id) {\n                            Some(contingent_order)\n                                if matches!(\n                                    contingency_type,\n                                    Some(ContingencyType::Oco | ContingencyType::Ouo)\n                                ) && !order.is_closed()\n                                    && contingent_order.is_closed() =>\n                            {\n                                break 'validate Some(\n                                    format!(\"Contingent order {client_order_id} already closed\")\n                                        .into(),\n                                );\n                            }\n                            None => panic!(\"Cannot find contingent order for {client_order_id}\"),\n                            _ => {}\n                        }\n                    }\n                }\n            }\n\n            // Check for valid order quantity precision\n            if order.quantity().precision != self.instrument.size_precision() {\n                break 'validate Some(\n                    format!(\n                        \"Invalid order quantity precision for order {}, was {} when {} size precision is {}\",\n                        order.client_order_id(),\n                        order.quantity().precision,\n                        self.instrument.id(),\n                        self.instrument.size_precision()\n                    )\n                    .into(),\n                );","sourceCodeStart":2858,"sourceCodeEnd":2894,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/execution/src/matching_engine/mod.rs#L2858-L2894","documentation":"While validating contingent-order constraints, the engine matched a case where the linked (contingent) order's snapshot was None — i.e. the order referenced via linked_order_ids is not in the cache — and panicked instead of continuing validation. An order that participates in a contingency chain must exist locally; its absence means broken chain state. The panic guards against silently mis-validating OCO/OTO relationships.","triggerScenarios":"Validating an order whose linked_order_ids contains a client_order_id with no entry in the matching-engine cache (order_snapshot returns None) during contingency checks.","commonSituations":"OCO/OTO chains built on a different node or lost by a cache restart; cancel/replace races where the linked order was already finalized and evicted; adapters replaying orders with stale linked_order_ids.","solutions":["Ensure every order in linked_order_ids is submitted/cached on the same node that validates the chain.","Enable cache persistence so contingent chains survive restarts, or rebuild links during reconciliation.","Filter out orders whose linked orders cannot be resolved before dispatching them to the matching engine.","Avoid evicting/finalizing one member of a chain while siblings are still being validated; update the whole chain atomically."],"exampleFix":"// before\norder.linked_order_ids = Some(vec![missing_order_id]);\n// after\nlet linked = linked_ids.into_iter().filter(|id| cache.order(id).is_some()).collect::<Vec<_>>();\norder.linked_order_ids = (!linked.is_empty()).then_some(linked);","handlingStrategy":"validation","validationCode":"let linked = order.linked_order_ids().unwrap_or_default();\nlet all_cached = linked.iter().all(|id| engine.order_snapshot(id).is_some());\nif !all_cached { return Err(anyhow!(\"contingent chain incomplete\")); }","typeGuard":"fn chain_complete(engine: &OrderMatchingEngine, order: &OrderAny) -> bool {\n    order.linked_order_ids().map_or(true, |ids| ids.iter().all(|id| engine.order_snapshot(id).is_some()))\n}","tryCatchPattern":null,"preventionTips":["Keep every member of an OCO/OTO chain on the same node and in the same cache.","Finalize and evict chains atomically, not member-by-member.","Rebuild contingency links after restarts via reconciliation.","Filter stale linked_order_ids before order submission."],"tags":["rust","matching-engine","contingent-orders","panic"],"backgroundTag":"entity-not-found","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"}