Skip to content

The agent that grows with you

fix(onboarding): claim the trial after the run record, so a crash keeps onboarding due

alt-glitchb1aa179085e3
diff --git a/apps/shared/src/gateway-contract.generated.ts b/apps/shared/src/gateway-contract.generated.ts
index 1b98f855ce4..a0742c80108 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 before the chat exists; a failed claim is error 5079 and writes nothing. */
+/** ``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. */
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 8c43aadeed9..a9100439bba 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 before the chat exists; a failed claim is error 5079\nand writes nothing.",
+ "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.",
"properties": {
"rerun": {
"default": false,
diff --git a/tests/tui_gateway/test_onboarding_welcome_claim.py b/tests/tui_gateway/test_onboarding_welcome_claim.py
index 1379649f568..e3efad88162 100644
--- a/tests/tui_gateway/test_onboarding_welcome_claim.py
+++ b/tests/tui_gateway/test_onboarding_welcome_claim.py
@@ -1,6 +1,6 @@
"""``onboarding.state`` / ``onboarding.start`` and the desktop's welcome trial: a new run on a first
-install claims it before the chat exists, a rerun never does, a failed claim writes nothing, and only
-the desktop's local backend opens onboarding by itself."""
+install claims it once its run record exists, a rerun never does, a failed claim leaves no guest and no
+chat, and only the desktop's local backend opens onboarding by itself."""
from __future__ import annotations
@@ -75,6 +75,24 @@ def test_a_failed_claim_opens_nothing_and_the_next_launch_tries_again(portal, mo
assert anon_auth.free_inference_active()
+def test_a_crash_right_after_the_claim_keeps_onboarding_due(portal, monkeypatch):
+ as_local_desktop_backend(monkeypatch)
+
+ mark = install_state.mark_machine_used
+
+ def die(*_args, **_kwargs):
+ raise RuntimeError("the process died here")
+ monkeypatch.setattr(install_state, "mark_machine_used", die) # the guest is minted, then the crash
+
+ assert _call("onboarding.start")["error"]["code"] == 5078
+ monkeypatch.setattr(install_state, "mark_machine_used", mark)
+ install_state.probe.cache_clear() # the next launch
+
+ state = _call("onboarding.state")["result"]
+ assert state["run"] is True and state["eligible"] is True
+ assert portal.creates() == 1
+
+
def test_only_the_local_desktop_backend_opens_onboarding_by_itself(portal, monkeypatch):
assert _call("onboarding.state")["result"]["eligible"] is False # CLI / SSH / URL backend
diff --git a/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py b/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py
index fcc61ab0468..d0cc1c0c992 100644
--- a/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py
+++ b/tui_gateway/contracts/profiles_vault_complete_foreign_subagents.py
@@ -402,8 +402,8 @@ 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 before the chat exists; a failed claim is error 5079
- and writes nothing."""
+ 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: bool = False
fresh_launch: bool = False
diff --git a/tui_gateway/methods_onboarding.py b/tui_gateway/methods_onboarding.py
index 20684060573..3a6165ca8ef 100644
--- a/tui_gateway/methods_onboarding.py
+++ b/tui_gateway/methods_onboarding.py
@@ -85,16 +85,21 @@ def _(rid, params: dict) -> dict:
# The tours setting is the default profile's, whichever profile launched the backend.
home = _profile_home("default")
scope = {"profile_home": str(home) if home else None}
- if not params.get("rerun"):
- # 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):
- 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")
# The record exists before the agent is built, so the build folds the onboarding toolset in.
start(db, stored, facts)
+ if not params.get("rerun"):
+ # After the record: onboarding.run is on disk before the claim makes this machine
+ # read as used, so a crash in between still opens onboarding on the next launch.
+ # A rerun never claims: it runs on the configured model.
+ try:
+ with _session_profile_runtime_scope(scope):
+ claimed = claim_desktop_free_tier(assume_fresh=bool(params.get("assume_fresh")))
+ except AuthError:
+ _discard_unfinished_runs(db, [stored]) # a refused claim leaves no chat behind
+ raise
else:
facts = Facts.from_stored(load(db, stored)["facts"])
run_id = load(db, stored).get("run_id") or ""
@@ -112,7 +117,7 @@ def _(rid, params: dict) -> dict:
# A chat with no messages never got its opening (a restart between start and the first turn).
opening = None if (db.get_session(stored) or {}).get("message_count") else opening_prompt(facts)
except AuthError as e:
- # The trial claim failed (portal down, rate limited): nothing was written, so the next
+ # The trial claim failed (portal down, rate limited): no guest and no chat, so the next
# 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))