{"record":{"id":"709b4ddb49d05e29","repo":"nautechsystems/nautilus_trader","slug":"mbo-delta-index-overflow","errorCode":null,"errorMessage":"MBO delta index overflow","messagePattern":"MBO delta index overflow","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/adapters/databento/src/decode/market_data.rs","lineNumber":250,"sourceCode":"    queue: VecDeque<QueuedMboDelta>,\n    tail: Option<(InstrumentId, u64)>,\n    tails: AHashMap<InstrumentId, u64>,\n    head: u64,\n    next: u64,\n}\n\nimpl MboDeltaBuffer {\n    pub(crate) fn push(\n        &mut self,\n        msg: &dbn::MboMsg,\n        instrument_id: InstrumentId,\n        delta: Option<OrderBookDelta>,\n    ) {\n        if let Some(delta) = delta {\n            self.release(instrument_id, 0);\n\n            let index = self.next;\n            self.next = self.next.checked_add(1).expect(\"MBO delta index overflow\");\n            let ready = msg.flags.is_last();\n            self.queue.push_back(QueuedMboDelta { delta, ready });\n\n            if !ready\n                && let Some((tail_instrument_id, tail)) = self.tail.replace((instrument_id, index))\n            {\n                self.tails.insert(tail_instrument_id, tail);\n            }\n        } else if msg.flags.is_last() {\n            self.release(instrument_id, dbn::flags::LAST);\n        }\n    }\n\n    pub(crate) fn pop_ready(&mut self) -> Option<OrderBookDelta> {\n        if !self.queue.front().is_some_and(|queued| queued.ready) {\n            return None;\n        }\n","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/adapters/databento/src/decode/market_data.rs#L232-L268","documentation":"This panic comes from the MBO (market-by-order) delta buffer in the Databento decoder. Each buffered delta gets a monotonically increasing u64 index via `checked_add`; the `.expect` fires if that counter would wrap past u64::MAX, which would silently corrupt delta ordering. The library throws it as a hard invariant because delta sequence integrity is essential for correct order-book reconstruction.","triggerScenarios":"Pushing more than u64::MAX deltas through a single long-lived `MboDeltaBuffer` instance without ever resetting it — i.e. after 2^64 `push` calls on the same stream state.","commonSituations":"In practice only reachable in extremely long-running live feeds, a leaked/never-dropped buffer reused across many sessions, or a bug elsewhere that repeatedly re-creates decoding state while sharing the buffer. It is effectively unreachable in normal use.","solutions":["Restart the data feed / drop and recreate the decoder so the buffer's `next` counter resets.","Audit for a buffer instance being kept alive far longer than one subscription session and recreate it per session.","If legitimately near the limit, switch the counter type to u128 in the buffer implementation."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Recreate the decoder/buffer per subscription session instead of reusing one across sessions.","Treat this panic as a bug report trigger: capture instrument_id and message count if it ever fires."],"tags":["rust","panic","overflow","market-data"],"backgroundTag":"value-out-of-range","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"}