{"record":{"id":"4892acacda83da6b","repo":"pydantic/monty","slug":"identity-enum-payload-fits-in-14-bytes","errorCode":null,"errorMessage":"identity enum payload fits in 14 bytes","messagePattern":"identity enum payload fits in 14 bytes","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/monty/src/identity.rs","lineNumber":153,"sourceCode":"            Self::DefFunction(_) => 12,\n            Self::Marker(_) => 14,\n            Self::Property(_) => 15,\n            Self::Heap(_) => 16,\n        }\n    }\n}\n\n/// Returns a prefix-preserving integer for a short byte sequence.\nfn bytes_payload(bytes: &[u8]) -> u128 {\n    bytes\n        .iter()\n        .fold(1, |payload, byte| (payload << u8::BITS) | u128::from(*byte))\n}\n\n/// Serializes a small enum payload into a stack buffer and preserves its length.\nfn fixed_serde_payload(value: &impl Serialize) -> u128 {\n    let mut buffer = [0; MAX_FIXED_BYTES];\n    let serialized = postcard::to_slice(value, &mut buffer).expect(\"identity enum payload fits in 14 bytes\");\n    bytes_payload(serialized)\n}\n\n/// Maps signed integers into `u64` while keeping small magnitudes compact.\nfn zigzag_i64(value: i64) -> u64 {\n    if value >= 0 {\n        value.unsigned_abs() << 1\n    } else {\n        ((value.unsigned_abs() - 1) << 1) | 1\n    }\n}\n\n/// Reorders float fields so common powers of two have compact identities.\nfn compact_float_bits(bits: u64) -> u64 {\n    const MANTISSA_BITS: u8 = 52;\n    const EXPONENT_MASK: u64 = (1 << 11) - 1;\n    const MANTISSA_MASK: u64 = (1 << MANTISSA_BITS) - 1;\n","sourceCodeStart":135,"sourceCodeEnd":171,"githubUrl":"https://github.com/pydantic/monty/blob/adc986b362e3961f407868cb118a99fe831b9e61/crates/monty/src/identity.rs#L135-L171","documentation":"An internal invariant `expect` in `fixed_serde_payload`, which serializes small identity-enum payloads (via postcard) into a fixed 16-byte stack buffer so they can be packed into a `u128`. The assertion states every serialized variant payload fits within `MAX_FIXED_BYTES` (14); the `Identity::bytes_size` mapping in the same file is what keeps variants within that bound. It fires only if a new variant or payload grows past the fixed size — a compile-time-adjacent design invariant, not a runtime condition reachable from Python code.","triggerScenarios":"Thrown at crates/monty/src/identity.rs:153 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["This expect enforces the invariant that every identity enum variant's serialized payload is at most MAX_FIXED_BYTES (14); a new variant larger than that must either shrink its payload or raise MAX_FIXED_BYTES with matching updates to the per-variant size table.","At runtime no recovery exists — the payload cannot be truncated without corrupting id() uniqueness; fix the variant definition instead."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"adc986b362e3961f407868cb118a99fe831b9e61","analyzedAt":"2026-09-13T19:19:18.698Z","contentChangedAt":"2026-09-13T19:19:18.698Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}