{"record":{"id":"038e79fb84c6fd6f","repo":"nautechsystems/nautilus_trader","slug":"ouo-quantity-overflow-for-order-client-order-id","errorCode":null,"errorMessage":"OUO quantity overflow for order {client_order_id}","messagePattern":"OUO quantity overflow for order (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/execution/src/matching_engine/mod.rs","lineNumber":5526,"sourceCode":"            };\n\n            if sibling.is_closed() || sibling.is_active_local() || !sibling.is_passive() {\n                continue;\n            }\n\n            // Cancellation also covers core orders whose acceptance is not yet acknowledged\n            if leaves.is_zero() {\n                self.cancel_order(&sibling, Some(false));\n                continue;\n            }\n\n            if !sibling.is_open() {\n                continue;\n            }\n\n            let leaves = self.parent_capped_leaves(&sibling, leaves);\n            let target = sibling.filled_qty().checked_add(leaves).ok_or_else(|| {\n                anyhow::anyhow!(\"OUO quantity overflow for order {client_order_id}\")\n            })?;\n\n            if sibling.quantity() != target {\n                self.generate_order_updated(\n                    &sibling,\n                    target,\n                    sibling.price(),\n                    sibling.trigger_price(),\n                    None,\n                );\n            }\n\n            if leaves.is_zero() {\n                self.cancel_order(&sibling, Some(false));\n            }\n        }\n        Ok(())\n    }","sourceCodeStart":5508,"sourceCodeEnd":5544,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/execution/src/matching_engine/mod.rs#L5508-L5544","documentation":"When an OrderUpdated (OUO) event cascades quantity changes to sibling orders (e.g. contingent/OCO legs), the engine caps each sibling's leaves and computes target = sibling.filled_qty + capped leaves with checked addition. Overflow means the sibling's new total quantity is not representable, so the engine raises this error naming the originating client_order_id.","triggerScenarios":"An order-update/replace flow where the parent's new quantity (after capping) is enormous, or sibling filled_qty uses a different precision such that their sum exceeds Decimal capacity during sibling quantity maintenance.","commonSituations":"OCO/bracket setups where a parent order is amended to an unrealistic quantity; custom strategy code calling modify_order with extreme quantities; high-precision instruments amplifying magnitude.","solutions":["Clamp the amended/updated quantity passed to the parent order to a sane, representable range before the update.","Normalize sibling filled_qty and computed leaves to a common precision before addition.","Review the OUO handler at crates/execution/src/matching_engine/mod.rs (~line 5510-5526) and log sibling.filled_qty and leaves to see the overflowing operands.","Fix strategy code that generates extreme quantity updates (e.g. percentage-based sizing on zero/degenerate balances)."],"exampleFix":"// before: amending parent to an extreme quantity cascades to siblings\nengine.modify_order(&order, Some(Quantity::from(u64::MAX)), None)?;\n// after: bound the amendment to representable position sizes\nlet new_qty = new_qty.min(max_representable_qty(instrument));\nengine.modify_order(&order, Some(new_qty), None)?;","handlingStrategy":"validation","validationCode":"// clamp amended quantities so sibling targets cannot overflow\nlet new_qty = requested_qty.min(max_representable_qty);\nlet target = sibling.filled_qty().checked_add(new_qty - sibling.filled_qty());\nassert!(target.is_some(), \"sibling target quantity would overflow\");","typeGuard":null,"tryCatchPattern":"match engine.iteration(&mut command_queue) {\n    Err(e) if e.to_string().starts_with(\"OUO quantity overflow\") => {\n        log::error!(\"{e}; aborting quantity cascade for order\");\n        // cancel the order family and re-issue with bounded quantities\n    }\n    other => other,\n}","preventionTips":["Bound order amendments to realistic position sizes in strategy code.","Keep parent and sibling orders on instruments with the same quantity precision.","Test OCO/bracket amend paths with boundary quantities before production runs."],"tags":["matching-engine","order-updated","decimal-overflow","contingent-orders"],"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-14T05:17:10.506Z"}