: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
chore(workflows): drop delay_duration from conditional_branch (#102233)
Daniel Marchuk91952fa3c268
diff --git a/nodejs/src/cdp/schema/hogflow.ts b/nodejs/src/cdp/schema/hogflow.tsindex a5f5a0bf4a6f..70ffd386a734 100644--- a/nodejs/src/cdp/schema/hogflow.ts+++ b/nodejs/src/cdp/schema/hogflow.ts@@ -134,7 +134,6 @@ export const HogFlowActionSchema = z.discriminatedUnion('type', [name: z.string().optional(), // Custom name for the condition})),- delay_duration: z.string().optional(),}),}),z.object({diff --git a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.ts b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.tsindex 053705f84cb7..bfabeeda7baa 100644--- a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.ts+++ b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.test.ts@@ -93,31 +93,31 @@ describe('action.conditional_branch', () => {expect(result).toEqual({})})+ // A wait arrives here already normalised into a conditional_branch, so its ceiling comes in+ // as `repark` rather than off the action. A branch without one never parks.describe('wait logic', () => {- it('should handle wait duration and schedule next check', async () => {- action.config.delay_duration = '2h'- const result = await checkConditions(invocation, action)- expect(result).toEqual({- // A conditional_branch has no matcher coverage, so it keeps the ten-minute cap.- scheduledAt: DateTime.utc().plus({ minutes: 10 }),- })+ const repark = (maxWaitDuration: string) => ({ maxWaitDuration, recheckSeconds: 60 * 60 })++ it('should cap the next check at the backstop', async () => {+ const result = await checkConditions(invocation, action, undefined, repark('2h'))+ expect(result).toEqual({ scheduledAt: DateTime.utc().plus({ hours: 1 }) })})it('should not schedule for later than the max wait duration', async () => {- action.config.delay_duration = '5m'+ const result = await checkConditions(invocation, action, undefined, repark('5m'))+ expect(result).toEqual({ scheduledAt: DateTime.utc().plus({ minutes: 5 }) })+ })++ it('should not schedule at all without a ceiling', async () => {const result = await checkConditions(invocation, action)- expect(result).toEqual({- // Should schedule for 5 minutes from now- scheduledAt: DateTime.utc().plus({ minutes: 5 }),- })+ expect(result).toEqual({})})it('should throw error if action started at timestamp is invalid', async () => {invocation.state.currentAction = undefined- action.config.delay_duration = '300s'- await expect(async () => checkConditions(invocation, action)).rejects.toThrow(- "'startedAtTimestamp' is not set or is invalid"- )+ await expect(async () =>+ checkConditions(invocation, action, undefined, repark('300s'))+ ).rejects.toThrow("'startedAtTimestamp' is not set or is invalid")})})})@@ -453,25 +453,6 @@ describe('action.conditional_branch', () => {expect(result.scheduledAt).toEqual(DateTime.utc().plus({ hours: 1 }))})- it('keeps the ten-minute cap for a delayed conditional_branch, which the matcher never wakes', async () => {- // Every parked-job lookup in the subscription matcher is scoped to wait_until_condition, so- // a delayed branch has no wake at all and the re-check is the only thing that advances it.- // Sending it through the handler is what exercises the call site that picks the cap.- const branchAction = {- ...waitAction,- type: 'conditional_branch',- config: { conditions: [], delay_duration: '4h' },- } as unknown as typeof waitAction-- const result = await handler.execute({- invocation: waitInvocation,- action: branchAction,- result: createInvocationResult(waitInvocation),- })-- expect(result.scheduledAt).toEqual(DateTime.utc().plus({ minutes: 10 }))- })-it('parks a wait shorter than the backstop for its own duration', async () => {// The cap only shortens a park; a 30-minute wait must still resolve at 30 minutes rather// than being stretched to the hourly re-check.diff --git a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.ts b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.tsindex 878a66f27412..77dc805af7e6 100644--- a/nodejs/src/cdp/services/hogflows/actions/conditional_branch.ts+++ b/nodejs/src/cdp/services/hogflows/actions/conditional_branch.ts@@ -10,10 +10,6 @@ import { findContinueAction, findNextAction, isEvaluableCondition } from '../hogimport { ActionHandler, ActionHandlerOptions, ActionHandlerResult } from './action.interface'import { calculatedScheduledAt } from './delay'-// A parked conditional_branch has no matcher coverage: every parked-job lookup in the subscription-// matcher is scoped to wait_until_condition, so this re-check is the only thing that advances a-// delayed branch.-const BRANCH_RECHECK_SECONDS = 10 * 60// A wait is woken by the matcher on a matching signal, so its re-check only has to reconcile a wake// lost between the condition being evaluated and the job being persisted.const WAIT_RECHECK_SECONDS = 60 * 60@@ -108,7 +104,6 @@ export class ConditionalBranchHandler implements ActionHandler {// 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,},}@@ -116,7 +111,9 @@ export class ConditionalBranchHandler implements ActionHandler {invocation,conditionalAction,this.createMemberCohortIdsLoader(invocation),- action.type === 'wait_until_condition' ? WAIT_RECHECK_SECONDS : BRANCH_RECHECK_SECONDS+ action.type === 'wait_until_condition' && action.config.max_wait_duration+ ? { maxWaitDuration: action.config.max_wait_duration, recheckSeconds: WAIT_RECHECK_SECONDS }+ : undefined)const isWait = action.type === 'wait_until_condition'@@ -191,9 +188,9 @@ export async function checkConditions(invocation: CyclotronJobInvocationHogFlow,action: Extract<HogFlowAction, { type: 'conditional_branch' }>,loadMemberCohortIds?: () => Promise<number[]>,- // A wait is normalised into a conditional_branch before it gets here, so the caller decides which- // cap applies; the type on `action` can no longer tell the two apart.- recheckSeconds: number = BRANCH_RECHECK_SECONDS+ // Only a wait re-parks; a conditional_branch routes on the spot. A wait is normalised into a+ // branch before it gets here, so the caller passes its ceiling rather than the type carrying it.+ repark?: { maxWaitDuration: string; recheckSeconds: number }): Promise<{scheduledAt?: DateTimenextAction?: HogFlowAction@@ -228,14 +225,13 @@ export async function checkConditions(}}- if (action.config.delay_duration) {- // Re-park on the cap for this step type. A wake arriving between this evaluation and the job- // being persisted finds no available row and is never replayed, so neither step type can rely- // on the matcher alone.+ if (repark) {+ // A wake arriving between this evaluation and the job being persisted finds no available row+ // and is never replayed, so a wait cannot rely on the matcher alone.const scheduledAt = calculatedScheduledAt(- action.config.delay_duration,+ repark.maxWaitDuration,invocation.state.currentAction?.startedAtTimestamp,- recheckSeconds+ repark.recheckSeconds)if (scheduledAt) {diff --git a/products/workflows/backend/api/hog_flow.py b/products/workflows/backend/api/hog_flow.pyindex bc7c11c3fbf2..7e1ba2f988e4 100644--- a/products/workflows/backend/api/hog_flow.py+++ b/products/workflows/backend/api/hog_flow.py@@ -252,6 +252,24 @@ def _wait_condition_already_stored(action: dict, context: dict) -> bool:return _authored_condition(stored[action_id]) == _authored_condition((action.get("config") or {}).get("condition"))+def _branch_delay_duration_already_stored(action: dict, context: dict) -> bool:+ """+ True when this branch resends the delay_duration already persisted for the same action.++ The field does nothing on a branch, but it was accepted before the gate existed and the builder+ renders no control for it. Without this, a flow that already stores one could not be published,+ enabled or resumed, and no one could remove the value that blocks it. Changing it is still+ refused, so the gate keeps policing every new write.+ """+ stored = context.get("stored_branch_delay_durations")+ if not stored:+ return False+ action_id = action.get("id")+ if action_id not in stored:+ return False+ return stored[action_id] == (action.get("config") or {}).get("delay_duration")++def _reject_clock_based_wait(config: dict, team: Team) -> None:"""Refuse a wait whose condition depends on the clock rather than on something happening.@@ -1783,14 +1801,23 @@ class HogFlowActionSerializer(serializers.Serializer):if strict and max_wait_duration not in (None, "") and not is_duration(max_wait_duration):raise serializers.ValidationError({"config": duration_error("max_wait_duration")})- if is_conditional_branch:- # A branch that matches no condition re-parks on this optional delay, which- # conditional_branch.ts hands to the same parser as max_wait_duration above. Absent or- # empty means "do not re-park", so only a value that actually reaches the parser needs the- # format, and emptiness is the test for the same reason as above.- delay_duration = data.get("config", {}).get("delay_duration")- if strict and delay_duration not in (None, "") and not is_duration(delay_duration):- raise serializers.ValidationError({"config": duration_error("delay_duration")})+ if (+ is_conditional_branch+ and strict+ and data.get("config", {}).get("delay_duration") not in (None, "")+ and not _branch_delay_duration_already_stored(data, self.context)+ ):+ # The worker borrows this name to carry a wait's ceiling once a wait is normalised into a+ # branch, which is why it used to be accepted here. A branch never parks, so a value set+ # on one does nothing.+ raise serializers.ValidationError(+ {+ "config": (+ "delay_duration is not supported on conditional_branch. "+ "To wait for a condition to become true, use a wait step."+ )+ }+ )if data.get("type") == "delay":self._validate_delay(data, strict)@@ -3033,6 +3060,16 @@ class HogFlowSerializer(HogFlowMinimalSerializer):if isinstance(action, dict) and action.get("id") and action.get("type") == "wait_until_condition"}+ # delay_duration values a branch already carries, so the rejection below polices new writes+ # only. Unlike the flag-gated set this does not require an active flow: enabling a draft that+ # stores one is the case that would otherwise be refused, and the field is inert at runtime,+ # so there is no gate to bypass by smuggling it through a lenient draft save.+ self.context["stored_branch_delay_durations"] = {+ action["id"]: (action.get("config") or {}).get("delay_duration")+ for action in ((instance.actions if instance else None) or [])+ if isinstance(action, dict) and action.get("id") and action.get("type") == "conditional_branch"+ }+# Action ids already stored with a flag-gated template, so the gate only polices new# adoption: a flow that was allowed to hold the step keeps validating after a flag# dial-down or eval blip (the gate fails closed), instead of becoming un-editable anddiff --git a/products/workflows/backend/api/test/test_hog_flow.py b/products/workflows/backend/api/test/test_hog_flow.pyindex 273339df41e7..ccdb38a530a9 100644--- a/products/workflows/backend/api/test/test_hog_flow.py+++ b/products/workflows/backend/api/test/test_hog_flow.py@@ -1020,21 +1020,8 @@ class TestHogFlowAPI(APIBaseTest):}return flow- @parameterized.expand(- [- ("no_unit", "5"),- ("unsupported_unit", "10x"),- ("iso_8601", "P30D"),- ("numeric", 1800),- ("unicode_digits", "\u0665d"),- # Falsy in Python, truthy in the worker, which would hand the parser a container.- ("empty_object", {}),- ("empty_array", []),- ]- )- def test_hog_flow_conditional_branch_validation_rejects_malformed_delay_duration(self, _name, delay_duration):- # A branch that matches nothing re-parks on delay_duration through the same parser as a delay- # step, so a value only that parser rejects has to be rejected at write time too+ @parameterized.expand([("duration", "30s"), ("garbage", "10x"), ("numeric", 1800)])+ def test_hog_flow_conditional_branch_validation_rejects_delay_duration(self, _name, delay_duration):response = self.client.post(f"/api/projects/{self.team.id}/hog_flows",self._make_conditional_branch_flow({"delay_duration": delay_duration}),@@ -1044,29 +1031,54 @@ class TestHogFlowAPI(APIBaseTest):"attr": "actions__1__config","code": "invalid_input","detail": (- "delay_duration must be a duration string such as '30s', '30m', '2h', '1.5d'. "- "ISO-8601 formats are not supported."+ "delay_duration is not supported on conditional_branch. "+ "To wait for a condition to become true, use a wait step."),"type": "validation_error",}@parameterized.expand([- ("seconds", {"delay_duration": "30s"}),- ("fractional_days", {"delay_duration": "1.5d"}),- # The re-park is optional, and every branch the editor writes omits it, so a branch with- # no delay must keep saving("absent", {}),("null", {"delay_duration": None}),("empty_string", {"delay_duration": ""}),])- def test_hog_flow_conditional_branch_validation_accepts_canonical_delay_duration(self, _name, config):+ def test_hog_flow_conditional_branch_saves_without_a_delay_duration(self, _name, config):response = self.client.post(f"/api/projects/{self.team.id}/hog_flows", self._make_conditional_branch_flow(config))assert response.status_code == 201, response.json()+ def test_hog_flow_conditional_branch_grandfathers_a_stored_delay_duration(self):+ create_response = self.client.post(+ f"/api/projects/{self.team.id}/hog_flows", self._make_conditional_branch_flow({})+ )+ assert create_response.status_code == 201, create_response.json()+ flow_id = create_response.json()["id"]++ # Seed a row from before the rejection existed, bypassing the serializer that now refuses it.+ flow = HogFlow.objects.get(id=flow_id)+ actions = flow.actions+ actions[1]["config"]["delay_duration"] = "2h"+ flow.actions = actions+ flow.save()++ # An unrelated edit that resends the unchanged value must still succeed. The builder renders+ # no control for the field, so a refusal here would leave the flow stuck with no way out.+ unrelated_edit = self.client.patch(+ f"/api/projects/{self.team.id}/hog_flows/{flow_id}",+ {"name": "Renamed", "actions": actions},+ )+ assert unrelated_edit.status_code == 200, unrelated_edit.json()+ assert unrelated_edit.json()["actions"][1]["config"]["delay_duration"] == "2h"++ # Changing the stored value is still refused.+ changed = [{**action} for action in actions]+ changed[1] = {**changed[1], "config": {**changed[1]["config"], "delay_duration": "3h"}}+ changed_response = self.client.patch(f"/api/projects/{self.team.id}/hog_flows/{flow_id}", {"actions": changed})+ assert changed_response.status_code == 400, changed_response.json()+@parameterized.expand([("bare_string", "greeting", {"key": "greeting"}),diff --git a/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsx b/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsxindex 0ff737c0e09b..e135de1e054e 100644--- a/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsx+++ b/products/workflows/frontend/Workflows/hogflows/hogFlowEditorLogic.tsx@@ -275,7 +275,14 @@ export interface hogFlowEditorLogicActions {}| {config: {- reason?: string | undefined+ conditions: {+ filters: {+ actions?: any[] | undefined+ events?: any[] | undefined+ properties?: any[] | undefined+ }+ name?: string | undefined+ }[]}created_at?: number | undefineddescription: string@@ -305,20 +312,12 @@ export interface hogFlowEditorLogicActions {}[]| null| undefined- type: 'exit'+ type: 'conditional_branch'updated_at?: number | undefined}| {config: {- conditions: {- filters: {- actions?: any[] | undefined- events?: any[] | undefined- properties?: any[] | undefined- }- name?: string | undefined- }[]- delay_duration?: string | undefined+ reason?: string | undefined}created_at?: number | undefineddescription: string@@ -348,7 +347,7 @@ export interface hogFlowEditorLogicActions {}[]| null| undefined- type: 'conditional_branch'+ type: 'exit'updated_at?: number | undefined}| {@@ -1133,7 +1132,14 @@ export interface hogFlowEditorLogicActions {}| {config: {- reason?: string | undefined+ conditions: {+ filters: {+ actions?: any[] | undefined+ events?: any[] | undefined+ properties?: any[] | undefined+ }+ name?: string | undefined+ }[]}created_at?: number | undefineddescription: string@@ -1163,20 +1169,12 @@ export interface hogFlowEditorLogicActions {}[]| null| undefined- type: 'exit'+ type: 'conditional_branch'updated_at?: number | undefined}| {config: {- conditions: {- filters: {- actions?: any[] | undefined- events?: any[] | undefined- properties?: any[] | undefined- }- name?: string | undefined- }[]- delay_duration?: string | undefined+ reason?: string | undefined}created_at?: number | undefineddescription: string@@ -1206,7 +1204,7 @@ export interface hogFlowEditorLogicActions {}[]| null| undefined- type: 'conditional_branch'+ type: 'exit'updated_at?: number | undefined}| {diff --git a/products/workflows/frontend/Workflows/hogflows/steps/stepDelayLogic.ts b/products/workflows/frontend/Workflows/hogflows/steps/stepDelayLogic.tsindex 289b7c3b201a..78d9d4cca497 100644--- a/products/workflows/frontend/Workflows/hogflows/steps/stepDelayLogic.ts+++ b/products/workflows/frontend/Workflows/hogflows/steps/stepDelayLogic.ts@@ -180,12 +180,6 @@ export interface stepDelayLogicActions {percentage: number}[]}- | {- reason?: string | undefined- }- | {- type: 'schedule'- }| {conditions: {filters: {@@ -195,7 +189,12 @@ export interface stepDelayLogicActions {}name?: string | undefined}[]- delay_duration?: string | undefined+ }+ | {+ reason?: string | undefined+ }+ | {+ type: 'schedule'}| {filters: {@@ -477,12 +476,6 @@ export interface stepDelayLogicActions {percentage: number}[]}- | {- reason?: string | undefined- }- | {- type: 'schedule'- }| {conditions: {filters: {@@ -492,7 +485,12 @@ export interface stepDelayLogicActions {}name?: string | undefined}[]- delay_duration?: string | undefined+ }+ | {+ reason?: string | undefined+ }+ | {+ type: 'schedule'}| {filters: {diff --git a/products/workflows/frontend/Workflows/hogflows/steps/stepWaitUntilTimeWindowLogic.ts b/products/workflows/frontend/Workflows/hogflows/steps/stepWaitUntilTimeWindowLogic.tsindex 3581b8912674..17bea541cd16 100644--- a/products/workflows/frontend/Workflows/hogflows/steps/stepWaitUntilTimeWindowLogic.ts+++ b/products/workflows/frontend/Workflows/hogflows/steps/stepWaitUntilTimeWindowLogic.ts@@ -105,12 +105,6 @@ export interface stepWaitUntilTimeWindowLogicActions {percentage: number}[]}- | {- reason?: string | undefined- }- | {- type: 'schedule'- }| {conditions: {filters: {@@ -120,7 +114,12 @@ export interface stepWaitUntilTimeWindowLogicActions {}name?: string | undefined}[]- delay_duration?: string | undefined+ }+ | {+ reason?: string | undefined+ }+ | {+ type: 'schedule'}| {filters: {@@ -403,12 +402,6 @@ export interface stepWaitUntilTimeWindowLogicActions {percentage: number}[]}- | {- reason?: string | undefined- }- | {- type: 'schedule'- }| {conditions: {filters: {@@ -418,7 +411,12 @@ export interface stepWaitUntilTimeWindowLogicActions {}name?: string | undefined}[]- delay_duration?: string | undefined+ }+ | {+ reason?: string | undefined+ }+ | {+ type: 'schedule'}| {filters: {diff --git a/products/workflows/frontend/Workflows/hogflows/steps/types.ts b/products/workflows/frontend/Workflows/hogflows/steps/types.tsindex 59eab4276934..d657744cd80c 100644--- a/products/workflows/frontend/Workflows/hogflows/steps/types.ts+++ b/products/workflows/frontend/Workflows/hogflows/steps/types.ts@@ -232,7 +232,6 @@ export const HogFlowActionSchema = z.discriminatedUnion('type', [name: z.string().optional(), // Custom name for the condition})),- delay_duration: z.string().optional(),}),}),z.object({diff --git a/products/workflows/frontend/Workflows/workflowLogic.ts b/products/workflows/frontend/Workflows/workflowLogic.tsindex 866dc22fcadb..f6c8813eee67 100644--- a/products/workflows/frontend/Workflows/workflowLogic.ts+++ b/products/workflows/frontend/Workflows/workflowLogic.ts@@ -350,7 +350,6 @@ export interface workflowLogicActions {}name?: string | undefined}[]- delay_duration?: string | undefined}created_at?: number | undefineddescription: string@@ -1208,7 +1207,6 @@ export interface workflowLogicActions {}name?: string | undefined}[]- delay_duration?: string | undefined}created_at?: number | undefineddescription: string@@ -2069,12 +2067,6 @@ export interface workflowLogicActions {percentage: number}[]}- | {- reason?: string | undefined- }- | {- type: 'schedule'- }| {conditions: {filters: {@@ -2084,7 +2076,12 @@ export interface workflowLogicActions {}name?: string | undefined}[]- delay_duration?: string | undefined+ }+ | {+ reason?: string | undefined+ }+ | {+ type: 'schedule'}| {filters: {@@ -2455,12 +2452,6 @@ export interface workflowLogicActions {percentage: number}[]}- | {- reason?: string | undefined- }- | {- type: 'schedule'- }| {conditions: {filters: {@@ -2470,7 +2461,12 @@ export interface workflowLogicActions {}name?: string | undefined}[]- delay_duration?: string | undefined+ }+ | {+ reason?: string | undefined+ }+ | {+ type: 'schedule'}| {filters: {