: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(llma): report judge rate limits only on the last attempt (#113139)
Carlos Marchal3cb17e928a64
diff --git a/posthog/temporal/ai_observability/evaluation_llm_judge.py b/posthog/temporal/ai_observability/evaluation_llm_judge.pyindex 5143de9cf988..962c450bc321 100644--- a/posthog/temporal/ai_observability/evaluation_llm_judge.py+++ b/posthog/temporal/ai_observability/evaluation_llm_judge.py@@ -44,7 +44,7 @@ from posthog.temporal.ai_observability.metrics import (increment_user_errors,)from posthog.temporal.ai_observability.model_resolution import model_spec-from posthog.temporal.common.errors import NonReportableError+from posthog.temporal.common.errors import NonReportableApplicationError, NonReportableErrorfrom posthog.temporal.common.utils import close_db_connectionsfrom products.ai_observability.backend.llm import DEFAULT_MODEL_BY_PROVIDER, Client, CompletionRequest, Usage@@ -772,7 +772,9 @@ def call_llm_judge()except RetryableRateLimitError as e:increment_errors("rate_limit", provider=provider)- raise ApplicationError(+ # A retry usually gets through, so only an outage that outlasts every attempt reaches error tracking.+ error_class = ApplicationError if _is_last_judge_attempt() else NonReportableApplicationError+ raise error_class(str(e),{"error_type": "provider_unavailable", "provider": provider},next_retry_delay=timedelta(seconds=e.retry_after) if e.retry_after is not None else None,diff --git a/posthog/temporal/ai_observability/test_run_evaluation.py b/posthog/temporal/ai_observability/test_run_evaluation.pyindex 0aa78e8920b4..a82dc0f9ec6b 100644--- a/posthog/temporal/ai_observability/test_run_evaluation.py+++ b/posthog/temporal/ai_observability/test_run_evaluation.py@@ -748,9 +748,18 @@ def test_endpoint_host_that_never_resolves_skips_the_run_with_the_reason() -> No),],)+ "attempt,reportable",+ [+ pytest.param(1, False, id="first attempt"),+ pytest.param(3, True, id="last attempt"),+ ],+)def test_custom_provider_rate_limit_retries_without_disabling_the_evaluation(- provider: str, success_payload: dict[str, Any]+ provider: str, success_payload: dict[str, Any], attempt: int, reportable: bool) -> None:+ env = ActivityEnvironment()+ env.info = dataclasses.replace(env.info, attempt=attempt)key = MagicMock(provider=provider,encrypted_config={"api_key": "example-token", "base_url": "https://decisions.example.com/v1"},@@ -777,13 +786,16 @@ def test_custom_provider_rate_limit_retries_without_disabling_the_evaluation(provider=provider, model="example-judge-v1", provider_key=key, is_byok=True)with pytest.raises(ApplicationError) as error:- call_llm_judge(- evaluation={"team_id": 1, "evaluation_config": {"prompt": "Polite?"}},- system_prompt="",- user_prompt="Hello!",- allows_na=False,+ env.run(+ lambda: call_llm_judge(+ evaluation={"team_id": 1, "evaluation_config": {"prompt": "Polite?"}},+ system_prompt="",+ user_prompt="Hello!",+ allows_na=False,+ ))assert not error.value.non_retryable+ assert isinstance(error.value, NonReportableError) is not reportableassert error.value.next_retry_delay == timedelta(seconds=15)assert terminal_user_error_result_from_application_error(error.value, allows_na=False) is Noneassert transport.call_count == 1