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.

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.js
index 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.yml
index 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_worker
run: |
# 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'; then
echo "changed=true" >> $GITHUB_OUTPUT
else
diff --git a/posthog/management/commands/start_temporal_worker.py b/posthog/management/commands/start_temporal_worker.py
index 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_ACTIVITIES
diff --git a/posthog/schema_migrations/README.md b/posthog/schema_migrations/README.md
index 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 migration
diff --git a/posthog/temporal/schedule.py b/posthog/temporal/schedule.py
index 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_schedule
from posthog.temporal.ingestion_acceptance_test.schedule import create_ingestion_acceptance_test_schedule
from posthog.temporal.logs_alerting.schedule import create_logs_alert_check_schedule
from posthog.temporal.mcp_analytics.intent_clustering.schedule import create_intent_clustering_coordinator_schedule
-from posthog.temporal.product_analytics.upgrade_queries_workflow import UpgradeQueriesWorkflowInputs
from posthog.temporal.quota_limiting.run_quota_limiting import RunQuotaLimitingInputs
from posthog.temporal.salesforce_enrichment.conversations_slack_workflow import ConversationsSlackEnrichmentInputs
from 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_schedule
from products.managed_warehouse.backend.facade.temporal import DucklakeCompactionInput
+from products.product_analytics.backend.facade.temporal import UpgradeQueriesWorkflowInputs
from products.replay_vision.backend.temporal.estimates import create_replay_vision_estimates_schedule
from 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.txt
index 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.py
1 posthog/temporal/mcp_analytics/intent_clustering/coordinator.py
1 posthog/temporal/mcp_analytics/intent_clustering/team_discovery.py
-1 posthog/temporal/product_analytics/upgrade_queries_workflow.py
1 posthog/temporal/session_replay/rasterize_recording/activities/stuck_counter.py
1 posthog/temporal/tests/common/test_logger.py
1 posthog/temporal/tests/data_modeling/test_log_routing.py
@@ -163,6 +162,7 @@
1 products/posthog_ai/eval_harness/scorers/tracing.py
1 products/product_analytics/backend/hogql_queries/funnels/funnel_event_query.py
1 products/product_analytics/backend/hogql_queries/paths/test/test_paths_query_runner.py
+1 products/product_analytics/backend/temporal/upgrade_queries_workflow.py
1 products/product_tours/backend/generate_tour_content/generate.py
1 products/pulse/backend/temporal/activities.py
1 products/replay_vision/backend/tests/test_gemini_cleanup_activities.py
diff --git a/products/model_crossing_uses_baseline.txt b/products/model_crossing_uses_baseline.txt
index 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-colle
product_analytics.Insight posthog.models.product_intent.product_intent instance-many(filter) 2
product_analytics.Insight posthog.models.resource_transfer.visitors.insight other(Return) 1
product_analytics.Insight posthog.models.sharing_configuration passed-as-class(cast) 1
-product_analytics.Insight posthog.temporal.product_analytics.upgrade_queries_activities instance-many(filter) 1
product_analytics.Insight products.actions.backend.api.action instance-many(extra) 1
product_analytics.Insight products.alerts.backend.max_tools instance-many(filter) 1
product_analytics.Insight products.alerts.backend.max_tools passed-as-class(cast) 1
diff --git a/products/product_analytics/backend/facade/temporal.py b/products/product_analytics/backend/facade/temporal.py
new file mode 100644
index 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__.py
similarity index 54%
rename from posthog/temporal/product_analytics/__init__.py
rename to products/product_analytics/backend/temporal/__init__.py
index 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_batch
from .upgrade_queries_workflow import UpgradeQueriesWorkflow
WORKFLOWS = [
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__.py
new file mode 100644
index 000000000000..e69de29bb2d1
diff --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.ambr
similarity index 100%
rename from posthog/temporal/tests/product_analytics/__snapshots__/test_upgrade_queries_workflow.ambr
rename to products/product_analytics/backend/temporal/tests/__snapshots__/test_upgrade_queries_workflow.ambr
diff --git a/products/product_analytics/backend/temporal/tests/conftest.py b/products/product_analytics/backend/temporal/tests/conftest.py
new file mode 100644
index 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.py
similarity index 98%
rename from posthog/temporal/tests/product_analytics/test_upgrade_queries_workflow.py
rename to products/product_analytics/backend/temporal/tests/test_upgrade_queries_workflow.py
index 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 NodeKind
import posthog.schema_migrations as schema_migrations_module
from 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.py
similarity index 100%
rename from posthog/temporal/product_analytics/upgrade_queries_activities.py
rename to products/product_analytics/backend/temporal/upgrade_queries_activities.py
diff --git a/posthog/temporal/product_analytics/upgrade_queries_workflow.py b/products/product_analytics/backend/temporal/upgrade_queries_workflow.py
similarity index 97%
rename from posthog/temporal/product_analytics/upgrade_queries_workflow.py
rename to products/product_analytics/backend/temporal/upgrade_queries_workflow.py
index 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 workflow
from temporalio.common import RetryPolicy
from 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.json
index 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/**"
],