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(notifications): dispatch approval_resolved realtime notifications (#56154)

Yasen92f7399b0140
diff --git a/posthog/approvals/notifications.py b/posthog/approvals/notifications.py
index a7c374967ece..027d04b64611 100644
--- a/posthog/approvals/notifications.py
+++ b/posthog/approvals/notifications.py
@@ -78,6 +78,32 @@ def _dispatch_realtime_requested(change_request: "ChangeRequest") -> None:
)
+def _dispatch_realtime_resolved(change_request: "ChangeRequest", *, title: str, body: str) -> None:
+ if not change_request.created_by_id:
+ return
+ try:
+ create_notification(
+ NotificationData(
+ team_id=change_request.team_id,
+ notification_type=NotificationType.APPROVAL_RESOLVED,
+ priority=Priority.NORMAL,
+ title=title[:100],
+ body=body[:200],
+ target_type=TargetType.USER,
+ target_id=str(change_request.created_by_id),
+ resource_type=NotificationOnlyResourceType.APPROVAL,
+ resource_id=str(change_request.id),
+ source_url=f"/project/{change_request.team.project_id}/approvals/{change_request.id}",
+ )
+ )
+ except Exception as e:
+ logger.exception(
+ "send_approval_resolved_notification.realtime_failed",
+ change_request_id=str(change_request.id),
+ error=str(e),
+ )
+
+
def _send_approval_email(
recipient: User,
template_name: str,
@@ -204,6 +230,10 @@ def send_approval_decision_notification(
error=str(e),
)
+ summary = _change_summary(change_request)
+ realtime_body = summary if is_approved else f"Declined by {approver_name} — {summary}"
+ _dispatch_realtime_resolved(change_request, title=subject, body=realtime_body)
+
def send_approval_expired_notification(change_request: "ChangeRequest") -> None:
"""
@@ -230,19 +260,25 @@ def send_approval_expired_notification(change_request: "ChangeRequest") -> None:
error=str(e),
)
+ _dispatch_realtime_resolved(
+ change_request,
+ title="Your change request expired",
+ body=_change_summary(change_request),
+ )
+
def send_approval_applied_notification(change_request: "ChangeRequest") -> None:
"""
Notify the requester that their change request has been successfully applied.
"""
- try:
- if not change_request.created_by:
- logger.info(
- "send_approval_applied_notification.no_requester",
- change_request_id=str(change_request.id),
- )
- return
+ if not change_request.created_by:
+ logger.info(
+ "send_approval_applied_notification.no_requester",
+ change_request_id=str(change_request.id),
+ )
+ return
+ try:
_send_approval_email(
recipient=change_request.created_by,
template_name="approval_applied",
@@ -255,3 +291,9 @@ def send_approval_applied_notification(change_request: "ChangeRequest") -> None:
change_request_id=str(change_request.id),
error=str(e),
)
+
+ _dispatch_realtime_resolved(
+ change_request,
+ title="Your change is now live",
+ body=_change_summary(change_request),
+ )
diff --git a/posthog/approvals/tests/test_notifications.py b/posthog/approvals/tests/test_notifications.py
index 3284926d8853..56464cddc050 100644
--- a/posthog/approvals/tests/test_notifications.py
+++ b/posthog/approvals/tests/test_notifications.py
@@ -51,6 +51,16 @@ class TestApprovalNotifications(BaseTest):
expires_at=timezone.now() + timedelta(days=14),
)
+ def _create_change_request_with_approvers(self, _approvers: list) -> ChangeRequest:
+ return self.change_request
+
+ def _create_approval(self, change_request: ChangeRequest, decision: str = "approved") -> Approval:
+ return Approval.objects.create(
+ change_request=change_request,
+ created_by=self.approver,
+ decision=decision,
+ )
+
class TestCustomerIOTemplateIDs(TestApprovalNotifications):
def test_all_approval_templates_have_customer_io_ids(self):
@@ -471,3 +481,84 @@ class TestEmailTemplateRendering(TestApprovalNotifications):
self.assertIn(
expected_cta, message.html_body, f"Template {template_name} should have CTA button '{expected_cta}'"
)
+
+
+class TestRealtimeDispatchOnResolve(TestApprovalNotifications):
+ @patch("posthog.approvals.notifications.create_notification")
+ @patch("posthog.approvals.notifications._send_approval_email")
+ def test_decision_approved_dispatches_realtime(self, _mock_email, mock_create_notification):
+ approval = self._create_approval(self.change_request, decision="approved")
+
+ send_approval_decision_notification(self.change_request, approval)
+
+ data = mock_create_notification.call_args.args[0]
+ assert data.notification_type.value == "approval_resolved"
+ assert "approved" in data.title.lower()
+ assert data.target_id == str(self.user.id)
+ assert data.resource_type.value == "approval"
+ assert data.source_url == f"/project/{self.team.project_id}/approvals/{self.change_request.id}"
+
+ @patch("posthog.approvals.notifications.create_notification")
+ @patch("posthog.approvals.notifications._send_approval_email")
+ def test_decision_rejected_dispatches_realtime(self, _mock_email, mock_create_notification):
+ approval = self._create_approval(self.change_request, decision="rejected")
+
+ send_approval_decision_notification(self.change_request, approval)
+
+ data = mock_create_notification.call_args.args[0]
+ assert "declined" in data.title.lower()
+
+ @patch("posthog.approvals.notifications.create_notification")
+ @patch("posthog.approvals.notifications._send_approval_email")
+ def test_applied_dispatches_realtime(self, _mock_email, mock_create_notification):
+ send_approval_applied_notification(self.change_request)
+
+ data = mock_create_notification.call_args.args[0]
+ assert "live" in data.title.lower()
+
+ @patch("posthog.approvals.notifications.create_notification")
+ @patch("posthog.approvals.notifications._send_approval_email")
+ def test_expired_dispatches_realtime(self, _mock_email, mock_create_notification):
+ send_approval_expired_notification(self.change_request)
+
+ data = mock_create_notification.call_args.args[0]
+ assert "expired" in data.title.lower()
+
+ @patch("posthog.approvals.notifications.create_notification")
+ @patch("posthog.approvals.notifications._send_approval_email")
+ def test_skips_realtime_when_no_requester(self, _mock_email, mock_create_notification):
+ self.change_request.created_by = None
+ self.change_request.save()
+
+ send_approval_applied_notification(self.change_request)
+ send_approval_expired_notification(self.change_request)
+
+ mock_create_notification.assert_not_called()
+
+ @patch("posthog.approvals.notifications.create_notification")
+ @patch("posthog.approvals.notifications._send_approval_email")
+ def test_email_failure_does_not_block_realtime(self, mock_email, mock_create_notification):
+ mock_email.side_effect = RuntimeError("smtp down")
+
+ send_approval_applied_notification(self.change_request)
+
+ mock_create_notification.assert_called_once()
+
+ @patch("posthog.approvals.notifications.create_notification")
+ @patch("posthog.approvals.notifications._send_approval_email")
+ def test_body_uses_intent_display_description(self, _mock_email, mock_create_notification):
+ send_approval_applied_notification(self.change_request)
+
+ data = mock_create_notification.call_args.args[0]
+ assert data.body == "Update rollout to 50%"
+
+ @patch("posthog.approvals.notifications.create_notification")
+ @patch("posthog.approvals.notifications._send_approval_email")
+ def test_body_falls_back_to_action_key_when_no_description(self, _mock_email, mock_create_notification):
+ self.change_request.intent_display = {}
+ self.change_request.save()
+
+ send_approval_applied_notification(self.change_request)
+
+ data = mock_create_notification.call_args.args[0]
+ assert data.body == self.change_request.action_key
diff --git a/products/notifications/backend/facade/enums.py b/products/notifications/backend/facade/enums.py
index d5462ec031b0..c2701d39f474 100644
--- a/products/notifications/backend/facade/enums.py
+++ b/products/notifications/backend/facade/enums.py
@@ -10,6 +10,7 @@ class NotificationType(str, Enum):
ALERT_FIRING = "alert_firing"
ISSUE_ASSIGNED = "issue_assigned"
APPROVAL_REQUESTED = "approval_requested"
+ APPROVAL_RESOLVED = "approval_resolved"
class Priority(str, Enum):
diff --git a/products/notifications/backend/migrations/0008_alter_notificationevent_notification_type.py b/products/notifications/backend/migrations/0008_alter_notificationevent_notification_type.py
new file mode 100644
index 000000000000..2466c7123bc7
--- /dev/null
+++ b/products/notifications/backend/migrations/0008_alter_notificationevent_notification_type.py
@@ -0,0 +1,26 @@
+# Generated by Django 5.2.13 on 2026-05-06 09:04
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ("notifications", "0007_alter_notificationevent_notification_type"),
+ ]
+
+ operations = [
+ migrations.AlterField(
+ model_name="notificationevent",
+ name="notification_type",
+ field=models.CharField(
+ choices=[
+ ("comment_mention", "COMMENT_MENTION"),
+ ("alert_firing", "ALERT_FIRING"),
+ ("issue_assigned", "ISSUE_ASSIGNED"),
+ ("approval_requested", "APPROVAL_REQUESTED"),
+ ("approval_resolved", "APPROVAL_RESOLVED"),
+ ],
+ max_length=32,
+ ),
+ ),
+ ]
diff --git a/products/notifications/backend/migrations/max_migration.txt b/products/notifications/backend/migrations/max_migration.txt
index 1bf1c5238a6c..ed9c42310dcc 100644
--- a/products/notifications/backend/migrations/max_migration.txt
+++ b/products/notifications/backend/migrations/max_migration.txt
@@ -1 +1 @@
-0007_alter_notificationevent_notification_type
+0008_alter_notificationevent_notification_type