Skip to content

The agent that grows with you

fix(onboarding): a blocked trial claim opens no chat that nothing can run

alt-glitchafc4651c6266
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.ts
index a0742c80108..61cd9bcd4e9 100644
--- a/apps/shared/src/gateway-contract.generated.ts
+++ b/apps/shared/src/gateway-contract.generated.ts
@@ -2196,7 +2196,7 @@ export interface OnboardingSetRunParams {
run: boolean
mark_profile_offered?: boolean
}
-/** ``rerun``: start a new onboarding chat even when one is in progress (Settings, Run onboarding again; it never claims the welcome trial). ``fresh_launch``: the app's once-per-launch start; a run the app was closed on does not count, so its chat is deleted and the run starts over. ``facts_source``: whether the backend runs on the user's own computer. ``locale``: the desktop's UI language, preferred over the backend OS locale. ``assume_fresh``: as on ``onboarding.state``. A new run on a first install claims the welcome trial once its run record exists; a failed claim is error 5079 and leaves no guest and no chat. */
+/** ``rerun``: start a new onboarding chat even when one is in progress (Settings, Run onboarding again; it never claims the welcome trial). ``fresh_launch``: the app's once-per-launch start; a run the app was closed on does not count, so its chat is deleted and the run starts over. ``facts_source``: whether the backend runs on the user's own computer. ``locale``: the desktop's UI language, preferred over the backend OS locale. ``assume_fresh``: as on ``onboarding.state``. A new run on a first install claims the welcome trial before its chat exists; a failed claim is error 5079 and leaves no guest and no chat. A claim that is blocked (another install took the trial) with no trial or provider to run on is error 5080 and opens no chat. */
export interface OnboardingStartParams {
rerun?: boolean
fresh_launch?: boolean
diff --git a/apps/shared/src/gateway-contract.openrpc.json b/apps/shared/src/gateway-contract.openrpc.json
index a9100439bba..ba761e0f919 100644
--- a/apps/shared/src/gateway-contract.openrpc.json
+++ b/apps/shared/src/gateway-contract.openrpc.json
@@ -20437,7 +20437,7 @@
},
"OnboardingStartParams": {
"additionalProperties": false,
- "description": "``rerun``: start a new onboarding chat even when one is in progress (Settings, Run onboarding\nagain; it never claims the welcome trial). ``fresh_launch``: the app's once-per-launch start; a run\nthe app was closed on does not count, so its chat is deleted and the run starts over.\n``facts_source``: whether the backend runs on the user's own computer. ``locale``: the desktop's UI\nlanguage, preferred over the backend OS locale. ``assume_fresh``: as on ``onboarding.state``. A new\nrun on a first install claims the welcome trial once its run record exists; a failed claim is error\n5079 and leaves no guest and no chat.",
+ "description": "``rerun``: start a new onboarding chat even when one is in progress (Settings, Run onboarding\nagain; it never claims the welcome trial). ``fresh_launch``: the app's once-per-launch start; a run\nthe app was closed on does not count, so its chat is deleted and the run starts over.\n``facts_source``: whether the backend runs on the user's own computer. ``locale``: the desktop's UI\nlanguage, preferred over the backend OS locale. ``assume_fresh``: as on ``onboarding.state``. A new\nrun on a first install claims the welcome trial before its chat exists; a failed claim is error\n5079 and leaves no guest and no chat. A claim that is blocked (another install took the trial) with\nno trial or provider to run on is error 5080 and opens no chat.",
"properties": {
"rerun": {
"default": false,
diff --git a/tests/tui_gateway/test_onboarding_fresh_launch.py b/tests/tui_gateway/test_onboarding_fresh_launch.py
index cb7a373137a..07d1fa5ba92 100644
--- a/tests/tui_gateway/test_onboarding_fresh_launch.py
+++ b/tests/tui_gateway/test_onboarding_fresh_launch.py
@@ -25,6 +25,7 @@ def root(tmp_path, monkeypatch) -> Path:
monkeypatch.setattr(server, "_hermes_home", str(home))
monkeypatch.setattr(server, "_db", None)
monkeypatch.setattr("agent.onboarding_facts.read_facts", lambda **kw: FACTS)
+ (home / ".env").write_text("OPENROUTER_API_KEY=sk-or-test\n", encoding="utf-8") # a model to run on
return home
diff --git a/tests/tui_gateway/test_onboarding_session.py b/tests/tui_gateway/test_onboarding_session.py
index ddf7c1a652f..395d548a654 100644
--- a/tests/tui_gateway/test_onboarding_session.py
+++ b/tests/tui_gateway/test_onboarding_session.py
@@ -27,6 +27,7 @@ def root(tmp_path, monkeypatch) -> Path:
monkeypatch.setattr(server, "_hermes_home", str(home))
monkeypatch.setattr(server, "_db", None)
monkeypatch.setattr("agent.onboarding_facts.read_facts", lambda **kw: FACTS)
+ (home / ".env").write_text("OPENROUTER_API_KEY=sk-or-test\n", encoding="utf-8") # a model to run on
return home
diff --git a/tests/tui_gateway/test_onboarding_welcome_claim.py b/tests/tui_gateway/test_onboarding_welcome_claim.py
index 4af9c3b09b6..00f049589de 100644
--- a/tests/tui_gateway/test_onboarding_welcome_claim.py
+++ b/tests/tui_gateway/test_onboarding_welcome_claim.py
@@ -1,6 +1,7 @@
"""``onboarding.state`` / ``onboarding.start`` and the desktop's welcome trial: a new run on a first
install claims it with the install already marked due, a rerun never does, a failed claim leaves no guest
-and no chat and the next launch still due, and only the desktop's local backend opens onboarding by itself."""
+and no chat and the next launch still due, a blocked claim with nothing to run on opens no chat, and only
+the desktop's local backend opens onboarding by itself."""
from __future__ import annotations
@@ -81,6 +82,27 @@ def test_a_failed_claim_opens_nothing_and_the_next_launch_tries_again(portal, mo
assert anon_auth.free_inference_active()
+def test_a_trial_another_install_took_first_opens_no_chat_it_cannot_run(portal, root, monkeypatch):
+ """Two installs answered "due" before either claimed. The first takes the trial; the second start
+ opens no chat with no model behind it, so the desktop lands on provider setup and sign-in. The
+ install stays due: once a provider is set, the next start runs onboarding on it."""
+ from hermes_cli import free_tier_bootstrap
+
+ as_local_desktop_backend(monkeypatch)
+ free_tier_bootstrap.run_bootstrap(announce=False)
+ assert _call("onboarding.state")["result"]["eligible"] is True
+ install_state.mark_machine_used() # the other install's claim consumed the reservation
+
+ refused = _call("onboarding.start", {"fresh_launch": True})
+
+ assert refused["error"]["code"] == 5080
+ state = _call("onboarding.state")["result"]
+ assert (state["run"], state["eligible"], state["session_id"]) == (True, False, None)
+ assert portal.creates() == 0
+ (root / ".env").write_text("OPENROUTER_API_KEY=sk-or-test\n", encoding="utf-8")
+ assert "result" in _call("onboarding.start", {"fresh_launch": True})
+
+
def test_a_crash_right_after_the_claim_keeps_onboarding_due(portal, monkeypatch):
as_local_desktop_backend(monkeypatch)
diff --git a/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py b/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py
index d0cc1c0c992..79519693dd5 100644
--- a/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py
+++ b/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py
@@ -402,8 +402,9 @@ class OnboardingStartParams(Params):
the app was closed on does not count, so its chat is deleted and the run starts over.
``facts_source``: whether the backend runs on the user's own computer. ``locale``: the desktop's UI
language, preferred over the backend OS locale. ``assume_fresh``: as on ``onboarding.state``. A new
- run on a first install claims the welcome trial once its run record exists; a failed claim is error
- 5079 and leaves no guest and no chat."""
+ run on a first install claims the welcome trial before its chat exists; a failed claim is error
+ 5079 and leaves no guest and no chat. A claim that is blocked (another install took the trial) with
+ no trial or provider to run on is error 5080 and opens no chat."""
rerun: bool = False
fresh_launch: bool = False
diff --git a/tui_gateway/methods_onboarding.py b/tui_gateway/methods_onboarding.py
index 736a1e695b2..e4b0c071b84 100644
--- a/tui_gateway/methods_onboarding.py
+++ b/tui_gateway/methods_onboarding.py
@@ -119,15 +119,25 @@ def _active_run() -> dict:
return {"session_id": session_id, "run_id": (load(db, session_id) or {}).get("run_id") if session_id else None}
+class _NoModelForTheRun(Exception):
+ """The claim was blocked and nothing else can carry the run's first chat."""
+
+
def _claim_before_run(scope: dict, *, assume_fresh: bool):
"""Claim the welcome trial with ``onboarding.run: true`` already on disk, so a crash after the claim
makes this machine read as used still opens onboarding next launch. The run's chat comes after:
- a refused claim (error 5079) leaves no guest and no chat, and the install still due."""
+ a refused claim (error 5079) leaves no guest and no chat, and the install still due. A blocked claim
+ (another install took the trial since the due check) with no trial or provider to run on is error
+ 5080, with no chat either: the desktop lands on provider setup and sign-in, not a chat that fails."""
+ from hermes_cli import anon_auth
from hermes_cli.onboarding_run import set_run
- from hermes_cli.welcome_trial import claim_desktop_free_tier
+ from hermes_cli.welcome_trial import claim_desktop_free_tier, provider_configured
set_run(True)
with _session_profile_runtime_scope(scope):
- return claim_desktop_free_tier(assume_fresh=assume_fresh)
+ claimed = claim_desktop_free_tier(assume_fresh=assume_fresh)
+ if claimed is None and not (anon_auth.free_inference_active() or provider_configured()):
+ raise _NoModelForTheRun("The welcome trial is not available here, and no provider is set up.")
+ return claimed
@method("onboarding.start")
@@ -183,6 +193,9 @@ def _(rid, params: dict) -> dict:
# launch is still a first install and tries again.
logger.info("onboarding.start: welcome trial not claimed: %s", e)
return _err(rid, 5079, str(e))
+ except _NoModelForTheRun as e:
+ logger.info("onboarding.start: no chat opened: %s", e)
+ return _err(rid, 5080, str(e))
except Exception as e:
logger.exception("onboarding.start failed")
return _err(rid, 5078, str(e))