: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(cdp): Empty property condition no longer fires a wait step immediately (#62747)
Daniel Marchuka588b23b60c1
diff --git a/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.test.ts b/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.test.tsindex 7543b10fb483..6b8e57b62310 100644--- a/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.test.ts+++ b/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.test.ts@@ -626,6 +626,67 @@ describe('CdpHogflowSubscriptionMatcherConsumer', () => {expect(update).toBeUndefined()})+ it('does not wake on an empty property condition (always-true bytecode)', async () => {+ // A condition with no properties compiles to always-true bytecode and would otherwise+ // wake the job on any incoming event, bypassing the events the wait is configured for.+ matcher.findRows = [+ {+ id: 'job-1',+ team_id: 1,+ function_id: 'flow-1',+ action_id: 'wait_node',+ distinct_id: 'user-1',+ person_id: null,+ },+ ]+ matcher.wakeRows = [{ ...matcher.findRows[0], state: stateBuffer({ currentAction: { id: 'wait_node' } }) }]+ matcher.updateRowCount = 1+ matcher.setHogFlows({+ 'flow-1': makeHogFlow({+ id: 'flow-1',+ actions: [+ {+ id: 'trigger_node',+ name: 'Trigger',+ type: 'trigger',+ config: { type: 'event', filters: {} },+ },+ {+ id: 'wait_node',+ name: 'Wait',+ type: 'wait_until_condition',+ config: {+ events: [+ {+ filters: {+ bytecode: eventBytecode('wuc_subscribed'),+ events: [+ {+ id: 'wuc_subscribed',+ name: 'wuc_subscribed',+ type: 'events',+ order: 0,+ },+ ],+ },+ },+ ],+ // Empty property condition: bytecode is TRUE (op 29), no properties.+ condition: { filters: { bytecode: ['_H', 1, 29], properties: [] } },+ max_wait_duration: '5m',+ },+ },+ { id: 'exit_node', name: 'Exit', type: 'exit', config: {} },+ ],+ } as any),+ })++ await matcher.runWake([makeGlobals({ event: { ...makeGlobals({}).event, event: 'unrelated_event' } })])++ const update = matcher.calls.find((c) => c.sql.startsWith('UPDATE cyclotron_jobs'))+ expect(update).toBeUndefined()+ })+it('skips candidates whose hogflow is not in cache', async () => {matcher.findRows = [{@@ -868,4 +929,190 @@ describe('CdpHogflowSubscriptionMatcherConsumer', () => {expect(getTeam).toHaveBeenCalledWith(1)})})++ // The full combination matrix lives here (mocked pg, ~ms each) rather than in the E2E suite:+ // it exercises the same wake decision the matcher makes for every events/property/action shape.+ describe('wake matrix: events / property / action combinations', () => {+ const ALWAYS_TRUE = ['_H', 1, 29]+ // Real, serializer-compiled bytecode for event.properties.plan == 'growth'.+ const PROPERTY_BYTECODE = ['_H', 1, 32, 'growth', 32, 'plan', 32, 'properties', 1, 2, 11]++ const eventEntry = { filters: { bytecode: eventBytecode('wakeup_event'), events: [{ id: 'wakeup_event' }] } }+ const actionEntry = {+ filters: { bytecode: eventBytecode('action_event'), events: [], actions: [{ id: 3, type: 'actions' }] },+ }+ const emptyEventEntry = { filters: { bytecode: ALWAYS_TRUE, events: [] } }+ const propertyCondition = {+ filters: {+ bytecode: PROPERTY_BYTECODE,+ properties: [{ key: 'plan', type: 'event', value: 'growth', operator: 'exact' }],+ },+ }+ const emptyCondition = { filters: { bytecode: ALWAYS_TRUE, properties: [] } }+ // A real condition expressed through an events-shaped filter (no top-level `properties`).+ // Guards the regression where the guard keyed on `properties` and skipped this as "empty".+ const eventShapedCondition = {+ filters: { bytecode: eventBytecode('special_event'), events: [{ id: 'special_event' }] },+ }++ const wakeWith = (event: string, properties: Record<string, any> = {}): HogFunctionInvocationGlobals =>+ makeGlobals({ event: { ...makeGlobals({}).event, event, properties } })+ const matchingEvent = (): HogFunctionInvocationGlobals => wakeWith('wakeup_event')+ const actionEvent = (): HogFunctionInvocationGlobals => wakeWith('action_event')+ const propertyEvent = (): HogFunctionInvocationGlobals => wakeWith('some_event', { plan: 'growth' })+ const unrelatedEvent = (): HogFunctionInvocationGlobals => wakeWith('unrelated_event', { plan: 'starter' })++ interface WakeCase {+ name: string+ config: Record<string, any>+ event: () => HogFunctionInvocationGlobals+ woken: boolean+ }++ const cases: WakeCase[] = [+ // ---- real combinations that SHOULD wake ----+ {+ name: 'event only + matching event',+ config: { events: [eventEntry] },+ event: matchingEvent,+ woken: true,+ },+ {+ name: 'property only + satisfying event',+ config: { condition: propertyCondition },+ event: propertyEvent,+ woken: true,+ },+ {+ name: 'event + property + matching event',+ config: { events: [eventEntry], condition: propertyCondition },+ event: matchingEvent,+ woken: true,+ },+ {+ name: 'event + property + satisfying event',+ config: { events: [eventEntry], condition: propertyCondition },+ event: propertyEvent,+ woken: true,+ },+ {+ name: 'action only + action event',+ config: { events: [actionEntry] },+ event: actionEvent,+ woken: true,+ },+ {+ name: 'action + property + action event',+ config: { events: [actionEntry], condition: propertyCondition },+ event: actionEvent,+ woken: true,+ },+ {+ name: 'action + property + satisfying event',+ config: { events: [actionEntry], condition: propertyCondition },+ event: propertyEvent,+ woken: true,+ },+ {+ name: 'event + empty property (suppressed) + matching event',+ config: { events: [eventEntry], condition: emptyCondition },+ event: matchingEvent,+ woken: true,+ },+ {+ name: 'empty events (suppressed) + property + satisfying event',+ config: { events: [emptyEventEntry], condition: propertyCondition },+ event: propertyEvent,+ woken: true,+ },+ {+ name: 'condition via events shape (no properties) + matching event',+ config: { condition: eventShapedCondition },+ event: () => wakeWith('special_event'),+ woken: true,+ },+ // ---- combinations that must NOT wake ----+ {+ name: 'event only + unrelated event',+ config: { events: [eventEntry] },+ event: unrelatedEvent,+ woken: false,+ },+ {+ name: 'property only + unrelated event',+ config: { condition: propertyCondition },+ event: unrelatedEvent,+ woken: false,+ },+ {+ name: 'event + property + unrelated event',+ config: { events: [eventEntry], condition: propertyCondition },+ event: unrelatedEvent,+ woken: false,+ },+ {+ name: 'empty property only + unrelated event',+ config: { condition: emptyCondition },+ event: unrelatedEvent,+ woken: false,+ },+ {+ name: 'empty events only + unrelated event',+ config: { events: [emptyEventEntry] },+ event: unrelatedEvent,+ woken: false,+ },+ {+ name: 'empty events + empty property + unrelated event',+ config: { events: [emptyEventEntry], condition: emptyCondition },+ event: unrelatedEvent,+ woken: false,+ },+ ]++ it.each(cases)('$name -> woken: $woken', async ({ config, event, woken }) => {+ matcher.findRows = [+ {+ id: 'job-1',+ team_id: 1,+ function_id: 'flow-1',+ action_id: 'wait_node',+ distinct_id: 'user-1',+ person_id: null,+ },+ ]+ // Wire the wake path so that IF the job is woken, an UPDATE is produced.+ matcher.wakeRows = [{ ...matcher.findRows[0], state: stateBuffer({ currentAction: { id: 'wait_node' } }) }]+ matcher.updateRowCount = 1+ matcher.setHogFlows({+ 'flow-1': makeHogFlow({+ id: 'flow-1',+ actions: [+ {+ id: 'trigger_node',+ name: 'Trigger',+ type: 'trigger',+ config: { type: 'event', filters: {} },+ },+ {+ id: 'wait_node',+ name: 'Wait',+ type: 'wait_until_condition',+ config: { max_wait_duration: '5m', ...config },+ },+ { id: 'exit_node', name: 'Exit', type: 'exit', config: {} },+ ],+ } as any),+ })++ await matcher.runWake([event()])++ const update = matcher.calls.find((c) => c.sql.startsWith('UPDATE cyclotron_jobs'))+ if (woken) {+ expect(update).toBeDefined()+ } else {+ expect(update).toBeUndefined()+ }+ })+ })})diff --git a/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.ts b/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.tsindex 4c5fe93c3330..50365ef2e2fa 100644--- a/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.ts+++ b/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.ts@@ -11,6 +11,7 @@ import { HealthCheckResult, PluginsServerConfig, RawClickHouseEvent } from '../.import { parseJSON } from '../../utils/json-parse'import { logger } from '../../utils/logger'import { captureException } from '../../utils/posthog'+import { isEvaluableCondition } from '../services/hogflows/hogflow-utils'import { HogFlowInvocationContext, HogFunctionInvocationGlobals } from '../types'import { convertToHogFunctionInvocationGlobals } from '../utils'import { execHog } from '../utils/hog-exec'@@ -240,6 +241,12 @@ export class CdpHogflowSubscriptionMatcherConsumer<return true}}+ // An empty condition compiles to always-true bytecode, which would wake the job on the next+ // event of any kind. Only evaluate the condition when it has a real compiled filter;+ // otherwise the wait relies on its `events` / the step timeout.+ if (!isEvaluableCondition(action.config.condition)) {+ return false+ }return runBytecode(action.config.condition?.filters?.bytecode, filterGlobals, context)}diff --git a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.ts b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.tsindex 82b83b4316a9..030f3cf5d1d3 100644--- a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.ts+++ b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.ts@@ -233,5 +233,20 @@ describe('action.conditional_branch', () => {expect(result.scheduledAt).toBeDefined()expect(result.nextAction).toBeUndefined()})++ it('does not fire immediately when the condition has no properties (always-true bytecode)', async () => {+ // An empty property condition compiles to always-true bytecode. It must not match on+ // entry and advance the wait; the step should park until an event wakes it or it times out.+ waitAction.config.condition = { filters: HOG_FILTERS_EXAMPLES.no_filters.filters }++ const result = await handler.execute({+ invocation: waitInvocation,+ action: waitAction,+ result: createInvocationResult(waitInvocation),+ })++ expect(result.scheduledAt).toBeDefined()+ expect(result.nextAction).toBeUndefined()+ })})})diff --git a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.ts b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.tsindex d715f301cbbb..b0bf00abd07d 100644--- a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.ts+++ b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.ts@@ -4,7 +4,7 @@ import { CyclotronJobInvocationHogFlow } from '~/cdp/types'import { filterFunctionInstrumented } from '~/cdp/utils/hog-function-filtering'import { HogFlowAction } from '~/schema/hogflow'-import { findContinueAction, findNextAction } from '../hogflow-utils'+import { findContinueAction, findNextAction, isEvaluableCondition } from '../hogflow-utils'import { ActionHandler, ActionHandlerOptions, ActionHandlerResult } from './action.interface'import { calculatedScheduledAt } from './delay'@@ -38,7 +38,10 @@ export class ConditionalBranchHandler implements ActionHandler {...action,type: 'conditional_branch',config: {- conditions: [action.config.condition],+ // An empty condition compiles to always-true bytecode, which would match on+ // entry and fire the wait immediately. Only honor a condition with a real+ // compiled filter; otherwise the wait relies on its events / the timeout.+ conditions: isEvaluableCondition(action.config.condition) ? [action.config.condition] : [],delay_duration: action.config.max_wait_duration,},}diff --git a/nodejs/src/cdp/services/hogflows/hogflow-utils.test.ts b/nodejs/src/cdp/services/hogflows/hogflow-utils.test.tsnew file mode 100644index 000000000000..c3db518042e3--- /dev/null+++ b/nodejs/src/cdp/services/hogflows/hogflow-utils.test.ts@@ -0,0 +1,23 @@+import { isEvaluableCondition } from './hogflow-utils'++describe('isEvaluableCondition', () => {+ it('treats a filter that targets nothing as absent (compiles to always-true)', () => {+ // These are exactly the shapes the compiler turns into always-true bytecode.+ expect(isEvaluableCondition(undefined)).toBe(false)+ expect(isEvaluableCondition({})).toBe(false)+ expect(isEvaluableCondition({ filters: {} })).toBe(false)+ expect(isEvaluableCondition({ filters: { properties: [] } })).toBe(false)+ expect(isEvaluableCondition({ filters: { properties: [], events: [], actions: [] } })).toBe(false)+ // A compiled empty condition still carries always-true bytecode, but it targets nothing.+ expect(isEvaluableCondition({ filters: { properties: [], bytecode: ['_H', 1, 29] } } as any)).toBe(false)+ })++ it('evaluates a real condition regardless of which filter field expresses it', () => {+ expect(isEvaluableCondition({ filters: { properties: [{ key: 'plan' }] } } as any)).toBe(true)+ // Expressed through events/actions (no top-level `properties`) — must still be evaluable.+ expect(isEvaluableCondition({ filters: { events: [{ id: '$pageview' }] } } as any)).toBe(true)+ expect(isEvaluableCondition({ filters: { actions: [{ id: 3 }] } } as any)).toBe(true)+ // Test-account filtering alone is a real filter (compiler emits team test-account predicates).+ expect(isEvaluableCondition({ filters: { filter_test_accounts: true } })).toBe(true)+ })+})diff --git a/nodejs/src/cdp/services/hogflows/hogflow-utils.ts b/nodejs/src/cdp/services/hogflows/hogflow-utils.tsindex eaa5d6be5041..a5a32336141b 100644--- a/nodejs/src/cdp/services/hogflows/hogflow-utils.ts+++ b/nodejs/src/cdp/services/hogflows/hogflow-utils.ts@@ -105,6 +105,32 @@ export const actionIdForLogging = (action: Pick<HogFlowAction, 'id'>): string =>return `[Action:${action.id}]`}+// A wait condition that targets nothing compiles to always-true bytecode (Python's filter compiler+// returns `Constant(true)` for an empty filter), which would match on entry and wake the job on every+// event. We detect that structurally — the same way the compiler decides: a filter is empty when it+// has no properties, no events, no actions, and no test-account filtering. Checking the structure+// rather than the compiled bytecode is robust to bytecode/version changes (no need to enumerate the+// always-true forms) and keeps a real condition expressed through any of those fields evaluable.+export function isEvaluableCondition(condition?: {+ filters?: {+ properties?: unknown[]+ events?: unknown[]+ actions?: unknown[]+ filter_test_accounts?: boolean+ }+}): boolean {+ const filters = condition?.filters+ if (!filters) {+ return false+ }+ return (+ (filters.properties?.length ?? 0) > 0 ||+ (filters.events?.length ?? 0) > 0 ||+ (filters.actions?.length ?? 0) > 0 ||+ Boolean(filters.filter_test_accounts)+ )+}+const DELAY_ACTION_TYPES: HogFlowAction['type'][] = ['delay', 'wait_until_condition', 'wait_until_time_window']export function hasDelayActions(actions: HogFlowAction[]): boolean {diff --git a/nodejs/src/cdp/workflows-e2e.test.ts b/nodejs/src/cdp/workflows-e2e.test.tsindex c294fe12effb..a2c03a580f9a 100644--- a/nodejs/src/cdp/workflows-e2e.test.ts+++ b/nodejs/src/cdp/workflows-e2e.test.ts@@ -297,6 +297,11 @@ describe.each(['postgres-v2' as const, 'postgres' as const])('Workflows E2E (%s)// actions. Empty filters compile to always-true bytecode (op 29), which must NOT wake on every// event. ['_H', 1, 29] is exactly what the Django compiler emits for empty filters.const emptyEventFilter = () => ({ filters: { events: [], bytecode: ['_H', 1, 29] } })+ // A wait CONDITION with no property filters: the state left when a condition's last filter is+ // removed, or one is added but never filled in. Django compiles it to the same always-true+ // bytecode (op 29). Unlike an events entry, the executor evaluates the condition on entry, so+ // without the guard this fires the wait immediately. Mirrors the serializer's compiled shape.+ const emptyConditionFilters = () => ({ bytecode: ['_H', 1, 29], properties: [] })describe('simple workflow: trigger → function → exit', () => {beforeEach(async () => {@@ -784,6 +789,45 @@ describe.each(['postgres-v2' as const, 'postgres' as const])('Workflows E2E (%s)expect(jobs.every((j: any) => j.status === 'available' && new Date(j.scheduled) > new Date())).toBe(true)expect(mockFetch).not.toHaveBeenCalled()})++ it('does not fire on entry for an empty property condition; takes the timeout branch', async () => {+ // An empty condition compiles to always-true bytecode. The executor evaluates the+ // condition on entry, so without the guard the wait advances down the matched branch+ // immediately. With no events and no real condition it must park and time out instead.+ await createWaitUntilWorkflow({+ condition: { filters: emptyConditionFilters() },+ max_wait_duration: '2s',+ })+ await triggerWorkflow(createGlobals())++ // If it fired on entry this would be the matched branch; it must be the timeout branch.+ await waitForExpect(() => {+ expect(mockFetch).toHaveBeenCalledTimes(1)+ }, 15000)+ expect(mockFetch).toHaveBeenCalledWith('https://example.com/timed-out', expect.anything())+ })++ it('does not fire on entry when an empty condition coexists with a real events entry; still wakes on the event', async () => {+ // The reported bug: an empty (always-true) condition alongside a real "events to wait+ // for" entry. Without the guard the empty condition matches on entry and the wait fires+ // immediately, ignoring the configured event. It must park and only wake when the event+ // actually fires.+ await createWaitUntilWorkflow({+ condition: { filters: emptyConditionFilters() },+ events: [eventNameFilter('wakeup_event')],+ max_wait_duration: '5m',+ })+ await triggerWorkflow(createGlobals())+ await expectParked()++ // The configured event fires — the matcher wakes the job via the events entry.+ await matcher.processBatch([createGlobals({ event: 'wakeup_event' })])++ await waitForExpect(() => {+ expect(mockFetch).toHaveBeenCalledTimes(1)+ }, 10000)+ expect(mockFetch).toHaveBeenCalledWith('https://example.com/condition-matched', expect.anything())+ })})describe('wait_until_time_window: window in the future', () => {