{"record":{"id":"55a3618ad00ce89e","repo":"BoundaryML/baml","slug":"failed-to-convert-timestamp-to-epochmstimestamp","errorCode":null,"errorMessage":"Failed to convert timestamp to EpochMsTimestamp","messagePattern":"Failed to convert timestamp to EpochMsTimestamp","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/tracingv2/publisher/rpc_converters/mod.rs","lineNumber":37,"sourceCode":"    fn type_lookup(&self, name: &str) -> Option<Arc<BamlTypeId>>;\n    fn function_lookup(&self, name: &str) -> Option<Arc<BamlFunctionId>>;\n    fn baml_src_hash(&self) -> Option<String>;\n}\n\npub trait IRRpcState: TypeLookup + BlobStorage {}\n\nimpl<T: TypeLookup + BlobStorage> IRRpcState for T {}\n\npub(crate) trait IntoRpcEvent<'a, RpcOutputType> {\n    fn to_rpc_event(&'a self, lookup: &(impl IRRpcState + ?Sized)) -> RpcOutputType;\n}\n\npub(super) fn to_rpc_event<'a>(\n    event: &'a TraceEventWithMeta,\n    lookup: &(impl IRRpcState + ?Sized),\n) -> baml_rpc::runtime_api::BackendTraceEvent<'a> {\n    let timestamp = baml_rpc::EpochMsTimestamp::try_from(event.timestamp)\n        .expect(\"Failed to convert timestamp to EpochMsTimestamp\");\n\n    // Convert the content to RPC format\n    let mut content = event.content.to_rpc_event(lookup);\n\n    // Extract blobs from the content\n    let blob_cache = lookup.blob_cache();\n    extract_blobs_from_trace_data(&mut content, blob_cache, &event.call_id.to_string());\n\n    baml_rpc::runtime_api::BackendTraceEvent {\n        call_id: event.call_id.clone(),\n        function_event_id: event.function_event_id.clone(),\n        call_stack: event.call_stack.clone(),\n        timestamp,\n        content,\n    }\n}\n\n// Helper function to extract blobs from TraceData","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/tracingv2/publisher/rpc_converters/mod.rs#L19-L55","documentation":"This is a panic message (via .expect) in to_rpc_event when converting a trace event's timestamp into baml_rpc::EpochMsTimestamp fails. EpochMsTimestamp::try_from only fails if the timestamp cannot be represented as epoch milliseconds (e.g. out-of-range datetime), which should be impossible for system-generated timestamps. Hitting it indicates an internal invariant violation — a corrupted or synthetic timestamp in the trace event metadata.","triggerScenarios":"A TraceEventWithMeta carries a timestamp that TryFrom<...> for EpochMsTimestamp rejects — e.g. a negative or absurdly large time value introduced by a mocked clock, corrupted metadata, or a library bug.","commonSituations":"Custom test harnesses injecting fake timestamps, system clock misconfiguration producing invalid times, or a genuine BAML bug during version upgrades of baml_rpc timestamp types.","solutions":["Check system clock sanity (date/timezone) on the machine generating traces.","If using a fake/mock clock, ensure it produces realistic epoch-millisecond values.","Upgrade to the latest BAML version; if reproducible on current versions, file a bug with the failing timestamp value."],"exampleFix":"// before\nlet ts = Utc.timestamp_opt(-100_000_000, 0).unwrap(); // invalid for EpochMsTimestamp\n// after\nlet ts = Utc::now(); // realistic timestamp within epoch-ms range","handlingStrategy":"validation","validationCode":"# sanity-check the clock before running BAML\nimport time; assert 0 < time.time() < 4102444800, \"system clock invalid\"","typeGuard":"fn is_epoch_ms_representable(t: &DateTime<Utc>) -> bool {\n    let ms = t.timestamp_millis();\n    (0..=i64::MAX).contains(&ms) && ms / 1000 < 253_402_300_800\n}","tryCatchPattern":"// to_rpc_event panics via expect; guard at the event-construction boundary\nlet timestamp = EpochMsTimestamp::try_from(event.timestamp)\n    .map_err(|_| anyhow!(\"invalid trace timestamp: {}\", event.timestamp))?;","preventionTips":["Keep system clocks synced (NTP) in CI and containers","Avoid injecting mock timestamps outside epoch-ms range in tests","Upgrade BAML if the panic reproduces on valid timestamps","Treat this as a bug report trigger: capture the timestamp value and file an issue"],"tags":["timestamp","panic","baml","tracing"],"backgroundTag":"internal-invariant-violation","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"}