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(aio): stop worker drains from filing llm judge error issues (#96852)

Radu Raicea55caf4df6007
diff --git a/posthog/temporal/ai_observability/evaluation_llm_judge.py b/posthog/temporal/ai_observability/evaluation_llm_judge.py
index 8c7eeb18af49..a7373d1b7cab 100644
--- a/posthog/temporal/ai_observability/evaluation_llm_judge.py
+++ b/posthog/temporal/ai_observability/evaluation_llm_judge.py
@@ -416,6 +416,13 @@ def call_llm_judge(
increment_errors("connection_error", provider=provider)
raise
+ except temporalio.exceptions.CancelledError:
+ # A worker drain or a workflow cancel interrupts the judge at whatever line it reached, so
+ # the fingerprint differs per cancellation. Logging it would file a new error tracking issue
+ # every time, so track it as a metric and re-raise for the retry policy instead.
+ increment_errors("cancelled", provider=provider)
+ raise
+
except Exception as e:
logger.exception(
"Unhandled error from LLM client",
diff --git a/posthog/temporal/ai_observability/test_run_evaluation.py b/posthog/temporal/ai_observability/test_run_evaluation.py
index b620446df959..a65952436ab2 100644
--- a/posthog/temporal/ai_observability/test_run_evaluation.py
+++ b/posthog/temporal/ai_observability/test_run_evaluation.py
@@ -10,7 +10,7 @@ from asgiref.sync import sync_to_async
from parameterized import parameterized
from temporalio import activity
from temporalio.api.enums.v1 import EventType
-from temporalio.exceptions import ApplicationError
+from temporalio.exceptions import ApplicationError, CancelledError
from temporalio.testing import WorkflowEnvironment
from temporalio.worker import Replayer, UnsandboxedWorkflowRunner, Worker
@@ -1528,6 +1528,37 @@ class TestRunEvaluationWorkflow:
mock_increment_errors.assert_called_once_with(expected_label, provider="openai")
+ @pytest.mark.django_db(transaction=True)
+ def test_execute_llm_judge_activity_cancellation_is_counted_but_not_logged(self, setup_data, active_key_config):
+ evaluation_obj = setup_data["evaluation"]
+ team = setup_data["team"]
+
+ evaluation = {
+ "id": str(evaluation_obj.id),
+ "name": "Test Evaluation",
+ "evaluation_type": "llm_judge",
+ "evaluation_config": {"prompt": "Is this accurate?"},
+ "output_type": "boolean",
+ "output_config": {},
+ "team_id": team.id,
+ }
+ event_data = create_mock_event_data(team.id)
+
+ with (
+ patch("posthog.temporal.ai_observability.evaluation_llm_judge.Client") as mock_client_class,
+ patch("posthog.temporal.ai_observability.evaluation_llm_judge.increment_errors") as mock_increment_errors,
+ patch("posthog.temporal.ai_observability.evaluation_llm_judge.logger") as mock_logger,
+ ):
+ mock_client = MagicMock()
+ mock_client_class.return_value = mock_client
+ mock_client.complete.side_effect = CancelledError("Cancelled")
+
+ with pytest.raises(CancelledError):
+ execute_llm_judge_activity(ExecuteLLMJudgeInputs(evaluation=evaluation, event_data=event_data))
+
+ mock_increment_errors.assert_called_once_with("cancelled", provider="openai")
+ mock_logger.exception.assert_not_called()
+
@pytest.mark.django_db(transaction=True)
def test_execute_llm_judge_activity_terminal_team_requires_provider_key(self, setup_data):
team = setup_data["team"]