:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(personhog): standardize changelog timestamps to epoch milliseconds (#79145)
Zach Brown3a890fea952d
diff --git a/nodejs/src/common/generated/personhog/personhog/types/v1/person_pb.ts b/nodejs/src/common/generated/personhog/personhog/types/v1/person_pb.tsindex d88f213c5b7e..564964890b66 100644--- a/nodejs/src/common/generated/personhog/personhog/types/v1/person_pb.ts+++ b/nodejs/src/common/generated/personhog/personhog/types/v1/person_pb.ts@@ -54,6 +54,8 @@ export type Person = Message<'personhog.types.v1.Person'> & {propertiesLastOperation: Uint8Array/**+ * Epoch milliseconds, as are all timestamps in this message.+ ** @generated from field: int64 created_at = 7;*/createdAt: bigint@@ -74,6 +76,8 @@ export type Person = Message<'personhog.types.v1.Person'> & {isUserId?: boolean/**+ * Epoch milliseconds (matching created_at); the writer decodes it as such.+ ** @generated from field: optional int64 last_seen_at = 11;*/lastSeenAt?: bigintdiff --git a/proto/personhog/types/v1/person.proto b/proto/personhog/types/v1/person.protoindex dea9bb032f4e..987bea24c750 100644--- a/proto/personhog/types/v1/person.proto+++ b/proto/personhog/types/v1/person.proto@@ -11,10 +11,12 @@ message Person {bytes properties = 4;bytes properties_last_updated_at = 5;bytes properties_last_operation = 6;+ // Epoch milliseconds, as are all timestamps in this message.int64 created_at = 7;int64 version = 8;bool is_identified = 9;optional bool is_user_id = 10;+ // Epoch milliseconds (matching created_at); the writer decodes it as such.optional int64 last_seen_at = 11;}diff --git a/rust/personhog-leader/src/pg.rs b/rust/personhog-leader/src/pg.rsindex 1a2d9ec90f4d..5a6b9d282be3 100644--- a/rust/personhog-leader/src/pg.rs+++ b/rust/personhog-leader/src/pg.rs@@ -109,7 +109,7 @@ pub async fn load_person_from_pg(team_id: team_id as i64,approx_bytes: approx_person_bytes(properties_text_len),properties,- created_at: created_at.timestamp(),+ created_at: created_at.timestamp_millis(),version: version.unwrap_or(0),is_identified,}))diff --git a/rust/personhog-leader/src/service.rs b/rust/personhog-leader/src/service.rsindex 66c6ebdb15de..70d580b60098 100644--- a/rust/personhog-leader/src/service.rs+++ b/rust/personhog-leader/src/service.rs@@ -406,9 +406,9 @@ impl PersonHogLeaderService {/// writer's upsert verbatim. Properties are guaranteed by admission/// (NUL sanitization plus the exact size measure); this checks the/// identity fields against the writer's bind conversions — uuid must-/// parse, team_id must fit the column's `integer`, and created_at must-/// sit inside a sanity range ([1970, 9999]) any legitimately created-/// person satisfies.+/// parse, team_id must fit the column's `integer`, and created_at — epoch+/// milliseconds, like every timestamp in the proto — must sit inside a+/// sanity range ([1970, 9999]) any legitimately created person satisfies.////// These three are the only fields that need checking because they are/// the only writer-bound fields representable in `CachedPerson`: the@@ -416,7 +416,7 @@ impl PersonHogLeaderService {/// unconditionally empty in `cached_person_to_proto`, so a leader-produced/// record structurally cannot carry values the writer would refuse there.fn assert_writeable(p: &CachedPerson) -> Result<(), String> {- const MAX_EPOCH_SECS_YEAR_9999: i64 = 253_402_300_799;+ const MAX_EPOCH_MS_YEAR_9999: i64 = 253_402_300_799_999;if Uuid::parse_str(&p.uuid).is_err() {return Err("uuid does not parse as a UUID".to_string());}@@ -426,7 +426,7 @@ fn assert_writeable(p: &CachedPerson) -> Result<(), String> {p.team_id));}- if p.created_at < 0 || p.created_at > MAX_EPOCH_SECS_YEAR_9999 {+ if p.created_at < 0 || p.created_at > MAX_EPOCH_MS_YEAR_9999 {return Err(format!("created_at epoch {} is outside sane bounds",p.created_atdiff --git a/rust/personhog-writer/src/pg.rs b/rust/personhog-writer/src/pg.rsindex 7fc89da60c42..012ea281f74f 100644--- a/rust/personhog-writer/src/pg.rs+++ b/rust/personhog-writer/src/pg.rs@@ -123,13 +123,13 @@ fn push_person<'a>(arrays: &mut PreparedArrays<'a>, p: &'a Person) -> Result<(),.map_err(|e| unbindable("properties_last_updated_at", e))?;let properties_last_operation = bytes_to_optional_json_str(&p.properties_last_operation).map_err(|e| unbindable("properties_last_operation", e))?;- let created_at = epoch_secs_to_datetime(p.created_at)+ let created_at = epoch_ms_to_datetime(p.created_at).ok_or_else(|| unbindable("created_at", format!("epoch {} out of range", p.created_at)))?;let last_seen_at = match p.last_seen_at {None => None,- Some(secs) => Some(- epoch_secs_to_datetime(secs)- .ok_or_else(|| unbindable("last_seen_at", format!("epoch {secs} out of range")))?,+ Some(ms) => Some(+ epoch_ms_to_datetime(ms)+ .ok_or_else(|| unbindable("last_seen_at", format!("epoch {ms} out of range")))?,),};@@ -312,8 +312,8 @@ fn bytes_to_optional_json_str(bytes: &[u8]) -> Result<Option<&str>, String> {.map_err(|e| format!("non-UTF-8 JSON bytes: {e}"))}-fn epoch_secs_to_datetime(epoch_secs: i64) -> Option<DateTime<Utc>> {- Utc.timestamp_opt(epoch_secs, 0).single()+fn epoch_ms_to_datetime(epoch_ms: i64) -> Option<DateTime<Utc>> {+ Utc.timestamp_millis_opt(epoch_ms).single()}#[cfg(test)]@@ -365,10 +365,10 @@ mod tests {}#[test]- fn epoch_secs_conversion() {- let dt = epoch_secs_to_datetime(1700000000).unwrap();- assert_eq!(dt.timestamp(), 1700000000);- assert!(epoch_secs_to_datetime(i64::MAX).is_none());+ fn epoch_ms_conversion() {+ let dt = epoch_ms_to_datetime(1700000000000).unwrap();+ assert_eq!(dt.timestamp_millis(), 1700000000000);+ assert!(epoch_ms_to_datetime(i64::MAX).is_none());}#[tokio::test]