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.

feat(workflows): add per-workflow email pause columns (#92261)

Meikel Ratzc825d1dd82ba
diff --git a/products/workflows/backend/migrations/0024_hogflow_email_sending_paused_at_and_more.py b/products/workflows/backend/migrations/0024_hogflow_email_sending_paused_at_and_more.py
new file mode 100644
index 000000000000..f2c71464f454
--- /dev/null
+++ b/products/workflows/backend/migrations/0024_hogflow_email_sending_paused_at_and_more.py
@@ -0,0 +1,30 @@
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("workflows", "0023_teamworkflowsconfig_workflow_task_rate_limit_per_day_and_more"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="hogflow",
+ name="email_sending_paused_at",
+ field=models.DateTimeField(blank=True, null=True),
+ ),
+ migrations.AddField(
+ model_name="hogflow",
+ name="email_sending_paused_reason",
+ field=models.TextField(blank=True, db_default="", default=""),
+ ),
+ migrations.AddField(
+ model_name="hogflow",
+ name="email_sending_resumed_at",
+ field=models.DateTimeField(blank=True, null=True),
+ ),
+ migrations.AddField(
+ model_name="hogflow",
+ name="email_sending_warned_at",
+ field=models.DateTimeField(blank=True, null=True),
+ ),
+ ]
diff --git a/products/workflows/backend/migrations/max_migration.txt b/products/workflows/backend/migrations/max_migration.txt
index 240531e445b0..56fa7aa38414 100644
--- a/products/workflows/backend/migrations/max_migration.txt
+++ b/products/workflows/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0023_teamworkflowsconfig_workflow_task_rate_limit_per_day_and_more
+0024_hogflow_email_sending_paused_at_and_more
diff --git a/products/workflows/backend/models/hog_flow/hog_flow.py b/products/workflows/backend/models/hog_flow/hog_flow.py
index 45594ac1693b..3f12e713a5d6 100644
--- a/products/workflows/backend/models/hog_flow/hog_flow.py
+++ b/products/workflows/backend/models/hog_flow/hog_flow.py
@@ -161,6 +161,20 @@ class HogFlow(UUIDTModel):
# Enforced per workflow by the email worker, which spreads sends instead of dropping them.
email_sending_rate_limit = models.JSONField(null=True, blank=True)
+ # Automatic per-workflow email pause, set by the deliverability detector when this workflow's
+ # complaint or hard-bounce rate crosses a threshold. All workflow email shares one SES account,
+ # so one bad workflow degrades every customer's deliverability. Enforced at the send choke point
+ # in the email worker. Only the resume endpoint (or a staff admin action) clears it; a normal
+ # workflow update must not, so the API exposes these read-only.
+ email_sending_paused_at = models.DateTimeField(null=True, blank=True)
+ email_sending_paused_reason = models.TextField(blank=True, default="", db_default="")
+ # Start bound for every detector window on this workflow. Without it, resuming instantly
+ # re-trips on the feedback that caused the pause in the first place.
+ email_sending_resumed_at = models.DateTimeField(null=True, blank=True)
+ # When the deliverability detector last warned this workflow's admins that its rates are
+ # approaching the pause thresholds. Bounds how often the warning email can repeat.
+ email_sending_warned_at = models.DateTimeField(null=True, blank=True)
+
edges = models.JSONField(default=dict)
actions = models.JSONField(default=dict)
# Secret function inputs (schema fields marked secret, e.g. API keys / auth headers) split out of
diff --git a/products/workflows/backend/test/test_hog_flow.py b/products/workflows/backend/test/test_hog_flow.py
index 9c87d74f42cb..dcecd349385a 100644
--- a/products/workflows/backend/test/test_hog_flow.py
+++ b/products/workflows/backend/test/test_hog_flow.py
@@ -2,6 +2,7 @@ from unittest.mock import patch
from django.core.management import call_command
from django.test import TestCase
+from django.utils import timezone
from posthog.models.user import User
@@ -34,6 +35,19 @@ class TestHogFlow(TestCase):
hog_flow.save(update_fields=["draft", "name"])
mock_reload.assert_called_once_with(team_id=self.team.id, hog_flow_ids=[str(hog_flow.id)])
+ @patch("products.workflows.backend.models.hog_flow.hog_flow.reload_hog_flows_on_workers")
+ def test_email_pause_save_reloads_the_workers(self, mock_reload):
+ # The worker enforces the pause off its cached config, so a pause that does not publish a
+ # reload lets in-flight runs and queued batch sends keep sending for the cache's lifetime.
+ hog_flow = HogFlow.objects.create(name="Test Flow", team=self.team)
+ mock_reload.reset_mock()
+
+ hog_flow.email_sending_paused_at = timezone.now()
+ hog_flow.email_sending_paused_reason = "Spam complaints reached 2%."
+ hog_flow.save(update_fields=["email_sending_paused_at", "email_sending_paused_reason"])
+
+ mock_reload.assert_called_once_with(team_id=self.team.id, hog_flow_ids=[str(hog_flow.id)])
+
@patch("products.workflows.backend.tasks.hog_flows.refresh_affected_hog_flows.delay")
def test_action_saved_receiver(self, mock_refresh):
action = Action.objects.create(team=self.team, name="Test Action")