: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(workflows): read the person fresh when a matched event wakes a wait (#105089)
Daniel Marchuk533488dd2102
diff --git a/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.consumer.ts b/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.consumer.tsindex 34c8237deef9..edcac442d0a8 100644--- a/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.consumer.ts+++ b/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.consumer.ts@@ -155,10 +155,14 @@ export class CdpCyclotronWorkerHogFlow extends CdpCyclotronWorker {// A push cannot be recalled, and the cached person can predate a device that// unregistered since the last read, so a flow that sends push bypasses the cache here.+ // A wait woken by a match advances without re-evaluating, so the steps after it would+ // otherwise read the person cached when the wait parked, without the write that woke it.+ const forceFreshPerson =+ hasPushActions(hogFlow.actions) || hogFlowInvocationState.currentAction?.eventMatched === trueconst [person, groups] = await Promise.all([personIdOrDistinctId? this.personsManager.getCyclotronPerson(hogFlow.team_id, personIdOrDistinctId, kind, {- forceFresh: hasPushActions(hogFlow.actions),+ forceFresh: forceFreshPerson,}): undefined,this.groupsManager.getGroupsForEvent(diff --git a/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.test.ts b/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.test.tsindex 8c5746f354df..670df3c4e068 100644--- a/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.test.ts+++ b/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.test.ts@@ -507,6 +507,39 @@ describe('CdpCyclotronWorkerHogFlow', () => {})})+ it('reads the person fresh at dequeue when a matched event woke the wait', async () => {+ const event = { distinct_id: 'distinct_A_1', properties: {} } as any+ await processor.processInvocations([createSerializedHogFlowInvocation(hogFlows[2], { event })])++ const personRepository = processor['personsManager'][+ 'personRepository'+ ] as jest.Mocked<PersonReadRepository>+ personRepository.fetchPersonsByDistinctIds.mockResolvedValueOnce([+ {+ ...toInternalPerson({+ id: '1',+ uuid: 'dd3d6f80-60ad-45c3-bd61-e2300f2ba7e1',+ teamId: team.id,+ distinctId: 'distinct_A_1',+ properties: { name: 'Person A 1', email: '[email protected]' },+ }),+ distinct_id: 'distinct_A_1',+ },+ ])++ const results = (await processor.processInvocations([+ createSerializedHogFlowInvocation(hogFlows[2], {+ event,+ currentAction: { id: 'wait', startedAtTimestamp: Date.now(), eventMatched: true },+ }),+ ])) as CyclotronJobInvocationResult<CyclotronJobInvocationHogFlow>[]++ expect(results[0].invocation.person?.properties).toEqual({+ name: 'Person A 1',+ email: '[email protected]',+ })+ })+it('keeps the cached read at dequeue when the flow has no push step', async () => {const getPerson = jest.spyOn(processor['personsManager'], 'getCyclotronPerson')