: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
refactor(growth): move the signup-enrichment temporal runner into growth (#82158)
Matt Brookerc4517f220fac
diff --git a/.github/workflows/container-images-cd.yml b/.github/workflows/container-images-cd.ymlindex fceb0b8fe116..80640301367b 100644--- a/.github/workflows/container-images-cd.yml+++ b/.github/workflows/container-images-cd.yml@@ -471,7 +471,7 @@ jobs:- name: Check for changes that affect signup enrichment temporal workerid: check_changes_signup_enrichment_temporal_workerrun: |- if git diff --name-only HEAD^ HEAD | grep -qE '^posthog/temporal/signup_enrichment/|^products/growth/backend/|^ee/billing/salesforce_enrichment/|^posthog/temporal/common|^posthog/management/commands/start_temporal_worker.py$|^pyproject.toml$|^bin/temporal-django-worker$|^posthog/clickhouse/migrations/'; then+ if git diff --name-only HEAD^ HEAD | grep -qE '^products/growth/backend/|^ee/billing/salesforce_enrichment/|^posthog/temporal/common|^posthog/management/commands/start_temporal_worker.py$|^pyproject.toml$|^bin/temporal-django-worker$|^posthog/clickhouse/migrations/'; thenecho "changed=true" >> $GITHUB_OUTPUTelseecho "changed=false" >> $GITHUB_OUTPUTdiff --git a/posthog/api/signup.py b/posthog/api/signup.pyindex 7dfc402f5f22..e3e0b6e6d87d 100644--- a/posthog/api/signup.py+++ b/posthog/api/signup.py@@ -40,11 +40,11 @@ from posthog.models.organization_invite import INVITE_DAYS_VALIDITYfrom posthog.models.webauthn_credential import WebauthnCredentialfrom posthog.permissions import CanCreateOrgfrom posthog.rate_limit import SignupEmailPrecheckThrottle, SignupIPThrottle, SignupResendInviteThrottle-from posthog.temporal.signup_enrichment.trigger import start_signup_enrichment_workflowfrom posthog.utils import get_can_create_org, get_trusted_client_ip, is_relative_urlfrom posthog.workos_radar import RadarAction, RadarAuthMethod, evaluate_auth_attemptfrom products.demo.backend.facade.api import HedgeboxMatrix, MatrixManager+from products.growth.backend.temporal.signup_enrichment.trigger import start_signup_enrichment_workflowlogger = structlog.get_logger(__name__)diff --git a/posthog/management/commands/start_temporal_worker.py b/posthog/management/commands/start_temporal_worker.pyindex 0fe558ed8b3f..c235d4211018 100644--- a/posthog/management/commands/start_temporal_worker.py+++ b/posthog/management/commands/start_temporal_worker.py@@ -142,10 +142,6 @@ from posthog.temporal.session_replay.surfacing_scoring_sweep import (SURFACING_SCORING_SWEEP_ACTIVITIES,SURFACING_SCORING_SWEEP_WORKFLOWS,)-from posthog.temporal.signup_enrichment import (- ACTIVITIES as SIGNUP_ENRICHMENT_ACTIVITIES,- WORKFLOWS as SIGNUP_ENRICHMENT_WORKFLOWS,-)from posthog.temporal.sync_events_retention import SYNC_EVENTS_RETENTION_ACTIVITIES, SYNC_EVENTS_RETENTION_WORKFLOWSfrom posthog.temporal.sync_person_distinct_ids import (ACTIVITIES as SYNC_PERSON_DISTINCT_IDS_ACTIVITIES,@@ -206,6 +202,10 @@ from products.exports.backend.temporal.subscriptions import (ACTIVITIES as SUBSCRIPTION_ACTIVITIES,WORKFLOWS as SUBSCRIPTION_WORKFLOWS,)+from products.growth.backend.temporal import (+ ACTIVITIES as GROWTH_ACTIVITIES,+ WORKFLOWS as GROWTH_WORKFLOWS,+)from products.logs.backend.facade.temporal import (ACTIVITIES as LOGS_ALERTING_ACTIVITIES,WORKFLOWS as LOGS_ALERTING_WORKFLOWS,@@ -326,7 +326,7 @@ _task_queue_specs = [+ JOB_LOGS_WORKFLOWS+ CI_SIGNALS_WORKFLOWS+ NOTEBOOKS_WORKFLOWS- + SIGNUP_ENRICHMENT_WORKFLOWS+ + GROWTH_WORKFLOWS+ LOGS_RETENTION_ENTITLEMENTS_WORKFLOWS,PROXY_SERVICE_ACTIVITIES+ DELETE_PERSONS_ACTIVITIES@@ -347,7 +347,7 @@ _task_queue_specs = [+ JOB_LOGS_ACTIVITIES+ CI_SIGNALS_ACTIVITIES+ NOTEBOOKS_ACTIVITIES- + SIGNUP_ENRICHMENT_ACTIVITIES+ + GROWTH_ACTIVITIES+ LOGS_RETENTION_ENTITLEMENTS_ACTIVITIES,),# Dedicated landing zone for signup enrichment. Defaults to the general-purpose queue name (so it@@ -355,8 +355,8 @@ _task_queue_specs = [# worker registers these workflows under the dedicated queue, letting dispatch move there with no code change.(settings.SIGNUP_ENRICHMENT_TASK_QUEUE,- SIGNUP_ENRICHMENT_WORKFLOWS,- SIGNUP_ENRICHMENT_ACTIVITIES,+ GROWTH_WORKFLOWS,+ GROWTH_ACTIVITIES,),(settings.EXPERIMENTS_RECALCULATION_TASK_QUEUE,diff --git a/posthog/temporal/signup_enrichment/__init__.py b/posthog/temporal/signup_enrichment/__init__.pydeleted file mode 100644index 7d3cec316090..000000000000--- a/posthog/temporal/signup_enrichment/__init__.py+++ /dev/null@@ -1,5 +0,0 @@-from posthog.temporal.signup_enrichment.workflow import SignupEnrichmentWorkflow, enrich_signup_organization_activity--WORKFLOWS = [SignupEnrichmentWorkflow]--ACTIVITIES = [enrich_signup_organization_activity]diff --git a/posthog/test/dataclass_frozen_baseline.txt b/posthog/test/dataclass_frozen_baseline.txtindex a96b08840fb0..e92b684f8a01 100644--- a/posthog/test/dataclass_frozen_baseline.txt+++ b/posthog/test/dataclass_frozen_baseline.txt@@ -85,7 +85,6 @@1 posthog/temporal/product_analytics/upgrade_queries_workflow.py1 posthog/temporal/session_replay/rasterize_recording/activities/stuck_counter.py1 posthog/temporal/session_replay/session_summary/activities/capture_timing.py-1 posthog/temporal/signup_enrichment/workflow.py1 posthog/temporal/tests/common/test_logger.py1 posthog/temporal/tests/data_modeling/test_log_routing.py1 posthog/temporal/tests/session_replay/gemini_cleanup_sweep/test_activities.py@@ -155,6 +154,7 @@1 products/growth/backend/enrichment/fields.py1 products/growth/backend/enrichment/providers.py1 products/growth/backend/enrichment/snapshot.py+1 products/growth/backend/temporal/signup_enrichment/workflow.py1 products/growth/dags/product_push_campaigns.py1 products/growth/dags/team_production_event_activation.py1 products/live_debugger/backend/models.pydiff --git a/products/growth/backend/management/commands/backfill_signup_enrichment.py b/products/growth/backend/management/commands/backfill_signup_enrichment.pyindex 804c08ec3ed1..3e8084675799 100644--- a/products/growth/backend/management/commands/backfill_signup_enrichment.py+++ b/products/growth/backend/management/commands/backfill_signup_enrichment.py@@ -14,10 +14,11 @@ from django.conf import settingsfrom django.core.management.base import BaseCommand, CommandError, CommandParserfrom posthog.models.organization import Organization, OrganizationMembership-from posthog.temporal.signup_enrichment.trigger import dispatch_signup_enrichment, domain_from_email-from posthog.temporal.signup_enrichment.workflow import SignupEnrichmentInputsfrom posthog.utils import GenericEmails, get_instance_region+from products.growth.backend.temporal.signup_enrichment.trigger import dispatch_signup_enrichment, domain_from_email+from products.growth.backend.temporal.signup_enrichment.workflow import SignupEnrichmentInputs+_generic_emails = GenericEmails()# The signup creator's membership is written in the signup transaction, so it lands within@@ -44,7 +45,7 @@ class Command(BaseCommand):# must not defeat it if it was turned off for a compliance, cost, or vendor reason.if not settings.GROWTH_SIGNUP_ENRICHMENT_ENABLED:raise CommandError("Signup enrichment is disabled (GROWTH_SIGNUP_ENRICHMENT_ENABLED); refusing to dispatch")- # Cloud only, mirrors the signup-path region gate (posthog/temporal/signup_enrichment/trigger.py).+ # Cloud only, mirrors the signup-path region gate (products/growth/backend/temporal/signup_enrichment/trigger.py).if get_instance_region() not in ("US", "EU"):raise CommandError("Signup enrichment is US/EU-only; refusing to dispatch in this region")diff --git a/products/growth/backend/temporal/__init__.py b/products/growth/backend/temporal/__init__.pyindex 8b137891791f..52bda83f5291 100644--- a/products/growth/backend/temporal/__init__.py+++ b/products/growth/backend/temporal/__init__.py@@ -1 +1,8 @@+from products.growth.backend.temporal.signup_enrichment import (+ ACTIVITIES as SIGNUP_ENRICHMENT_ACTIVITIES,+ WORKFLOWS as SIGNUP_ENRICHMENT_WORKFLOWS,+)+WORKFLOWS = [*SIGNUP_ENRICHMENT_WORKFLOWS]++ACTIVITIES = [*SIGNUP_ENRICHMENT_ACTIVITIES]diff --git a/products/growth/backend/temporal/signup_enrichment/__init__.py b/products/growth/backend/temporal/signup_enrichment/__init__.pynew file mode 100644index 000000000000..fc620870e0b2--- /dev/null+++ b/products/growth/backend/temporal/signup_enrichment/__init__.py@@ -0,0 +1,8 @@+from products.growth.backend.temporal.signup_enrichment.workflow import (+ SignupEnrichmentWorkflow,+ enrich_signup_organization_activity,+)++WORKFLOWS = [SignupEnrichmentWorkflow]++ACTIVITIES = [enrich_signup_organization_activity]diff --git a/posthog/temporal/tests/signup_enrichment/__init__.py b/products/growth/backend/temporal/signup_enrichment/tests/__init__.pysimilarity index 100%rename from posthog/temporal/tests/signup_enrichment/__init__.pyrename to products/growth/backend/temporal/signup_enrichment/tests/__init__.pydiff --git a/posthog/temporal/tests/signup_enrichment/test_activity.py b/products/growth/backend/temporal/signup_enrichment/tests/test_activity.pysimilarity index 96%rename from posthog/temporal/tests/signup_enrichment/test_activity.pyrename to products/growth/backend/temporal/signup_enrichment/tests/test_activity.pyindex 631cb5d8e040..1b9dac9addee 100644--- a/posthog/temporal/tests/signup_enrichment/test_activity.py+++ b/products/growth/backend/temporal/signup_enrichment/tests/test_activity.py@@ -7,17 +7,16 @@ from unittest.mock import AsyncMock, MagicMock, patchfrom asgiref.sync import sync_to_asyncfrom temporalio.testing import ActivityEnvironment-from posthog.temporal.signup_enrichment.workflow import (+from products.growth.backend.enrichment.fields import EnrichmentFields+from products.growth.backend.temporal.signup_enrichment.workflow import (MAX_ENRICH_ATTEMPTS,SignupEnrichmentInputs,enrich_signup_organization_activity,)-from products.growth.backend.enrichment.fields import EnrichmentFields-pytestmark = pytest.mark.asyncio-_MODULE = "posthog.temporal.signup_enrichment.workflow"+_MODULE = "products.growth.backend.temporal.signup_enrichment.workflow"_INPUTS = SignupEnrichmentInputs(organization_id="org-1", distinct_id="d1", domain="stripe.com")diff --git a/posthog/temporal/tests/signup_enrichment/test_trigger.py b/products/growth/backend/temporal/signup_enrichment/tests/test_trigger.pysimilarity index 85%rename from posthog/temporal/tests/signup_enrichment/test_trigger.pyrename to products/growth/backend/temporal/signup_enrichment/tests/test_trigger.pyindex 136df39e4015..26e0666e13fb 100644--- a/posthog/temporal/tests/signup_enrichment/test_trigger.py+++ b/products/growth/backend/temporal/signup_enrichment/tests/test_trigger.py@@ -5,8 +5,11 @@ from django.test import override_settingsfrom temporalio.exceptions import WorkflowAlreadyStartedError-from posthog.temporal.signup_enrichment.trigger import dispatch_signup_enrichment, start_signup_enrichment_workflow-from posthog.temporal.signup_enrichment.workflow import SignupEnrichmentInputs+from products.growth.backend.temporal.signup_enrichment.trigger import (+ dispatch_signup_enrichment,+ start_signup_enrichment_workflow,+)+from products.growth.backend.temporal.signup_enrichment.workflow import SignupEnrichmentInputsclass _InlineExecutor:@@ -16,18 +19,21 @@ class _InlineExecutor:@pytest.fixture(autouse=True)def _run_dispatch_pool_inline():- with patch("posthog.temporal.signup_enrichment.trigger._dispatch_executor", _InlineExecutor()):+ with patch("products.growth.backend.temporal.signup_enrichment.trigger._dispatch_executor", _InlineExecutor()):yielddef _dispatch_mocks(region="US"):"""Patch out the transaction/Temporal/DB boundaries so on_commit fires inline."""return (- patch("posthog.temporal.signup_enrichment.trigger.transaction.on_commit", side_effect=lambda fn: fn()),- patch("posthog.temporal.signup_enrichment.trigger.sync_connect"),- patch("posthog.temporal.signup_enrichment.trigger.asyncio.run"),- patch("posthog.temporal.signup_enrichment.trigger.get_instance_region", return_value=region),- patch("posthog.temporal.signup_enrichment.trigger.record_signup_work_email"),+ patch(+ "products.growth.backend.temporal.signup_enrichment.trigger.transaction.on_commit",+ side_effect=lambda fn: fn(),+ ),+ patch("products.growth.backend.temporal.signup_enrichment.trigger.sync_connect"),+ patch("products.growth.backend.temporal.signup_enrichment.trigger.asyncio.run"),+ patch("products.growth.backend.temporal.signup_enrichment.trigger.get_instance_region", return_value=region),+ patch("products.growth.backend.temporal.signup_enrichment.trigger.record_signup_work_email"),)@@ -128,7 +134,7 @@ def test_work_email_write_failure_does_not_block_dispatch():on_commit, connect, run, region, record = _dispatch_mocks()with on_commit, connect as connect_mock, run, region, record as record_mock:record_mock.side_effect = RuntimeError("db down")- with patch("posthog.temporal.signup_enrichment.trigger.capture_exception") as capture_mock:+ with patch("products.growth.backend.temporal.signup_enrichment.trigger.capture_exception") as capture_mock:start_signup_enrichment_workflow(organization_id="org-1", distinct_id="d1", email="[email protected]")connect_mock.assert_called_once()capture_mock.assert_called_once()@@ -144,7 +150,7 @@ def test_work_email_write_failure_does_not_block_dispatch():)def test_dispatch_signup_enrichment_swallows_only_already_started(error, propagates):inputs = SignupEnrichmentInputs(organization_id="org-1", distinct_id="d1", domain="stripe.com")- with patch("posthog.temporal.signup_enrichment.trigger._start_workflow", side_effect=error):+ with patch("products.growth.backend.temporal.signup_enrichment.trigger._start_workflow", side_effect=error):if propagates:with pytest.raises(RuntimeError):dispatch_signup_enrichment(inputs)@@ -156,7 +162,7 @@ def test_duplicate_workflow_is_logged_not_captured():on_commit, connect, run, region, record = _dispatch_mocks()with on_commit, connect, run as run_mock, region, record:run_mock.side_effect = WorkflowAlreadyStartedError("signup-enrichment-org-1", "signup-enrichment")- with patch("posthog.temporal.signup_enrichment.trigger.capture_exception") as capture_mock:+ with patch("products.growth.backend.temporal.signup_enrichment.trigger.capture_exception") as capture_mock:start_signup_enrichment_workflow(organization_id="org-1", distinct_id="d1", email="[email protected]")capture_mock.assert_not_called()@@ -168,7 +174,7 @@ def test_dispatch_dropped_when_backlog_full():full = threading.BoundedSemaphore(1)full.acquire()on_commit, connect, run, region, record = _dispatch_mocks()- with patch("posthog.temporal.signup_enrichment.trigger._dispatch_slots", full):+ with patch("products.growth.backend.temporal.signup_enrichment.trigger._dispatch_slots", full):with on_commit, connect as connect_mock, run, region, record:start_signup_enrichment_workflow(organization_id="org-1", distinct_id="d1", email="[email protected]")connect_mock.assert_not_called()@@ -180,7 +186,7 @@ def test_dispatch_slot_released_after_run():single = threading.BoundedSemaphore(1)on_commit, connect, run, region, record = _dispatch_mocks()- with patch("posthog.temporal.signup_enrichment.trigger._dispatch_slots", single):+ with patch("products.growth.backend.temporal.signup_enrichment.trigger._dispatch_slots", single):with on_commit, connect as connect_mock, run, region, record:start_signup_enrichment_workflow(organization_id="org-1", distinct_id="d1", email="[email protected]")start_signup_enrichment_workflow(organization_id="org-2", distinct_id="d2", email="[email protected]")@@ -197,7 +203,7 @@ def test_signup_geoip_country_is_threaded_into_workflow_inputs():region,record,patch(- "posthog.temporal.signup_enrichment.trigger.get_geoip_properties",+ "products.growth.backend.temporal.signup_enrichment.trigger.get_geoip_properties",return_value={"$geoip_country_code": "US"},),):@@ -218,7 +224,7 @@ def test_geoip_failure_degrades_to_no_country_and_still_dispatches():region,record,patch(- "posthog.temporal.signup_enrichment.trigger.get_geoip_properties",+ "products.growth.backend.temporal.signup_enrichment.trigger.get_geoip_properties",side_effect=RuntimeError("geoip db missing"),),):diff --git a/posthog/temporal/tests/signup_enrichment/test_workflow.py b/products/growth/backend/temporal/signup_enrichment/tests/test_workflow.pysimilarity index 97%rename from posthog/temporal/tests/signup_enrichment/test_workflow.pyrename to products/growth/backend/temporal/signup_enrichment/tests/test_workflow.pyindex 9a48b9011470..cd60f90e3a88 100644--- a/posthog/temporal/tests/signup_enrichment/test_workflow.py+++ b/products/growth/backend/temporal/signup_enrichment/tests/test_workflow.py@@ -6,17 +6,16 @@ from unittest.mock import AsyncMock, MagicMock, patchfrom temporalio.testing import WorkflowEnvironmentfrom temporalio.worker import UnsandboxedWorkflowRunner, Worker-from posthog.temporal.signup_enrichment.workflow import (+from products.growth.backend.enrichment.fields import EnrichmentFields+from products.growth.backend.temporal.signup_enrichment.workflow import (SignupEnrichmentInputs,SignupEnrichmentWorkflow,enrich_signup_organization_activity,)-from products.growth.backend.enrichment.fields import EnrichmentFields-pytestmark = pytest.mark.asyncio-_MODULE = "posthog.temporal.signup_enrichment.workflow"+_MODULE = "products.growth.backend.temporal.signup_enrichment.workflow"_INPUTS = SignupEnrichmentInputs(organization_id="org-1", distinct_id="d1", domain="stripe.com")_TASK_QUEUE = "signup-enrichment-test-queue"diff --git a/posthog/temporal/signup_enrichment/trigger.py b/products/growth/backend/temporal/signup_enrichment/trigger.pysimilarity index 98%rename from posthog/temporal/signup_enrichment/trigger.pyrename to products/growth/backend/temporal/signup_enrichment/trigger.pyindex 9a51da01a277..9323da259338 100644--- a/posthog/temporal/signup_enrichment/trigger.py+++ b/products/growth/backend/temporal/signup_enrichment/trigger.py@@ -23,10 +23,10 @@ from temporalio.service import RPCErrorfrom posthog.exceptions_capture import capture_exceptionfrom posthog.geoip import get_geoip_propertiesfrom posthog.temporal.common.client import sync_connect-from posthog.temporal.signup_enrichment.workflow import SignupEnrichmentInputsfrom posthog.utils import GenericEmails, get_instance_regionfrom products.growth.backend.enrichment.writer import record_signup_work_email+from products.growth.backend.temporal.signup_enrichment.workflow import SignupEnrichmentInputslogger = structlog.get_logger(__name__)diff --git a/posthog/temporal/signup_enrichment/workflow.py b/products/growth/backend/temporal/signup_enrichment/workflow.pysimilarity index 99%rename from posthog/temporal/signup_enrichment/workflow.pyrename to products/growth/backend/temporal/signup_enrichment/workflow.pyindex 016d809648d6..4fce913b38c1 100644--- a/posthog/temporal/signup_enrichment/workflow.py+++ b/products/growth/backend/temporal/signup_enrichment/workflow.py@@ -3,7 +3,7 @@The workflow wraps the orchestration-agnostic enrichment core (products/growth), writes thelive stores, wires the write-once at-signup snapshot, and emits a launch fill-rate/failuresignal. It is dispatched from the signup request path behind a kill switch and must never-block or fail signup — see posthog/temporal/signup_enrichment/trigger.py.+block or fail signup — see products/growth/backend/temporal/signup_enrichment/trigger.py."""import json