BoundaryML/baml · error
Failed to convert timestamp to EpochMsTimestamp
Error message
Failed to convert timestamp to EpochMsTimestamp
What it means
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.
Source
Thrown at engine/baml-runtime/src/tracingv2/publisher/rpc_converters/mod.rs:37
fn type_lookup(&self, name: &str) -> Option<Arc<BamlTypeId>>;
fn function_lookup(&self, name: &str) -> Option<Arc<BamlFunctionId>>;
fn baml_src_hash(&self) -> Option<String>;
}
pub trait IRRpcState: TypeLookup + BlobStorage {}
impl<T: TypeLookup + BlobStorage> IRRpcState for T {}
pub(crate) trait IntoRpcEvent<'a, RpcOutputType> {
fn to_rpc_event(&'a self, lookup: &(impl IRRpcState + ?Sized)) -> RpcOutputType;
}
pub(super) fn to_rpc_event<'a>(
event: &'a TraceEventWithMeta,
lookup: &(impl IRRpcState + ?Sized),
) -> baml_rpc::runtime_api::BackendTraceEvent<'a> {
let timestamp = baml_rpc::EpochMsTimestamp::try_from(event.timestamp)
.expect("Failed to convert timestamp to EpochMsTimestamp");
// Convert the content to RPC format
let mut content = event.content.to_rpc_event(lookup);
// Extract blobs from the content
let blob_cache = lookup.blob_cache();
extract_blobs_from_trace_data(&mut content, blob_cache, &event.call_id.to_string());
baml_rpc::runtime_api::BackendTraceEvent {
call_id: event.call_id.clone(),
function_event_id: event.function_event_id.clone(),
call_stack: event.call_stack.clone(),
timestamp,
content,
}
}
// Helper function to extract blobs from TraceDataView on GitHub (pinned to bd85ce9dee)
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.
Example fix
// before let ts = Utc.timestamp_opt(-100_000_000, 0).unwrap(); // invalid for EpochMsTimestamp // after let ts = Utc::now(); // realistic timestamp within epoch-ms range
Defensive patterns
Strategy: validation
Validate before calling
# sanity-check the clock before running BAML import time; assert 0 < time.time() < 4102444800, "system clock invalid"
Type guard
fn is_epoch_ms_representable(t: &DateTime<Utc>) -> bool {
let ms = t.timestamp_millis();
(0..=i64::MAX).contains(&ms) && ms / 1000 < 253_402_300_800
} Try / catch
// to_rpc_event panics via expect; guard at the event-construction boundary
let timestamp = EpochMsTimestamp::try_from(event.timestamp)
.map_err(|_| anyhow!("invalid trace timestamp: {}", event.timestamp))?; Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- baml.panics.IntegerOverflow
- baml.panics.IndexOutOfBounds
- baml.panics.InvalidFieldAccess
- baml.panics.MapKeyNotFound
- baml.panics.StackOverflow
AI-assisted analysis of BoundaryML/baml@bd85ce9dee (2026-09-12).
Data as JSON: /api/errors/55a3618ad00ce89e.
Report an issue: GitHub.