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(tasks): keep error_type a string when an activity times out (#83831)

Alessandro Pogliaghi412aa947338c
diff --git a/products/tasks/backend/temporal/process_task/tests/test_failure_error_type.py b/products/tasks/backend/temporal/process_task/tests/test_failure_error_type.py
new file mode 100644
index 000000000000..3284457ef3d4
--- /dev/null
+++ b/products/tasks/backend/temporal/process_task/tests/test_failure_error_type.py
@@ -0,0 +1,56 @@
+from unittest import TestCase
+
+import temporalio.exceptions
+from parameterized import parameterized
+
+from products.tasks.backend.temporal.process_task.workflow import _failure_error_type
+
+
+class TestFailureErrorType(TestCase):
+ @parameterized.expand(
+ [
+ (
+ "application_error_type",
+ temporalio.exceptions.ApplicationError("boom", type="SandboxProvisionError"),
+ "SandboxProvisionError",
+ ),
+ (
+ "timeout_start_to_close",
+ temporalio.exceptions.TimeoutError(
+ "timed out",
+ type=temporalio.exceptions.TimeoutType.START_TO_CLOSE,
+ last_heartbeat_details=[],
+ ),
+ "start_to_close",
+ ),
+ (
+ "timeout_heartbeat",
+ temporalio.exceptions.TimeoutError(
+ "timed out",
+ type=temporalio.exceptions.TimeoutType.HEARTBEAT,
+ last_heartbeat_details=[],
+ ),
+ "heartbeat",
+ ),
+ (
+ "timeout_without_type",
+ temporalio.exceptions.TimeoutError("timed out", type=None, last_heartbeat_details=[]),
+ "RuntimeError",
+ ),
+ ("no_cause", None, "RuntimeError"),
+ (
+ "cause_without_type",
+ temporalio.exceptions.CancelledError("cancelled"),
+ "RuntimeError",
+ ),
+ (
+ "application_error_empty_type",
+ temporalio.exceptions.ApplicationError("boom", type=""),
+ "RuntimeError",
+ ),
+ ]
+ )
+ def test_always_returns_a_string(self, _name: str, cause: BaseException | None, expected: str) -> None:
+ result = _failure_error_type(cause, RuntimeError("outer"))
+ assert result == expected
+ assert isinstance(result, str)
diff --git a/products/tasks/backend/temporal/process_task/workflow.py b/products/tasks/backend/temporal/process_task/workflow.py
index 422e2d9c061d..a0601ac97a37 100644
--- a/products/tasks/backend/temporal/process_task/workflow.py
+++ b/products/tasks/backend/temporal/process_task/workflow.py
@@ -128,6 +128,15 @@ def _is_dead_sandbox_failure(error: BaseException) -> bool:
return isinstance(cause, temporalio.exceptions.ApplicationError) and cause.type in DEAD_SANDBOX_ERROR_TYPES
+def _failure_error_type(cause: BaseException | None, exc: Exception) -> str:
+ cause_type = getattr(cause, "type", None)
+ if isinstance(cause_type, temporalio.exceptions.TimeoutType):
+ return cause_type.name.lower()
+ if isinstance(cause_type, str) and cause_type:
+ return cause_type
+ return type(exc).__name__
+
+
def _message_dedupe_key(
message_id: str,
actor_user_id: int | None,
@@ -1123,7 +1132,7 @@ class ProcessTaskWorkflow(PostHogWorkflow):
# the UI show the persisted message, so surface the cause instead.
cause = e.cause if isinstance(e, temporalio.exceptions.ActivityError) else None
cause_message = getattr(cause, "message", None) or (str(cause) if cause is not None else None)
- error_type = getattr(cause, "type", None) or type(e).__name__
+ error_type = _failure_error_type(cause, e)
error_message = truncate_error_message(cause_message or str(e))
if self._context:
if self._current_progress_step is not None: