: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): stop counting matcher wakes as poll-only wait advances (#100205)
Daniel Marchukada51ed01b86
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 e388f7a1c487..b1c759359ceb 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@@ -1421,6 +1421,8 @@ describe('CdpHogflowSubscriptionMatcherConsumer', () => {// Not attributed as a merge re-key: counterHogflowRekeyWake measures whether waking on a merge// is wasted churn, so a first-mapping fill must stay out of that ratio.expect(newState.state.currentAction?.rekeyWake).toBeUndefined()+ // Flagged as a matcher wake instead, which is what keeps the poll-only counter off it.+ expect(newState.state.currentAction?.anchorWake).toBe(true)})it('scopes a first mapping to jobs with no anchor, leaving anchored waits alone', async () => {diff --git a/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.ts b/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.tsindex f93b89ef2d2b..8f4cdf85fcd3 100644--- a/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.ts+++ b/nodejs/src/cdp/consumers/cdp-hogflow-subscription-matcher.consumer.ts@@ -1477,12 +1477,14 @@ function rewriteStatePersonId(personIdRepointed: true,personIdRepointVersion: newVersion,}- // Mark this as a re-key wake so the wait handler can attribute its re-check outcome to the- // re-key (see rekeyWake). currentAction is always a wait_until_condition here (re-key scope).- // Only for merges: counterHogflowRekeyWake exists to judge whether waking on a merge is wasted- // churn, so folding first-mapping fills into it would blend two causes into one ratio.- if (parsed.state.currentAction && !fillingNullAnchor) {- parsed.state.currentAction = { ...parsed.state.currentAction, rekeyWake: true }+ // Mark the wake so the wait handler knows the matcher woke this job rather than a polling+ // re-check. currentAction is always a wait_until_condition here (re-key scope). The two causes+ // stay separate flags: counterHogflowRekeyWake judges whether waking on a merge is wasted churn,+ // so folding first-mapping fills into it would blend two causes into one ratio.+ if (parsed.state.currentAction) {+ parsed.state.currentAction = fillingNullAnchor+ ? { ...parsed.state.currentAction, anchorWake: true }+ : { ...parsed.state.currentAction, rekeyWake: true }}return Buffer.from(JSON.stringify(parsed))} catch (err) {diff --git a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.ts b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.tsindex f0f426c658eb..ccdbaeec6fe0 100644--- a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.ts+++ b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.ts@@ -528,6 +528,28 @@ describe('action.conditional_branch', () => {expect(await pollOnlyAdvanceCount()).toBe(0)})+ // A matcher wake reaches here without eventMatched, so before this both read as poll advances.+ it.each(['rekeyWake', 'anchorWake'] as const)('does not count a %s matcher wake as poll-only', async (flag) => {+ waitAction.config.condition = {+ filters: {+ bytecode: ['_H', 1, 32, 'test', 32, 'event', 1, 1, 11],+ events: [{ id: 'test', name: 'test', type: 'events', order: 0 }],+ },+ }+ waitInvocation.state.currentAction!.pollReparked = true+ waitInvocation.state.currentAction![flag] = true++ const result = await handler.execute({+ invocation: waitInvocation,+ action: waitAction,+ result: createInvocationResult(waitInvocation),+ })++ expect(result.nextAction).toEqual(findActionById(waitInvocation.hogFlow, 'matched_target'))+ expect(await pollOnlyAdvanceCount()).toBe(0)+ expect(waitInvocation.state.currentAction![flag]).toBe(false)+ })+it('records a rekey wake as advanced and consumes the one-shot flag when the merge makes the condition match', async () => {// A merge re-keyed this parked wait onto the survivor and woke it (rekeyWake). The re-check// now finds the condition true. Consuming the flag is what keeps the next re-check fromdiff --git a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.ts b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.tsindex 3a6b271719fb..e5bff8e4b387 100644--- a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.ts+++ b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.ts@@ -52,6 +52,13 @@ export class ConditionalBranchHandler implements ActionHandler {invocation.state.currentAction.rekeyWake = false}+ // Same for a first-mapping anchor fill: a matcher wake that also carries no eventMatched.+ const anchorWoken =+ action.type === 'wait_until_condition' && invocation.state?.currentAction?.anchorWake === true+ if (anchorWoken && invocation.state.currentAction) {+ invocation.state.currentAction.anchorWake = false+ }+// The subscription matcher sets eventMatched when an incoming event matched this// step's wait condition. Honor it as a forced match and advance immediately,// rather than re-evaluating the stored condition against the original event.@@ -119,9 +126,9 @@ export class ConditionalBranchHandler implements ActionHandler {}return { scheduledAt: conditionResult.scheduledAt, result: { conditionResult } }} else if (conditionResult.nextAction) {- // Poll-only advance: a wait whose condition matched on a re-check (not via the matcher's- // eventMatched short-circuit above, and not on entry). This is the wake the streams missed.- if (isWait && invocation.state.currentAction?.pollReparked === true) {+ // Poll-only advance: a wait matched on a re-check that no matcher wake caused, and not on+ // entry. Re-key and anchor wakes arrive without eventMatched, so both must be excluded.+ if (isWait && !rekeyWoken && !anchorWoken && invocation.state.currentAction?.pollReparked === true) {counterHogflowWaitPollOnlyAdvance.labels({ team_id: invocation.hogFlow.team_id, hog_flow_id: invocation.hogFlow.id }).inc()diff --git a/nodejs/src/cdp/types.ts b/nodejs/src/cdp/types.tsindex 64cae2d74da5..b4e5343663ce 100644--- a/nodejs/src/cdp/types.ts+++ b/nodejs/src/cdp/types.ts@@ -458,6 +458,9 @@ export type HogFlowInvocationContext = {// it (scheduled=now). The wait handler consumes it to attribute the re-check outcome// (advanced vs re-parked) to the re-key, so the wasted-re-park churn is observable.rekeyWake?: boolean+ // Set when a distinct_id's first mapping fills a parked wait's missing person anchor and wakes+ // it. A matcher wake carrying no eventMatched, so the handler consumes it like rekeyWake.+ anchorWake?: boolean// Set by hog-function action handler when it returns `finished: false` without an// explicit `queueScheduledAt` — i.e. the reschedule is purely to move the job onto a// dedicated queue (e.g. 'email' for SES rate-limit gating) and the next dequeue will