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.

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.py
index 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 Heartbeater
from posthog.temporal.exports.types import ExportAssetActivityInputs, ExportAssetResult
from 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, ExportCancelled
logger = 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.defn
async def export_asset_activity(inputs: ExportAssetActivityInputs) -> ExportAssetResult:
@@ -59,7 +63,7 @@ async def export_asset_activity(inputs: ExportAssetActivityInputs) -> ExportAsse
truncate_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 e
await 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.py
index 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 settings
import temporalio.workflow
from asgiref.sync import sync_to_async
+from playwright.sync_api import TimeoutError as PlaywrightTimeoutError
+from selenium.common import TimeoutException
from temporalio.client import Client, WorkflowFailureError
-from temporalio.exceptions import ActivityError
+from temporalio.exceptions import ActivityError, ApplicationError
from temporalio.testing import WorkflowEnvironment
from temporalio.worker import UnsandboxedWorkflowRunner, Worker
@@ -21,7 +23,7 @@ from posthog.temporal.exports.retry_policy import EXPORT_RETRY_POLICY
from posthog.temporal.exports.types import ExportAssetActivityInputs, ExportAssetResult
from 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, ExportCancelled
pytestmark = [pytest.mark.asyncio, pytest.mark.django_db(transaction=True)]
@@ -115,3 +117,33 @@ async def test_export_asset_activity_propagates_user_errors(mock_exporter: Magic
app_error = activity_error.cause
assert app_error is not None
assert "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