: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(cohorts): forward no person payload for personless events (#106414)
Matheus Batistadd9cec52cd39
diff --git a/rust/cohort-event-shuffler/src/consumer.rs b/rust/cohort-event-shuffler/src/consumer.rsindex cd69f5a59694..1ec6c99852bf 100644--- a/rust/cohort-event-shuffler/src/consumer.rs+++ b/rust/cohort-event-shuffler/src/consumer.rs@@ -24,16 +24,16 @@ use serde::{de::IgnoredAny, Deserialize};use tokio::task::JoinError;use tracing::{debug, error, info, warn};-use crate::event::CohortStreamEvent;+use crate::event::{personless_mode, CohortStreamEvent};use crate::filter_team_index::TeamIndex;use crate::ledger::{DeliveryOutcome, Ledger, NextOffset, Observation, Resolution, SourceOffset, SourcePartition,};use crate::observability::metrics::{COMMITS, COMMIT_ERRORS, EVENTS_ABANDONED, EVENTS_CONSUMED, EVENTS_DROPPED_NO_PERSON_ID,- EVENTS_FORWARDED, EVENTS_SKIPPED_TEAM_GATE, EVENTS_UNPARSEABLE, FORWARDS_ENQUEUED,- FORWARDS_INFLIGHT, LEDGER_PARTITIONS, PRODUCE_ACK_SECONDS, PRODUCE_ERRORS, PRODUCE_QUEUE_FULL,- UNCOMMITTED_EVENTS,+ EVENTS_FORWARDED, EVENTS_PERSON_PAYLOAD_DROPPED, EVENTS_SKIPPED_TEAM_GATE, EVENTS_UNPARSEABLE,+ FORWARDS_ENQUEUED, FORWARDS_INFLIGHT, LEDGER_PARTITIONS, PRODUCE_ACK_SECONDS, PRODUCE_ERRORS,+ PRODUCE_QUEUE_FULL, UNCOMMITTED_EVENTS,};use crate::producer::{CohortStreamProducer, EnqueueError};@@ -359,6 +359,9 @@ impl EventShuffler {}};+ if let Some(person_mode) = personless_mode(event.person_mode) {+ counter!(EVENTS_PERSON_PAYLOAD_DROPPED, "person_mode" => person_mode).increment(1);+ }let forward = Box::new(PendingForward {event: CohortStreamEvent::from_clickhouse(*event,diff --git a/rust/cohort-event-shuffler/src/event.rs b/rust/cohort-event-shuffler/src/event.rsindex 8385a1be8143..c850719abecf 100644--- a/rust/cohort-event-shuffler/src/event.rs+++ b/rust/cohort-event-shuffler/src/event.rs@@ -1,9 +1,10 @@//! The `cohort_stream_events` envelope and the canonical re-key derivation.//!//! Forwards only the fields the downstream bytecode evaluation needs; group properties,-//! `person_mode`, `created_at`, `project_id` and similar are intentionally dropped.+//! `created_at`, `project_id` and similar are intentionally dropped. `person_mode` is consumed, not+//! forwarded: it decides whether `person_properties` is the person's properties or a placeholder.-use common_types::ClickHouseEvent;+use common_types::{ClickHouseEvent, PersonMode};use serde::{Deserialize, Serialize};/// Single source of truth for the re-key string. Every producer targeting a topic co-partitioned@@ -32,9 +33,23 @@ pub struct CohortStreamEvent {pub source_partition: i32,}+/// The label of a `person_mode` under which ingestion processed the event without a person profile.+/// Such an event carries the real `person_id` but `{}` as `person_properties`, and the processor+/// cannot tell that placeholder from a person who has no properties. `None` for `full`, the only+/// mode under which ingestion attaches the person's properties to the event.+pub(crate) fn personless_mode(mode: PersonMode) -> Option<&'static str> {+ match mode {+ PersonMode::Full => None,+ PersonMode::Propertyless => Some("propertyless"),+ PersonMode::ForceUpgrade => Some("force_upgrade"),+ }+}+impl CohortStreamEvent {/// Moves every owned field out of `event` rather than cloning; `person_id` is extracted- /// upstream and passed in separately.+ /// upstream and passed in separately. A personless event forwards `person_properties` as null,+ /// so the processor leaves the person's record alone and still counts the event for behavioral+ /// conditions.pub fn from_clickhouse(event: ClickHouseEvent,person_id: String,@@ -49,7 +64,9 @@ impl CohortStreamEvent {event: event.event,timestamp: event.timestamp,properties: event.properties,- person_properties: event.person_properties,+ person_properties: event+ .person_properties+ .filter(|_| personless_mode(event.person_mode).is_none()),elements_chain: event.elements_chain,source_offset,source_partition,@@ -63,7 +80,6 @@ impl CohortStreamEvent {#[cfg(test)]pub(crate) fn sample_clickhouse_event(team_id: i32, person_id: Option<&str>) -> ClickHouseEvent {- use common_types::PersonMode;use uuid::Uuid;ClickHouseEvent {@@ -160,6 +176,35 @@ mod tests {assert!(envelope.elements_chain.is_none());}+ #[test]+ fn from_clickhouse_forwards_a_person_payload_only_for_a_full_event() {+ let envelope = |person_mode| {+ let event = ClickHouseEvent {+ person_mode,+ person_properties: Some("{}".to_string()),+ ..sample_event(2, Some("p"))+ };+ CohortStreamEvent::from_clickhouse(event, "p".to_string(), 0, 0)+ };++ let full = envelope(PersonMode::Full);+ assert_eq!(+ full.person_properties.as_deref(),+ Some("{}"),+ "a full event with no person properties still describes the person"+ );+ for mode in [PersonMode::Propertyless, PersonMode::ForceUpgrade] {+ assert_eq!(+ envelope(mode),+ CohortStreamEvent {+ person_properties: None,+ ..full.clone()+ },+ "a {mode:?} event drops only its person payload"+ );+ }+ }+#[test]fn envelope_partition_key_matches_free_function() {let event = sample_event(99, Some("xyz"));diff --git a/rust/cohort-event-shuffler/src/observability/metrics.rs b/rust/cohort-event-shuffler/src/observability/metrics.rsindex 784c030c4ec1..e8ad5819d338 100644--- a/rust/cohort-event-shuffler/src/observability/metrics.rs+++ b/rust/cohort-event-shuffler/src/observability/metrics.rs@@ -13,6 +13,9 @@ pub const EVENTS_DROPPED_NO_PERSON_ID: &str = "shuffler_events_dropped_no_personpub const EVENTS_SKIPPED_TEAM_GATE: &str = "shuffler_events_skipped_team_gate_total";/// Serde failure at either gate or survivor parse; the event settles and is committed over.pub const EVENTS_UNPARSEABLE: &str = "shuffler_events_unparseable_total";+/// Survivors taken in with `person_properties` replaced by null, because ingestion processed them+/// without a person profile; label `person_mode` = `"propertyless"` | `"force_upgrade"`.+pub const EVENTS_PERSON_PAYLOAD_DROPPED: &str = "shuffler_events_person_payload_dropped_total";/// Delivery failures + fatal enqueue errors.pub const PRODUCE_ERRORS: &str = "shuffler_produce_errors_total";pub const ACTIVE_TEAMS: &str = "shuffler_active_teams";diff --git a/rust/cohort-stream-processor/tests/person_record_fold.rs b/rust/cohort-stream-processor/tests/person_record_fold.rsindex 2c62ff13b653..d776c36016ca 100644--- a/rust/cohort-stream-processor/tests/person_record_fold.rs+++ b/rust/cohort-stream-processor/tests/person_record_fold.rs@@ -154,6 +154,45 @@ fn row0_inactive_person_side_neither_reads_nor_writes_the_record() {assert!(record(&store, alice).is_none(), "row 0 writes no record");}+#[test]+fn row0_null_payload_keeps_the_record_so_an_older_full_event_still_evaluates() {+ let (_dir, store) = temp_store();+ let f = filters(vec![email_leaf(), plan_leaf()]);+ let alice = person(1);++ feed(+ &store,+ &f,+ &event(alice, PRO, 0, "2026-05-26 10:00:00.000000"),+ );+ let before = record(&store, alice).unwrap();++ // The shuffler forwards an event that ingestion processed without a person profile with a null+ // payload. It carries no person state, so its newer timestamp must not advance the stamp.+ let personless = CohortStreamEvent {+ person_properties: None,+ ..event(alice, PRO, 1, "2026-05-26 11:00:00.000000")+ };+ let out = feed(&store, &f, &personless);+ assert!(out.transitions.is_empty(), "a null payload flips nothing");+ assert_eq!(+ record(&store, alice).unwrap(),+ before,+ "a null payload leaves the record byte-identical"+ );++ let out = feed(+ &store,+ &f,+ &event(alice, FREE, 2, "2026-05-26 10:30:00.000000"),+ );+ assert_eq!(+ sorted(&out.transitions),+ vec![(PLAN_HASH, TransitionKind::Left)],+ "a full event older than the personless one is not stale"+ );+}+#[test]fn row4b_first_eval_enters_true_conditions_and_writes_the_record() {let (_dir, store) = temp_store();diff --git a/rust/cohort-stream-processor/tests/stage1_worker.rs b/rust/cohort-stream-processor/tests/stage1_worker.rsindex 1926b50df108..3a38631c2d16 100644--- a/rust/cohort-stream-processor/tests/stage1_worker.rs+++ b/rust/cohort-stream-processor/tests/stage1_worker.rs@@ -1106,34 +1106,37 @@ fn empty_person_properties_does_not_skip_a_behavioral_match() {cohort(vec![behavioral_leaf(7), person_leaf()]),)]);let behavioral_lsk = filters.by_condition_to_lsk[&BEHAVIORAL_HASH][0];- let alice = person(1);// Empty-string person_properties is JS-falsy: Node skips the person path but still runs the- // behavioral one, so it must not skip the whole event and drop the behavioral match.- let ev = CohortStreamEvent {- person_properties: Some(String::new()),- ..event(alice, 1, 0)- };- let out = process_event(PARTITION_ID, &store, &filters, &ev).unwrap();+ // behavioral one, so it must not skip the whole event and drop the behavioral match. The shuffler+ // forwards null for an event ingested without a person profile, and that event counts the same.+ for (n, payload) in [(1, None), (2, Some(String::new()))] {+ let who = person(n);+ let ev = CohortStreamEvent {+ person_properties: payload,+ ..event(who, 1, 0)+ };+ let out = process_event(PARTITION_ID, &store, &filters, &ev).unwrap();- assert_eq!(- out.skipped, None,- "empty person_properties is not a whole-event skip"- );- assert_eq!(out.transitions.len(), 1);- assert_eq!(out.transitions[0].kind, TransitionKind::Entered);- assert_eq!(- transition_kind(&filters, &out.transitions[0]),- "behavioral_entered"- );- assert!(- state_at(&store, behavioral_lsk, alice).is_some(),- "behavioral row written"- );- assert!(- person_record_at(&store, alice).is_none(),- "empty person_properties → person path inactive, no record",- );+ assert_eq!(+ out.skipped, None,+ "empty person_properties is not a whole-event skip"+ );+ assert_eq!(out.transitions.len(), 1);+ assert_eq!(out.transitions[0].kind, TransitionKind::Entered);+ assert_eq!(+ transition_kind(&filters, &out.transitions[0]),+ "behavioral_entered"+ );+ assert!(+ state_at(&store, behavioral_lsk, who).is_some(),+ "behavioral row written"+ );+ assert!(+ person_record_at(&store, who).is_none(),+ "empty person_properties → person path inactive, no record",+ );+ }}#[test]