{"record":{"id":"0c83e57693d7b09f","repo":"nautechsystems/nautilus_trader","slug":"seconds-timestamp-should-fit-i64-0c83e5","errorCode":null,"errorMessage":"seconds timestamp should fit i64","messagePattern":"seconds timestamp should fit i64","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/common/src/generators/position_id.rs","lineNumber":133,"sourceCode":"    }\n\n    #[inline]\n    fn refresh_fixed_prefix(&mut self, timestamp_ms: u64) {\n        let epoch_second = timestamp_ms / 1_000;\n        if epoch_second == self.epoch_second {\n            return;\n        }\n\n        write_fixed_prefix(&mut self.buf, &self.trader_tag, epoch_second);\n        self.fixed_prefix_len = self.buf.len();\n        self.epoch_second = epoch_second;\n    }\n}\n\nfn write_fixed_prefix(buf: &mut String, trader_tag: &str, epoch_second: u64) {\n    let now_utc = Offset::UTC.to_datetime(\n        Timestamp::from_second(\n            i64::try_from(epoch_second).expect(\"seconds timestamp should fit i64\"),\n        )\n        .expect(\"seconds timestamp should be within valid range\"),\n    );\n\n    buf.clear();\n\n    write!(\n        buf,\n        \"P-{:04}{:02}{:02}-{:02}{:02}{:02}-{trader_tag}-\",\n        now_utc.year(),\n        now_utc.month(),\n        now_utc.day(),\n        now_utc.hour(),\n        now_utc.minute(),\n        now_utc.second(),\n    )\n    .expect(\"writing to String should not fail\");\n}","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/nautechsystems/nautilus_trader/blob/18893faf8b356be3320add8de2f861b0b647cf06/crates/common/src/generators/position_id.rs#L115-L151","documentation":"This panic comes from `i64::try_from(epoch_second).expect(\"seconds timestamp should fit i64\")` inside `write_fixed_prefix` in crates/common/src/generators/position_id.rs. The function builds the fixed date-time prefix for generated PositionId values and needs to hand the epoch seconds to jiff's `Timestamp::from_second`, which takes i64. An epoch_second value that cannot fit in an i64 is treated as an invariant violation and panics.","triggerScenarios":"Calling `refresh_fixed_prefix` for the PositionIdGenerator with an `epoch_second: u64` larger than i64::MAX. Ordinary Unix time can never reach this; only synthetic/overflow values trigger it.","commonSituations":"Fuzz or property tests supplying u64::MAX, an overflowing or uninitialized nanos-to-secs conversion feeding the generator, or corrupt clock state in a test harness.","solutions":["Feed the generator real wall-clock epoch seconds instead of synthetic u64 values","Validate/clamp the u64 upstream: reject values exceeding i64::MAX as u64","Fix test fixtures to use realistic epoch seconds"],"exampleFix":"// before\nlet bad_epoch: u64 = u64::MAX;\ngenerator.refresh_fixed_prefix(bad_epoch);\n// after\nlet epoch: u64 = current_unix_seconds();\nassert!(epoch <= i64::MAX as u64);\ngenerator.refresh_fixed_prefix(epoch);","handlingStrategy":"validation","validationCode":"fn valid_epoch_seconds(secs: u64) -> bool { secs <= i64::MAX as u64 }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the real clock as the source of epoch seconds","Validate u64-to-i64 conversions at the boundary"],"tags":["rust","panic","timestamp","integer-conversion"],"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"}