: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
fix(exports): retry render timeouts in export asset activity (#62656)
Vasco de Krijger72a86577f098
diff --git a/posthog/temporal/exports/activities.py b/posthog/temporal/exports/activities.pyindex a17453da2dda..ee94f842a68f 100644--- a/posthog/temporal/exports/activities.py+++ b/posthog/temporal/exports/activities.py@@ -12,10 +12,14 @@ from posthog.temporal.common.heartbeat import Heartbeaterfrom posthog.temporal.exports.types import ExportAssetActivityInputs, ExportAssetResultfrom products.exports.backend.models.exported_asset import ExportedAsset-from products.exports.backend.tasks.failure_handler import SYSTEM_ERROR_NAMES+from products.exports.backend.tasks.failure_handler import SYSTEM_ERROR_NAMES, TIMEOUT_ERROR_NAMES, ExportCancelledlogger = structlog.get_logger(__name__)+# Render/query timeouts are transient and must stay retryable; an explicit+# cancellation is terminal even though it lives in TIMEOUT_ERROR_NAMES.+RETRYABLE_ERROR_NAMES = SYSTEM_ERROR_NAMES | (TIMEOUT_ERROR_NAMES - {ExportCancelled.__name__})+@temporalio.activity.defnasync def export_asset_activity(inputs: ExportAssetActivityInputs) -> ExportAssetResult:@@ -59,7 +63,7 @@ async def export_asset_activity(inputs: ExportAssetActivityInputs) -> ExportAssetruncate_for_temporal_payload(str(e), MAX_ERROR_MESSAGE_CHARS),truncate_for_temporal_payload(error_trace, MAX_ERROR_TRACE_CHARS),type=exception_class,- non_retryable=exception_class not in SYSTEM_ERROR_NAMES,+ non_retryable=exception_class not in RETRYABLE_ERROR_NAMES,) from eawait database_sync_to_async(asset.refresh_from_db, thread_sensitive=False)()diff --git a/posthog/temporal/tests/test_export_activities.py b/posthog/temporal/tests/test_export_activities.pyindex 8f3e360c9a58..fa1294c51b78 100644--- a/posthog/temporal/tests/test_export_activities.py+++ b/posthog/temporal/tests/test_export_activities.py@@ -10,8 +10,10 @@ from django.conf import settingsimport temporalio.workflowfrom asgiref.sync import sync_to_async+from playwright.sync_api import TimeoutError as PlaywrightTimeoutError+from selenium.common import TimeoutExceptionfrom temporalio.client import Client, WorkflowFailureError-from temporalio.exceptions import ActivityError+from temporalio.exceptions import ActivityError, ApplicationErrorfrom temporalio.testing import WorkflowEnvironmentfrom temporalio.worker import UnsandboxedWorkflowRunner, Worker@@ -21,7 +23,7 @@ from posthog.temporal.exports.retry_policy import EXPORT_RETRY_POLICYfrom posthog.temporal.exports.types import ExportAssetActivityInputs, ExportAssetResultfrom products.exports.backend.models.exported_asset import ExportedAsset-from products.exports.backend.tasks.failure_handler import ExcelColumnLimitExceeded+from products.exports.backend.tasks.failure_handler import ExcelColumnLimitExceeded, ExportCancelledpytestmark = [pytest.mark.asyncio, pytest.mark.django_db(transaction=True)]@@ -115,3 +117,33 @@ async def test_export_asset_activity_propagates_user_errors(mock_exporter: Magicapp_error = activity_error.causeassert app_error is not Noneassert "ExcelColumnLimitExceeded" in str(app_error) or "18,278 columns" in str(app_error)+++ "exception,expected_non_retryable",+ [+ (TimeoutError("Timeout while waiting for the page to load"), False),+ (PlaywrightTimeoutError("Timeout 30000ms exceeded"), False),+ (TimeoutException("renderer timed out"), False),+ (ExportCancelled("export canceled"), True),+ (ValueError("bad input"), True),+ ],+)+@patch("posthog.temporal.exports.activities.exporter")+async def test_export_asset_activity_timeout_errors_are_retryable(+ mock_exporter: MagicMock, activity_environment, team, exception, expected_non_retryable+):+ asset = await sync_to_async(ExportedAsset.objects.create)(+ team=team,+ export_format=ExportedAsset.ExportFormat.PNG,+ )++ def fake_export(asset_obj, **kwargs):+ raise exception++ mock_exporter.export_asset_direct = fake_export++ with pytest.raises(ApplicationError) as exc_info:+ await activity_environment.run(export_asset_activity, ExportAssetActivityInputs(exported_asset_id=asset.id))++ assert exc_info.value.non_retryable is expected_non_retryable