The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(auth): actionable CAPTCHA-aware guidance on Nous device-auth timeout
HexLabfbf26e384534
diff --git a/hermes_cli/auth.py b/hermes_cli/auth.pyindex ebc0af0e45b..2ed16339d43 100644--- a/hermes_cli/auth.py+++ b/hermes_cli/auth.py@@ -5058,6 +5058,25 @@ def _request_device_code(return data+def _nous_device_auth_timeout_message(portal_base_url: str) -> str:+ """Actionable timeout text for Nous device-code login failures.++ A bare "Timed out waiting for device authorization" gives the user+ nothing to act on. The most common cause is Portal sign-in failing in+ the opened browser tab (including the server-side CAPTCHA loop from+ #20605), so point at the Portal login page and the retry command.+ """+ portal = (portal_base_url or DEFAULT_NOUS_PORTAL_URL).rstrip("/")+ return (+ "Timed out waiting for device authorization.\n"+ " Portal sign-in is required before the device code can be approved.\n"+ " If the browser showed a CAPTCHA / 'You did not pass CAPTCHA' error,\n"+ " finish signing in at the Portal in a normal browser tab, then retry:\n"+ " hermes portal\n"+ f" Portal login: {portal}/login"+ )++def _poll_for_token(client: httpx.Client,portal_base_url: str,@@ -8612,14 +8631,19 @@ def _nous_device_code_login(effective_interval = max(1, min(interval, DEVICE_AUTH_POLL_INTERVAL_CAP_SECONDS))print(f"Waiting for approval (polling every {effective_interval}s)...")- token_data = _poll_for_token(- client=client,- portal_base_url=portal_base_url,- client_id=client_id,- device_code=str(device_data["device_code"]),- expires_in=expires_in,- poll_interval=interval,- )+ try:+ token_data = _poll_for_token(+ client=client,+ portal_base_url=portal_base_url,+ client_id=client_id,+ device_code=str(device_data["device_code"]),+ expires_in=expires_in,+ poll_interval=interval,+ )+ except TimeoutError as exc:+ raise TimeoutError(+ _nous_device_auth_timeout_message(portal_base_url)+ ) from excnow = datetime.now(timezone.utc)token_expires_in = _coerce_ttl_seconds(token_data.get("expires_in", 0))diff --git a/tests/hermes_cli/test_auth_nous_provider.py b/tests/hermes_cli/test_auth_nous_provider.pyindex dbc5a2375ee..55f432554f2 100644--- a/tests/hermes_cli/test_auth_nous_provider.py+++ b/tests/hermes_cli/test_auth_nous_provider.py@@ -1064,3 +1064,72 @@ class TestStalePortalBaseUrlMigration:auth_mod.resolve_nous_runtime_credentials()assert refresh_calls == [auth_mod.DEFAULT_NOUS_PORTAL_URL]+++# =============================================================================+# Device-auth timeout guidance (#20605 kernel from PR #75290)+# =============================================================================+++class TestNousDeviceAuthTimeoutMessage:+ def test_timeout_message_mentions_captcha_login_and_retry(self):+ from hermes_cli.auth import _nous_device_auth_timeout_message++ msg = _nous_device_auth_timeout_message("https://portal.nousresearch.com")+ assert "CAPTCHA" in msg+ assert "hermes portal" in msg+ assert "https://portal.nousresearch.com/login" in msg+ # Must NOT point at the nonexistent /device page (live Portal 404s it).+ assert "/device" not in msg++ def test_timeout_message_falls_back_to_default_portal(self):+ from hermes_cli.auth import (+ DEFAULT_NOUS_PORTAL_URL,+ _nous_device_auth_timeout_message,+ )++ msg = _nous_device_auth_timeout_message("")+ assert f"{DEFAULT_NOUS_PORTAL_URL.rstrip('/')}/login" in msg+++def test_nous_device_code_login_timeout_raises_actionable_message(monkeypatch):+ """Poll timeout must surface the CAPTCHA-aware guidance, not a bare line."""+ import pytest++ import hermes_cli.auth as auth_mod++ monkeypatch.setattr(+ auth_mod,+ "_request_device_code",+ lambda **kwargs: {+ "device_code": "device",+ "user_code": "SMCL-97YT",+ "verification_uri": "https://portal.nousresearch.com/manage-subscription",+ "verification_uri_complete": (+ "https://portal.nousresearch.com/manage-subscription"+ "?user_code=SMCL-97YT"+ ),+ "expires_in": 600,+ "interval": 1,+ },+ )++ def _timeout(**kwargs):+ raise TimeoutError("Timed out waiting for device authorization")++ monkeypatch.setattr(auth_mod, "_poll_for_token", _timeout)+ monkeypatch.setattr(auth_mod.webbrowser, "open", lambda url: True)+ monkeypatch.setattr("builtins.print", lambda *a, **k: None)++ with pytest.raises(TimeoutError) as excinfo:+ auth_mod._nous_device_code_login(+ portal_base_url="https://portal.nousresearch.com",+ inference_base_url="https://inference.example.com/v1",+ open_browser=False,+ timeout_seconds=1,+ )++ msg = str(excinfo.value)+ assert "CAPTCHA" in msg+ assert "hermes portal" in msg+ assert "https://portal.nousresearch.com/login" in msg