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): limit how often one person enters a suggested workflow (#120765)

Daniel Marchuka33b388fcd09
diff --git a/products/workflows/backend/services/data_suggestions/builder.py b/products/workflows/backend/services/data_suggestions/builder.py
index 936c9dbc93cf..5b42d25a0156 100644
--- a/products/workflows/backend/services/data_suggestions/builder.py
+++ b/products/workflows/backend/services/data_suggestions/builder.py
@@ -23,6 +23,7 @@ logger = structlog.get_logger(__name__)
_TEMPLATE_TAGS = re.compile(r"\{\{.*?\}\}|\{%.*?%\}|\{[^{}]*\}", re.DOTALL)
_EXIT_ID = "exit_node"
_DEFAULT_MAX_WAIT = "3d"
+_REPEAT_ENTRY_SECONDS = 7 * 24 * 60 * 60
@frozen
@@ -131,12 +132,12 @@ def build_workflow(idea: WorkflowIdea, plan: PlannedWorkflow, context: BuildCont
"edges": edges,
"conversion": {"filters": [], "window_minutes": None},
"exit_condition": "exit_only_at_end",
- # A person who repeats a welcome or onboarding event would otherwise start the whole sequence again.
- **(
- {"trigger_masking": {"hash": "{person.id}", "ttl": None, "threshold": None}}
- if context.once_per_person
- else {}
- ),
+ # A person who repeats the trigger event would otherwise start the sequence again and get every email again.
+ "trigger_masking": {
+ "hash": "{person.id}",
+ "ttl": None if context.once_per_person else _REPEAT_ENTRY_SECONDS,
+ "threshold": None,
+ },
},
)
diff --git a/products/workflows/backend/test/test_data_suggestions.py b/products/workflows/backend/test/test_data_suggestions.py
index 175eb0e59849..000569fa2a00 100644
--- a/products/workflows/backend/test/test_data_suggestions.py
+++ b/products/workflows/backend/test/test_data_suggestions.py
@@ -253,7 +253,7 @@ class TestDataSuggestions(SimpleTestCase):
assert email["html"] == "<p>saved</p>"
assert "text" not in email
- def test_build_workflow_puts_a_wait_between_back_to_back_emails(self) -> None:
+ def test_build_workflow_spaces_out_emails_for_a_person(self) -> None:
built = build_workflow(
IDEA, plan(step("first", next="second"), step("second", email_subject="Second")), context()
)
@@ -264,6 +264,7 @@ class TestDataSuggestions(SimpleTestCase):
"function_email",
]
assert built.workflow["actions"][2]["config"] == {"delay_duration": "1d"}
+ assert built.workflow["trigger_masking"] == {"hash": "{person.id}", "ttl": 7 * 24 * 60 * 60, "threshold": None}
assert edges(built)[1:3] == [
("action_0_email", "action_1_delay", "continue", None),
("action_1_delay", "action_2_email", "continue", None),