{"record":{"id":"3a2b1927031d17ba","repo":"nautechsystems/nautilus_trader","slug":"order-for-not-found-to-determine-position-id","errorCode":null,"errorMessage":"Order for {} not found to determine position ID","messagePattern":"Order for (.+?) not found to determine position ID","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"crates/execution/src/engine/mod.rs","lineNumber":3296,"sourceCode":"\n        let position_id = match (oms_type, fill.position_id) {\n            (OmsType::Hedging, Some(position_id)) => position_id,\n            (OmsType::Hedging, None) => self.determine_hedging_position_id(fill, order),\n            (OmsType::Netting, _) => self.determine_netting_position_id(fill),\n            _ => self.determine_netting_position_id(fill),\n        };\n\n        if !self.validate_fill_for_position(position_id, fill) {\n            return None;\n        }\n\n        let order = if let Some(o) = order {\n            o.clone()\n        } else {\n            let cache = self.cache.borrow();\n            cache.order(&fill.client_order_id()).map_or_else(\n                || {\n                    panic!(\n                        \"Order for {} not found to determine position ID\",\n                        fill.client_order_id()\n                    )\n                },\n                |o| o.clone(),\n            )\n        };\n\n        if order.exec_algorithm_id().is_some()\n            && let Some(exec_spawn_id) = order.exec_spawn_id()\n        {\n            let cache = self.cache.borrow();\n            let primary = if let Some(p) = cache.order(&exec_spawn_id) {\n                p.clone()\n            } else {\n                log::warn!(\n                    \"Primary exec spawn order {exec_spawn_id} not found, \\\n                     skipping position ID propagation\"","sourceCodeStart":3278,"sourceCodeEnd":3314,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/execution/src/engine/mod.rs#L3278-L3314","documentation":"The execution engine received an order fill event but could not locate the corresponding order in the cache, so it cannot determine the position ID to attribute the fill to. NautilusTrader treats this as an unrecoverable internal inconsistency: a fill can only exist for an order the engine has seen, so it panics rather than silently dropping the fill. This indicates a state synchronization bug between the client/engine and the cache.","triggerScenarios":"Calling the fill-handling path (e.g. via ExecEngineFunctions.handle_fill / process_fill for a Fill or OrderFilled event) with fill.client_order_id() that has no matching order in the cache and no explicit `order` argument passed in.","commonSituations":"Applying a reconciliation fill report for an order that was purged or never stored in the execution cache; running with cache persistence/cleanup that removed the order before the fill arrives; an exec client emitting a fill for an order submitted by a different node instance sharing the same venue.","solutions":["Pass the order explicitly to the fill-handling call so the cache lookup is not needed (the `order: Option<OrderAny>` parameter).","Verify the order was successfully submitted and stored in the cache before the fill event is processed; check that client_order_id values match between client and engine.","Check cache retention/cleanup configuration (e.g. purge settings) so orders are not removed while fills are still in flight.","If this arises during reconciliation, ensure the reconciliation flow creates/updates the local order from the order report before processing the fill report."],"exampleFix":"// before\nengine.process_fill(&fill, None);\n// after\nlet order = cache.borrow().order(&fill.client_order_id());\nengine.process_fill(&fill, order); // pass the cached order explicitly","handlingStrategy":"validation","validationCode":"// Rust\nlet order = cache.borrow().order(&fill.client_order_id());\nif order.is_none() {\n    // skip or request order status before processing the fill\n    return Err(anyhow!(\"order {} not cached; cannot process fill\", fill.client_order_id()));\n}","typeGuard":"fn order_in_cache(cache: &Cache, id: &ClientOrderId) -> Option<OrderAny> {\n    cache.order(id)\n}","tryCatchPattern":null,"preventionTips":["Pass the cached order explicitly into fill-handling calls rather than relying on lookup-by-ID.","Never purge orders from cache while fills may still arrive.","During reconciliation, cache the order report before applying the fill report.","Log and monitor cache misses on client_order_id lookups."],"tags":["rust","cache","execution-engine","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"}