{"record":{"id":"3467712884f9458e","repo":"nautechsystems/nautilus_trader","slug":"fill-queue-availability-was-checked-before-cache-m","errorCode":null,"errorMessage":"fill queue availability was checked before cache mutation","messagePattern":"fill queue availability was checked before cache mutation","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/live/src/execution/manager.rs","lineNumber":5235,"sourceCode":"                matches!(\n                    event,\n                    OrderEventAny::Canceled(_) | OrderEventAny::Expired(_),\n                )\n            }) {\n                order_events.pop()\n            } else {\n                None\n            };\n\n            if order_events\n                .last()\n                .is_some_and(|event| matches!(event, OrderEventAny::Filled(_)))\n            {\n                order_events.pop();\n            }\n\n            let fill_queue =\n                fill_queue.expect(\"fill queue availability was checked before cache mutation\");\n            for (fill_event, fill_key) in prepared_fills {\n                fill_queue.push(&mut order_events, fill_event, fill_key);\n            }\n\n            if !defer_terminal\n                && let Some(inferred_qty) = inferred_qty\n                && let Some(inferred_fill) = create_inferred_fill_for_qty(\n                    &order,\n                    report,\n                    &account_id,\n                    instrument,\n                    inferred_qty,\n                    ts_now,\n                    inferred_commission,\n                )\n            {\n                order_events.push(inferred_fill);\n            }","sourceCodeStart":5217,"sourceCodeEnd":5253,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/live/src/execution/manager.rs#L5217-L5253","documentation":"While applying order events, the manager unwraps an optional fill queue with `.expect(\"fill queue availability was checked before cache mutation\")`. The surrounding pipeline is supposed to have verified the queue exists before any cache mutation; reaching this line with `fill_queue == None` means that internal invariant was broken. On stock code this should be unreachable and indicates a bug (e.g. in a patched build or an out-of-order event path).","triggerScenarios":"A path where `prepared_fills` is non-empty but the fill-queue lookup returned `None` — e.g. custom modifications that moved the availability check after cache mutation, or an adapter emitting fills for an order whose execution queue was never registered.","commonSituations":"Custom forks/patches of the live execution manager; out-of-order event handling where a fill arrives before queue registration; concurrency bugs mutating the order cache between check and use in modified builds.","solutions":["On stock nautilus, capture the full log/stacktrace and report a bug — this invariant should hold","In custom code, verify the queue-availability check runs before any cache mutation and before `order_events.pop()`","Ensure fills are only emitted for orders registered with the execution manager (correct venue/routing)","Replace the `expect` with an error return including order id and venue context to aid diagnosis in patched builds"],"exampleFix":"// before\nlet fill_queue = fill_queue.expect(\"fill queue availability was checked before cache mutation\");\n// after\nlet fill_queue = fill_queue.ok_or_else(||\n    anyhow::anyhow!(\"fill queue missing for order {} before cache mutation\", client_order_id))?;","handlingStrategy":"try-catch","validationCode":"if fill_queue.is_none() && !prepared_fills.is_empty() {\n    return Err(anyhow::anyhow!(\"fill queue unavailable while fills pending\"));\n}","typeGuard":"fn fill_queue_ready(fq: &Option<FillQueue>, prepared: &[PreparedFill]) -> bool {\n    fq.is_some() || prepared.is_empty()\n}","tryCatchPattern":"let fq = fill_queue.ok_or_else(|| anyhow!(\"fill queue missing before cache mutation\"))?;","preventionTips":["Keep the availability check before any order-cache mutation in patched code","Only route fills to orders registered with the execution manager","On stock builds, treat this panic as a bug: capture logs and report it"],"tags":["panic","invariant","execution-engine"],"backgroundTag":"internal-invariant-violation","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"}