The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(onboarding): eligibility reads the default profile; a claim refreshes the setup record
alt-glitch61a0e06bfa79
diff --git a/tests/tui_gateway/test_onboarding_run_rpc.py b/tests/tui_gateway/test_onboarding_run_rpc.pyindex c666e53b80d..63e32f599b7 100644--- a/tests/tui_gateway/test_onboarding_run_rpc.py+++ b/tests/tui_gateway/test_onboarding_run_rpc.py@@ -34,6 +34,7 @@ def _onboarding(home: Path) -> dict:def test_state_answers_run_and_eligible(launched_under_work, monkeypatch):+ root, _work = launched_under_work# The user's own "work" profile is install history, so an unset flag is not due, and on the# desktop's local backend nothing carries a first chat: the trial is never claimed on a used machine.as_local_desktop_backend(monkeypatch)@@ -41,7 +42,8 @@ def test_state_answers_run_and_eligible(launched_under_work, monkeypatch):monkeypatch.delenv(var, raising=False)assert _call("onboarding.state")["result"] == {"run": False, "eligible": False, "session_id": None, "run_id": None}- monkeypatch.setenv("OPENROUTER_API_KEY", "sk-or-test")+ # Onboarding runs in the default profile, so its key is what makes the run eligible.+ (root / ".env").write_text("OPENROUTER_API_KEY=sk-or-test\n", encoding="utf-8")assert _call("onboarding.state")["result"]["eligible"] is Truediff --git a/tests/tui_gateway/test_onboarding_welcome_claim.py b/tests/tui_gateway/test_onboarding_welcome_claim.pyindex ee7e8eaa6b9..1379649f568 100644--- a/tests/tui_gateway/test_onboarding_welcome_claim.py+++ b/tests/tui_gateway/test_onboarding_welcome_claim.py@@ -86,6 +86,30 @@ def test_only_the_local_desktop_backend_opens_onboarding_by_itself(portal, monkeassert _call("onboarding.state")["result"]["eligible"] is True+def test_eligible_follows_the_default_profile_not_the_launch_profile(portal, root, monkeypatch):+ from hermes_cli import profiles+ work = profiles.create_profile("work", no_alias=True)+ monkeypatch.setenv("HERMES_HOME", str(work))+ monkeypatch.setattr(server, "_hermes_home", str(work))+ monkeypatch.delenv("OPENROUTER_API_KEY", raising=False)+ (root / ".env").write_text("OPENROUTER_API_KEY=sk-or-test\n", encoding="utf-8")+ as_local_desktop_backend(monkeypatch)+ install_state.mark_machine_used()++ assert _call("onboarding.state")["result"]["eligible"] is True+++def test_a_claim_refreshes_the_setup_record(portal, monkeypatch):+ from hermes_cli import free_tier_bootstrap+ as_local_desktop_backend(monkeypatch)+ free_tier_bootstrap.run_bootstrap(announce=False)++ assert "result" in _call("onboarding.start")++ record = free_tier_bootstrap.current_record()+ assert record is not None and record.free_tier_account is True++def test_the_dev_fresh_install_switch_treats_a_used_machine_as_new(portal, monkeypatch):as_local_desktop_backend(monkeypatch)install_state.mark_machine_used()diff --git a/tui_gateway/methods_onboarding.py b/tui_gateway/methods_onboarding.pyindex e7246b8c91b..20684060573 100644--- a/tui_gateway/methods_onboarding.py+++ b/tui_gateway/methods_onboarding.py@@ -34,9 +34,13 @@ def _run_state(*, assume_fresh: bool = False) -> dict:from hermes_cli.onboarding_run import should_runfrom hermes_cli.welcome_trial import inference_available- return {"run": should_run(assume_fresh=assume_fresh),- "eligible": on_local_desktop_backend() and inference_available(assume_fresh=assume_fresh),- **_active_run()}+ eligible = on_local_desktop_backend()+ if eligible:+ # Read in the default profile, where onboarding runs, not the launch profile.+ home = _profile_home("default")+ with _session_profile_runtime_scope({"profile_home": str(home) if home else None}):+ eligible = inference_available(assume_fresh=assume_fresh)+ return {"run": should_run(assume_fresh=assume_fresh), "eligible": eligible, **_active_run()}# ── first-run onboarding: one chat in the default profile, driven by setup_beat ───────────────@@ -62,12 +66,14 @@ def _(rid, params: dict) -> dict:from agent.onboarding_record import advance, load, open_session_ids, startfrom agent.onboarding_text import CHAT_TITLE, opening_promptfrom hermes_cli.auth_constants import AuthError+ from hermes_cli import free_tier_bootstrapfrom hermes_cli.welcome_trial import claim_desktop_free_tier# The app's once-per-launch start: closing the app mid-run does not count, so that run's chat goes# and the run starts over. A second window or a reconnect sends no flag and gets the run back.fresh_launch = bool(params.get("fresh_launch"))# Held through the opening submit: two windows pressing start at once get one chat and one opening.with _onboarding_start_lock:+ claimed = Nonetry:with _profile_db(_ONBOARDING_PROFILE, writer=True) as db:if db is None:@@ -83,7 +89,7 @@ def _(rid, params: dict) -> dict:# Before the chat exists, so onboarding's own writes are not what the machine# check sees. A rerun never claims: it runs on the configured model.with _session_profile_runtime_scope(scope):- claim_desktop_free_tier(assume_fresh=bool(params.get("assume_fresh")))+ claimed = claim_desktop_free_tier(assume_fresh=bool(params.get("assume_fresh")))with _session_profile_runtime_scope(scope, hydrate_secrets=False):facts = read_facts(facts_source=params.get("facts_source") or "local", locale=params.get("locale"))stored = db.create_session(new_session_id(), "desktop")@@ -113,6 +119,9 @@ def _(rid, params: dict) -> dict:except Exception as e:logger.exception("onboarding.start failed")return _err(rid, 5078, str(e))+ if claimed is not None:+ # Outside the default-profile scope: setup.status serves the launch profile's record.+ free_tier_bootstrap.refresh_record()_withdraw_setup_cards([] if fresh_launch else replaced)resumed = _methods["session.resume"](rid, {**_ONBOARDING_PROFILE, "session_id": stored, "source": "desktop"})if "error" in resumed: