The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(agent): name a non-retryable API failure on the attempt line
teknium19c75ae13eef3
diff --git a/agent/turn_api_error.py b/agent/turn_api_error.pyindex 7ff73b728b6..aeba4702192 100644--- a/agent/turn_api_error.py+++ b/agent/turn_api_error.py@@ -141,6 +141,7 @@ def handle_api_error(error_type, error_msg, _provider, _base, _model = log_api_error_attempt(agent, api_error, retry_count=retry_count, max_retries=max_retries, status_code=status_code,elapsed_time=elapsed_time, api_messages=api_messages, approx_tokens=approx_tokens,+ retryable=bool(classified.retryable),)if agent._interrupt_requested:diff --git a/agent/turn_recovery.py b/agent/turn_recovery.pyindex 32b388ff980..7c471178cc8 100644--- a/agent/turn_recovery.py+++ b/agent/turn_recovery.py@@ -1093,22 +1093,28 @@ def max_retries_exhausted_result(def log_api_error_attempt(agent: Any, api_error: Exception, *, retry_count: int, max_retries: int,status_code: Optional[int], elapsed_time: float, api_messages: Any, approx_tokens: int,+ retryable: bool = True,) -> Tuple[str, str, Any, Any, Any]:"""Log one failed API attempt (warning + buffered retry trace, OpenRouter "no toolendpoints" hint, bare-404 missing-vendor-prefix hint); the buffer only surfaces if every- retry+fallback exhausts. Returns ``(error_type, error_msg, provider, base_url, model)``."""+ retry+fallback exhausts. Returns ``(error_type, error_msg, provider, base_url, model)``.++ ``retryable=False`` (the classifier's verdict, e.g. a 401 on a static-key route) is+ named on the line: a bare ``attempt 1/3`` promises a second attempt that never comes+ and sends readers hunting for a retry bug (#73237)."""error_type = type(api_error).__name__error_msg = str(api_error).lower()_error_summary = agent._summarize_api_error(api_error)+ _attempt = f"attempt {retry_count}/{max_retries}" + ("" if retryable else ", not retryable")logger.warning(- "API call failed (attempt %s/%s) error_type=%s %s summary=%s",- retry_count, max_retries, error_type, agent._client_log_context(), _error_summary,+ "API call failed (%s) error_type=%s %s summary=%s",+ _attempt, error_type, agent._client_log_context(), _error_summary,)_provider = getattr(agent, "provider", "unknown")_base = getattr(agent, "base_url", "unknown")_model = getattr(agent, "model", "unknown")- _blines(agent, f"⚠️ Attempt {retry_count}/{max_retries} failed: {_error_summary}")+ _blines(agent, f"⚠️ {_attempt[0].upper()}{_attempt[1:]} failed: {_error_summary}")# Exception class, endpoint, raw body and token counts are developer detail: verbose only.if getattr(agent, "verbose_logging", False):_status_code_str = f" [HTTP {status_code}]" if status_code else ""diff --git a/tests/agent/test_turn_recovery_attempt_line.py b/tests/agent/test_turn_recovery_attempt_line.pynew file mode 100644index 00000000000..f2e08daf1fc--- /dev/null+++ b/tests/agent/test_turn_recovery_attempt_line.py@@ -0,0 +1,45 @@+"""A non-retryable API failure names itself instead of promising a second attempt.++A 401 on a static-key route (no credential to refresh, no pool entry to rotate to)+goes straight to the fallback chain, so the log used to read ``API call failed+(attempt 1/3)`` while ``attempt 2/3`` never appeared — which reads as a retry+counter that failed to advance (#73237). The classifier's verdict now rides the+same line on both surfaces (logger + buffered status trace)."""++import logging+from unittest.mock import MagicMock++from agent.turn_recovery import log_api_error_attempt+++def _agent():+ agent = MagicMock()+ agent._summarize_api_error.return_value = "HTTP 401 invalid key"+ agent._client_log_context.return_value = "provider=custom"+ agent._is_openrouter_url.return_value = False+ agent.verbose_logging = False+ agent.provider, agent.base_url, agent.model = "custom", "https://x.test/v1", "m"+ return agent+++def _call(agent, retryable):+ return log_api_error_attempt(+ agent, RuntimeError("401"), retry_count=1, max_retries=3, status_code=401,+ elapsed_time=0.1, api_messages=[], approx_tokens=10, retryable=retryable,+ )+++def test_non_retryable_failure_is_named_on_log_and_status_line(caplog):+ agent = _agent()+ with caplog.at_level(logging.WARNING, logger="agent.conversation_loop"):+ _call(agent, retryable=False)+ assert "attempt 1/3, not retryable" in caplog.text+ assert "not retryable" in agent._buffer_vprint.call_args_list[0].args[0]+++def test_retryable_failure_keeps_the_plain_attempt_counter(caplog):+ agent = _agent()+ with caplog.at_level(logging.WARNING, logger="agent.conversation_loop"):+ _call(agent, retryable=True)+ assert "(attempt 1/3)" in caplog.text+ assert "not retryable" not in caplog.text