hermes-agent/tests/agent/test_nonretryable_result_carries_verdict.py
Teknium 97ca90f184 fix(desktop): expired OAuth grant shows a one-click 'Sign in again' instead of a retryable Provider error
A rejected OAuth token (HTTP 401 'User not found' from Nous Portal, Codex,
xAI…) reached the desktop error card as 'Provider error' with Retry as the
first action, which just replays the same dead credential.

Backend: nonretryable_client_error_result dropped failure_reason /
failure_retryable, so error_surface classified every non-retryable 4xx as a
retryable provider failure. It now stamps the classifier verdict like the
max-retries path, and auth-layer descriptors carry auth_kind
(oauth|api_key, derived from the provider catalog tab) + provider_label.

Desktop: an auth/oauth surface renders 'Authentication error', explains that
the <provider> sign-in expired/was revoked, and offers 'Sign in to <provider>
again' which launches that provider's existing onboarding OAuth flow scoped
to the failed session's gateway profile. Retry stays as the follow-up click.
Re-login to the provider already in use keeps the current model instead of
swapping in the recommended default.
2026-09-09 16:30:24 -07:00

43 lines
1.7 KiB
Python

"""A non-retryable 4xx (rejected OAuth token, bad key) must reach UI clients with the
classifier's verdict: without ``failure_reason`` the desktop error card read a 401 as a
retryable "Provider error" and offered Retry instead of a re-login."""
from __future__ import annotations
from agent.error_classifier import classify_api_error
from agent.error_surface import LAYER_AUTH, build_error_surface_from_result
from agent.turn_recovery import nonretryable_client_error_result
class _Rejected(Exception):
status_code = 401
def __init__(self) -> None:
super().__init__("HTTP 401: User not found.")
class _Agent:
log_prefix = ""
verbose = False
def _summarize_api_error(self, error):
return str(error)
def __getattr__(self, name): # status/persist/print helpers the terminal path calls
return lambda *args, **kwargs: None
def test_nonretryable_401_result_classifies_as_auth_for_the_ui():
error = _Rejected()
classified = classify_api_error(error, provider="nous", model="m")
result = nonretryable_client_error_result(
_Agent(), error, classified, status_code=401, api_kwargs=None, api_messages=[], messages=[],
conversation_history=None, api_call_count=1, approx_tokens=10, provider="nous",
base_url="https://inference-api.nousresearch.com/v1", model="m",
)
assert result["failure_reason"] == classified.reason.value
assert result["failure_retryable"] is classified.retryable is False
surface = build_error_surface_from_result(result, provider="nous", model="m")
assert surface["layer"] == LAYER_AUTH
assert surface["retryable"] is False
assert surface["auth_kind"] == "oauth"