: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(alerts): push platform alert inventory every 5 minutes (#122626)
Jon McCallum19e9b11c080b
diff --git a/docs/internal/alerts-platform-temporal.md b/docs/internal/alerts-platform-temporal.mdindex 4b49a4d491ec..3d66f5fd84d6 100644--- a/docs/internal/alerts-platform-temporal.md+++ b/docs/internal/alerts-platform-temporal.md@@ -155,6 +155,9 @@ Registration never deletes a schedule, so the rollout above deletes the old ID bOne tick is one `alerts-platform-orchestrate` execution. It takes an `OrchestrateInputs`; the schedule passes `{}` and every field defaults.The first run records the tick cutoff (the scheduled start time, or the workflow start time for manual runs) and a deadline 45 seconds after the run started.Discovery runs once per tick. The loop then starts one `alerts-platform-source-dispatch` child per source with demand, ID `{tick_id}-{source}-p{page}`, on the orchestration queue.+The tick does not record inventory. A separate schedule, `alerts-platform-record-inventory-schedule`, starts the `alerts-platform-record-inventory` workflow every 5 minutes on the orchestration queue at the lowest Temporal priority.+It counts configurations and alerts for every source in two queries, each with a 500 ms statement timeout, and pushes the `alerts_platform_configurations` and `alerts_platform_alerts` gauges to the PushGateway under the `alerts_platform_inventory` job.+The push replaces the job's group, so the region holds one series per label set. A failed count is logged and the next run tries again.Dispatchers are part of the tick: the orchestrator awaits each dispatcher's report and keeps the default `TERMINATE` close policy on that edge.They run on the tick's own fleet because the tick awaits them. On the evaluation queue, an evaluation fleet with no free slotsleaves the dispatcher unpicked, and the tick waits on a report that cannot arrive. A dispatcher starts no activities,diff --git a/posthog/metrics.py b/posthog/metrics.pyindex c19096a1e584..ec1f2511e1fe 100644--- a/posthog/metrics.py+++ b/posthog/metrics.py@@ -84,7 +84,7 @@ def push_registry(job_name: str, registry: CollectorRegistry, *, replace_group:@contextmanager-def pushed_metrics_registry(job_name: str) -> Iterator[CollectorRegistry]:+def pushed_metrics_registry(job_name: str, *, timeout: float = 30) -> Iterator[CollectorRegistry]:"""Return a temporary Prometheus registry that will be pushed to thePushGateway when the context closes.@@ -101,4 +101,4 @@ def pushed_metrics_registry(job_name: str) -> Iterator[CollectorRegistry]:registry = CollectorRegistry()yield registry- push_registry(job_name, registry, replace_group=True)+ push_registry(job_name, registry, replace_group=True, timeout=timeout)diff --git a/posthog/temporal/schedule.py b/posthog/temporal/schedule.pyindex 9cde1c577cb6..93e870daa291 100644--- a/posthog/temporal/schedule.py+++ b/posthog/temporal/schedule.py@@ -79,7 +79,10 @@ from posthog.temporal.warehouse_sources_queue_partition_management.schedule impo)from posthog.temporal.weekly_digest.types import WeeklyDigestInput-from products.alerts_platform.backend.facade.temporal import create_alerts_platform_tick_schedule+from products.alerts_platform.backend.facade.temporal import (+ create_alerts_platform_inventory_schedule,+ create_alerts_platform_tick_schedule,+)from products.autoresearch.backend.facade.temporal import create_autoresearch_daily_schedulefrom products.billing_alerts.backend.temporal.schedule import create_schedule_due_billing_alert_checks_schedulefrom products.business_knowledge.backend.temporal.schedule import (@@ -991,6 +994,7 @@ schedules = [create_heatmap_page_history_schedule,create_data_catalog_weekly_digest_schedule,create_alerts_platform_tick_schedule,+ create_alerts_platform_inventory_schedule,create_logs_alert_check_schedule,disable_logs_volume_tick_schedule,create_schedule_due_alert_checks_schedule,diff --git a/products/alerts_platform/backend/facade/temporal.py b/products/alerts_platform/backend/facade/temporal.pyindex ed10cc6530af..ad9891d7cc0b 100644--- a/products/alerts_platform/backend/facade/temporal.py+++ b/products/alerts_platform/backend/facade/temporal.py@@ -2,7 +2,10 @@ from products.alerts_platform.backend.temporal.metrics import (ALERTS_PLATFORM_LATENCY_HISTOGRAM_BUCKETS,ALERTS_PLATFORM_LATENCY_HISTOGRAM_METRICS,)-from products.alerts_platform.backend.temporal.schedule import create_alerts_platform_tick_schedule+from products.alerts_platform.backend.temporal.schedule import (+ create_alerts_platform_inventory_schedule,+ create_alerts_platform_tick_schedule,+)from products.alerts_platform.backend.temporal.sources import source_evaluation_timeoutfrom products.alerts_platform.backend.temporal.telemetry import AlertsPlatformTelemetryInterceptorfrom products.alerts_platform.backend.temporal.workflows import (@@ -27,6 +30,7 @@ __all__ = ["SHARED_ORCHESTRATION_ACTIVITIES","SHARED_ORCHESTRATION_WORKFLOWS","AlertsPlatformTelemetryInterceptor",+ "create_alerts_platform_inventory_schedule","create_alerts_platform_tick_schedule","source_evaluation_timeout","start_deliveries",diff --git a/products/alerts_platform/backend/logic/inventory.py b/products/alerts_platform/backend/logic/inventory.pynew file mode 100644index 000000000000..96300c804aa6--- /dev/null+++ b/products/alerts_platform/backend/logic/inventory.py@@ -0,0 +1,72 @@+"""How many platform alerts exist and what state they are in, across every team.++Counted once a tick for the worker health dashboard. Every source and label+combination is returned, zeros included, because a gauge keeps its last value until it is set again.+"""++import datetime as dt++from django.db.models import Count, Q++from posthog.dataclasses import frozen+from posthog.models.utils import execute_with_timeout++from products.alerts_platform.backend.facade.contracts import SourceKind+from products.alerts_platform.backend.facade.enums import PlatformAlertState+from products.alerts_platform.backend.models import PlatformAlert, PlatformAlertConfiguration++# Per statement. The counts scan every configuration, unlike discovery, which reads only the due index,+# so a slow scan fails fast and holds no Postgres connection the tick needs.+INVENTORY_STATEMENT_TIMEOUT_MS = 500+++@frozen+class AlertCount:+ state: PlatformAlertState+ muted: bool+ count: int+++@frozen+class SourceInventory:+ source: SourceKind+ enabled_configurations: int+ disabled_configurations: int+ alerts: tuple[AlertCount, ...]+++def count_inventory(now: dt.datetime) -> tuple[SourceInventory, ...]:+ # Cross-team by definition, like demand discovery. Both queries are evaluated inside the block,+ # because the timeout is transaction-local.+ with execute_with_timeout(INVENTORY_STATEMENT_TIMEOUT_MS):+ configuration_counts = {+ (row["source_kind"], row["enabled"]): row["n"]+ for row in PlatformAlertConfiguration.objects.unscoped()+ .values("source_kind", "enabled")+ .annotate(n=Count("id"))+ }+ is_muted = Q(snooze_until__gt=now) | Q(configuration__snooze_until__gt=now)+ alert_counts = {+ (row["configuration__source_kind"], row["state"]): (row["total"], row["muted"])+ for row in PlatformAlert.objects.unscoped()+ .filter(configuration__enabled=True)+ .values("configuration__source_kind", "state")+ .annotate(total=Count("id"), muted=Count("id", filter=is_muted))+ }++ inventories: list[SourceInventory] = []+ for source in SourceKind:+ alerts: list[AlertCount] = []+ for state in PlatformAlertState:+ total, muted_count = alert_counts.get((source.value, state.value), (0, 0))+ alerts.append(AlertCount(state=state, muted=True, count=muted_count))+ alerts.append(AlertCount(state=state, muted=False, count=total - muted_count))+ inventories.append(+ SourceInventory(+ source=source,+ enabled_configurations=configuration_counts.get((source.value, True), 0),+ disabled_configurations=configuration_counts.get((source.value, False), 0),+ alerts=tuple(alerts),+ )+ )+ return tuple(inventories)diff --git a/products/alerts_platform/backend/temporal/inventory_metrics.py b/products/alerts_platform/backend/temporal/inventory_metrics.pynew file mode 100644index 000000000000..6bdb9e658bdd--- /dev/null+++ b/products/alerts_platform/backend/temporal/inventory_metrics.py@@ -0,0 +1,40 @@+"""Inventory gauges for the worker health dashboard.++Pushed to the PushGateway rather than exported through Temporal's meter, so the region holds one+series per label set and no worker replica keeps an older count. The PushGateway's+`push_time_seconds` for the job shows how fresh the counts are.+"""++from collections.abc import Sequence++from prometheus_client import Gauge++from posthog.metrics import pushed_metrics_registry++from products.alerts_platform.backend.logic.inventory import SourceInventory++# The timeout applies to the connect and to the response separately, so a stalled PushGateway+# holds the push for up to 10 seconds. That stays inside the 20-second activity timeout.+PUSH_TIMEOUT_SECONDS = 5+++def push_inventory(inventories: Sequence[SourceInventory]) -> None:+ with pushed_metrics_registry("alerts_platform_inventory", timeout=PUSH_TIMEOUT_SECONDS) as registry:+ configurations = Gauge(+ "alerts_platform_configurations",+ "Platform alert configurations, by source and whether they are enabled",+ ["source", "enabled"],+ registry=registry,+ )+ alerts = Gauge(+ "alerts_platform_alerts",+ "Runtime rows of enabled platform alert configurations, by state and whether they are muted",+ ["source", "state", "muted"],+ registry=registry,+ )+ for inventory in inventories:+ source = inventory.source.value+ configurations.labels(source=source, enabled="true").set(inventory.enabled_configurations)+ configurations.labels(source=source, enabled="false").set(inventory.disabled_configurations)+ for alert in inventory.alerts:+ alerts.labels(source=source, state=alert.state.value, muted=str(alert.muted).lower()).set(alert.count)diff --git a/products/alerts_platform/backend/temporal/schedule.py b/products/alerts_platform/backend/temporal/schedule.pyindex 0c4b6ec3e1a6..1f58f047bdc8 100644--- a/products/alerts_platform/backend/temporal/schedule.py+++ b/products/alerts_platform/backend/temporal/schedule.py@@ -4,7 +4,7 @@ from typing import TYPE_CHECKINGfrom django.conf import settingsfrom temporalio.client import Schedule, ScheduleActionStartWorkflow, ScheduleOverlapPolicy, SchedulePolicy, ScheduleSpec-from temporalio.common import RetryPolicy+from temporalio.common import Priority, RetryPolicyfrom posthog.temporal.common.schedule import a_create_schedule, a_schedule_exists, a_update_schedule@@ -12,6 +12,7 @@ if TYPE_CHECKING:from temporalio.client import ClientSCHEDULE_ID = "alerts-platform-check-due-schedule"+INVENTORY_SCHEDULE_ID = "alerts-platform-record-inventory-schedule"async def create_alerts_platform_tick_schedule(client: "Client") -> None:@@ -28,10 +29,32 @@ async def create_alerts_platform_tick_schedule(client: "Client") -> None: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()+ await _create_or_update(client, SCHEDULE_ID, schedule)+++async def create_alerts_platform_inventory_schedule(client: "Client") -> None:+ schedule = Schedule(+ action=ScheduleActionStartWorkflow(+ "alerts-platform-record-inventory",+ {},+ id=INVENTORY_SCHEDULE_ID,+ task_queue=settings.ALERTS_PLATFORM_SHARED_ORCHESTRATION_TASK_QUEUE,+ execution_timeout=dt.timedelta(seconds=30),+ retry_policy=RetryPolicy(maximum_attempts=1),+ # Lowest Temporal priority, so the count never takes a slot ahead of a tick or a dispatcher.+ priority=Priority(priority_key=5),+ ),+ spec=ScheduleSpec(cron_expressions=["*/5 * * * *"]),+ policy=SchedulePolicy(overlap=ScheduleOverlapPolicy.SKIP, catchup_window=dt.timedelta(minutes=1)),+ )+ await _create_or_update(client, INVENTORY_SCHEDULE_ID, schedule)+++async def _create_or_update(client: "Client", schedule_id: str, schedule: Schedule) -> None:+ if await a_schedule_exists(client, schedule_id):+ description = await client.get_schedule_handle(schedule_id).describe()# nosemgrep: insight-alert-state-direct-mutation,platform-alert-state-direct-mutation (Temporal schedule state, not an alert)schedule.state = description.schedule.state- await a_update_schedule(client, SCHEDULE_ID, schedule)+ await a_update_schedule(client, schedule_id, schedule)else:- await a_create_schedule(client, SCHEDULE_ID, schedule, trigger_immediately=False)+ await a_create_schedule(client, schedule_id, schedule, trigger_immediately=False)diff --git a/products/alerts_platform/backend/temporal/workflows.py b/products/alerts_platform/backend/temporal/workflows.pyindex 9f0bf83e04de..608b20b16ad6 100644--- a/products/alerts_platform/backend/temporal/workflows.py+++ b/products/alerts_platform/backend/temporal/workflows.py@@ -50,6 +50,8 @@ with workflow.unsafe.imports_passed_through():TickPage,)from products.alerts_platform.backend.logic.demand import discover_demand+ from products.alerts_platform.backend.logic.inventory import count_inventory+ from products.alerts_platform.backend.temporal.inventory_metrics import push_inventoryfrom products.alerts_platform.backend.temporal.postgres import check_postgres_connectionfrom products.alerts_platform.backend.temporal.sources import SOURCE_BINDINGS, discovery_limits@@ -108,6 +110,19 @@ async def alerts_platform_discover_demand_activity(inputs: DemandDiscoveryInputsreturn demand+async def alerts_platform_record_inventory_activity() -> None:+ """A failed count is logged rather than raised, so a slow count never reads as a failed workflow."""+ now = dt.datetime.now(dt.UTC)+ try:+ inventories = await database_sync_to_async_pool(count_inventory)(now)+ except Exception as error:+ await LOGGER.awarning("alerts_platform_inventory_failed", error=str(error))+ return+ # A failed push is logged and captured inside `push_registry`, never raised.+ await asyncio.to_thread(push_inventory, inventories)++@activity.defnasync def alerts_platform_probe_postgres_activity() -> None:try:@@ -393,6 +408,20 @@ class AlertsPlatformSourceDispatchWorkflow(PostHogWorkflow):)[email protected](name="alerts-platform-record-inventory")+class AlertsPlatformRecordInventoryWorkflow(PostHogWorkflow):+ inputs_cls = AlertsPlatformInputs+ inputs_optional = True++ @workflow.run+ async def run(self, inputs: AlertsPlatformInputs) -> None:+ await workflow.execute_activity(+ alerts_platform_record_inventory_activity,+ start_to_close_timeout=dt.timedelta(seconds=20),+ retry_policy=RetryPolicy(maximum_attempts=1),+ )++def _should_continue_as_new() -> bool:return workflow.info().is_continue_as_new_suggested()@@ -525,8 +554,12 @@ class AlertsPlatformOrchestrateWorkflow(PostHogWorkflow):SHARED_ORCHESTRATION_WORKFLOWS: list[type[PostHogWorkflow]] = [AlertsPlatformOrchestrateWorkflow,AlertsPlatformSourceDispatchWorkflow,+ AlertsPlatformRecordInventoryWorkflow,+]+SHARED_ORCHESTRATION_ACTIVITIES: list[Callable[..., object]] = [+ alerts_platform_discover_demand_activity,+ alerts_platform_record_inventory_activity,]-SHARED_ORCHESTRATION_ACTIVITIES: list[Callable[..., object]] = [alerts_platform_discover_demand_activity]EVALUATION_WORKFLOWS: list[type[PostHogWorkflow]] = [AlertsPlatformEvaluateWorkflow]EVALUATION_ACTIVITIES: list[Callable[..., object]] = [alerts_platform_probe_postgres_activity,diff --git a/products/alerts_platform/backend/tests/test_inventory.py b/products/alerts_platform/backend/tests/test_inventory.pynew file mode 100644index 000000000000..d786ead2b275--- /dev/null+++ b/products/alerts_platform/backend/tests/test_inventory.py@@ -0,0 +1,118 @@+from collections.abc import Callable+from datetime import UTC, datetime, timedelta++import pytest+from posthog.test.base import BaseTest+from unittest.mock import patch++from django.db import OperationalError, connection++from posthog.models import Team++from products.alerts_platform.backend.facade.contracts import SourceKind+from products.alerts_platform.backend.facade.enums import PlatformAlertState+from products.alerts_platform.backend.logic.inventory import AlertCount, SourceInventory, count_inventory+from products.alerts_platform.backend.models import PlatformAlert, PlatformAlertConfiguration+from products.alerts_platform.backend.temporal.inventory_metrics import push_inventory++NOW = datetime(2026, 10, 23, 12, tzinfo=UTC)+LATER = NOW + timedelta(hours=1)+EARLIER = NOW - timedelta(hours=1)+++class TestSourceInventory(BaseTest):+ def _configuration(+ self,+ team: Team,+ *,+ source: SourceKind = SourceKind.LOGS,+ enabled: bool = True,+ snooze_until: datetime | None = None,+ alerts: list[tuple[str, datetime | None]] | None = None,+ ) -> None:+ configuration = PlatformAlertConfiguration.objects.unscoped().create(+ team=team,+ name="alert",+ enabled=enabled,+ source_kind=source.value,+ source_config={},+ check_interval_minutes=5,+ snooze_until=snooze_until,+ )+ for index, (state, alert_snooze) in enumerate(alerts or []):+ PlatformAlert.objects.unscoped().create(+ team=team,+ configuration=configuration,+ grouping_key=str(index),+ state=state,+ snooze_until=alert_snooze,+ )++ def test_counts_each_source_across_teams_split_by_state_and_mute(self) -> None:+ other_team = Team.objects.create(organization=self.organization)+ self._configuration(+ self.team,+ alerts=[("firing", None), ("firing", LATER), ("not_firing", EARLIER)],+ )+ self._configuration(other_team, snooze_until=LATER, alerts=[("firing", None)])+ self._configuration(other_team, alerts=[("broken", None)])+ self._configuration(other_team, enabled=False, alerts=[("firing", None)])+ self._configuration(self.team, source=SourceKind.INSIGHT, alerts=[("firing", None)])++ by_source = {inventory.source: inventory for inventory in count_inventory(NOW)}++ assert set(by_source) == set(SourceKind)+ logs = by_source[SourceKind.LOGS]+ assert (logs.enabled_configurations, logs.disabled_configurations) == (3, 1)+ assert {(a.state.value, a.muted): a.count for a in logs.alerts if a.count} == {+ ("firing", False): 1,+ ("firing", True): 2,+ ("not_firing", False): 1,+ ("broken", False): 1,+ }+ assert len(logs.alerts) == len(PlatformAlertState) * 2+ insight = by_source[SourceKind.INSIGHT]+ assert (insight.enabled_configurations, insight.disabled_configurations) == (1, 0)+ assert {(a.state.value, a.muted): a.count for a in insight.alerts if a.count} == {("firing", False): 1}++ def test_a_slow_count_is_canceled_by_the_statement_timeout(self) -> None:+ def slow_count(+ execute: Callable[[str, object, bool, dict[str, object]], object],+ sql: str,+ params: object,+ many: bool,+ context: dict[str, object],+ ) -> object:+ if "COUNT(" in sql:+ return execute("SELECT pg_sleep(5)", None, False, context)+ return execute(sql, params, many, context)++ with (+ patch("products.alerts_platform.backend.logic.inventory.INVENTORY_STATEMENT_TIMEOUT_MS", 50),+ connection.execute_wrapper(slow_count),+ pytest.raises(OperationalError) as caught,+ ):+ count_inventory(NOW)++ assert getattr(caught.value.__cause__, "sqlstate", None) == "57014"+++def test_push_replaces_the_group_with_the_dashboard_labels() -> None:+ inventory = SourceInventory(+ source=SourceKind.LOGS,+ enabled_configurations=3,+ disabled_configurations=1,+ alerts=(AlertCount(state=PlatformAlertState.FIRING, muted=True, count=2),),+ )++ with patch("posthog.metrics.push_registry") as push:+ push_inventory([inventory])++ assert push.call_args.args[0] == "alerts_platform_inventory"+ assert push.call_args.kwargs == {"replace_group": True, "timeout": 5}+ registry = push.call_args.args[1]+ assert registry.get_sample_value("alerts_platform_configurations", {"source": "logs", "enabled": "true"}) == 3+ assert registry.get_sample_value("alerts_platform_configurations", {"source": "logs", "enabled": "false"}) == 1+ assert (+ registry.get_sample_value("alerts_platform_alerts", {"source": "logs", "state": "firing", "muted": "true"}) == 2+ )diff --git a/products/alerts_platform/backend/tests/test_temporal_schedule.py b/products/alerts_platform/backend/tests/test_temporal_schedule.pyindex 103461ea16bc..18f83adaad4d 100644--- a/products/alerts_platform/backend/tests/test_temporal_schedule.py+++ b/products/alerts_platform/backend/tests/test_temporal_schedule.py@@ -1,4 +1,5 @@import datetime as dt+from collections.abc import Awaitable, Callableimport pytestfrom unittest.mock import AsyncMock, MagicMock, patch@@ -6,15 +7,38 @@ from unittest.mock import AsyncMock, MagicMock, patchfrom django.test import override_settingsfrom temporalio.client import Client, ScheduleActionStartWorkflow, ScheduleOverlapPolicy, ScheduleState+from temporalio.common import Priority-from products.alerts_platform.backend.temporal.schedule import SCHEDULE_ID, create_alerts_platform_tick_schedule+from products.alerts_platform.backend.temporal.schedule import (+ INVENTORY_SCHEDULE_ID,+ SCHEDULE_ID,+ create_alerts_platform_inventory_schedule,+ create_alerts_platform_tick_schedule,+)MODULE = "products.alerts_platform.backend.temporal.schedule"+TICK = (create_alerts_platform_tick_schedule, SCHEDULE_ID, "alerts-platform-orchestrate", "* * * * *", 50, Priority())+INVENTORY = (+ create_alerts_platform_inventory_schedule,+ INVENTORY_SCHEDULE_ID,+ "alerts-platform-record-inventory",+ "*/5 * * * *",+ 30,+ Priority(priority_key=5),+)++@pytest.mark.asyncio[email protected]("target", [TICK, INVENTORY], ids=["tick", "inventory"])@pytest.mark.parametrize("already_exists, paused", [(False, False), (True, False), (True, True)])-async def test_schedule_creates_or_updates_with_bounded_policy(already_exists: bool, paused: bool) -> None:+async def test_schedule_creates_or_updates_with_bounded_policy(+ already_exists: bool,+ paused: bool,+ target: tuple[Callable[[Client], Awaitable[None]], str, str, str, int, Priority],+) -> None:+ create_schedule, schedule_id, workflow_name, cron, timeout_seconds, priority = targetclient = MagicMock(spec=Client)state = ScheduleState(paused=paused, note="Operator-controlled state")client.get_schedule_handle.return_value.describe = AsyncMock(@@ -30,33 +54,34 @@ async def test_schedule_creates_or_updates_with_bounded_policy(already_exists: bpatch(f"{MODULE}.a_create_schedule") as create,patch(f"{MODULE}.a_update_schedule") as update,):- await create_alerts_platform_tick_schedule(client)+ await create_schedule(client)- exists.assert_awaited_once_with(client, SCHEDULE_ID)+ exists.assert_awaited_once_with(client, schedule_id)called = update if already_exists else createunused = create if already_exists else updatecalled.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.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.actionassert isinstance(action, ScheduleActionStartWorkflow)- assert action.workflow == "alerts-platform-orchestrate"+ assert action.workflow == workflow_nameassert list(action.args) == [{}]- assert action.id == SCHEDULE_ID+ assert action.id == schedule_idassert action.task_queue == "orchestration-test-queue"- assert action.execution_timeout == dt.timedelta(seconds=50)+ assert action.execution_timeout == dt.timedelta(seconds=timeout_seconds)+ assert action.priority == priorityassert action.retry_policy is not Noneassert action.retry_policy.maximum_attempts == 1- assert schedule.spec.cron_expressions == ["* * * * *"]+ assert schedule.spec.cron_expressions == [cron]assert schedule.policy.overlap == ScheduleOverlapPolicy.SKIPassert schedule.policy.catchup_window == dt.timedelta(minutes=1)assert not schedule.policy.pause_on_failureassert schedule.state.paused is pausedif already_exists:- client.get_schedule_handle.assert_called_once_with(SCHEDULE_ID)+ client.get_schedule_handle.assert_called_once_with(schedule_id)client.get_schedule_handle.return_value.describe.assert_awaited_once()assert schedule.state == stateelse:diff --git a/products/alerts_platform/backend/tests/test_temporal_workflows.py b/products/alerts_platform/backend/tests/test_temporal_workflows.pyindex 3a0273edfd2a..e2138a1888f0 100644--- a/products/alerts_platform/backend/tests/test_temporal_workflows.py+++ b/products/alerts_platform/backend/tests/test_temporal_workflows.py@@ -638,6 +638,20 @@ class TestDemandDiscovery(APIBaseTest):demand.discover_demand(self.tick.isoformat(), limits_by_source={SourceKind.LOGS: 0})+async def test_a_failed_inventory_count_does_not_raise() -> None:+ with (+ patch.object(+ alert_workflows,+ "count_inventory",+ side_effect=OperationalError("canceling statement due to statement timeout"),+ ),+ patch.object(alert_workflows, "push_inventory") as push,+ ):+ await alert_workflows.alerts_platform_record_inventory_activity()++ push.assert_not_called()++@pytest.mark.parametrize("scheduled", [False, True])async def test_discovery_uses_scheduled_cutoff_or_manual_start(scheduled: bool) -> None:tick_time = dt.datetime(2026, 9, 16, 10, tzinfo=dt.UTC)