The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(connectors): guest creation waits out a failed attempt, and only intent creates it
alt-glitch54eae7a160df
diff --git a/hermes_cli/anon_auth.py b/hermes_cli/anon_auth.pyindex 72a84166401..ef748b9af32 100644--- a/hermes_cli/anon_auth.py+++ b/hermes_cli/anon_auth.py@@ -48,9 +48,9 @@ ANON_SECRET_HEADER = "x-anonymous-api-secret"# The shared secret gates the anonymous surface during its integration phase. It is a deployment# secret (Sid's), read from the environment only.ANON_SECRET_ENV = "HERMES_ANON_API_SECRET"-# Launch gate for the whole free tier while it is pre-GA: exactly "1" turns it on for this process-# (CLI, gateway, serve backend alike); anything else leaves every surface behaving as if the free-# tier did not exist. Not a user preference: never written to+# Launch gate for the free tier while it is pre-GA: exactly "1" turns it on for this process (CLI,+# gateway, serve backend alike): the boot mint, the free model and the free-tier surfaces. A guest+# for connectors only needs ``nous.guest`` (``guest_allowed``). Not a user preference: never written to# config.yaml or .env, never shown in setup. Deleted at GA together with this comment.GUEST_ONBOARDING_ENV = "HERMES_GUEST_ONBOARDING"# Preview cohort for the free tier's connector set, sent once on account creation so the account@@ -598,7 +598,7 @@ def _note_mint_failure(err: AuthError) -> MintFailure:return failure-def _reconcile_and_provision(*, timeout_seconds: float) -> Optional[dict[str, Any]]:+def _reconcile_and_provision(*, timeout_seconds: float, force: bool = False) -> Optional[dict[str, Any]]:"""The lifecycle body, run under profile lock THEN shared lock (the documented order).1. The shared store is the identity of record for this Hermes root. If it holds an identity@@ -628,6 +628,10 @@ def _reconcile_and_provision(*, timeout_seconds: float) -> Optional[dict[str, Anif not shared:_write_shared_nous_state(profile_state)return profile_state+ # A caller queued on these locks behind a mint that just failed waits out its cooldown.+ failure = _mint_failure_for_profile()+ if failure and not force and time.monotonic() < failure.not_before:+ return Noneverify = _resolve_verify(insecure=None, ca_bundle=None, auth_state=None)with _nous_http_client(timeout_seconds, verify) as client:return _mint_locked(client, portal, auth_store)@@ -666,7 +670,7 @@ def ensure_portal_identity(if failure and not force and not current_nous_state() and time.monotonic() < failure.not_before:return None # in cooldown (or terminal) for this profile; do not hammer the portaltry:- state = _reconcile_and_provision(timeout_seconds=timeout_seconds)+ state = _reconcile_and_provision(timeout_seconds=timeout_seconds, force=force)except Exception as exc:err = classify_mint_exception(exc)noted = _note_mint_failure(err)@@ -675,7 +679,8 @@ def ensure_portal_identity(if err is exc:raiseraise err from exc- _clear_mint_failure()+ if state is not None:+ _clear_mint_failure()return statediff --git a/hermes_cli/free_tier_bootstrap.py b/hermes_cli/free_tier_bootstrap.pyindex c7f75e446db..63fdbe832af 100644--- a/hermes_cli/free_tier_bootstrap.py+++ b/hermes_cli/free_tier_bootstrap.py@@ -1,5 +1,4 @@-"""Serve-start bootstrap for the Nous free tier: the one place a free-tier identity that carries-inference is created.+"""Serve-start bootstrap for the Nous free tier: the boot-time creator of its identity.Every Hermes process that may need the free tier runs this once at boot (``hermes serve`` on adaemon thread beside the other background boots; the CLI first-run guard synchronously). It@@ -8,8 +7,8 @@ inventories credentials cheap-first, creates the identity only when the launch gthe answer in process memory, and tells every connected client with one ``setup.ready`` event.Besides this boot path, only the first hosted connector action mints, and only for a user with no-Nous identity (``tools.connectors.gateway.config.ensure_guest_identity``; that guest never opens the-free model). ``free_tier.status`` and ``setup.status`` read the record; provider resolution+Nous identity (``tools.connectors.gateway.config.ensure_guest_identity``; with the launch gate+closed that guest never opens the free model). ``free_tier.status`` and ``setup.status`` read the record; provider resolutionnever reaches the portal; a dead credential is replaced by the explicit re-mint in``auth_nous.resolve_nous_runtime_credentials``. Ruling: NS-845 Q1.2 (recorded on NS-847)."""diff --git a/hermes_cli/main.py b/hermes_cli/main.pyindex 9648352e37a..84a94685f78 100644--- a/hermes_cli/main.py+++ b/hermes_cli/main.py@@ -1092,7 +1092,7 @@ def _auth_store_logged_in(auth_file: Path, registry, strict_profile_scope: bool)def _has_any_provider_configured(*, strict_profile_scope: bool = False) -> bool:"""Check if at least one inference provider is usable. Never creates one: the Nous free tiercounts only once its identity exists, and the boot bootstrap (``hermes_cli.free_tier_bootstrap``)- is the only thing that creates one that carries inference; ``cmd_chat`` runs the bootstrap before asking.+ creates it at boot (a first connector use can too); ``cmd_chat`` runs the bootstrap before asking.``strict_profile_scope``: the caller has bound a NAMED profile's home andsecret scope and wants an answer for that profile only — launch-processdiff --git a/tools/connectors/gateway/config.py b/tools/connectors/gateway/config.pyindex 3b6471aed2c..b8f246673c6 100644--- a/tools/connectors/gateway/config.py+++ b/tools/connectors/gateway/config.py@@ -122,23 +122,34 @@ def guest_identity_pending() -> bool:return not failure or bool(failure["retryable"])+_SETUP_FAILED = "Hosted connectors could not be set up. "+++def guest_setup_failure() -> Optional[str]:+ """The last failed guest creation for this profile, worded with the wait still left, or None."""+ from hermes_cli.anon_auth import anon_failure_copy, last_mint_failure++ if not (failure := last_mint_failure()):+ return None+ return _SETUP_FAILED + anon_failure_copy(failure["error_code"], retry_after=failure["retry_after"])++def ensure_guest_identity() -> Optional[str]:"""Create the guest identity on the first hosted connector action, synchronously.- Returns None when an identity exists or was just created, else the failure copy for the model- (rate limit or portal down, with its wait)."""+ Returns None when an identity exists or was just created, else the failure copy for the model:+ a refusal, a rate limit or an unreachable portal, with the wait when there is one."""if not guest_identity_pending():return None- from hermes_cli.anon_auth import ensure_portal_identity, last_mint_failure+ from hermes_cli.anon_auth import ensure_portal_identityfrom hermes_cli.auth_constants import AuthErrortry:if ensure_portal_identity(explicit=True, for_connectors=True) is not None:return Noneexcept AuthError as exc:- return str(exc)- # Still inside the cooldown of an earlier failure: report that one.- return str((last_mint_failure() or {}).get("error") or "Connectors could not be set up. Try again shortly.")+ return _SETUP_FAILED + str(exc)+ return guest_setup_failure() or _SETUP_FAILED + "Try again shortly."def operation_session_key(session_id: Optional[str]) -> str:diff --git a/tools/connectors/search.py b/tools/connectors/search.pyindex 3b4a3a659db..1789ce3e094 100644--- a/tools/connectors/search.py+++ b/tools/connectors/search.py@@ -17,9 +17,13 @@ def connections_in_scope(tool_defs: Iterable[dict[str, Any]]) -> bool:def connectors_unavailable(failure: str, *, verb: str,names: Optional[list[str]] = None) -> dict[str, Any]:if failure == NOT_SET_UP:- field: dict[str, Any] = {"status": NOT_SET_UP, "hint": (- f"{NOT_SET_UP_MESSAGE} Hosted apps (Gmail, Calendar, Notion and more) are then searchable. "- "If the request is better served by the tools above, use those instead.")}+ from tools.connectors.gateway.config import guest_setup_failure++ hint = (f"{NOT_SET_UP_MESSAGE} Hosted apps (Gmail, Calendar, Notion and more) are then searchable. "+ "If the request is better served by the tools above, use those instead.")+ if last_failure := guest_setup_failure():+ hint += f" The last attempt failed, so tell the user before retrying: {last_failure}"+ field: dict[str, Any] = {"status": NOT_SET_UP, "hint": hint}if names:field["names"] = namesreturn fielddiff --git a/tui_gateway/methods_connectors.py b/tui_gateway/methods_connectors.pyindex 5f1f394dfb4..25a4b253756 100644--- a/tui_gateway/methods_connectors.py+++ b/tui_gateway/methods_connectors.py@@ -78,12 +78,20 @@ def _session_owner(rid, owner):def _account_gate_closed(rid):- from tools.connectors import connectors_available, ensure_guest_identity+ from tools.connectors import connectors_available+ from tui_gateway.contracts.connectors import ConnectorErrorReason++ if connectors_available():+ return None+ return _connector_rpc_error(rid, 4031, ConnectorErrorReason.connectors_unavailable, "Connectors are not available.")+++def _account_identity_error(rid):+ """Opening the Connectors page or connecting from it is the user asking for apps: create the+ guest identity here when the user has none. Operation polls never call this."""+ from tools.connectors import ensure_guest_identityfrom tui_gateway.contracts.connectors import ConnectorErrorReason- if not connectors_available():- return _connector_rpc_error(rid, 4031, ConnectorErrorReason.connectors_unavailable, "Connectors are not available.")- # Opening the Connectors page is the user asking for apps: create the guest identity here.if setup_error := ensure_guest_identity():return _connector_rpc_error(rid, 5034, ConnectorErrorReason.connector_request_failed, setup_error)return None@@ -234,6 +242,8 @@ def _connector_rpc(rid, params, action):with _account_scope(request):if closed := _account_gate_closed(rid):return _ok(rid, {"available": False, "connectors": []}) if action == "status" else closed+ if setup_error := _account_identity_error(rid):+ return setup_errorreturn _account_connector_list(rid) if action == "status" else _account_connector_connect(rid, request)runtime_token = _current_runtime_session_record.set(session)diff --git a/tui_gateway/methods_connectors_account.py b/tui_gateway/methods_connectors_account.pyindex a95c8351392..0c2e0b9675e 100644--- a/tui_gateway/methods_connectors_account.py+++ b/tui_gateway/methods_connectors_account.py@@ -21,7 +21,7 @@ def _account_method(params_model=None, *, invalid="", invalid_reason=ConnectorErfrom pydantic import ValidationErrorfrom tools.connectors.gateway.errors import GatewayAuthError- if gate_error := _account_gate_closed(rid):+ if gate_error := _account_gate_closed(rid) or _account_identity_error(rid):return gate_errortry:request = params if params_model is None else params_model.model_validate(params)diff --git a/website/docs/user-guide/features/tool-search.md b/website/docs/user-guide/features/tool-search.mdindex b015b6c4e23..75ed580ff3a 100644--- a/website/docs/user-guide/features/tool-search.md+++ b/website/docs/user-guide/features/tool-search.md@@ -185,8 +185,8 @@ tools:Connectors need a Nous identity. You do not have to sign in for one: if youhave no Nous account, the first `manage_connections` action (or opening thedesktop Connectors page) creates a free Nous identity for you, on every-surface. It is used for connectors and managed tools only and never changes-your model provider. Until it exists, `tool_search` sends nothing to the+surface. It does not change your model provider: outside builds that ship+the Nous free tier it is used for connectors and managed tools only. Until it exists, `tool_search` sends nothing to thegateway and its result says that hosted connectors are not set up yet andthat `manage_connections` sets them up. To opt out, set: