{"record":{"id":"7c5565ff80f1e112","repo":"nautechsystems/nautilus_trader","slug":"cannot-replay-order-for-inferred-fill-detection","errorCode":null,"errorMessage":"cannot replay order {} for inferred fill detection: {e}","messagePattern":"cannot replay order (.+?) for inferred fill detection: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/live/src/execution/manager.rs","lineNumber":2921,"sourceCode":"        anyhow::ensure!(\n            !position.is_opposite_side(report.order_side) || report.last_qty <= position.quantity,\n            \"fill {} without a venue position ID would cross position {position_id}\",\n            report.trade_id,\n        );\n\n        report.venue_position_id = Some(position_id);\n        Ok(PositionFillReportPreparation::Ready)\n    }\n\n    #[cfg(feature = \"node\")]\n    fn has_active_inferred_fill(order: &OrderAny) -> anyhow::Result<bool> {\n        let events = order.events();\n        let trade_ids = order.trade_ids();\n        let Some((first, remaining)) = events.split_first() else {\n            return Ok(false);\n        };\n        let mut projected = OrderAny::from_events(vec![(*first).clone()]).map_err(|e| {\n            anyhow::anyhow!(\n                \"cannot replay order {} for inferred fill detection: {e}\",\n                order.client_order_id(),\n            )\n        })?;\n\n        for event in remaining {\n            projected.apply((*event).clone()).map_err(|e| {\n                anyhow::anyhow!(\n                    \"cannot replay order {} for inferred fill detection: {e}\",\n                    order.client_order_id(),\n                )\n            })?;\n            let OrderEventAny::Filled(fill) = event else {\n                continue;\n            };\n\n            if !fill.reconciliation || !trade_ids.contains(&&fill.trade_id) {\n                continue;","sourceCodeStart":2903,"sourceCodeEnd":2939,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/live/src/execution/manager.rs#L2903-L2939","documentation":"For inferred fill detection the manager replays an order's event history: it builds a fresh OrderAny from the first event and applies the rest. If constructing the order from the initial event fails (event order invalid, unsupported event type, corrupted state), the error is wrapped with this message naming the client_order_id.","triggerScenarios":"OrderAny::from_events(first_event) returns Err while running inferred-fill detection on a cached order - e.g. the first event is not a valid initializing event, events were persisted out of order, or an event from an incompatible version cannot rebuild state.","commonSituations":"Cache/event-store containing events written by a different nautilus version; events truncated or reordered by a custom event store; adapter-emitted events that skip required initialization; corrupted Redis/Postgres cache snapshots.","solutions":["Verify the first event for the order is a valid order-initialized event in the event store/cache","Purge the corrupted order's events and re-reconcile the order from the venue","Check for nautilus version mismatches between what wrote the events and the running node","Fix any custom event-store serialization so event order and completeness are preserved"],"exampleFix":"// before (events fetched unsorted)\nlet events = store.load(client_order_id)?;\n// after\nlet mut events = store.load(client_order_id)?;\nevents.sort_by_key(|e| e.ts_init());","handlingStrategy":"try-catch","validationCode":"let events = order.events();\nlet ok = events.first().map_or(true, |e| matches!(e, OrderEventAny::Initialized(_)));","typeGuard":"fn first_event_initializes(events: &[OrderEventAny]) -> bool {\n    matches!(events.first(), Some(OrderEventAny::Initialized(_)))\n}","tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"cannot replay order\") => {\n        // mark order's cache entry corrupt and reconcile from venue\n    }\n    other => other?,\n}","preventionTips":["Store order events atomically and in ts_init order","Keep the nautilus version that reads the event store compatible with the one that wrote it","Never persist adapter events that bypass order initialization"],"tags":["rust","live-execution","event-replay","order-state"],"backgroundTag":"invalid-state-transition","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"}