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(alerts): schedule dev evaluation smoke checks (#99141)

Jon McCallumd78546a2eba0
diff --git a/docs/internal/alerts-product-temporal.md b/docs/internal/alerts-product-temporal.md
index 69f444e11909..88ff475a65dc 100644
--- a/docs/internal/alerts-product-temporal.md
+++ b/docs/internal/alerts-product-temporal.md
@@ -20,7 +20,26 @@ The option defaults to 8001, which the shared development worker already binds,
The shared development worker does not poll these queues.
See [Temporal development guidance](../../posthog/temporal/README.md) for worker setup.
-No schedule exists yet, so start an evaluation run by hand.
+## Dev schedule
+
+`python manage.py schedule_temporal_workflows` creates or updates `alerts-product-check-due-schedule`
+only when `CLOUD_DEPLOYMENT=DEV`. The normal deployment migration step runs this command.
+Registration does nothing in production, local development, or other environments, even with `DEBUG=True`.
+It does not delete schedules created manually in those environments.
+
+The schedule starts `alerts-product-check-due` with `{}` on the evaluation queue every minute (UTC).
+It uses SKIP overlap, a one-minute catchup window, a 50-second workflow execution timeout,
+and one workflow attempt. Creation does not trigger an immediate run; the next minute starts it.
+Delivery has no schedule: evaluation starts its delivery child.
+New schedules start unpaused. Registration updates existing schedules to this policy while retaining their state from Temporal, including manual pauses.
+To stop future smoke-test ticks, pause the schedule in Temporal; resume it there when ready. Pausing does not stop workflows already running.
+Disabling registration alone does not remove an existing Temporal schedule.
+
+Verify the Postgres activity result and the delivery child's completion separately.
+Parent completion does not prove either succeeded. Schedule creation also does not prove worker availability.
+Enable production only in a separate rollout after dev verification.
+
+For local development, start an evaluation run by hand.
The `execute_temporal_workflow` and `start_temporal_workflow` commands do not know these workflows and reject the name, so use the Temporal CLI in the dev stack:
```bash
@@ -78,8 +97,8 @@ Verify a successful probe, statement timeout and transaction reset through the c
`SELECT 1` alone does not verify the intended database identity, application grants, schema, or write readiness.
These tests do not replace deployment verification.
-This registration does not create schedules or deploy workers.
-Schedule registration will set the evaluation workflow's 50-second execution timeout separately.
+Worker registration does not deploy workers. The dev schedule sets the evaluation workflow's
+50-second execution timeout; manually started workflows must set their own timeout.
## Activity logs
diff --git a/posthog/temporal/schedule.py b/posthog/temporal/schedule.py
index 3eee32007b8a..cd8af3c413b2 100644
--- a/posthog/temporal/schedule.py
+++ b/posthog/temporal/schedule.py
@@ -78,6 +78,7 @@ from posthog.temporal.warehouse_sources_queue_partition_management.schedule impo
)
from posthog.temporal.weekly_digest.types import WeeklyDigestInput
+from products.alerts.backend.facade.temporal import create_alerts_product_check_due_schedule
from products.billing_alerts.backend.temporal.schedule import create_schedule_due_billing_alert_checks_schedule
from products.business_knowledge.backend.temporal.schedule import create_business_knowledge_refresh_coordinator_schedule
from products.context_layer.backend.temporal.schedule import create_context_layer_dream_schedule
@@ -924,6 +925,7 @@ schedules = [
create_error_tracking_weekly_digest_schedule,
create_wa_weekly_digest_schedule,
create_wa_digest_notification_schedule,
+ create_alerts_product_check_due_schedule,
create_logs_alert_check_schedule,
create_logs_volume_tick_schedule,
create_schedule_due_alert_checks_schedule,
diff --git a/products/alerts/backend/facade/temporal.py b/products/alerts/backend/facade/temporal.py
index f5b56bf9917e..3121192308f2 100644
--- a/products/alerts/backend/facade/temporal.py
+++ b/products/alerts/backend/facade/temporal.py
@@ -1,3 +1,4 @@
+from products.alerts.backend.temporal.schedule import create_alerts_product_check_due_schedule
from products.alerts.backend.temporal.telemetry import AlertsProductTelemetryInterceptor
from products.alerts.backend.temporal.workflows import (
DELIVERY_ACTIVITIES,
@@ -12,4 +13,5 @@ __all__ = [
"EVALUATION_ACTIVITIES",
"EVALUATION_WORKFLOWS",
"AlertsProductTelemetryInterceptor",
+ "create_alerts_product_check_due_schedule",
]
diff --git a/products/alerts/backend/temporal/schedule.py b/products/alerts/backend/temporal/schedule.py
new file mode 100644
index 000000000000..a5cc283a904f
--- /dev/null
+++ b/products/alerts/backend/temporal/schedule.py
@@ -0,0 +1,39 @@
+import datetime as dt
+from typing import TYPE_CHECKING
+
+from django.conf import settings
+
+from temporalio.client import Schedule, ScheduleActionStartWorkflow, ScheduleOverlapPolicy, SchedulePolicy, ScheduleSpec
+from temporalio.common import RetryPolicy
+
+from posthog.temporal.common.schedule import a_create_schedule, a_schedule_exists, a_update_schedule
+
+if TYPE_CHECKING:
+ from temporalio.client import Client
+
+SCHEDULE_ID = "alerts-product-check-due-schedule"
+
+
+async def create_alerts_product_check_due_schedule(client: "Client") -> None:
+ if settings.CLOUD_DEPLOYMENT != "DEV":
+ return
+
+ schedule = Schedule(
+ action=ScheduleActionStartWorkflow(
+ "alerts-product-check-due",
+ {},
+ id=SCHEDULE_ID,
+ task_queue=settings.ALERTS_PRODUCT_EVALUATION_TASK_QUEUE,
+ execution_timeout=dt.timedelta(seconds=50),
+ retry_policy=RetryPolicy(maximum_attempts=1),
+ ),
+ spec=ScheduleSpec(cron_expressions=["* * * * *"]),
+ policy=SchedulePolicy(overlap=ScheduleOverlapPolicy.SKIP, catchup_window=dt.timedelta(minutes=1)),
+ )
+
+ if await a_schedule_exists(client, SCHEDULE_ID):
+ description = await client.get_schedule_handle(SCHEDULE_ID).describe()
+ schedule.state = description.schedule.state
+ await a_update_schedule(client, SCHEDULE_ID, schedule)
+ else:
+ await a_create_schedule(client, SCHEDULE_ID, schedule, trigger_immediately=False)
diff --git a/products/alerts/backend/tests/test_temporal_schedule.py b/products/alerts/backend/tests/test_temporal_schedule.py
new file mode 100644
index 000000000000..427079021bf2
--- /dev/null
+++ b/products/alerts/backend/tests/test_temporal_schedule.py
@@ -0,0 +1,76 @@
+import datetime as dt
+
+import pytest
+from unittest.mock import AsyncMock, MagicMock, patch
+
+from django.test import override_settings
+
+from temporalio.client import Client, ScheduleActionStartWorkflow, ScheduleOverlapPolicy, ScheduleState
+
+from products.alerts.backend.temporal.schedule import SCHEDULE_ID, create_alerts_product_check_due_schedule
+
+MODULE = "products.alerts.backend.temporal.schedule"
+
+
[email protected]("deployment", ["US", "EU", "E2E", "", None])
+async def test_schedule_does_not_access_temporal_outside_dev(deployment: str | None) -> None:
+ client = MagicMock(spec=Client)
+ with (
+ override_settings(CLOUD_DEPLOYMENT=deployment, DEBUG=True),
+ patch(f"{MODULE}.a_schedule_exists") as exists,
+ patch(f"{MODULE}.a_create_schedule") as create,
+ patch(f"{MODULE}.a_update_schedule") as update,
+ ):
+ await create_alerts_product_check_due_schedule(client)
+ exists.assert_not_awaited()
+ create.assert_not_awaited()
+ update.assert_not_awaited()
+ assert client.mock_calls == []
+
+
[email protected]("already_exists, paused", [(False, False), (True, False), (True, True)])
+async def test_dev_schedule_creates_or_updates_with_bounded_policy(already_exists: bool, paused: bool) -> None:
+ client = MagicMock(spec=Client)
+ state = ScheduleState(paused=paused, note="Operator-controlled state")
+ client.get_schedule_handle.return_value.describe = AsyncMock(
+ return_value=MagicMock(schedule=MagicMock(state=state))
+ )
+ with (
+ override_settings(CLOUD_DEPLOYMENT="DEV", ALERTS_PRODUCT_EVALUATION_TASK_QUEUE="evaluation-test-queue"),
+ patch(f"{MODULE}.a_schedule_exists", return_value=already_exists) as exists,
+ patch(f"{MODULE}.a_create_schedule") as create,
+ patch(f"{MODULE}.a_update_schedule") as update,
+ ):
+ await create_alerts_product_check_due_schedule(client)
+
+ exists.assert_awaited_once_with(client, SCHEDULE_ID)
+ called = update if already_exists else create
+ unused = create if already_exists else update
+ called.assert_awaited_once()
+ unused.assert_not_awaited()
+ assert called.await_args is not None
+ assert called.await_args.args[:2] == (client, SCHEDULE_ID)
+ assert called.await_args.kwargs == ({} if already_exists else {"trigger_immediately": False})
+ schedule = called.await_args.args[2]
+ action = schedule.action
+ assert isinstance(action, ScheduleActionStartWorkflow)
+ assert action.workflow == "alerts-product-check-due"
+ assert list(action.args) == [{}]
+ assert action.id == SCHEDULE_ID
+ assert action.task_queue == "evaluation-test-queue"
+ assert action.execution_timeout == dt.timedelta(seconds=50)
+ assert action.retry_policy is not None
+ assert action.retry_policy.maximum_attempts == 1
+ assert schedule.spec.cron_expressions == ["* * * * *"]
+ assert schedule.policy.overlap == ScheduleOverlapPolicy.SKIP
+ assert schedule.policy.catchup_window == dt.timedelta(minutes=1)
+ assert not schedule.policy.pause_on_failure
+ assert schedule.state.paused is paused
+ if already_exists:
+ client.get_schedule_handle.assert_called_once_with(SCHEDULE_ID)
+ client.get_schedule_handle.return_value.describe.assert_awaited_once()
+ assert schedule.state == state
+ else:
+ client.get_schedule_handle.assert_not_called()