{"record":{"id":"6f77bda36bb1d797","repo":"BoundaryML/baml","slug":"combined-normal-and-reserved-capacity-overflowed-usize","errorCode":null,"errorMessage":"combined normal and reserved capacity overflowed usize","messagePattern":"combined normal and reserved capacity overflowed usize","errorType":"validation","errorClass":"LimitsError","httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_lsp_server/src/lsp_ingress.rs","lineNumber":266,"sourceCode":"            read_bytes: 2 * 1024 * 1024,\n            control_items: 64,\n            control_bytes: 64 * 1024,\n            outbound_response_items: 256,\n            outbound_response_bytes: 4 * 1024 * 1024,\n            response_reservation_bytes: 16 * 1024,\n        }\n    }\n}\n\n#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]\npub enum LimitsError {\n    #[error(\"all ingress capacities and the response reservation must be non-zero\")]\n    ZeroCapacity,\n    #[error(\"read capacity must fit inside normal capacity\")]\n    ReadExceedsNormal,\n    #[error(\"one response reservation must fit in the outbound byte capacity\")]\n    ResponseReservationTooLarge,\n    #[error(\"combined normal and reserved capacity overflowed usize\")]\n    CapacityOverflow,\n}\n\nimpl IngressLimits {\n    fn validate(self) -> Result<Self, LimitsError> {\n        if self.normal_items == 0\n            || self.normal_bytes == 0\n            || self.reserved_items == 0\n            || self.reserved_bytes == 0\n            || self.read_items == 0\n            || self.read_bytes == 0\n            || self.control_items == 0\n            || self.control_bytes == 0\n            || self.outbound_response_items == 0\n            || self.outbound_response_bytes == 0\n            || self.response_reservation_bytes == 0\n        {\n            return Err(LimitsError::ZeroCapacity);","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_lsp_server/src/lsp_ingress.rs#L248-L284","documentation":"`LimitsError::CapacityOverflow`. Adding the reserved byte capacity to the normal outbound byte capacity overflowed `usize`. The combined capacity is computed during validation and must fit in the platform's addressable integer range.","triggerScenarios":"Constructing `IngressLimits` with very large normal and reserved byte capacities whose sum exceeds `usize::MAX` (e.g. values parsed from user config near u64 max on 64-bit), then validating.","commonSituations":"Misconfigured 'huge' limits (e.g. u64::MAX from an env var) that overflow when combined; computing capacities via multiplication (n_items * max_msg) that wrapped before validation.","solutions":["Use realistic finite capacity values whose sum fits in usize","Sanity-check and clamp configured limits to sane maximums before constructing","Use checked arithmetic (checked_mul/checked_add) when deriving capacities from products","Log the offending values; validate at startup to fail fast with this clear message"],"exampleFix":"// before: unbounded config value flows into limits\nlet normal = env_or(\"OUTBOUND_BYTES\", usize::MAX);\nlet limits = IngressLimits::new(items, normal, read, reservation, normal)?;\n\n// after: clamp before constructing\nlet normal = env_or(\"OUTBOUND_BYTES\", 64 << 20).min(1 << 40);\nlet limits = IngressLimits::new(items, normal, read, reservation.min(normal), normal)?;","handlingStrategy":"validation","validationCode":"fn sums_fit(normal: usize, reserved: usize) -> bool { normal.checked_add(reserved).is_some() }","typeGuard":null,"tryCatchPattern":"let normal = normal.min(SANE_MAX);\nlet reserved = reserved.min(SANE_MAX - normal);\nlet limits = IngressLimits::new(items, normal, read, reserved.min(normal), normal + reserved)?;","preventionTips":["Clamp config/env-provided capacities to sane maxima","Use checked_mul/checked_add when deriving capacities from products","Treat u64::MAX-style sentinels from config as errors, not values"],"tags":["lsp","rust","validation","overflow"],"backgroundTag":"value-out-of-range","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}