: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
chore(product-analytics): move temporal code into the product (#97583)
Thomas Obermüller246969c75c55
diff --git a/.github/scripts/turbo-discover.js b/.github/scripts/turbo-discover.jsindex 8e47b13881ea..a2579a6a6f04 100644--- a/.github/scripts/turbo-discover.js+++ b/.github/scripts/turbo-discover.js@@ -873,10 +873,11 @@ const DJANGO_SEGMENTS = {'posthog/hogql/',],},- // batch-exports and tasks used to run their temporal suites here. They now run- // them in their own product jobs, which cost no extra infrastructure because- // every shard already starts the temporal profile. signals/emission is listed- // because select-tests routes it here; leaving it out under-counted the segment.+ // batch-exports, tasks and product-analytics used to run their temporal suites+ // here. They now run them in their own product jobs, which cost no extra+ // infrastructure because every shard already starts the temporal profile.+ // signals/emission is listed because select-tests routes it here; leaving it+ // out under-counted the segment.Temporal: {include: ['posthog/temporal/', 'products/signals/backend/emission/'],exclude: [],diff --git a/.github/workflows/container-images-cd.yml b/.github/workflows/container-images-cd.ymlindex 0908557737e5..e99109ef4026 100644--- a/.github/workflows/container-images-cd.yml+++ b/.github/workflows/container-images-cd.yml@@ -477,7 +477,7 @@ jobs:id: check_changes_general_purpose_temporal_workerrun: |# Changes to this detector must trigger once so newly covered code ships with the worker.- if git diff --name-only HEAD^ HEAD | grep -qE '^products/notebooks/backend/|^products/exports/backend/temporal/subscriptions|^products/engineering_analytics/backend/|^products/canvas/backend/|^posthog/llm/|^posthog/temporal/common|^posthog/temporal/dlq_replay|^posthog/temporal/session_recordings|^posthog/temporal/proxy_service|^posthog/temporal/(ai_observability|llm_analytics)|^posthog/temporal/product_analytics|^posthog/temporal/delete_persons|^posthog/temporal/delete_teams|^posthog/temporal/ingestion_acceptance_test|^posthog/temporal/backfill_group_type_created_at|^posthog/management/commands/start_temporal_worker.py$|^posthog/kafka_client/|^pyproject.toml$|^bin/temporal-django-worker$|^posthog/clickhouse/migrations/' \+ if git diff --name-only HEAD^ HEAD | grep -qE '^products/notebooks/backend/|^products/exports/backend/temporal/subscriptions|^products/engineering_analytics/backend/|^products/canvas/backend/|^posthog/llm/|^posthog/temporal/common|^posthog/temporal/dlq_replay|^posthog/temporal/session_recordings|^posthog/temporal/proxy_service|^posthog/temporal/(ai_observability|llm_analytics)|^products/product_analytics/backend/temporal/|^posthog/temporal/delete_persons|^posthog/temporal/delete_teams|^posthog/temporal/ingestion_acceptance_test|^posthog/temporal/backfill_group_type_created_at|^posthog/temporal/backfill_materialized_property|^posthog/management/commands/start_temporal_worker.py$|^posthog/kafka_client/|^pyproject.toml$|^bin/temporal-django-worker$|^posthog/clickhouse/migrations/' \|| git diff HEAD^ HEAD -- .github/workflows/container-images-cd.yml | grep -qE '^\+.*products/exports/backend/temporal/subscriptions'; thenecho "changed=true" >> $GITHUB_OUTPUTelsediff --git a/posthog/management/commands/start_temporal_worker.py b/posthog/management/commands/start_temporal_worker.pyindex cc7a9247fa8c..9fb409a84442 100644--- a/posthog/management/commands/start_temporal_worker.py+++ b/posthog/management/commands/start_temporal_worker.py@@ -37,6 +37,10 @@ from posthog.temporal.backfill_group_type_created_at import (ACTIVITIES as BACKFILL_GROUP_TYPE_CREATED_AT_ACTIVITIES,WORKFLOWS as BACKFILL_GROUP_TYPE_CREATED_AT_WORKFLOWS,)+from posthog.temporal.backfill_materialized_property import (+ ACTIVITIES as BACKFILL_MATERIALIZED_PROPERTY_ACTIVITIES,+ BackfillMaterializedPropertiesBatchWorkflow,+)from posthog.temporal.cleanup_property_definitions import (ACTIVITIES as CLEANUP_PROPDEFS_ACTIVITIES,WORKFLOWS as CLEANUP_PROPDEFS_WORKFLOWS,@@ -88,10 +92,6 @@ from posthog.temporal.mcp_analytics.intent_clustering import (MCP_ANALYTICS_INTENT_CLUSTERING_ACTIVITIES,MCP_ANALYTICS_INTENT_CLUSTERING_WORKFLOWS,)-from posthog.temporal.product_analytics import (- ACTIVITIES as PRODUCT_ANALYTICS_ACTIVITIES,- WORKFLOWS as PRODUCT_ANALYTICS_WORKFLOWS,-)from posthog.temporal.proxy_service import (ACTIVITIES as PROXY_SERVICE_ACTIVITIES,WORKFLOWS as PROXY_SERVICE_WORKFLOWS,@@ -237,6 +237,10 @@ from products.notebooks.backend.facade.temporal import (ACTIVITIES as NOTEBOOKS_ACTIVITIES,WORKFLOWS as NOTEBOOKS_WORKFLOWS,)+from products.product_analytics.backend.facade.temporal import (+ ACTIVITIES as PRODUCT_ANALYTICS_ACTIVITIES,+ WORKFLOWS as PRODUCT_ANALYTICS_WORKFLOWS,+)from products.pulse.backend.temporal.registry import (ACTIVITIES as PULSE_ACTIVITIES,WORKFLOWS as PULSE_WORKFLOWS,@@ -341,6 +345,7 @@ _task_queue_specs = [+ EXPERIMENT_CANARY_WORKFLOWS+ EXPERIMENT_ENROLLMENT_CENSUS_WORKFLOWS+ CLEANUP_PROPDEFS_WORKFLOWS+ + [BackfillMaterializedPropertiesBatchWorkflow]+ BACKFILL_GROUP_TYPE_CREATED_AT_WORKFLOWS+ INGESTION_ACCEPTANCE_TEST_WORKFLOWS+ WAREHOUSE_SOURCES_QUEUE_PARTITION_WORKFLOWS@@ -364,6 +369,7 @@ _task_queue_specs = [+ EXPERIMENT_CANARY_ACTIVITIES+ EXPERIMENT_ENROLLMENT_CENSUS_ACTIVITIES+ CLEANUP_PROPDEFS_ACTIVITIES+ + BACKFILL_MATERIALIZED_PROPERTY_ACTIVITIES+ BACKFILL_GROUP_TYPE_CREATED_AT_ACTIVITIES+ INGESTION_ACCEPTANCE_TEST_ACTIVITIES+ WAREHOUSE_SOURCES_QUEUE_PARTITION_ACTIVITIESdiff --git a/posthog/schema_migrations/README.md b/posthog/schema_migrations/README.mdindex 3e0b79bfd137..375a67330496 100644--- a/posthog/schema_migrations/README.md+++ b/posthog/schema_migrations/README.md@@ -19,7 +19,7 @@ Read/execute-time (always-on):- Insight serializers upgrade on read; caching, alerts, exports, and subscriptions go through `upgrade_insight`.- Endpoints upgrade their immutable `EndpointVersion.query` snapshots at execution/materialization time; cohorts upgrade their saved `query` when compiling.-Write-time (backfill): a Temporal schedule (`upgrade-queries-schedule`, every 6 hours, see `posthog/temporal/product_analytics/`) rewrites stored **insights** whose queries are below the latest versions. Other stores (endpoint snapshots, notebook content, dashboard templates, cohort queries) are _not_ rewritten and rely on read-time upgrades forever.+Write-time (backfill): a Temporal schedule (`upgrade-queries-schedule`, every 6 hours, see `products/product_analytics/backend/temporal/`) rewrites stored **insights** whose queries are below the latest versions. Other stores (endpoint snapshots, notebook content, dashboard templates, cohort queries) are _not_ rewritten and rely on read-time upgrades forever.## Adding a migrationdiff --git a/posthog/temporal/schedule.py b/posthog/temporal/schedule.pyindex 69e03692f245..3eee32007b8a 100644--- a/posthog/temporal/schedule.py+++ b/posthog/temporal/schedule.py@@ -59,7 +59,6 @@ from posthog.temporal.health_checks.schedule import create_health_check_schedulefrom posthog.temporal.ingestion_acceptance_test.schedule import create_ingestion_acceptance_test_schedulefrom posthog.temporal.logs_alerting.schedule import create_logs_alert_check_schedulefrom posthog.temporal.mcp_analytics.intent_clustering.schedule import create_intent_clustering_coordinator_schedule-from posthog.temporal.product_analytics.upgrade_queries_workflow import UpgradeQueriesWorkflowInputsfrom posthog.temporal.quota_limiting.run_quota_limiting import RunQuotaLimitingInputsfrom posthog.temporal.salesforce_enrichment.conversations_slack_workflow import ConversationsSlackEnrichmentInputsfrom posthog.temporal.salesforce_enrichment.stripe_workflow import StripeEnrichmentInputs@@ -110,6 +109,7 @@ from products.growth.backend.temporal.signup_enrichment.schedule import ()from products.logs.backend.facade.temporal import create_logs_volume_tick_schedulefrom products.managed_warehouse.backend.facade.temporal import DucklakeCompactionInput+from products.product_analytics.backend.facade.temporal import UpgradeQueriesWorkflowInputsfrom products.replay_vision.backend.temporal.estimates import create_replay_vision_estimates_schedulefrom products.replay_vision.backend.temporal.gemini_cleanup_sweep import (create_replay_vision_gemini_cleanup_sweep_schedule,diff --git a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt b/posthog/test/repo_invariants/dataclass_frozen_baseline.txtindex 622f2da59a04..ed1558f5030d 100644--- a/posthog/test/repo_invariants/dataclass_frozen_baseline.txt+++ b/posthog/test/repo_invariants/dataclass_frozen_baseline.txt@@ -76,7 +76,6 @@1 posthog/temporal/ingestion_acceptance_test/test_cases_discovery.py1 posthog/temporal/mcp_analytics/intent_clustering/coordinator.py1 posthog/temporal/mcp_analytics/intent_clustering/team_discovery.py-1 posthog/temporal/product_analytics/upgrade_queries_workflow.py1 posthog/temporal/session_replay/rasterize_recording/activities/stuck_counter.py1 posthog/temporal/tests/common/test_logger.py1 posthog/temporal/tests/data_modeling/test_log_routing.py@@ -163,6 +162,7 @@1 products/posthog_ai/eval_harness/scorers/tracing.py1 products/product_analytics/backend/hogql_queries/funnels/funnel_event_query.py1 products/product_analytics/backend/hogql_queries/paths/test/test_paths_query_runner.py+1 products/product_analytics/backend/temporal/upgrade_queries_workflow.py1 products/product_tours/backend/generate_tour_content/generate.py1 products/pulse/backend/temporal/activities.py1 products/replay_vision/backend/tests/test_gemini_cleanup_activities.pydiff --git a/products/model_crossing_uses_baseline.txt b/products/model_crossing_uses_baseline.txtindex 71eed67112db..c9733d4456a5 100644--- a/products/model_crossing_uses_baseline.txt+++ b/products/model_crossing_uses_baseline.txt@@ -323,7 +323,6 @@ product_analytics.Insight posthog.models.file_system.unfiled_file_saver in-colleproduct_analytics.Insight posthog.models.product_intent.product_intent instance-many(filter) 2product_analytics.Insight posthog.models.resource_transfer.visitors.insight other(Return) 1product_analytics.Insight posthog.models.sharing_configuration passed-as-class(cast) 1-product_analytics.Insight posthog.temporal.product_analytics.upgrade_queries_activities instance-many(filter) 1product_analytics.Insight products.actions.backend.api.action instance-many(extra) 1product_analytics.Insight products.alerts.backend.max_tools instance-many(filter) 1product_analytics.Insight products.alerts.backend.max_tools passed-as-class(cast) 1diff --git a/products/product_analytics/backend/facade/temporal.py b/products/product_analytics/backend/facade/temporal.pynew file mode 100644index 000000000000..d4e67bd27676--- /dev/null+++ b/products/product_analytics/backend/facade/temporal.py@@ -0,0 +1,16 @@+"""Facade re-exports for product analytics Temporal wiring.++Core registers these with the Temporal worker (``start_temporal_worker``) and the+schedule bootstrap (``posthog/temporal/schedule.py``). They cross the boundary as+objects, not data, so they live in their own facade submodule, which keeps the+``temporalio`` imports out of ``facade/api.py``.+"""++from products.product_analytics.backend.temporal import ACTIVITIES, WORKFLOWS+from products.product_analytics.backend.temporal.upgrade_queries_workflow import UpgradeQueriesWorkflowInputs++__all__ = [+ "ACTIVITIES",+ "WORKFLOWS",+ "UpgradeQueriesWorkflowInputs",+]diff --git a/posthog/temporal/product_analytics/__init__.py b/products/product_analytics/backend/temporal/__init__.pysimilarity index 54%rename from posthog/temporal/product_analytics/__init__.pyrename to products/product_analytics/backend/temporal/__init__.pyindex 784b72d5af65..070d6431293e 100644--- a/posthog/temporal/product_analytics/__init__.py+++ b/products/product_analytics/backend/temporal/__init__.py@@ -1,17 +1,10 @@-from posthog.temporal.backfill_materialized_property import (- ACTIVITIES as BACKFILL_ACTIVITIES,- BackfillMaterializedPropertiesBatchWorkflow,-)-from .upgrade_queries_activities import get_insights_to_migrate, migrate_insights_batchfrom .upgrade_queries_workflow import UpgradeQueriesWorkflowWORKFLOWS = [UpgradeQueriesWorkflow,- BackfillMaterializedPropertiesBatchWorkflow,]ACTIVITIES = [get_insights_to_migrate,migrate_insights_batch,- *BACKFILL_ACTIVITIES,]diff --git a/products/product_analytics/backend/temporal/tests/__init__.py b/products/product_analytics/backend/temporal/tests/__init__.pynew file mode 100644index 000000000000..e69de29bb2d1diff --git a/posthog/temporal/tests/product_analytics/__snapshots__/test_upgrade_queries_workflow.ambr b/products/product_analytics/backend/temporal/tests/__snapshots__/test_upgrade_queries_workflow.ambrsimilarity index 100%rename from posthog/temporal/tests/product_analytics/__snapshots__/test_upgrade_queries_workflow.ambrrename to products/product_analytics/backend/temporal/tests/__snapshots__/test_upgrade_queries_workflow.ambrdiff --git a/products/product_analytics/backend/temporal/tests/conftest.py b/products/product_analytics/backend/temporal/tests/conftest.pynew file mode 100644index 000000000000..494d3b5f391c--- /dev/null+++ b/products/product_analytics/backend/temporal/tests/conftest.py@@ -0,0 +1,8 @@+import pytest++from temporalio.testing import ActivityEnvironment+++def activity_environment():+ return ActivityEnvironment()diff --git a/posthog/temporal/tests/product_analytics/test_upgrade_queries_workflow.py b/products/product_analytics/backend/temporal/tests/test_upgrade_queries_workflow.pysimilarity index 98%rename from posthog/temporal/tests/product_analytics/test_upgrade_queries_workflow.pyrename to products/product_analytics/backend/temporal/tests/test_upgrade_queries_workflow.pyindex 84a8a0e37aee..aa013622c8cd 100644--- a/posthog/temporal/tests/product_analytics/test_upgrade_queries_workflow.py+++ b/products/product_analytics/backend/temporal/tests/test_upgrade_queries_workflow.py@@ -14,19 +14,19 @@ from posthog.schema import NodeKindimport posthog.schema_migrations as schema_migrations_modulefrom posthog.schema_migrations import LATEST_VERSIONS, MIGRATIONS, SchemaMigration, _discover_migrations-from posthog.temporal.product_analytics.upgrade_queries_activities import (++from products.product_analytics.backend.facade.models import Insight+from products.product_analytics.backend.temporal.upgrade_queries_activities import (GetInsightsToMigrateActivityInputs,MigrateInsightsBatchActivityInputs,get_insights_to_migrate,migrate_insights_batch,)-from posthog.temporal.product_analytics.upgrade_queries_workflow import (+from products.product_analytics.backend.temporal.upgrade_queries_workflow import (UpgradeQueriesWorkflow,UpgradeQueriesWorkflowInputs,)-from products.product_analytics.backend.facade.models import Insight-class InsightVizMigration1(SchemaMigration):targets = {NodeKind.INSIGHT_VIZ_NODE: 1}diff --git a/posthog/temporal/product_analytics/upgrade_queries_activities.py b/products/product_analytics/backend/temporal/upgrade_queries_activities.pysimilarity index 100%rename from posthog/temporal/product_analytics/upgrade_queries_activities.pyrename to products/product_analytics/backend/temporal/upgrade_queries_activities.pydiff --git a/posthog/temporal/product_analytics/upgrade_queries_workflow.py b/products/product_analytics/backend/temporal/upgrade_queries_workflow.pysimilarity index 97%rename from posthog/temporal/product_analytics/upgrade_queries_workflow.pyrename to products/product_analytics/backend/temporal/upgrade_queries_workflow.pyindex e17edfbb3165..a51b0cb5f494 100644--- a/posthog/temporal/product_analytics/upgrade_queries_workflow.py+++ b/products/product_analytics/backend/temporal/upgrade_queries_workflow.py@@ -7,7 +7,8 @@ from temporalio import workflowfrom temporalio.common import RetryPolicyfrom posthog.temporal.common.base import PostHogWorkflow-from posthog.temporal.product_analytics.upgrade_queries_activities import (++from products.product_analytics.backend.temporal.upgrade_queries_activities import (GetInsightsToMigrateActivityInputs,MigrateInsightsBatchActivityInputs,get_insights_to_migrate,diff --git a/products/product_analytics/turbo.json b/products/product_analytics/turbo.jsonindex 3b7f17cb427f..6b64e49f7047 100644--- a/products/product_analytics/turbo.json+++ b/products/product_analytics/turbo.json@@ -8,6 +8,8 @@"backend/routes.py","backend/models/**","backend/migrations/**",+ "backend/temporal/**",+ "!backend/temporal/tests/**","backend/hogql_queries/trends/**","!backend/hogql_queries/trends/test/**"],