Skip to content

The agent that grows with you

fix(nous): keep the reconnect copy for a named account on the welcome host

kshitijk4poorc0e604cd4532
diff --git a/agent/error_classifier.py b/agent/error_classifier.py
index fc097f640e2..f54f34f1b6c 100644
--- a/agent/error_classifier.py
+++ b/agent/error_classifier.py
@@ -580,11 +580,17 @@ def _nous_welcome_tier(c: _Ctx) -> Optional[Verdict]:
400/403 whose message names the wrong host or a dark tier is deterministic for the request.
The parsed refusal rides ``error_context`` so the terminal copy can say what happened.
"""
- if not c.anonymous:
- return None
from hermes_cli.anon_auth import (
WELCOME_TIER_GATE_REASONS, parse_welcome_refusal, welcome_route_refusal)
status = c.status_code
+ if not c.anonymous:
+ # A named credential's fairshare 429 is an ordinary rate limit, whatever its body says. The
+ # one welcome refusal it does receive is the gateway's mirror 400 on the welcome host; its
+ # reconnect copy stands, only the sign-in card is withheld (``_welcome_surface_kind``).
+ if status == 400 and welcome_route_refusal(status, c.msg) == "named_on_welcome_host":
+ return _v(_R.format_error, retryable=False, should_fallback=True,
+ error_context={"welcome_route": "named_on_welcome_host"})
+ return None
if status == 429:
refusal = parse_welcome_refusal(c.body)
if refusal is None:
diff --git a/agent/turn_recovery.py b/agent/turn_recovery.py
index ccceea924a1..e34020b9ec7 100644
--- a/agent/turn_recovery.py
+++ b/agent/turn_recovery.py
@@ -737,6 +737,9 @@ def _welcome_surface_kind(classified: Any) -> str:
route = ctx.get("welcome_route") if isinstance(ctx, dict) else None
if route == "tier_disabled":
return "disabled"
+ # A named account on the welcome host has already signed in: no sign-in card, copy only.
+ if route == "named_on_welcome_host":
+ return ""
return "route" if route else ""
@@ -890,9 +893,9 @@ def nonretryable_client_error_result(
"failure_reason": classified.reason.value,
"failure_retryable": bool(classified.retryable),
})
- if _welcome_hint:
+ if _welcome_hint and (_kind := _welcome_surface_kind(classified)):
# The card form: the desktop renders the sign-in as a button, so no "To sign in" tail.
- _stamp_free_tier(result, _welcome_surface_kind(classified),
+ _stamp_free_tier(result, _kind,
_welcome_tier_guidance(classified, model=model, in_chat=True, door=False))
return result
diff --git a/tests/agent/test_error_classifier.py b/tests/agent/test_error_classifier.py
index 138c6419795..907dd1221c5 100644
--- a/tests/agent/test_error_classifier.py
+++ b/tests/agent/test_error_classifier.py
@@ -1841,11 +1841,11 @@ class TestNousWelcomeTier:
assert result.retryable is False and result.should_fallback is True
assert result.error_context["welcome_route"] == "anon_on_paid_host"
- def test_named_caller_on_the_welcome_host_keeps_standard_errors(self):
+ def test_named_caller_on_the_welcome_host_is_deterministic(self):
body = {"status": 400, "message": "This endpoint serves anonymous Hermes Agent accounts only. Use https://inference-api.nousresearch.com with your API key or signed-in account."}
err = MockAPIError(f"Error code: 400 - {body}", status_code=400, body=body)
result = classify_api_error(err, provider="nous", api_key=make_jwt(account_tier="free"))
- assert "welcome_route" not in result.error_context
+ assert result.error_context["welcome_route"] == "named_on_welcome_host"
assert result.retryable is False
def test_dark_tier_403_never_triggers_a_credential_refresh(self):
diff --git a/tests/agent/test_welcome_error_identity.py b/tests/agent/test_welcome_error_identity.py
index aa6af6f30fd..863b71fd6fa 100644
--- a/tests/agent/test_welcome_error_identity.py
+++ b/tests/agent/test_welcome_error_identity.py
@@ -30,12 +30,11 @@ def agent_for(api_key, base_url):
make_jwt(account_tier="paid", client_id="hermes-cli"), "sk-named", None,
], ids=["named-free", "named-paid", "api-key", "unknown"])
@pytest.mark.parametrize("base_url", [NAMED, WELCOME])
[email protected]("case", ["rate_limited", "at_capacity", "admission_closed", "model_not_free", "feature_not_free", "403", "named_route", "503"])
[email protected]("case", ["rate_limited", "at_capacity", "admission_closed", "model_not_free", "feature_not_free", "403", "503"])
def test_named_errors_do_not_offer_anonymous_recovery(api_key, base_url, case):
"""A shared fairshare body or wrong welcome URL cannot establish anonymous identity."""
- status = 403 if case in {"403", "named_route"} else 503 if case == "503" else 429
- message = ("This host serves anonymous Hermes Agent accounts only." if case == "named_route"
- else "You tried to access something that you don't have permissions for." if case == "403"
+ status = 403 if case == "403" else 503 if case == "503" else 429
+ message = ("You tried to access something that you don't have permissions for." if case == "403"
else "The service refused this request.")
body = {"status": status, "message": message, "reason": case, "retry_after": 158}
error = Exception(message)
@@ -137,3 +136,19 @@ def test_anonymous_claim_does_not_classify_other_providers_as_nous():
error.body = {"reason": "rate_limited", "retry_after": 600}
classified = classify_api_error(error, provider="custom", api_key=make_jwt(), base_url=WELCOME)
assert "welcome_refusal" not in classified.error_context
+
+
+def test_named_account_on_welcome_host_gets_reconnect_copy_without_signin_card():
+ """The gateway's mirror 400 keeps its reconnect copy for a signed-in user; the sign-in card would
+ ask for a sign-in that already happened."""
+ message = "This endpoint serves anonymous Hermes Agent accounts only. Use https://inference-api.nousresearch.com with your API key or signed-in account."
+ error = Exception(message)
+ error.status_code, error.body = 400, {"status": 400, "message": message}
+ agent = agent_for(make_jwt(account_tier="free", client_id="hermes-cli"), WELCOME)
+ classified = classify_api_error(error, provider="nous", model=agent.model, base_url=WELCOME, api_key=agent.api_key)
+ result = nonretryable_client_error_result(
+ agent, error, classified, status_code=400, api_kwargs=None, api_messages=[], messages=[],
+ conversation_history=[], api_call_count=1, approx_tokens=10, provider="nous", base_url=WELCOME, model=agent.model)
+ assert "needs to reconnect" in result["final_response"]
+ assert "free_tier" not in result
+ assert "sign in" not in result["final_response"].lower()