The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
perf(aux): bound the anonymous Nous cooldown marker instead of skipping it
kshitijk4poor86d393d7851e
diff --git a/agent/auxiliary_client.py b/agent/auxiliary_client.pyindex 0ad9dc2f90e..d4eda237371 100644--- a/agent/auxiliary_client.py+++ b/agent/auxiliary_client.py@@ -2265,7 +2265,6 @@ def _try_nous(vision: bool = False) -> Tuple[Optional[OpenAI], Optional[str]]:base_url = str((nous or {}).get("inference_base_url") or _scoped_key_env("NOUS_INFERENCE_BASE_URL") or _NOUS_DEFAULT_BASE_URL).rstrip("/")- # Resolve the request identity before consulting its cross-session cooldown.with contextlib.suppress(Exception):from agent.nous_rate_guard import nous_rate_limit_remainingfrom hermes_cli.anon_auth import is_anonymous_request@@ -2273,9 +2272,10 @@ def _try_nous(vision: bool = False) -> Tuple[Optional[OpenAI], Optional[str]]:remaining = nous_rate_limit_remaining(anonymous=anonymous)if remaining is not None and remaining > 0:logger.debug("Auxiliary: skipping Nous Portal (rate-limited, resets in %.0fs)", remaining)- # A provider-wide cache would outlive signing in with a named account.- if not anonymous:- _mark_provider_unhealthy("nous", ttl=remaining)+ # The health marker is provider-wide, so a full-length anonymous cooldown would+ # outlive signing in mid-cooldown; bound it instead of re-resolving credentials+ # (auth store lock, pool read) on every auxiliary call for the cooldown's duration.+ _mark_provider_unhealthy("nous", ttl=min(remaining, 60.0) if anonymous else remaining)return None, Nonelane = "vision" if vision else "text"# The free tier's host serves exactly one model, for every lane: asking it for the Portal'sdiff --git a/tests/agent/test_welcome_error_identity.py b/tests/agent/test_welcome_error_identity.pyindex 863b71fd6fa..b9d34aca965 100644--- a/tests/agent/test_welcome_error_identity.py+++ b/tests/agent/test_welcome_error_identity.py@@ -98,7 +98,9 @@ def test_signing_in_does_not_inherit_anonymous_cooldown(tmp_path, monkeypatch, tassert nous_rate_limit_remaining() > 0-def test_auxiliary_anonymous_cooldown_does_not_cache_named_provider_as_unhealthy(tmp_path, monkeypatch):+def test_auxiliary_anonymous_cooldown_does_not_outlive_signing_in(tmp_path, monkeypatch):+ """An anonymous cooldown marks the provider unhealthy only briefly: a named sign-in+ mid-cooldown must not inherit the anonymous allowance's wait."""import agent.auxiliary_client as auxfrom agent.nous_rate_guard import record_nous_rate_limit@@ -108,12 +110,12 @@ def test_auxiliary_anonymous_cooldown_does_not_cache_named_provider_as_unhealthymonkeypatch.setattr(aux, "_read_nous_auth", lambda: {})monkeypatch.setattr(aux, "_resolve_nous_runtime_api", lambda **kw: tuple(runtime))unhealthy = []- monkeypatch.setattr(aux, "_mark_provider_unhealthy", lambda *a, **kw: unhealthy.append(a))+ monkeypatch.setattr(aux, "_mark_provider_unhealthy", lambda *a, **kw: unhealthy.append(kw.get("ttl")))client = object()monkeypatch.setattr(aux, "_create_openai_client", lambda **kw: client)monkeypatch.setattr(aux, "_aux_probe_active", lambda: True)assert aux._try_nous() == (None, None)- assert unhealthy == []+ assert unhealthy and all(ttl <= 60 for ttl in unhealthy)runtime[:] = [make_jwt(account_tier="free", client_id="hermes-cli"), NAMED]assert aux._try_nous()[0] is client