Skip to content

The agent that grows with you

fix(free-tier): drop guest pool rows, note failed mints under the lock, share connectors_token

alt-glitchda8b41246082
diff --git a/agent/credential_pool.py b/agent/credential_pool.py
index ce32f09f71b..522a2d2ca41 100644
--- a/agent/credential_pool.py
+++ b/agent/credential_pool.py
@@ -2639,13 +2639,12 @@ def _seed_anthropic_singletons(seed: _Seeder) -> None:
def _seed_nous_singleton(seed: _Seeder, auth_store: dict[str, Any]) -> None:
state, source_path = _load_provider_state_with_source(auth_store, "nous")
- from hermes_cli.anon_auth import guest_without_free_tier
- if guest_without_free_tier(state) or owned_profile_reads_root_state(auth_store, "nous", source_path):
- return # a guest kept for connectors only; an agent_key-only row surviving a fork strip/heal
- has_runtime_material = bool(
- isinstance(state, dict)
- and (str(state.get("access_token") or "").strip() or str(state.get("agent_key") or "").strip())
- )
+ if owned_profile_reads_root_state(auth_store, "nous", source_path):
+ # e.g. an agent_key-only row surviving a fork strip/heal
+ return
+ from hermes_cli.anon_auth import guest_without_free_tier # kept for connectors only: no inference rows
+ has_runtime_material = not guest_without_free_tier(state) and bool(isinstance(state, dict) and (
+ str(state.get("access_token") or "").strip() or str(state.get("agent_key") or "").strip()))
if state and not has_runtime_material:
seed.changed |= _retain_sources_not_in(seed.entries, {"device_code", "manual:device_code"})
if not (state and has_runtime_material):
diff --git a/hermes_cli/anon_auth.py b/hermes_cli/anon_auth.py
index ef748b9af32..bef848169ee 100644
--- a/hermes_cli/anon_auth.py
+++ b/hermes_cli/anon_auth.py
@@ -633,8 +633,16 @@ def _reconcile_and_provision(*, timeout_seconds: float, force: bool = False) ->
if failure and not force and time.monotonic() < failure.not_before:
return None
verify = _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)
+ try:
+ with _nous_http_client(timeout_seconds, verify) as client:
+ return _mint_locked(client, portal, auth_store)
+ except Exception as exc:
+ # Noted before the locks are released, so a caller queued on them sees the cooldown.
+ err = classify_mint_exception(exc)
+ err.mint_failure = _note_mint_failure(err)
+ if err is exc:
+ raise
+ raise err from exc
def ensure_portal_identity(
@@ -673,7 +681,7 @@ def ensure_portal_identity(
state = _reconcile_and_provision(timeout_seconds=timeout_seconds, force=force)
except Exception as exc:
err = classify_mint_exception(exc)
- noted = _note_mint_failure(err)
+ noted = getattr(err, "mint_failure", None) or _note_mint_failure(err)
logger.info("Nous free tier not set up (%s, attempt %d%s)", noted.code, noted.attempts,
f", next try in {noted.retry_after:.0f}s" if noted.retryable else ", not retried")
if err is exc:
diff --git a/hermes_cli/auth_nous.py b/hermes_cli/auth_nous.py
index 52081cab733..b22d728438e 100644
--- a/hermes_cli/auth_nous.py
+++ b/hermes_cli/auth_nous.py
@@ -442,7 +442,7 @@ def _nous_shared_shape(src: dict[str, Any]) -> dict[str, Any]:
"inference_base_url": src.get("inference_base_url") or (
DEFAULT_NOUS_WELCOME_URL if src.get("auth_method") == "anonymous" else DEFAULT_NOUS_INFERENCE_URL),
"obtained_at": src.get("obtained_at"), "expires_at": src.get("expires_at"),
- **{k: src[k] for k in ("auth_method", "account_tier", "anon_token", "user_id", "org_id")
+ **{k: src[k] for k in ("auth_method", "account_tier", "anon_token", "user_id", "org_id", "connectors_token")
if src.get(k) not in (None, "")}}
diff --git a/tests/agent/test_credential_pool_connectors_guest.py b/tests/agent/test_credential_pool_connectors_guest.py
new file mode 100644
index 00000000000..d62b4644569
--- /dev/null
+++ b/tests/agent/test_credential_pool_connectors_guest.py
@@ -0,0 +1,24 @@
+"""A guest kept for connectors only never serves inference through the credential pool.
+
+A guest that carried inference in a build with the free-tier launch gate leaves a ``device_code``
+row in ``credential_pool.nous``. In a process without the gate (plain CLI, gateway) the pool must
+drop that row instead of handing its welcome-host token to the runtime.
+"""
+
+from hermes_cli import anon_auth
+from tests.hermes_cli.anon_portal import install_portal
+
+
+def test_guest_pool_row_is_dropped_when_the_free_tier_is_off(monkeypatch, tmp_path):
+ from agent.credential_pool import load_pool
+ from hermes_cli.auth_nous import resolve_nous_runtime_credentials
+
+ install_portal(monkeypatch, tmp_path)
+ assert anon_auth.is_guest_state(anon_auth.ensure_portal_identity(explicit=True))
+ resolve_nous_runtime_credentials() # the guest now carries an inference token
+ assert any(e.source == "device_code" for e in load_pool("nous").entries())
+
+ monkeypatch.delenv("HERMES_GUEST_ONBOARDING")
+
+ assert not any(e.source == "device_code" for e in load_pool("nous").entries())
+ assert anon_auth.has_guest()