The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: surface the narrowed error when the aux recovery ladder is exhausted
teknium127faf9ced2f8
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex ffc747d390c..853d01b1ec1 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -6862,8 +6862,6 @@ class _LadderStep(NamedTuple):args: tuple-_RERAISE_ORIGINAL = object()-# Ordered (predicate, reason) pairs for the provider-fallback rung: first match# wins, so a payment-flavoured 429 reads as "payment error", not "rate limit"._FALLBACK_REASONS: Tuple[Tuple[Callable[[Exception], bool], str], ...] = (@@ -7163,7 +7161,7 @@ def _ladder_provider_fallback(first_err: Exception, route: _LadderRoute):# All fallback layers exhausted — emit a single user-visible warning so the operator# knows aux task is about to fail. (#26882) The error itself is re-raised below.# (#26882)- "(fallback_chain + main agent model). Raising original error.",+ "(fallback_chain + main agent model). Raising the last error.",task or "call", tag, reason, resolved_provider)return None@@ -7178,7 +7176,7 @@ def _aux_recovery_ladder("""Ordered recovery rungs after the primary request failed (generator): parameterstrips → Nous heal/refresh → credential refresh/pool rotation → provider fallback.Each rung returns a response, narrows ``first_err`` and falls through, or re-raises.- Returns ``_RERAISE_ORIGINAL`` when exhausted (after evicting a connection-poisoned client)."""+ Raises the narrowed ``first_err`` when exhausted (after evicting a connection-poisoned client)."""tag = " (async)" if async_mode else ""route = _LadderRoute(client, task, tag, async_mode, base_info, resolved_provider, resolved_model,@@ -7210,7 +7208,9 @@ def _aux_recovery_ladder(except Exception:logger.debug("Auxiliary%s: cache eviction after connection error failed",tag, exc_info=True)- return _RERAISE_ORIGINAL+ # The narrowed error is the actionable one (e.g. a 404 "requires credits" from the+ # retry after a healed 401), so surface it rather than the original.+ raise first_errdef _drive_ladder(ladder, perform: Callable[[_LadderStep], Any]) -> Any:@@ -7477,12 +7477,9 @@ def _call_llm_impl(if kind == "retry":return _retry_same_provider_sync(**kw)return _call_fallback_candidate_sync(*args, **kw)- result = _drive_ladder(+ return _drive_ladder(_start_recovery_ladder(first_err, req, retry_kwargs, task=task, async_mode=False, route_info=route_info),_perform)- if result is _RERAISE_ORIGINAL:- raise- return resultdef _coerce_llm_message(response):@@ -7628,12 +7625,9 @@ async def _async_call_llm_impl(fb_client, fb_model, fb_label = argsfb_client, _ = _to_async_client(fb_client, fb_model or "", is_vision=(task == "vision"))return await _call_fallback_candidate_async(fb_client, fb_model, fb_label, **kw)- result = await _drive_ladder_async(+ return await _drive_ladder_async(_start_recovery_ladder(first_err, req, retry_kwargs, task=task, async_mode=True, route_info=route_info),_perform)- if result is _RERAISE_ORIGINAL:- raise- return result# ---- BEGIN PLUGIN-COMPAT (revert-scheduled; see COMPAT_MANIFEST.md) ----diff --git a/tests/agent/test_auxiliary_auth_rung_fallthrough.py b/tests/agent/test_auxiliary_auth_rung_fallthrough.pyindex 5f4539b7f39..5e64f508045 100644--- a/tests/agent/test_auxiliary_auth_rung_fallthrough.py+++ b/tests/agent/test_auxiliary_auth_rung_fallthrough.py@@ -281,3 +281,27 @@ def test_auth_refresh_retry_failure_reaches_the_configured_chain_over_http("401, then the refreshed retry fails on credits, then the configured chain: %r"% (seen,))+++def test_exhausted_ladder_raises_the_narrowed_error(monkeypatch, hermetic):+ """No chain answers: the retry's own failure surfaces, not the healed 401."""+ monkeypatch.setattr(aux, "_refresh_nous_auxiliary_client",+ lambda **kwargs: (_FakeClient(), AUX_MODEL))++ def _no_chain(first_err, route):+ hermetic.append(first_err)+ yield from ()+ return None++ monkeypatch.setattr(aux, "_ladder_provider_fallback", _no_chain)+ failure = _credit_error()++ def perform(step):+ raise failure++ with pytest.raises(_ApiError) as raised:+ aux._drive_ladder(_ladder(), perform)++ assert raised.value is failure, (+ "the ladder must surface the actionable retry failure, got %r" % (raised.value,))+ assert hermetic == [failure]