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(workflows): respect a device that unregisters while a flow waits (#100032)

Daniel Marchukb01d621d2aa5
diff --git a/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.consumer.ts b/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.consumer.ts
index c901be0a761a..34c8237deef9 100644
--- a/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.consumer.ts
+++ b/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.consumer.ts
@@ -1,6 +1,7 @@
import { DateTime } from 'luxon'
import { HogFlow } from '~/cdp/schema/hogflow'
+import { hasPushActions } from '~/cdp/services/hogflows/hogflow-utils'
import { instrumented } from '~/common/tracing/tracing-utils'
import { logger } from '~/common/utils/logger'
import { PluginsServerConfig } from '~/types'
@@ -152,9 +153,13 @@ export class CdpCyclotronWorkerHogFlow extends CdpCyclotronWorker {
const kind =
resolveByRepointedPerson || !hogFlowInvocationState.event.distinct_id ? 'person_id' : 'distinct_id'
+ // 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.
const [person, groups] = await Promise.all([
personIdOrDistinctId
- ? this.personsManager.getCyclotronPerson(hogFlow.team_id, personIdOrDistinctId, kind)
+ ? this.personsManager.getCyclotronPerson(hogFlow.team_id, personIdOrDistinctId, kind, {
+ forceFresh: hasPushActions(hogFlow.actions),
+ })
: undefined,
this.groupsManager.getGroupsForEvent(
hogFlow.team_id,
diff --git a/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.test.ts b/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.test.ts
index 5c77e232af36..8c5746f354df 100644
--- a/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.test.ts
+++ b/nodejs/src/cdp/consumers/cdp-cyclotron-worker-hogflow.test.ts
@@ -471,6 +471,56 @@ describe('CdpCyclotronWorkerHogFlow', () => {
})
})
+ it('reads the person fresh at dequeue when the flow has a push step', async () => {
+ const pushFlow = await insertHogFlow(
+ hub.postgres,
+ new FixtureHogFlowBuilder()
+ .withName('Test Hog Flow with a push')
+ .withTeamId(team.id)
+ .withStatus('active')
+ .withWorkflow({
+ actions: {
+ trigger: { type: 'trigger', config: { type: 'event', filters: {} } },
+ push: {
+ type: 'function_push',
+ config: { template_id: 'template-native-push', inputs: {} } as any,
+ },
+ exit: { type: 'exit', config: {} },
+ },
+ edges: [
+ { from: 'trigger', to: 'push', type: 'continue' },
+ { from: 'push', to: 'exit', type: 'continue' },
+ ],
+ } as any)
+ .build()
+ )
+ const getPerson = jest.spyOn(processor['personsManager'], 'getCyclotronPerson')
+
+ await processor.processInvocations([
+ createSerializedHogFlowInvocation(pushFlow, {
+ event: { distinct_id: 'distinct_A_1', properties: {} } as any,
+ }),
+ ])
+
+ expect(getPerson).toHaveBeenCalledWith(expect.any(Number), 'distinct_A_1', 'distinct_id', {
+ forceFresh: true,
+ })
+ })
+
+ it('keeps the cached read at dequeue when the flow has no push step', async () => {
+ const getPerson = jest.spyOn(processor['personsManager'], 'getCyclotronPerson')
+
+ await processor.processInvocations([
+ createSerializedHogFlowInvocation(hogFlows[0], {
+ event: { distinct_id: 'distinct_A_1', properties: {} } as any,
+ }),
+ ])
+
+ expect(getPerson).toHaveBeenCalledWith(expect.any(Number), 'distinct_A_1', 'distinct_id', {
+ forceFresh: false,
+ })
+ })
+
it('terminates invocations as canceled when the workflow is disabled after being queued', async () => {
const hogFlow = hogFlows[0]
diff --git a/nodejs/src/cdp/services/hogflows/hogflow-utils.ts b/nodejs/src/cdp/services/hogflows/hogflow-utils.ts
index ae83444f87f4..9a4b0fe40cfd 100644
--- a/nodejs/src/cdp/services/hogflows/hogflow-utils.ts
+++ b/nodejs/src/cdp/services/hogflows/hogflow-utils.ts
@@ -217,6 +217,10 @@ export function hasDelayActions(actions: HogFlowAction[]): boolean {
return actions.some((action) => DELAY_ACTION_TYPES.includes(action.type))
}
+export function hasPushActions(actions: HogFlowAction[]): boolean {
+ return actions.some((action) => action.type === 'function_push')
+}
+
const workflowE2eLagMsSummary = new Summary({
name: 'workflow_e2e_lag_ms',
help: 'Time difference in ms between event capture time and workflow finishing time',