Skip to content

: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.

fix(ingestion): compare shadow checking reads on identity only (#110152)

Zach Brownb36553d643c9
diff --git a/nodejs/src/ingestion/common/persons/routing-persons-store.test.ts b/nodejs/src/ingestion/common/persons/routing-persons-store.test.ts
index 1f9b035e0bab..4c608bedb0e9 100644
--- a/nodejs/src/ingestion/common/persons/routing-persons-store.test.ts
+++ b/nodejs/src/ingestion/common/persons/routing-persons-store.test.ts
@@ -163,6 +163,25 @@ describe('RoutingPersonsStore', () => {
expect(personhogStoreShadowComparedCounter.labels).toHaveBeenCalledWith({ verb: 'fetchForUpdate' })
})
+ it.each([
+ ['empty properties', { properties: {} }, []],
+ ['another person', { uuid: 'other-uuid' }, [{ verb: 'fetchForChecking', field: 'uuid' }]],
+ ])(
+ 'compares a checking read on identity only, given a shadow answer with %s',
+ async (_case, shadowDiff, expected) => {
+ const stores = makeStores()
+ stores.pg.fetchForChecking.mockResolvedValue({ ...person(1, '1'), properties: { plan: 'pro' } })
+ stores.personhogMock.fetchForChecking.mockResolvedValue({ ...person(1, '1'), ...shadowDiff })
+ const store = makeStore(stores, 'shadow')
+
+ await store.fetchForChecking(1, 'd1', 0)
+
+ // personhog answers a checking read from the identity service, without properties.
+ expect(divergences()).toEqual(expected)
+ expect(personhogStoreShadowComparedCounter.labels).toHaveBeenCalledWith({ verb: 'fetchForChecking' })
+ }
+ )
+
it.each([
['a nested object whose keys arrived in another order', { a: 1, b: 2 }, { b: 2, a: 1 }, false],
['an array whose order actually differs', [1, 2], [2, 1], true],
diff --git a/nodejs/src/ingestion/common/persons/routing-persons-store.ts b/nodejs/src/ingestion/common/persons/routing-persons-store.ts
index 9f9bbee3d340..d98d0a3c0a49 100644
--- a/nodejs/src/ingestion/common/persons/routing-persons-store.ts
+++ b/nodejs/src/ingestion/common/persons/routing-persons-store.ts
@@ -233,7 +233,12 @@ export class RoutingPersonsStore implements PersonsStore {
* are not compared because the backends allocate independently; the
* uuid is derived the same way on both.
*/
- private comparePerson(verb: string, authoritative: unknown, shadow: unknown): void {
+ private comparePerson(
+ verb: string,
+ authoritative: unknown,
+ shadow: unknown,
+ compareProperties: boolean = true
+ ): void {
// Absence arrives as null from either backend, and as undefined from
// a caller that answered nothing at all; both mean the same thing
// here and neither may be dereferenced.
@@ -254,7 +259,7 @@ export class RoutingPersonsStore implements PersonsStore {
if (left.is_identified !== right.is_identified) {
this.recordDivergence(verb, 'is_identified')
}
- if (!propertiesMatch(left.properties, right.properties)) {
+ if (compareProperties && !propertiesMatch(left.properties, right.properties)) {
this.recordDivergence(verb, 'properties')
}
}
@@ -293,7 +298,13 @@ export class RoutingPersonsStore implements PersonsStore {
'fetchForChecking',
() => this.pg.fetchForChecking(teamId, distinctId, batchId),
() => this.personhog.fetchForChecking(teamId, distinctId, batchId),
- { compare: (authoritative, shadow) => this.comparePerson('fetchForChecking', authoritative, shadow) }
+ // A checking read resolves identity only: personhog answers it from the identity service without
+ // the leader's document, so its properties are empty unless a projection happens to be cached, and
+ // the personless step never reads them.
+ {
+ compare: (authoritative, shadow) =>
+ this.comparePerson('fetchForChecking', authoritative, shadow, false),
+ }
)
}