The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(aux): explicit-provider auth fallback stays on the task chain through the quarantine re-walk
teknium1e6d4dcf91790
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex 20d9e04b673..9fbd2e881d0 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -7407,15 +7407,18 @@ def _ladder_credential_rungs(def _next_fallback_after_quarantine(task: Optional[str], resolved_provider: str, is_auto: bool, route: _LadderRoute,- failed_model: Optional[str], failure_scope: Any,+ failed_model: Optional[str], failure_scope: Any, *, task_chain_only: bool = False,) -> Tuple[Optional[Any], Optional[str], str]:"""Next candidate after a fallback entry was quarantined mid-request (dead credential or acapacity error): remaining configured entries (task chain, then main chain on auto) before the- discovery chain."""+ discovery chain. ``task_chain_only`` (explicit-provider auth error) stops at the task chain —+ the user never opted that task into discovery or the main model."""reason = "fallback candidate unavailable"fb = _try_configured_fallback_chain(task, resolved_provider or "auto", reason=reason, failed_model=failed_model,failed_base_url=route.base_info, failure_scope=failure_scope)+ if task_chain_only:+ return fbif fb[0] is None and is_auto:fb = _try_main_fallback_chain(task, resolved_provider or "auto", reason=reason, failed_model=failed_model,@@ -7509,7 +7512,8 @@ def _ladder_provider_fallback(first_err: Exception, route: _LadderRoute):if fb_resp is not None:return fb_respfb_client, fb_model, fb_label = _next_fallback_after_quarantine(- task, resolved_provider, is_auto, route, _chain_failed_model, _chain_failure_scope)+ task, resolved_provider, is_auto, route, _chain_failed_model, _chain_failure_scope,+ task_chain_only=explicit_auth_with_task_chain)# All fallback layers exhausted — one user-visible warning, then re-raise.logger.warning("Auxiliary %s%s: %s on %s and all fallbacks exhausted "# All fallback layers exhausted — emit a single user-visible warning so the operatordiff --git a/tests/agent/test_auxiliary_auth_rung_fallthrough.py b/tests/agent/test_auxiliary_auth_rung_fallthrough.pyindex f33bde6d25d..8668a6a66c7 100644--- a/tests/agent/test_auxiliary_auth_rung_fallthrough.py+++ b/tests/agent/test_auxiliary_auth_rung_fallthrough.py@@ -161,22 +161,31 @@ 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 = [][email protected]("spare_survives", [True, False])+def test_explicit_provider_auth_uses_its_configured_task_fallback(monkeypatch, spare_survives):+ """An explicit route may leave a 401 only through its own configured chain — including the+ re-walk after a chain entry is quarantined mid-request; an exhausted chain raises the primary+ error instead of spilling onto discovery / the main model."""+ dead_client, fallback_client = _ExplicitProviderClient(), _FakeClient()+ chain = [("fallback_chain[0](custom:dead)", dead_client)]+ if spare_survives:+ chain.append(("fallback_chain[1](custom:backup)", fallback_client))monkeypatch.setattr(aux,"_get_auxiliary_task_config",- lambda task: {"fallback_chain": [{"provider": "custom:backup", "model": FALLBACK_MODEL}]},+ lambda task: {"fallback_chain": [{"provider": "custom:dead"}, {"provider": "custom:backup"}]},)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)+ for name in ("_try_payment_fallback", "_try_main_fallback_chain", "_try_main_agent_model_fallback"):+ monkeypatch.setattr(aux, name, lambda *a, _n=name, **k: pytest.fail(f"{_n} must stay gated for explicit auth"))def configured_chain(*args, **kwargs):- configured_chain_calls.append((args, kwargs))- return fallback_client, FALLBACK_MODEL, "fallback_chain[0](custom:backup)"+ if not chain:+ return None, None, ""+ label, client = chain.pop(0)+ return client, FALLBACK_MODEL, labelmonkeypatch.setattr(aux, "_try_configured_fallback_chain", configured_chain)ladder = aux._aux_recovery_ladder(@@ -199,11 +208,17 @@ def test_explicit_provider_auth_uses_its_configured_task_fallback(monkeypatch):def perform(step):assert step.kind == "fallback"- assert step.args == (fallback_client, FALLBACK_MODEL, "fallback_chain[0](custom:backup)")+ if step.args[0] is dead_client:+ return None # quarantined mid-request → the ladder re-walks the chain+ assert step.args == (fallback_client, FALLBACK_MODEL, "fallback_chain[1](custom:backup)")return "fallback-response"- assert aux._drive_ladder(ladder, perform) == "fallback-response"- assert configured_chain_calls+ if spare_survives:+ assert aux._drive_ladder(ladder, perform) == "fallback-response"+ else:+ with pytest.raises(_ApiError, match="Unauthorized"):+ aux._drive_ladder(ladder, perform)+ assert not chaindef test_explicit_provider_auth_never_uses_an_unconfigured_fallback(monkeypatch):