Skip to content

The agent that grows with you

fix(auxiliary): honor task fallback after explicit auth failure

KoNit-Kac70c4f0427c
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.py
index c2509d21e4f..20d9e04b673 100644
--- a/agent/auxiliary_client.py
+++ b/agent/auxiliary_client.py
@@ -7432,7 +7432,8 @@ def _ladder_provider_fallback(first_err: Exception, route: _LadderRoute):
chain, explicit: main-agent-model net). Returns the response or None.
Capacity errors (payment/quota, connection, exhausted 429, model incompatible, malformed
response) bypass the explicit-provider gate — the provider cannot serve this request
- regardless of user intent. Auth errors only fall back in auto mode."""
+ regardless of user intent. Auth errors from an explicit provider may only use the task's
+ own configured fallback_chain; they never imply an unconfigured provider hop."""
task, tag, resolved_provider = route.task, route.tag, route.resolved_provider
# Respect explicit provider choice for transient errors (auth, request validation, etc.) but allow
# fallback when the provider clearly cannot serve the request due to capacity: payment/quota exhaustion
@@ -7444,7 +7445,12 @@ def _ladder_provider_fallback(first_err: Exception, route: _LadderRoute):
reason = next((label for predicate, label in _FALLBACK_REASONS if predicate(first_err)), None)
is_capacity_error = any(
predicate(first_err) for predicate, label in _FALLBACK_REASONS if label != "auth error")
- if reason is None or not (is_auto or is_capacity_error):
+ task_chain = _get_auxiliary_task_config(task).get("fallback_chain") if task else None
+ has_task_fallback_chain = isinstance(task_chain, list) and bool(task_chain)
+ explicit_auth_with_task_chain = (
+ reason == "auth error" and not is_auto and has_task_fallback_chain
+ )
+ if reason is None or not (is_auto or is_capacity_error or explicit_auth_with_task_chain):
return None
if reason == "payment error":
# Mark the concrete backend (not the "auto" label) unhealthy so later aux calls skip
@@ -7483,7 +7489,7 @@ def _ladder_provider_fallback(first_err: Exception, route: _LadderRoute):
fb_client, fb_model, fb_label = _try_payment_fallback(
resolved_provider, task, reason=reason, failed_base_url=route.base_info,
failure_scope=_chain_failure_scope, main_runtime=route.main_runtime)
- elif fb_client is None:
+ elif fb_client is None and not explicit_auth_with_task_chain:
fb_client, fb_model, fb_label = _try_main_agent_model_fallback(
resolved_provider, task, reason=reason, failed_model=_chain_failed_model,
failed_base_url=route.base_info, failure_scope=_chain_failure_scope)
diff --git a/tests/agent/test_auxiliary_auth_rung_fallthrough.py b/tests/agent/test_auxiliary_auth_rung_fallthrough.py
index 5e64f508045..f33bde6d25d 100644
--- a/tests/agent/test_auxiliary_auth_rung_fallthrough.py
+++ b/tests/agent/test_auxiliary_auth_rung_fallthrough.py
@@ -69,6 +69,11 @@ class _FakeClient:
base_url = "https://%s/v1" % NOUS_HOST
+class _ExplicitProviderClient:
+ api_key = "stale-key"
+ base_url = "https://vertex.example/v1"
+
+
def _ladder(base_info=("https://%s/v1" % NOUS_HOST), resolved_provider="nous"):
return aux._aux_recovery_ladder(
_auth_error(),
@@ -156,6 +161,84 @@ def test_post_refresh_retry_owns_the_ladder_outcome(
assert result == "chain-response"
+def test_explicit_provider_auth_uses_its_configured_task_fallback(monkeypatch):
+ """An explicit route may leave a 401 only through its own configured chain."""
+ fallback_client = _FakeClient()
+ configured_chain_calls = []
+ monkeypatch.setattr(
+ aux,
+ "_get_auxiliary_task_config",
+ lambda task: {"fallback_chain": [{"provider": "custom:backup", "model": FALLBACK_MODEL}]},
+ )
+ monkeypatch.setattr(aux, "_auth_refresh_provider_for_route", lambda *args, **kwargs: "vertex")
+ monkeypatch.setattr(aux, "_refresh_provider_credentials", lambda *args, **kwargs: False)
+ monkeypatch.setattr(aux, "_recoverable_pool_provider", lambda *args, **kwargs: None)
+
+ def configured_chain(*args, **kwargs):
+ configured_chain_calls.append((args, kwargs))
+ return fallback_client, FALLBACK_MODEL, "fallback_chain[0](custom:backup)"
+
+ monkeypatch.setattr(aux, "_try_configured_fallback_chain", configured_chain)
+ ladder = aux._aux_recovery_ladder(
+ _auth_error(),
+ client=_ExplicitProviderClient(),
+ kwargs={"model": AUX_MODEL},
+ task="compression",
+ async_mode=False,
+ base_info="https://vertex.example/v1",
+ resolved_provider="vertex",
+ resolved_model=AUX_MODEL,
+ resolved_base_url=None,
+ resolved_api_key=None,
+ resolved_api_mode=None,
+ final_model=AUX_MODEL,
+ max_tokens=None,
+ main_runtime=None,
+ route_info={},
+ )
+
+ def perform(step):
+ assert step.kind == "fallback"
+ assert step.args == (fallback_client, FALLBACK_MODEL, "fallback_chain[0](custom:backup)")
+ return "fallback-response"
+
+ assert aux._drive_ladder(ladder, perform) == "fallback-response"
+ assert configured_chain_calls
+
+
+def test_explicit_provider_auth_never_uses_an_unconfigured_fallback(monkeypatch):
+ """A 401 without a task chain preserves the explicit-provider boundary."""
+ monkeypatch.setattr(aux, "_get_auxiliary_task_config", lambda task: {})
+ monkeypatch.setattr(aux, "_auth_refresh_provider_for_route", lambda *args, **kwargs: "vertex")
+ monkeypatch.setattr(aux, "_refresh_provider_credentials", lambda *args, **kwargs: False)
+ monkeypatch.setattr(aux, "_recoverable_pool_provider", lambda *args, **kwargs: None)
+ monkeypatch.setattr(
+ aux,
+ "_try_main_agent_model_fallback",
+ lambda *args, **kwargs: pytest.fail("explicit auth must not use the main-agent fallback"),
+ )
+ ladder = aux._aux_recovery_ladder(
+ _auth_error(),
+ client=_ExplicitProviderClient(),
+ kwargs={"model": AUX_MODEL},
+ task="compression",
+ async_mode=False,
+ base_info="https://vertex.example/v1",
+ resolved_provider="vertex",
+ resolved_model=AUX_MODEL,
+ resolved_base_url=None,
+ resolved_api_key=None,
+ resolved_api_mode=None,
+ final_model=AUX_MODEL,
+ max_tokens=None,
+ main_runtime=None,
+ route_info={},
+ )
+
+ with pytest.raises(_ApiError, match="Unauthorized"):
+ aux._drive_ladder(ladder, lambda step: pytest.fail("no fallback request expected"))
+
+
@pytest.fixture
def nous_ladder_endpoint(monkeypatch):
"""A local endpoint that answers the Nous host, recording every request.