Skip to content

Self-improving AI Employees for everyone

fix(temporal): a planned LLM retry is a benign failure (1b.28)

trohitg0c427055e9fc
diff --git a/docs-internal/native_llm_sdk.md b/docs-internal/native_llm_sdk.md
index 2f3a0acb..fbfb393c 100644
--- a/docs-internal/native_llm_sdk.md
+++ b/docs-internal/native_llm_sdk.md
@@ -369,9 +369,12 @@ SDK HTTP transport errors use this same boundary. OpenAI Responses failures
in a successful HTTP body or `response.failed` event are classified before
recording any output; valid max-token incomplete responses remain supported.
Failed streamed attempts are withdrawn immediately, while an owner's Stop
-keeps the intentionally saved partial reply. Planned Temporal retries log
-a warning with activity context instead of a runtime traceback; terminal
-quota, credential, and unexpected programming failures keep their tracebacks.
+keeps the intentionally saved partial reply. A planned Temporal retry is a
+benign `ApplicationError` (`category=BENIGN`): the SDK logs it at DEBUG,
+without a traceback (`core/logging.ExpectedLLMRetryFilter`), and counts no
+failure metric; the retry itself shows at WARNING when the next attempt
+starts (the `activity_retry` interceptor). Terminal quota, credential, and
+unexpected programming failures keep their tracebacks.
The legacy `factory.py` (`create_provider` / `is_native_provider` /
`NATIVE_PROVIDERS`) was **removed** — `ChatUnifier` + `registry.py` is the
diff --git a/server/core/logging.py b/server/core/logging.py
index f24c49c6..17bd810a 100644
--- a/server/core/logging.py
+++ b/server/core/logging.py
@@ -254,11 +254,13 @@ class WebSocketLogHandler(logging.Handler):
class ExpectedLLMRetryFilter(logging.Filter):
- """Keep planned provider retries visible without an exception traceback.
+ """Keep planned provider retries readable, without an exception traceback.
- Temporal raises an ApplicationError to schedule the next attempt. That
- expected control flow should be a warning with activity context; terminal
- rejections and unexpected runtime errors retain their complete tracebacks.
+ The LLM step raises a benign ApplicationError to schedule the next
+ attempt, which the SDK logs at DEBUG ("Completing activity as failed")
+ and counts as no failure. Where that record is shown, it reads as a
+ one-line retry notice; terminal rejections and unexpected runtime errors
+ keep their complete tracebacks at WARNING.
"""
def filter(self, record: logging.LogRecord) -> bool:
diff --git a/server/services/temporal/agent_activities.py b/server/services/temporal/agent_activities.py
index a35fc533..f7cd314b 100644
--- a/server/services/temporal/agent_activities.py
+++ b/server/services/temporal/agent_activities.py
@@ -252,7 +252,7 @@ def _as_temporal_llm_error(error: Any, *, attempt: Optional[int] = None):
and therefore in Temporal history for operators.
"""
- from temporalio.exceptions import ApplicationError
+ from temporalio.exceptions import ApplicationError, ApplicationErrorCategory
from services.llm.protocol import valid_retry_delay
category_value = getattr(getattr(error, "category", None), "value", None)
@@ -300,6 +300,9 @@ def _as_temporal_llm_error(error: Any, *, attempt: Optional[int] = None):
type=f"LLMError.{category}",
non_retryable=not details["retryable"],
next_retry_delay=next_retry_delay,
+ # A planned retry is no failure: the SDK logs it at DEBUG and counts
+ # no failure metric for it.
+ category=ApplicationErrorCategory.BENIGN if details["retryable"] else ApplicationErrorCategory.UNSPECIFIED,
)
diff --git a/server/tests/temporal/test_agent_llm_contract.py b/server/tests/temporal/test_agent_llm_contract.py
index 1654ba75..db06774b 100644
--- a/server/tests/temporal/test_agent_llm_contract.py
+++ b/server/tests/temporal/test_agent_llm_contract.py
@@ -418,9 +418,13 @@ class TestLlmStepActivity:
)
temporal_error = _as_temporal_llm_error(provider_error)
+ from temporalio.exceptions import ApplicationErrorCategory
+
assert "raw body" not in str(temporal_error)
assert temporal_error.type == "LLMError.rate_limit"
assert temporal_error.non_retryable is False
+ # A planned retry is no failure (1b.28).
+ assert temporal_error.category == ApplicationErrorCategory.BENIGN
# The provider's Retry-After hint paces the next Temporal attempt.
assert temporal_error.next_retry_delay == timedelta(seconds=1.5)
assert temporal_error.details == (
diff --git a/server/tests/temporal/test_llm_retry_status.py b/server/tests/temporal/test_llm_retry_status.py
index f26b81f7..b689dee2 100644
--- a/server/tests/temporal/test_llm_retry_status.py
+++ b/server/tests/temporal/test_llm_retry_status.py
@@ -7,7 +7,7 @@ from unittest.mock import AsyncMock
import pytest
from google.genai.errors import ClientError, ServerError
-from temporalio.exceptions import ApplicationError
+from temporalio.exceptions import ApplicationError, ApplicationErrorCategory
from temporalio.testing import ActivityEnvironment
from services.llm.protocol import LLMError, LLMErrorCategory, LLMResponse, Message, StreamEvent, message_to_wire
@@ -49,6 +49,7 @@ async def test_internal_error_announces_backoff_then_clears_on_success(step, att
failure = raised.value
assert failure.type == "LLMError.server"
assert not failure.non_retryable
+ assert failure.category == ApplicationErrorCategory.BENIGN
assert failure.next_retry_delay == timedelta(seconds=delay)
assert failure.__suppress_context__
assert "secret" not in str(failure.details)
@@ -87,6 +88,8 @@ async def test_google_retry_info_paces_throttles_but_cannot_override_a_daily_blo
await env.run(execute_llm_step, payload)
failure = raised.value
assert failure.non_retryable is daily
+ # Only a planned retry is benign; the daily block fails for real.
+ assert failure.category == (ApplicationErrorCategory.UNSPECIFIED if daily else ApplicationErrorCategory.BENIGN)
if daily:
assert failure.next_retry_delay is None
assert failure.type == "LLMError.quota"