: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
feat(workflows): sweep parked runs on deleted timing steps and condition edits (#73925)
Harley Alexander45560fcf227a
diff --git a/products/workflows/backend/api/hog_flow.py b/products/workflows/backend/api/hog_flow.pyindex 05f2dbe4cf20..0ba344d07f64 100644--- a/products/workflows/backend/api/hog_flow.py+++ b/products/workflows/backend/api/hog_flow.py@@ -2238,7 +2238,9 @@ class HogFlowViewSet(def _maybe_reschedule_timing_edits(self, before: Optional[HogFlow], after: HogFlow) -> None:"""Kick off a reschedule sweep of parked runs when a go-live config change could move- their wake times earlier (issue #66380): shortened delays and moved wait windows.+ their wake times earlier or change what they resolve to (issue #66380): shortened+ delays, moved wait windows, edited wait conditions, and deleted timing steps (whose+ parked runs should skip forward or exit now, not at their old wake time).Called wherever the LIVE config changes - a direct save (the builder path, where saveis go-live), the graph endpoint, or publish - and never for draft writes, which don'tdiff --git a/products/workflows/backend/services/timing_reschedule.py b/products/workflows/backend/services/timing_reschedule.pyindex 8d83b596ddef..8c022bdc93ca 100644--- a/products/workflows/backend/services/timing_reschedule.py+++ b/products/workflows/backend/services/timing_reschedule.py@@ -100,19 +100,28 @@ def get_timing_reschedule_action_ids(- delay: trigger on a shortened effective duration; unparseable durations triggerconservatively (the worker throws on them at wake, and a spurious sweep is a cheapno-op re-park).- - wait_until_condition: trigger on a shortened max_wait_duration, same comparison as- delay. Condition edits never trigger - they don't move a parked run's wake time- (the matcher and the poll both evaluate live config at wake).+ - wait_until_condition: trigger on a shortened max_wait_duration (same comparison as+ delay) and on any condition edit - a swept run re-evaluates the live condition at+ wake (advance if it now matches, re-park if not), which keeps fixes to broken+ conditions taking effect promptly once the poll re-check is gone.- wait_until_time_window: trigger on any timing-config change - whether a window editmoves a given run's wake earlier depends on each person's timezone and position inthe week, so it isn't statically decidable.- type changed across the timing boundary: parked runs' action_id still points at thestep, and the new handler should run on the sweep's schedule, not the old wake time.- - added/deleted actions never trigger: nothing is parked on a new step, and deleted- steps are the graceful-exit path's concern.+ - deleted timing actions: runs parked on the removed step should wake now and take the+ skip-forward/graceful-exit path at the sweep's schedule, not at their old wake time+ (which for a wait_until_condition can be the full max_wait deadline once the poll+ backstop is gone).+ - added actions never trigger: nothing is parked on a new step."""before_by_id = {a["id"]: a for a in (before_actions or []) if isinstance(a, dict) and a.get("id")}- action_ids: set[str] = set()+ after_ids = {a["id"] for a in (after_actions or []) if isinstance(a, dict) and a.get("id")}+ action_ids: set[str] = {+ action_id+ for action_id, before in before_by_id.items()+ if action_id not in after_ids and before.get("type") in TIMING_ACTION_TYPES+ }for action in after_actions or []:if not isinstance(action, dict) or not action.get("id"):@@ -141,6 +150,8 @@ def get_timing_reschedule_action_ids(action_ids.add(action["id"])elif after_seconds < before_seconds:action_ids.add(action["id"])+ if after_type == "wait_until_condition" and before_config.get("condition") != after_config.get("condition"):+ action_ids.add(action["id"])elif after_type == "wait_until_time_window":if any(before_config.get(key) != after_config.get(key) for key in _TIME_WINDOW_CONFIG_KEYS):action_ids.add(action["id"])diff --git a/products/workflows/backend/test/test_timing_reschedule.py b/products/workflows/backend/test/test_timing_reschedule.pyindex 53aa3f36b6e7..841b95e80c42 100644--- a/products/workflows/backend/test/test_timing_reschedule.py+++ b/products/workflows/backend/test/test_timing_reschedule.py@@ -85,13 +85,13 @@ class TestTimingRescheduleDiff(SimpleTestCase):("max_wait_unchanged", _condition(), _condition(), False),("max_wait_clamped_shortening", _condition(max_wait="7d"), _condition(max_wait="168h"), True),("max_wait_unparseable_after", _condition(max_wait="7d"), _condition(max_wait="banana"), True),- # Condition edits never move a parked run's wake time (the matcher and the poll- # both evaluate live config), so they must not trigger a sweep+ # An edited condition must re-evaluate against parked runs promptly (e.g. fixing a+ # filter that could never match) - the sweep wake replaces the poll re-check("condition_only_change",_condition(),_condition(condition={"filters": {"events": [{"id": "$identify"}]}}),- False,+ True,),])@@ -130,15 +130,26 @@ class TestTimingRescheduleDiff(SimpleTestCase):result = get_timing_reschedule_action_ids([before], [after])assert result == (["a"] if expect_sweep else [])- def test_added_and_deleted_timing_actions_do_not_sweep(self):+ @parameterized.expand(+ [+ ("deleted_delay", _delay(action_id="a"), True),+ ("deleted_time_window", _window(action_id="a"), True),+ ("deleted_wait_condition", _condition(action_id="a"), True),+ ("deleted_non_timing", {"id": "a", "type": "function", "config": {}}, False),+ ]+ )+ def test_deleted_actions(self, _name, before_action, expect_sweep):+ result = get_timing_reschedule_action_ids([before_action], [])+ assert result == (["a"] if expect_sweep else [])++ def test_added_timing_actions_do_not_sweep(self):assert get_timing_reschedule_action_ids([], [_delay()]) == []- assert get_timing_reschedule_action_ids([_delay()], []) == []assert get_timing_reschedule_action_ids(None, None) == []def test_multiple_changed_actions_are_sorted_and_deduped(self):- before = [_delay("delay_b", "7d"), _delay("delay_a", "7d"), _window("wait_1")]+ before = [_delay("delay_b", "7d"), _delay("delay_a", "7d"), _window("wait_1"), _condition("cond_gone")]after = [_delay("delay_b", "1d"), _delay("delay_a", "1d"), _window("wait_1", day="weekend")]- assert get_timing_reschedule_action_ids(before, after) == ["delay_a", "delay_b", "wait_1"]+ assert get_timing_reschedule_action_ids(before, after) == ["cond_gone", "delay_a", "delay_b", "wait_1"]def test_pathological_diff_over_cap_sweeps_nothing(self):before = [_delay(f"delay_{i}", "7d") for i in range(101)]