The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(proxy): never wait on a free-tier challenge under the Nous adapter lock
kshitijk4poore955022eb181
diff --git a/hermes_cli/proxy/adapters/nous_portal.py b/hermes_cli/proxy/adapters/nous_portal.pyindex 4660cd223b9..e5d459aadc2 100644--- a/hermes_cli/proxy/adapters/nous_portal.py+++ b/hermes_cli/proxy/adapters/nous_portal.py@@ -6,6 +6,7 @@ import loggingimport threadingfrom typing import Any, Dict, FrozenSet, Optional+from hermes_cli.anon_challenge import background_callerfrom hermes_cli.auth import (AuthError,DEFAULT_NOUS_INFERENCE_URL,@@ -72,9 +73,12 @@ class NousPortalAdapter(UpstreamAdapter):if state is None:raise RuntimeError("Not logged into Nous Portal. Run `hermes auth add nous` first.")try:- refreshed = resolve_nous_runtime_credentials(- force_refresh=force_refresh, stale_access_token=stale_access_token or None- )+ # Every proxied request queues on self._lock: a free-tier browser challenge is+ # announced and raised, never waited on while holding it.+ with background_caller():+ refreshed = resolve_nous_runtime_credentials(+ force_refresh=force_refresh, stale_access_token=stale_access_token or None+ )except Exception as exc:if isinstance(exc, AuthError) and _is_terminal_nous_refresh_error(exc):_quarantine_nous_oauth_state(state, exc, reason="proxy_refresh_failure")diff --git a/tests/hermes_cli/test_proxy.py b/tests/hermes_cli/test_proxy.pyindex d71dbe6ee39..7636b27f266 100644--- a/tests/hermes_cli/test_proxy.py+++ b/tests/hermes_cli/test_proxy.py@@ -43,6 +43,22 @@ def _write_auth_store(hermes_home: Path, nous_state: Dict[str, Any]) -> Path:return auth_path+def test_nous_adapter_never_waits_on_a_free_tier_challenge_under_its_lock(tmp_path, monkeypatch):+ """Every proxied request queues on the adapter lock, so the credential read inside it is a+ background caller: a browser challenge is announced and raised, never waited on."""+ from hermes_cli import anon_challenge+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))+ _write_auth_store(tmp_path, {"access_token": "a", "refresh_token": "r"})+ seen = []++ def resolve(**_kwargs):+ seen.append(anon_challenge._background.get())+ return {"api_key": "k", "expires_at": "2099-01-01T00:00:00Z",+ "base_url": "https://inference-api.nousresearch.com/v1"}++ with patch("hermes_cli.proxy.adapters.nous_portal.resolve_nous_runtime_credentials", side_effect=resolve):+ NousPortalAdapter().get_credential()+ assert seen == [True]def test_nous_adapter_concurrent_refresh_serialized(tmp_path, monkeypatch):