From afc2db4aef01666f4efbc1dfdaa28e9ac734c0f3 Mon Sep 17 00:00:00 2001 From: Alexander Clarke Date: Tue, 1 Dec 2026 00:18:22 +0000 Subject: [PATCH 01/14] Desktop connected to an OpenBot elsewhere is not setup abandoned on quit Desktop sends setup_abandoned on quit, or at the next launch after a crash, while the installation is not activated and a setup step was viewed since setup last ended. A connection to an OpenBot that runs elsewhere never sends activated; a completed openbot_connect ends the setup session instead, but only for that launch. Every launch records the first screen viewed, and the first screen also shows again in an app that is already connected: a sign-in that ended (Sign in again, at launch or while OpenBot shows), a saved OpenBot that cannot be reached, or the choice of where OpenBot runs asked for again from Settings. Each of those started a new setup session, so quitting a connected app, even one that opened its OpenBot and never showed setup, counted as setup_abandoned. True before the connection was counted, and it would show in the onboarding funnel as abandonment by people who are set up. The app keeps the choice to be connected only once a connection has worked (Connect from the first screen, or Move to Cloud). Keeping it now closes any setup session still open, whether or not a completed was sent (a Connect whose window named no screen, or Move to Cloud from an OpenBot here whose activation was never recorded). While that choice is on record, the launch's first screen and every step_viewed from the setup window are recorded and sent as before, but start no setup session: neither a quit nor a crash says setup_abandoned for them, also after a Sign in again that only started or failed. A launch reads the choice before it opens its usage data, and closes a setup session the last run left open (a crash, or an earlier version's launch) without a setup_abandoned in that same write, so nothing false is queued. Choosing This computer there starts a setup on this computer at its first screen, as a first launch does, before the window shows anything; a quit or a crash before activated abandons it, as it does a first setup left at the same screen. The window's own first view is not counted twice. setup_failed still names the last screen shown, including one shown after setup, and nothing from before a usage-data opt-out names it after. Nothing changes in the window or in the event schema; choosing This computer sends one step_viewed welcome at once, as a launch does, even when the window then resumes past Welcome. After usage data is turned back on in Settings, the first view counts again under the new installation id. Tests: the library's session rule, the same screen then starting a setup, the last screen shown, the opt-out and the duplicate rule it resets, a launch that knows setup ended (a full queue, an earlier quit's real abandonment kept), and a kept connection ending the session; and through open_then_launch (initialize's launch), record_setup_event, use_this_computer and keep_moved_choice under the setup window's origin, with a real connection.json and exact events as the quit or the crash leaves them and after the next launch of an app on the same files and the choice the last run kept, an earlier version's crash, a sign-in ending while OpenBot shows (session_ended) and a saved OpenBot that cannot be reached (show_connected failing), a test each, and a setup failure after a screen shown again. App.test.tsx pins the window's step_viewed on the unreachable screen and on the choice asked for from Settings. Each rule fails its test when turned off, a Quit that does nothing included. desktop/TELEMETRY.md says what ends setup, what is still abandoned, what This computer sends, where a failure is placed, and that setup_abandoned is compared across this change by openbot_version; the CHANGELOG line also names This computer's welcome and the count after an opt-out. --- CHANGELOG.md | 8 + desktop/TELEMETRY.md | 8 +- desktop/src-tauri/src/connected_ipc_tests.rs | 371 +++++++++++++++ desktop/src-tauri/src/desktop_connected.rs | 18 + desktop/src-tauri/src/desktop_telemetry.rs | 123 ++++- desktop/src-tauri/src/main.rs | 11 +- desktop/src-tauri/src/telemetry.rs | 458 ++++++++++++++++++- desktop/src/App.test.tsx | 8 + 8 files changed, 976 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8998635947..64a22dd409 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,6 +39,14 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged. permission, `openbot`, which stands for all of them, decided on each request, including ones added later. An OpenBot that doesn't offer `openbot` is asked for every permission it lists, as before. +- **OpenBot Desktop connected to an OpenBot elsewhere no longer counts as setup abandoned.** While + you share usage data, quitting OpenBot Desktop, or a crash, once it is connected to an OpenBot + that runs elsewhere no longer counts as setup abandoned, at any launch or at its first screen + shown again (Sign in again, or Change from Settings): setup ended with that connection. The screen + is still counted. A first setup left at the same screen still counts. Choosing This computer + there now counts its first screen, `welcome`, at once, even when the window then resumes past + Welcome, and usage data turned off and back on in Settings counts the first screen after it + again ([desktop/TELEMETRY.md](desktop/TELEMETRY.md)). **API.** diff --git a/desktop/TELEMETRY.md b/desktop/TELEMETRY.md index 8ab48d635d..0a26f59466 100644 --- a/desktop/TELEMETRY.md +++ b/desktop/TELEMETRY.md @@ -56,7 +56,7 @@ All desktop event names begin with `oss.desktop.`. The Rust `EventData` enum and For `model_chosen`, providers are `openai`, `anthropic`, `google`, `xai`, `compatible`, or `none`; credential paths are `subscription`, `api_key`, `oauth`, or `none`. OpenAI and Anthropic plan sign-ins use `subscription`. xAI's native sign-in uses its named provider with `oauth` (Google's did, before Gemini took an API key only); Google's and xAI's API-key routes use `compatible`, matching the picker’s endpoint choice. A compatible endpoint uses `api_key` only when a nonblank key is supplied or its saved key is explicitly selected; keyless endpoints use `none`. Skipping model setup uses provider and credential path `none`. `custom_base_url` records only whether a nonblank base URL was selected, never its value. -`setup_failed` is sent by the desktop itself, never by the window, from every failed install or Start (once: a step that already said it failed is not counted again, and a Start cancelled by Stop is not a failure), and from every failed `local setup`, `local start`, `local update`, `local connect`, the Learning model's setup after Start, and an Account-step check that stops setup (an engine too small, or one local setup does not run on). `step` is the last screen shown; `failing_step` names the part that failed by the setup rows' step names (`install_engine`, `services`, `local_setup`, `account_check`, ...). `error_class` comes from the step, or where the step says nothing, from the failure's words, of which only the class is kept. `cli_reason` and `cli_failure` are the CLI's closed reason and the desktop's closed failure category. `resources`, for an engine too small, has `cpu_short`, `memory_short` and `disk_short`, and what setup needs against what was measured: CPUs in thousandths, memory and disk in MiB; anything not measured is absent. +`setup_failed` is sent by the desktop itself, never by the window, from every failed install or Start (once: a step that already said it failed is not counted again, and a Start cancelled by Stop is not a failure), and from every failed `local setup`, `local start`, `local update`, `local connect`, the Learning model's setup after Start, and an Account-step check that stops setup (an engine too small, or one local setup does not run on). `step` is the last screen shown since setup last ended, one shown once a connection is kept included (`install` when none); `failing_step` names the part that failed by the setup rows' step names (`install_engine`, `services`, `local_setup`, `account_check`, ...). `error_class` comes from the step, or where the step says nothing, from the failure's words, of which only the class is kept. `cli_reason` and `cli_failure` are the CLI's closed reason and the desktop's closed failure category. `resources`, for an engine too small, has `cpu_short`, `memory_short` and `disk_short`, and what setup needs against what was measured: CPUs in thousandths, memory and disk in MiB; anything not measured is absent. `setup_stalled` and `ui_stalled` report a hang, which is not a failure and so is never a `setup_failed`. Both are sent by the desktop itself, never by the window, with closed names and seconds only: never what the window showed, a log line, or what the step was working on. @@ -64,13 +64,13 @@ For `model_chosen`, providers are `openai`, `anthropic`, `google`, `xai`, `compa `ui_stalled` is a setup window that stopped taking what the desktop sends it. While the setup, start or update screens show, the page invokes `setup_heartbeat` every five seconds, and as soon as a row's progress reaches it, with the highest progress number it has taken (`setup:progress` carries one). The heartbeat is never awaited and runs off the window's thread. Progress left untaken for over 30 seconds while the window is shown, not minimised and, on macOS, not covered is a stall. The Desktop log says `[ui] the window has not answered for 31s during start_machine` when it is noticed and `[ui] the window stopped answering for 42s during start_machine` when it ends, and that end sends one `ui_stalled` with `stalled_seconds` and `step`, the setup row the desktop was reporting, by the same names as `failing_step`. It ends when the page catches up, the window leaves the screen, the window loads another page, or OpenBot quits. A page that has just loaded counts what was sent before it listened as taken, and a page that sends no heartbeat (OpenBot itself) is not watched. -`setup_abandoned` is setup ending before activation, or before a connection from the first screen completed (`openbot_connect`): Quit during setup, or, on the next launch, a crash. `setup_restart_required` is setup ending for the Windows restart that turning on Windows Subsystem for Linux needs, at the step it was on: Restart now, or Windows ending the app while that restart is owed (a restart from the Start menu). It is saved before Windows ends the app and sent by the launch after the restart, which carries on the same setup under the same installation UUID; that exit is never a `setup_abandoned`. A Quit while the restart is owed is still `setup_abandoned`. +`setup_abandoned` is setup ending before activation, or before a connection from the first screen completed (`openbot_connect`): Quit during setup, or, on the next launch, a crash. Once the app keeps a connection to an OpenBot that runs elsewhere (kept once signed in and that OpenBot answered, just before `openbot_connect` `completed` is counted when the first screen named its way; or by Move to Cloud), setup has ended: keeping it closes any setup session still open, whether or not a `completed` was sent, and nothing starts one while it is kept. Each launch, and the first screen whenever it shows again (Sign in again once a sign-in ended, at launch or while OpenBot shows; a saved OpenBot that cannot be reached; the choice made again from Settings), is still counted as `step_viewed`, but neither a quit nor a crash then sends `setup_abandoned`, even after a Sign in again that started, failed or was cancelled. A setup session the last run left open (a crash, or an earlier version, which started one at every launch) is closed without a `setup_abandoned` by a launch that finds the connection kept. Releases before this counted a quit or a crash of a connected app as `setup_abandoned`, at `welcome` or `connect_openbot`, and one that such a release recorded on quit but had not yet sent is still sent after the update, so compare `setup_abandoned` across this change by `openbot_version` (the app version every event carries). Choosing this computer there starts a setup on this computer at its first screen, as a first launch does: one `step_viewed` `welcome` is sent at once, before the window shows anything and even when the window then resumes past Welcome, and a quit or a crash before `activated` abandons it as any other. A screen said twice in a row is counted once, as every `step_viewed` is; usage data turned off and back on in Settings starts afresh, so the first screen after it is counted, and a setup failure before any screen is placed at `install`. `setup_restart_required` is setup ending for the Windows restart that turning on Windows Subsystem for Linux needs, at the step it was on: Restart now, or Windows ending the app while that restart is owed (a restart from the Start menu). It is saved before Windows ends the app and sent by the launch after the restart, which carries on the same setup under the same installation UUID; that exit is never a `setup_abandoned`. A Quit while the restart is owed is still `setup_abandoned`. `windows_probe` is one of the Windows readiness check's probes, which the setup window waits on before it shows its first screen, that ran long or was stopped at its limit. Sent by the desktop itself, once per such probe, on Windows only. `probe` is which one, by what it asks: `virtualization`, `administrator`, `wsl_feature`, `wsl_service`, `virtual_machine_platform_feature`, `wsl_version`, `wsl_system_start` (`wsl.exe --system`, which starts WSL's own VM) or `docker`. `outcome` is `slow` (it answered, after the probe's slow mark) or `timed_out` (it was stopped at its limit and counted as no answer). `duration_ms` is how long it ran. Slow marks are well under the limits: 5 seconds for the PowerShell probes and `wsl_version` (limit 30), 3 for `docker` (limit 10), and 20 for `wsl_system_start` (limit 60; a cold start measured about 6). A probe that answers in good time sends nothing. Never the command, its output, its error or a path. `business_opened` is OpenBot for Business's booker coming on screen because it was picked: on the first screen (`welcome`) or in Move to Cloud (`move_to_cloud`), once for each place each time the setup window's page loads (coming back to setup from OpenBot loads it again), however often it is picked again there. `business_booked` is a call booked in its calendar, said by Calendly from its own origin and the calendar's frame. The window sends both, with the place and nothing else: never the time booked or anything typed into the calendar. The calendar's address carries the same place as `utm_content` beside `utm_source=openbot_app` and `utm_medium=in_app`, which Calendly keeps on the booking, so a booking and these events name the same screen. -`openbot_connect` is the first screen's connection to an OpenBot that runs elsewhere, by the screen it was made on: OpenBot Cloud's sign-in (`cloud`) or a company's OpenBot by its address (`connect_openbot`). It counts that screen whenever it shows: on a first setup, and on a later launch that shows it again, such as a saved connection whose sign-in ended (Sign in again) or the choice of where OpenBot runs made again from Settings. The window sends `started` when the person presses Sign in, Connect, Try again or Sign in again, then `failed` when the address check or the browser sign-in fails, or `cancelled` when the person presses Cancel. The desktop itself sends `completed` once signed in and that OpenBot is shown, since the window has gone to it by then. Each ending has `duration_ms` from the press, and the outcomes are `sign_in`'s. A Cancel pressed just as the sign-in completes can give `cancelled` and then `completed` for one go: it did connect. `completed` also ends the setup session, as `activated` does for OpenBot on this computer, so a quit afterwards is not `setup_abandoned`; it is not `activated`, since nothing started here. Move to Cloud signs in its own way and never sends it. Opening a connection again with the sign-in this computer already has sends nothing, and a sign-in left behind when the screen goes says nothing when it ends. Never the address, its host or the sentence about what went wrong. It is not `sign_in`, which stays the Account step's CopilotKit sign-in. +`openbot_connect` is the first screen's connection to an OpenBot that runs elsewhere, by the screen it was made on: OpenBot Cloud's sign-in (`cloud`) or a company's OpenBot by its address (`connect_openbot`). It counts that screen whenever it shows: on a first setup, and on a later launch that shows it again, such as a saved connection whose sign-in ended (Sign in again) or the choice of where OpenBot runs made again from Settings. Shown again once a connection is kept, its `step_viewed` starts no setup session (see `setup_abandoned`). The window sends `started` when the person presses Sign in, Connect, Try again or Sign in again, then `failed` when the address check or the browser sign-in fails, or `cancelled` when the person presses Cancel. The desktop itself sends `completed` once signed in and that OpenBot is shown, since the window has gone to it by then. Each ending has `duration_ms` from the press, and the outcomes are `sign_in`'s. A Cancel pressed just as the sign-in completes can give `cancelled` and then `completed` for one go: it did connect. `completed` also ends the setup session, as `activated` does for OpenBot on this computer, so a quit afterwards is not `setup_abandoned`; it is not `activated`, since nothing started here. Move to Cloud signs in its own way and never sends it. Opening a connection again with the sign-in this computer already has sends nothing, and a sign-in left behind when the screen goes says nothing when it ends. Never the address, its host or the sentence about what went wrong. It is not `sign_in`, which stays the Account step's CopilotKit sign-in. `engine_measured` is what the Account step's check measured of the engine local setup runs on, too small or not: `resources` as `setup_failed` carries it for an engine too small, CPUs in thousandths and memory and free disk in MiB, against what setup needs. Sent by the desktop itself, never by the window, once a launch and again only when the engine's CPUs or memory change (a Podman machine made bigger). Free disk is sent with them, but a change in it alone, as the downloads fill the disk, sends nothing new. Every install that goes through the Account step runs that check, so each one whose engine answers it sends one; an engine not known yet, or one that does not answer, is not measured and sends nothing, and neither does a reinstall that goes straight to Install. Nothing is kept while usage data is off, so turning it on again in the same launch still sends the size. OpenBot Cloud and a company's OpenBot run nothing on this computer, so a connection never sends it. Never the engine's name, a drive, a path or a hostname. @@ -82,7 +82,7 @@ Image timing covers an explicit missing-only Compose pull, excluding startup and ## Delivery and verification -Events persist before sending and keep their event IDs across retries. The queue holds at most 256 events, dropping the oldest on overflow. An event the sink refuses (a 4xx other than 408 and 429) is dropped and the queue goes on; a 429, 408, 5xx or no answer holds the whole queue for a backoff from 10 seconds to 30 minutes with jitter, or the sink's `Retry-After` when that is longer (at most a day). Background delivery, bounded quit flushing, and replay on relaunch use the existing CopilotKit ingest contract. A crash before activation records abandonment on the next launch. Telemetry failures do not block setup. +Events persist before sending and keep their event IDs across retries. The queue holds at most 256 events, dropping the oldest on overflow. An event the sink refuses (a 4xx other than 408 and 429) is dropped and the queue goes on; a 429, 408, 5xx or no answer holds the whole queue for a backoff from 10 seconds to 30 minutes with jitter, or the sink's `Retry-After` when that is longer (at most a day). Background delivery, bounded quit flushing, and replay on relaunch use the existing CopilotKit ingest contract. A crash during a setup session (before activation) records abandonment on the next launch, unless that launch finds a connection kept. Telemetry failures do not block setup. The ingest must accept the new `oss.desktop.*` namespace: [oss-path-to-production #290](https://github.com/CopilotKit/oss-path-to-production/pull/290), merged on 2026-09-12. A successful HTTP response alone does not prove downstream acceptance; production ingest acknowledges filtered events too. Production desktop delivery depends on that change being deployed. diff --git a/desktop/src-tauri/src/connected_ipc_tests.rs b/desktop/src-tauri/src/connected_ipc_tests.rs index 28e7e3a9f7..018c10c8ff 100644 --- a/desktop/src-tauri/src/connected_ipc_tests.rs +++ b/desktop/src-tauri/src/connected_ipc_tests.rs @@ -83,6 +83,7 @@ mod connected_ipc { desktop_connected::sign_out_of_openbot, desktop_connected::use_this_computer, desktop_connected::take_connection_notice, + record_setup_event, ]) .build(context) .unwrap(); @@ -288,6 +289,376 @@ mod connected_ipc { } } + /// An app with `connection.json` in `config` (connected to `ADDRESS` when `connected`) and + /// usage data kept in `data`, launched as `desktop_telemetry::initialize` launches it once it + /// has read the usage-data setting (`open_then_launch`), sending nowhere. + fn launched_with_usage_data(connected: bool, data: &std::path::Path) -> Connected { + let shell = Connected::new(); + if connected { + shell.choose(choice::Mode::Connected, ADDRESS, None); + } + desktop_telemetry::initialize_for_test(shell.handle(), data.to_path_buf()); + shell + } + + /// The next launch after `after`: a new app on the same `connection.json`, as `after` left it, + /// and the same usage data in `data`. + fn relaunched(after: &Connected, data: &std::path::Path) -> Connected { + let shell = Connected::new(); + desktop_connected::use_for_test(shell.handle(), after.config.clone(), shell.store.clone()); + desktop_telemetry::initialize_for_test(shell.handle(), data.to_path_buf()); + shell + } + + fn queued(shell: &Connected) -> Vec { + shell + .app + .state::() + .queued() + } + + /// The window's own event, through `record_setup_event` from the setup window. + fn window_says(shell: &Connected, event: &serde_json::Value) { + assert_eq!( + shell.ask_with(SETUP, "record_setup_event", serde_json::json!({ "event": event })), + Ok(serde_json::Value::Null), + "{event}" + ); + } + + /// Once setup ended with a connection (the choice on record is connected), every launch and + /// every first screen shown again is counted and starts no setup session: a launch that opens + /// that OpenBot, a Sign in again, a Change from Settings, a sign-in that ends while OpenBot + /// shows. Neither a quit nor a crash then says `setup_abandoned`, at once or at the next launch, + /// also after a Sign in again that only started or failed. With no connection on record the + /// same launch and screens are a first setup, which a quit or a crash abandons at the last + /// step. Choosing This computer on the screen shown again (`use_this_computer`) starts a setup + /// on this computer at its first screen, before the window shows anything, which a quit or a + /// crash abandons; the window's own first view then is not counted twice. + /// + /// Each launch goes through `open_then_launch`, as `initialize` does, the window's events are + /// its own JSON (`App.tsx`, `useConnectToOpenBot`; pinned in `App.test.tsx`), and what is kept + /// is checked as the quit or the crash leaves it, then after the next launch of an app on the + /// same files and the `connection.json` the last run kept. + #[test] + fn a_first_screen_shown_again_after_a_connection_is_not_abandoned_on_quit_or_crash() { + use openbot_desktop_lib::telemetry::{ConnectOutcome, ConnectScreen, EventData, Step}; + let viewed = |step: &str| serde_json::json!({ "kind": "step_viewed", "step": step }); + let started = serde_json::json!({ + "kind": "openbot_connect", "screen": "connect_openbot", "outcome": "started" + }); + let failed = serde_json::json!({ + "kind": "openbot_connect", "screen": "connect_openbot", "outcome": "failed", + "duration_ms": 9000 + }); + let step = |step| EventData::StepViewed { step }; + let connect = |outcome, duration_ms| EventData::OpenbotConnect { + screen: ConnectScreen::ConnectOpenbot, + outcome, + duration_ms, + }; + struct Case { + connected: bool, + window: Vec, + /// This computer chosen, then the window's first local view or none before the exit. + this_computer: Option, + recorded: Vec, + abandoned: Option, + } + let shown_again_then_this_computer = vec![ + step(Step::Welcome), + step(Step::ConnectOpenbot), + step(Step::Welcome), + ]; + let cases = [ + // A launch that opens the OpenBot it is connected to: no setup screen at all. + Case { + connected: true, + window: vec![], + this_computer: None, + recorded: vec![step(Step::Welcome)], + abandoned: None, + }, + // Sign in again, or Change from Settings. + Case { + connected: true, + window: vec![viewed("connect_openbot")], + this_computer: None, + recorded: vec![step(Step::Welcome), step(Step::ConnectOpenbot)], + abandoned: None, + }, + Case { + connected: true, + window: vec![viewed("connect_openbot"), started.clone(), failed.clone()], + this_computer: None, + recorded: vec![ + step(Step::Welcome), + step(Step::ConnectOpenbot), + connect(ConnectOutcome::Started, None), + connect(ConnectOutcome::Failed, Some(9000)), + ], + abandoned: None, + }, + Case { + connected: true, + window: vec![viewed("connect_openbot")], + this_computer: Some(true), + recorded: shown_again_then_this_computer.clone(), + abandoned: Some(Step::Welcome), + }, + // Quit on "Checking your saved setup…", or behind a Windows blocker: no local view yet. + Case { + connected: true, + window: vec![viewed("connect_openbot")], + this_computer: Some(false), + recorded: shown_again_then_this_computer, + abandoned: Some(Step::Welcome), + }, + // A first setup. + Case { + connected: false, + window: vec![viewed("welcome")], + this_computer: None, + recorded: vec![step(Step::Welcome)], + abandoned: Some(Step::Welcome), + }, + Case { + connected: false, + window: vec![viewed("connect_openbot"), started, failed], + this_computer: None, + recorded: vec![ + step(Step::Welcome), + step(Step::ConnectOpenbot), + connect(ConnectOutcome::Started, None), + connect(ConnectOutcome::Failed, Some(9000)), + ], + abandoned: Some(Step::ConnectOpenbot), + }, + ]; + for case in cases { + for crash in [false, true] { + let data = temp_root("openbot-shown-again-telemetry"); + let shell = launched_with_usage_data(case.connected, &data); + for event in &case.window { + window_says(&shell, event); + } + if let Some(then_viewed) = case.this_computer { + assert_eq!(shell.ask(SETUP, "use_this_computer"), Ok(serde_json::Value::Null)); + if then_viewed { + window_says(&shell, &viewed("welcome")); + } + } + let what = format!( + "connected {}, window {:?}, this computer {:?}, crash {crash}", + case.connected, case.window, case.this_computer + ); + let abandoned: Vec = case + .abandoned + .map(|step| EventData::SetupAbandoned { step }) + .into_iter() + .collect(); + // As the quit or the crash leaves it. + let mut left = case.recorded.clone(); + if !crash { + desktop_telemetry::shutdown(shell.handle()); + left.extend(abandoned.clone()); + } + assert_eq!(queued(&shell), left, "{what}: on exit"); + // The next launch, of an app on the same files and the choice the last run kept + // (this computer once This computer was chosen): an abandonment the quit said is + // not said again, and a crash's is said once. + assert_eq!( + choice::read(&shell.config).mode == choice::Mode::Connected, + case.connected && case.this_computer.is_none(), + "{what}: the choice kept" + ); + let next = relaunched(&shell, &data); + let mut expected = case.recorded.clone(); + expected.extend(abandoned); + expected.push(step(Step::Welcome)); + assert_eq!(queued(&next), expected, "{what}: next launch"); + drop(shell); + drop(next); + let _ = std::fs::remove_dir_all(&data); + } + } + } + + /// A connected app whose last run left a setup session open (an earlier version, which started + /// one at every launch, then a crash): its first launch with the connection on record closes + /// that session as it opens its usage data, and queues no `setup_abandoned` for it. With no + /// connection on record the same run is a first setup the crash abandoned, and it is still + /// said, once. + #[test] + fn a_connected_launch_closes_the_session_an_earlier_crash_left() { + use openbot_desktop_lib::telemetry::{EventData, Step}; + for connected in [true, false] { + let data = temp_root("openbot-earlier-crash-telemetry"); + // The earlier version: its launch started a setup session, then the app crashed. + { + let earlier = desktop_telemetry::DesktopTelemetry::for_tests(data.clone(), true); + earlier.record_for_test(EventData::StepViewed { + step: Step::Welcome, + }); + } + let next = launched_with_usage_data(connected, &data); + let mut expected = vec![EventData::StepViewed { + step: Step::Welcome, + }]; + if !connected { + expected.push(EventData::SetupAbandoned { + step: Step::Welcome, + }); + } + expected.push(EventData::StepViewed { + step: Step::Welcome, + }); + assert_eq!(queued(&next), expected, "connected {connected}"); + desktop_telemetry::shutdown(next.handle()); + assert_eq!( + queued(&next).last(), + Some(&if connected { + EventData::StepViewed { + step: Step::Welcome, + } + } else { + EventData::SetupAbandoned { + step: Step::Welcome, + } + }), + "connected {connected}: quit" + ); + drop(next); + let _ = std::fs::remove_dir_all(&data); + } + } + + /// Move to Cloud from an OpenBot on this computer whose activation was never recorded (usage + /// data was off when it started): the connection it keeps ends the setup session this launch + /// opened, though the move says no `openbot_connect`, so neither the quit nor the next launch + /// says `setup_abandoned`. + #[test] + fn a_connection_kept_by_move_to_cloud_ends_the_setup_session() { + use openbot_desktop_lib::telemetry::{EventData, Step}; + let data = temp_root("openbot-moved-telemetry"); + let shell = launched_with_usage_data(false, &data); + desktop_connected::keep_moved_choice(shell.handle(), ADDRESS, "org_moved").unwrap(); + desktop_telemetry::shutdown(shell.handle()); + let welcome = EventData::StepViewed { + step: Step::Welcome, + }; + assert_eq!(queued(&shell), vec![welcome.clone()]); + let next = relaunched(&shell, &data); + assert_eq!(queued(&next), vec![welcome.clone(), welcome]); + drop(next); + drop(shell); + let _ = std::fs::remove_dir_all(&data); + } + + /// The first screen shown again by the desktop itself, then said by the window: a sign-in that + /// ends while OpenBot shows (`session_ended`, which puts setup back) when `ended`, otherwise a + /// saved OpenBot that cannot be reached (`show_connected`, asked by the window, failing). + /// Neither touches the choice on record, so the screen is counted and starts no setup session: + /// no `setup_abandoned` on quit, or at the next launch. + fn shown_again_by_the_desktop_is_not_abandoned(ended: bool) { + use openbot_desktop_lib::telemetry::{EventData, Step}; + // An address where nothing answers: a loopback port just closed. + let unreachable = { + let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); + format!("http://{}", listener.local_addr().unwrap()) + }; + let data = temp_root("openbot-shown-again-by-the-desktop"); + let shell = Connected::new(); + shell.choose( + choice::Mode::Connected, + if ended { ADDRESS } else { &unreachable }, + None, + ); + desktop_telemetry::initialize_for_test(shell.handle(), data.to_path_buf()); + if ended { + desktop_connected::session_ended(shell.handle(), "openbot.example.com"); + } else { + let refused = shell.ask(SETUP, "show_connected").unwrap_err(); + assert_eq!(refused["kind"], "unreachable", "{refused}"); + } + window_says( + &shell, + &serde_json::json!({ "kind": "step_viewed", "step": "connect_openbot" }), + ); + assert_eq!( + choice::read(&shell.config).mode, + choice::Mode::Connected, + "the choice kept" + ); + let shown = vec![ + EventData::StepViewed { + step: Step::Welcome, + }, + EventData::StepViewed { + step: Step::ConnectOpenbot, + }, + ]; + desktop_telemetry::shutdown(shell.handle()); + assert_eq!(queued(&shell), shown, "on quit"); + let next = relaunched(&shell, &data); + let mut expected = shown; + expected.push(EventData::StepViewed { + step: Step::Welcome, + }); + assert_eq!(queued(&next), expected, "next launch"); + drop(next); + drop(shell); + let _ = std::fs::remove_dir_all(&data); + } + + /// A sign-in that ends while OpenBot shows keeps the connection: Sign in again, shown then, is + /// not abandoned on quit or at the next launch. + #[test] + fn a_first_screen_shown_again_by_an_ended_sign_in_is_not_abandoned() { + shown_again_by_the_desktop_is_not_abandoned(true); + } + + /// A saved OpenBot that cannot be reached keeps the connection: the screen that says so is not + /// abandoned on quit or at the next launch. + #[test] + fn a_first_screen_shown_again_by_an_unreachable_openbot_is_not_abandoned() { + shown_again_by_the_desktop_is_not_abandoned(false); + } + + /// A setup failure is said at the last screen shown, a screen shown once setup ended with a + /// connection included, though that screen starts no setup session. Which part failed is + /// arbitrary here: the test is about where the failure is placed. + #[test] + fn a_setup_failure_after_a_screen_shown_again_names_that_screen() { + use openbot_desktop_lib::telemetry::{EventData, FailingStep, SetupErrorClass, Step}; + let data = temp_root("openbot-shown-again-failure"); + let shell = launched_with_usage_data(true, &data); + window_says( + &shell, + &serde_json::json!({ "kind": "step_viewed", "step": "connect_openbot" }), + ); + desktop_telemetry::setup_failed( + shell.handle(), + desktop_telemetry::SetupFailure::new( + FailingStep::LocalStart, + SetupErrorClass::NetworkUnavailable, + ), + ); + assert!( + matches!( + queued(&shell).last(), + Some(EventData::SetupFailed { + step: Step::ConnectOpenbot, + .. + }) + ), + "{:?}", + queued(&shell) + ); + drop(shell); + let _ = std::fs::remove_dir_all(&data); + } + /// OpenBot's page, served through the relay, may ask where it runs, sign out, change the /// connection and name the organisation. A page on another loopback port may not. #[test] diff --git a/desktop/src-tauri/src/desktop_connected.rs b/desktop/src-tauri/src/desktop_connected.rs index 65943c7fa3..2e63c651c8 100644 --- a/desktop/src-tauri/src/desktop_connected.rs +++ b/desktop/src-tauri/src/desktop_connected.rs @@ -152,6 +152,11 @@ fn keep( let written = config_dir(app) .ok_or_else(|| "the app has no configuration folder".to_owned()) .and_then(|dir| choice::write(&dir, chosen).map_err(|error| error.to_string())); + // Connected is kept only once a connection worked: setup on this computer ended with it, + // whether or not the connection was counted (`openbot_connect` `completed`, Move to Cloud). + if written.is_ok() && chosen.mode == choice::Mode::Connected { + crate::desktop_telemetry::setup_ended(app); + } written.map_err(|detail| { Problem::with( "OpenBot couldn't save your choice on this computer. Try again.", @@ -189,6 +194,17 @@ pub fn shown_origin(app: &tauri::AppHandle) -> Option(app: &tauri::AppHandle) -> bool { + app.try_state::().is_some() && chosen(app).mode == choice::Mode::Connected +} + /// The relay's origin, `http://127.0.0.1:`, while the window shows OpenBot through it. pub fn relay_origin(app: &tauri::AppHandle) -> Option { #[cfg(test)] @@ -740,6 +756,8 @@ pub async fn use_this_computer(app: tauri::AppHandle) -> R chosen.organization_id = None; keep(&app, &chosen)?; log::info!("[connect] the choice is OpenBot on this computer"); + // A setup starts here, from the first screen, as at a first launch. + crate::desktop_telemetry::launched(&app); crate::refresh_menus(&app); crate::show_setup(app).map_err(Problem::from) }) diff --git a/desktop/src-tauri/src/desktop_telemetry.rs b/desktop/src-tauri/src/desktop_telemetry.rs index 3432b256a3..e56c8578fe 100644 --- a/desktop/src-tauri/src/desktop_telemetry.rs +++ b/desktop/src-tauri/src/desktop_telemetry.rs @@ -85,6 +85,12 @@ impl DesktopTelemetry { .unwrap_or_default() } + /// `data` saved as an earlier run of the app saved it, with nothing sent. + #[cfg(test)] + pub(crate) fn record_for_test(&self, data: telemetry::EventData) { + self.emitter.record(data).unwrap(); + } + /// An emitter in `data_dir`, sharing or not, for tests that drive the app's commands. #[cfg(test)] pub(crate) fn for_tests(data_dir: std::path::PathBuf, sharing: bool) -> Self { @@ -130,24 +136,47 @@ pub fn initialize(app: &tauri::AppHandle) { .map(|directory| usage_data::saved(&directory)) .unwrap_or(true); usage_data::set_off(!shared); + open_then_launch( + app, + app.path() + .app_local_data_dir() + .ok() + .map(|directory| directory.join("telemetry")), + Some( + std::env::var("COPILOTKIT_TELEMETRY_URL") + .unwrap_or_else(|_| "https://telemetry.copilotkit.ai/ingest".into()), + ), + if shared { + telemetry::EnvOverride::Process + } else { + telemetry::EnvOverride::Disabled + }, + ); +} + +/// The emitter opened in `data_dir`, sending to `endpoint`, knowing whether setup already ended +/// with a connection, then this launch's first screen (`launched`). +fn open_then_launch( + app: &tauri::AppHandle, + data_dir: Option, + endpoint: Option, + env_override: telemetry::EnvOverride, +) { + // Read before the state is opened: a setup session the last run left open is then closed, or + // said abandoned, in the one write that opens it. + let setup_ended = crate::desktop_connected::setup_ended_with_connection(app); let initialized = (|| { let context = context(&app.package_info().version.to_string())?; - let emitter = telemetry::Telemetry::open_with_env( - app.path().app_local_data_dir().ok()?.join("telemetry"), + let emitter = telemetry::Telemetry::open_with_setup( + data_dir?, context, telemetry::Config { enabled: true, - endpoint: Some( - std::env::var("COPILOTKIT_TELEMETRY_URL") - .unwrap_or_else(|_| "https://telemetry.copilotkit.ai/ingest".into()), - ), + endpoint, max_queue: 256, }, - if shared { - telemetry::EnvOverride::Process - } else { - telemetry::EnvOverride::Disabled - }, + env_override, + setup_ended, ) .ok()?; app.manage(DesktopTelemetry::new(emitter)); @@ -157,14 +186,45 @@ pub fn initialize(app: &tauri::AppHandle) { log::warn!("[telemetry] local setup telemetry could not initialize"); return; } - record( + // The same reading of the choice that opened the state: one decision for the launch. + first_screen(app, setup_ended); +} + +/// `initialize` as the app runs it, sharing, in `data_dir` and sending nowhere: for tests of a +/// launch. +#[cfg(test)] +pub(crate) fn initialize_for_test( + app: &tauri::AppHandle, + data_dir: std::path::PathBuf, +) { + open_then_launch(app, Some(data_dir), None, telemetry::EnvOverride::Enabled); +} + +/** +The first screen viewed: at every launch, and when This computer is chosen once connected +(`desktop_connected::use_this_computer`), before the window has shown anything. Once setup ended +with a connection to an OpenBot that runs elsewhere (`desktop_connected::setup_ended_with_connection`) +it starts no setup session: a launch that opens that OpenBot, or shows the first screen to sign in +again, and is then quit is not `setup_abandoned`. Otherwise it is where a setup starts, as it always +was, so a quit before the window shows anything still abandons it. +*/ +pub fn launched(app: &tauri::AppHandle) { + first_screen( app, - telemetry::EventData::StepViewed { - step: telemetry::Step::Welcome, - }, + crate::desktop_connected::setup_ended_with_connection(app), ); } +/// `launched`, with whether setup already ended as already read. +fn first_screen(app: &tauri::AppHandle, setup_ended: bool) { + let step = telemetry::Step::Welcome; + if setup_ended { + record_step_after_setup(app, step); + } else { + record(app, telemetry::EventData::StepViewed { step }); + } +} + fn context(version: &str) -> Option { use telemetry::{ AppVersion, Architecture, Distribution, Engine, NumericVersion, Platform, RuntimeEnv, @@ -517,10 +577,37 @@ fn link_account_unlocked( } pub fn record(app: &tauri::AppHandle, event: telemetry::EventData) { + saved_then_sent(app, |emitter| emitter.record(event)); +} + +/// Setup ended with a connection the app now keeps (`desktop_connected::keep`): the open setup +/// session closes without a `setup_abandoned` (`Telemetry::end_setup_session`). +pub fn setup_ended(app: &tauri::AppHandle) { + let Some(state) = app.try_state::() else { + return; + }; + if state.emitter.end_setup_session().is_err() { + log::warn!("[telemetry] the setup session could not be closed"); + } +} + +/// A setup step shown again once setup ended with a connection (`Telemetry::record_step_after_setup`). +pub fn record_step_after_setup( + app: &tauri::AppHandle, + step: telemetry::Step, +) { + saved_then_sent(app, |emitter| emitter.record_step_after_setup(step)); +} + +/// An event saved by `save`, then sent in the background. +fn saved_then_sent( + app: &tauri::AppHandle, + save: impl FnOnce(&telemetry::Telemetry) -> telemetry::Result<()>, +) { let Some(state) = app.try_state::() else { return; }; - if state.emitter.record(event).is_err() { + if save(&state.emitter).is_err() { log::warn!("[telemetry] setup event could not be saved"); return; } @@ -613,9 +700,9 @@ pub fn setup_failed(app: &tauri::AppHandle, failure: Setup state.failures.fetch_add(1, Ordering::SeqCst); let step = state .emitter - .snapshot() + .last_step_shown() .ok() - .and_then(|state| state.last_step) + .flatten() .unwrap_or(telemetry::Step::Install); record(app, failure.event(step)); } diff --git a/desktop/src-tauri/src/main.rs b/desktop/src-tauri/src/main.rs index 88baacd1ea..6acbb6031e 100644 --- a/desktop/src-tauri/src/main.rs +++ b/desktop/src-tauri/src/main.rs @@ -1956,7 +1956,16 @@ fn record_setup_event(app: tauri::AppHandle, event: serde_ }), ) = serde_json::from_value(event) { - desktop_telemetry::record(&app, event); + match event { + // Setup already ended with a connection: a step it shows is counted, and a quit there + // is not `setup_abandoned`. + telemetry::EventData::StepViewed { step } + if desktop_connected::setup_ended_with_connection(&app) => + { + desktop_telemetry::record_step_after_setup(&app, step); + } + event => desktop_telemetry::record(&app, event), + } } } diff --git a/desktop/src-tauri/src/telemetry.rs b/desktop/src-tauri/src/telemetry.rs index 04c653fd50..041bf8d4bb 100644 --- a/desktop/src-tauri/src/telemetry.rs +++ b/desktop/src-tauri/src/telemetry.rs @@ -105,6 +105,9 @@ pub struct Telemetry { config: Config, state: Mutex>, session_last_step_viewed: Mutex>, + /// The last setup screen shown since setup last ended, whether or not it started a setup + /// session: where a setup failure happened (`last_step_shown`). + last_step_shown: Mutex>, flush_lock: Mutex<()>, client: Client, /// What this launch found about the version that ran before it, for `observe_launch` once. @@ -198,6 +201,22 @@ impl Telemetry { context: Context, config: Config, env_override: EnvOverride, + ) -> Result> { + Self::open_with_setup(data_dir, context, config, env_override, false) + } + + /** + `open_with_env`, knowing whether setup already ended before this launch (a connection to an + OpenBot that runs elsewhere is kept). A setup session the last run left open (a crash, or an + earlier version, which started one at every launch) is then closed without a + `setup_abandoned`, in the same write that opens the state, so nothing false is ever queued. + */ + pub fn open_with_setup( + data_dir: impl AsRef, + context: Context, + config: Config, + env_override: EnvOverride, + setup_ended: bool, ) -> Result> { let state_path = state_path(data_dir.as_ref()); if telemetry_disabled(env_override) || !config.enabled { @@ -232,10 +251,12 @@ impl Telemetry { if !state.activated { if let Some(step) = state.last_step.take() { - state.push_bounded( - Event::new(EventData::SetupAbandoned { step }, context.clone()), - normalized_max_queue(config.max_queue), - ); + if !setup_ended { + state.push_bounded( + Event::new(EventData::SetupAbandoned { step }, context.clone()), + normalized_max_queue(config.max_queue), + ); + } } } // An update the last launch started ends here: this launch is the version it was moving to, @@ -257,6 +278,7 @@ impl Telemetry { config, state: Mutex::new(Some(state)), session_last_step_viewed: Mutex::new(None), + last_step_shown: Mutex::new(None), flush_lock: Mutex::new(()), client: client()?, launch: Mutex::new(Some(LaunchSeen { @@ -350,6 +372,7 @@ impl Telemetry { config, state: Mutex::new(None), session_last_step_viewed: Mutex::new(None), + last_step_shown: Mutex::new(None), flush_lock: Mutex::new(()), client: client()?, launch: Mutex::new(None), @@ -394,6 +417,15 @@ impl Telemetry { pub fn stop_sharing(&self) -> Result<()> { let mut guard = self.state.lock().map_err(|_| TelemetryError::Poisoned)?; *guard = None; + // Nothing from before the opt-out names a step for what is said after it. + *self + .last_step_shown + .lock() + .map_err(|_| TelemetryError::Poisoned)? = None; + *self + .session_last_step_viewed + .lock() + .map_err(|_| TelemetryError::Poisoned)? = None; match fs::remove_file(&self.state_path) { Ok(()) => Ok(()), Err(error) if error.kind() == io::ErrorKind::NotFound => Ok(()), @@ -486,6 +518,22 @@ impl Telemetry { } pub fn record(&self, data: EventData) -> Result<()> { + self.record_in_setup(data, true) + } + + /** + A setup screen shown once setup has already ended on this computer, with a connection to an + OpenBot that runs elsewhere on record: each launch's first screen, a sign-in that ended (Sign in + again), or the choice of where OpenBot runs asked for again from Settings. `step_viewed` as any + other, but it starts no setup session, so a quit there is not `setup_abandoned`, on quit or at + the next launch. + */ + pub fn record_step_after_setup(&self, step: Step) -> Result<()> { + self.record_in_setup(EventData::StepViewed { step }, false) + } + + /// `starts_setup`: a `step_viewed` is the step a quit before activation abandons. + fn record_in_setup(&self, data: EventData, starts_setup: bool) -> Result<()> { let context = self .context .lock() @@ -524,15 +572,28 @@ impl Telemetry { match &data { EventData::StepViewed { step } => { + *self + .last_step_shown + .lock() + .map_err(|_| TelemetryError::Poisoned)? = Some(*step); + // A screen shown after setup ended, then the same screen starting a setup (This + // computer chosen there): the setup starts even though the view is not said twice. + let starts = starts_setup && state.last_step != Some(*step); + if starts { + state.last_step = Some(*step); + } let mut last_step = self .session_last_step_viewed .lock() .map_err(|_| TelemetryError::Poisoned)?; if *last_step == Some(*step) { - return Ok(()); + return if starts { + write_state(&self.state_path, state) + } else { + Ok(()) + }; } *last_step = Some(*step); - state.last_step = Some(*step); } EventData::Activated => { if state.activated { @@ -540,6 +601,10 @@ impl Telemetry { } state.activated = true; state.last_step = None; + *self + .last_step_shown + .lock() + .map_err(|_| TelemetryError::Poisoned)? = None; *self .session_last_step_viewed .lock() @@ -552,6 +617,10 @@ impl Telemetry { return Ok(()); } state.last_step = None; + *self + .last_step_shown + .lock() + .map_err(|_| TelemetryError::Poisoned)? = None; *self .session_last_step_viewed .lock() @@ -564,6 +633,10 @@ impl Telemetry { .. } => { state.last_step = None; + *self + .last_step_shown + .lock() + .map_err(|_| TelemetryError::Poisoned)? = None; *self .session_last_step_viewed .lock() @@ -721,6 +794,39 @@ impl Telemetry { .and_then(|state| (!state.activated).then_some(state.last_step).flatten())) } + /** + Setup ended with a connection to an OpenBot that runs elsewhere, kept by the app, whether or not + that connection was counted (`openbot_connect` `completed`): the setup session open now closes + without a `setup_abandoned`, and nothing is sent for it. + */ + pub fn end_setup_session(&self) -> Result<()> { + let mut guard = self.state.lock().map_err(|_| TelemetryError::Poisoned)?; + let Some(state) = guard.as_mut() else { + return Ok(()); + }; + if state.activated || state.last_step.take().is_none() { + return Ok(()); + } + *self + .last_step_shown + .lock() + .map_err(|_| TelemetryError::Poisoned)? = None; + *self + .session_last_step_viewed + .lock() + .map_err(|_| TelemetryError::Poisoned)? = None; + write_state(&self.state_path, state) + } + + /// The last setup screen shown since setup last ended, whether or not it started a setup + /// session: where a setup failure is said to have happened. + pub fn last_step_shown(&self) -> Result> { + Ok(*self + .last_step_shown + .lock() + .map_err(|_| TelemetryError::Poisoned)?) + } + pub fn shutdown(&self) -> Result<()> { if let Some(step) = self.setup_step()? { self.record(EventData::SetupAbandoned { step })?; @@ -3518,6 +3624,346 @@ mod tests { } } + /// The first screen shown again once setup ended with a connection (`record_step_after_setup`): + /// a later launch's Sign in again, or the choice asked for again from Settings. It is counted + /// as `step_viewed`, and a quit there is not `setup_abandoned`, after a Sign in again that only + /// started and failed or was cancelled too, neither on quit nor at the next launch. The same + /// screens in a first setup still are. Never `activated`. + #[test] + fn a_step_shown_again_after_setup_is_counted_and_a_quit_there_is_not_abandonment() { + let connect = |outcome| EventData::OpenbotConnect { + screen: ConnectScreen::ConnectOpenbot, + outcome, + duration_ms: None, + }; + for (after_setup, step, then, abandoned) in [ + (true, Step::ConnectOpenbot, vec![], vec![]), + ( + true, + Step::ConnectOpenbot, + vec![connect(ConnectOutcome::Started)], + vec![], + ), + ( + true, + Step::ConnectOpenbot, + vec![ + connect(ConnectOutcome::Started), + connect(ConnectOutcome::Failed), + ], + vec![], + ), + ( + true, + Step::ConnectOpenbot, + vec![ + connect(ConnectOutcome::Started), + connect(ConnectOutcome::Cancelled), + ], + vec![], + ), + (true, Step::Welcome, vec![], vec![]), + (false, Step::Welcome, vec![], vec![Step::Welcome]), + ( + false, + Step::ConnectOpenbot, + vec![], + vec![Step::ConnectOpenbot], + ), + ( + false, + Step::ConnectOpenbot, + vec![ + connect(ConnectOutcome::Started), + connect(ConnectOutcome::Failed), + ], + vec![Step::ConnectOpenbot], + ), + ( + false, + Step::ConnectOpenbot, + vec![ + connect(ConnectOutcome::Started), + connect(ConnectOutcome::Cancelled), + ], + vec![Step::ConnectOpenbot], + ), + ] { + let dir = temp_dir("shown-again-then-quit"); + let open = || { + Telemetry::open_with_env( + &dir, + context("1.2.3", Engine::None), + Config::disabled_for_tests(), + EnvOverride::Enabled, + ) + .unwrap() + }; + let telemetry = open(); + if after_setup { + telemetry.record_step_after_setup(step).unwrap(); + } else { + telemetry.record(EventData::StepViewed { step }).unwrap(); + } + for event in &then { + telemetry.record(event.clone()).unwrap(); + } + let case = format!("after setup {after_setup}, {step:?}, then {then:?}"); + assert_eq!( + telemetry.snapshot().unwrap().queue[0].data, + EventData::StepViewed { step }, + "{case}: counted" + ); + telemetry.shutdown().unwrap(); + drop(telemetry); + // The next launch reads what the quit left: it says nothing more. + let queue = open().snapshot().unwrap().queue; + let abandoned_at: Vec = queue + .iter() + .filter_map(|event| match event.data { + EventData::SetupAbandoned { step } => Some(step), + _ => None, + }) + .collect(); + assert_eq!(abandoned_at, abandoned, "{case}"); + assert!( + !queue + .iter() + .any(|event| matches!(event.data, EventData::Activated)), + "{case}" + ); + } + } + + /// A screen shown after setup ended, then the same screen starting a setup on this computer: + /// counted once, as any view said twice in a row, and the setup it starts is still abandoned + /// by a quit. Where a setup failure happened is the last screen shown either way, until setup + /// ends. With usage data off, nothing is recorded or kept. + #[test] + fn a_step_shown_after_setup_then_starting_one_is_counted_once_and_abandoned() { + let dir = temp_dir("shown-after-then-starting"); + let telemetry = Telemetry::open_with_env( + &dir, + context("1.2.3", Engine::None), + Config::disabled_for_tests(), + EnvOverride::Enabled, + ) + .unwrap(); + telemetry.record_step_after_setup(Step::Welcome).unwrap(); + assert_eq!(telemetry.last_step_shown().unwrap(), Some(Step::Welcome)); + assert_eq!(telemetry.snapshot().unwrap().last_step, None); + telemetry + .record(EventData::StepViewed { + step: Step::Welcome, + }) + .unwrap(); + assert_eq!( + telemetry.snapshot().unwrap().last_step, + Some(Step::Welcome), + "the setup started" + ); + telemetry.shutdown().unwrap(); + let queue: Vec = telemetry + .snapshot() + .unwrap() + .queue + .into_iter() + .map(|event| event.data) + .collect(); + assert_eq!( + queue, + vec![ + EventData::StepViewed { + step: Step::Welcome + }, + EventData::SetupAbandoned { + step: Step::Welcome + }, + ] + ); + assert_eq!(telemetry.last_step_shown().unwrap(), None, "setup ended"); + + let shown = Telemetry::open_with_env( + temp_dir("shown-after-then-connected"), + context("1.2.3", Engine::None), + Config::disabled_for_tests(), + EnvOverride::Enabled, + ) + .unwrap(); + shown.record_step_after_setup(Step::ConnectOpenbot).unwrap(); + assert_eq!(shown.last_step_shown().unwrap(), Some(Step::ConnectOpenbot)); + shown + .record(EventData::OpenbotConnect { + screen: ConnectScreen::ConnectOpenbot, + outcome: ConnectOutcome::Completed, + duration_ms: None, + }) + .unwrap(); + assert_eq!(shown.last_step_shown().unwrap(), None, "setup ended"); + + let off_dir = temp_dir("shown-after-off"); + let off = Telemetry::open_with_env( + &off_dir, + context("1.2.3", Engine::None), + Config::disabled_for_tests(), + EnvOverride::Disabled, + ) + .unwrap(); + off.record_step_after_setup(Step::ConnectOpenbot).unwrap(); + off.shutdown().unwrap(); + assert!(off.snapshot().is_err(), "nothing kept"); + assert!(!state_path(&off_dir).exists()); + } + + /// Usage data turned off then on in the same run: no step from before names a setup failure + /// after it, and the first view after it is said. + #[test] + fn a_step_shown_before_an_opt_out_names_nothing_after_it() { + let telemetry = Telemetry::open_with_env( + temp_dir("shown-then-opt-out"), + context("1.2.3", Engine::None), + Config::disabled_for_tests(), + EnvOverride::Enabled, + ) + .unwrap(); + telemetry.record_step_after_setup(Step::Welcome).unwrap(); + telemetry.stop_sharing().unwrap(); + telemetry.resume_sharing().unwrap(); + assert_eq!(telemetry.last_step_shown().unwrap(), None); + telemetry.record_step_after_setup(Step::Welcome).unwrap(); + assert_eq!( + telemetry.snapshot().unwrap().queue[0].data, + EventData::StepViewed { + step: Step::Welcome + } + ); + } + + /// A launch that knows setup already ended (a connection kept) closes the setup session the + /// last run left open (a crash) without a `setup_abandoned`, in the write that opens the state: + /// nothing is queued for it, so nothing is pushed out of a full queue, and what was queued + /// before, an abandonment an earlier quit said included, stays as it was. A launch that does + /// not know it still says the crash's abandonment, once. + #[test] + fn a_launch_after_setup_ended_closes_the_last_runs_session_without_abandoning_it() { + for setup_ended in [true, false] { + let dir = temp_dir("open-after-setup-ended"); + let config = Config { + enabled: true, + endpoint: None, + max_queue: 3, + }; + let open = |setup_ended| { + Telemetry::open_with_setup( + &dir, + context("1.2.3", Engine::None), + config.clone(), + EnvOverride::Enabled, + setup_ended, + ) + .unwrap() + }; + let earlier = open(false); + earlier + .record(EventData::StepViewed { + step: Step::Install, + }) + .unwrap(); + earlier.shutdown().unwrap(); + earlier + .record(EventData::StepViewed { + step: Step::Welcome, + }) + .unwrap(); + drop(earlier); + let kept: Vec = open(setup_ended) + .snapshot() + .unwrap() + .queue + .into_iter() + .map(|event| event.data) + .collect(); + let mut expected = vec![ + EventData::StepViewed { + step: Step::Install, + }, + EventData::SetupAbandoned { + step: Step::Install, + }, + EventData::StepViewed { + step: Step::Welcome, + }, + ]; + if !setup_ended { + expected.remove(0); + expected.push(EventData::SetupAbandoned { + step: Step::Welcome, + }); + } + assert_eq!(kept, expected, "setup ended {setup_ended}"); + } + } + + /// A connection kept ends the setup session open now, whether or not the connection was + /// counted: no `setup_abandoned` on quit or at the next launch, and nothing sent for it. With + /// no session open, or once activated, it changes nothing. + #[test] + fn a_connection_kept_ends_the_open_setup_session_and_sends_nothing() { + let dir = temp_dir("connection-kept-ends-setup"); + let telemetry = Telemetry::open_with_env( + &dir, + context("1.2.3", Engine::None), + Config::disabled_for_tests(), + EnvOverride::Enabled, + ) + .unwrap(); + telemetry + .record(EventData::StepViewed { + step: Step::ConnectOpenbot, + }) + .unwrap(); + telemetry.end_setup_session().unwrap(); + assert_eq!(telemetry.last_step_shown().unwrap(), None); + telemetry.end_setup_session().unwrap(); + telemetry.shutdown().unwrap(); + drop(telemetry); + let queue: Vec = Telemetry::open_with_env( + &dir, + context("1.2.3", Engine::None), + Config::disabled_for_tests(), + EnvOverride::Enabled, + ) + .unwrap() + .snapshot() + .unwrap() + .queue + .into_iter() + .map(|event| event.data) + .collect(); + assert_eq!( + queue, + vec![EventData::StepViewed { + step: Step::ConnectOpenbot + }] + ); + + // Once activated, the step it keeps stays as it was. + let activated = Telemetry::open_with_env( + temp_dir("connection-kept-after-activation"), + context("1.2.3", Engine::None), + Config::disabled_for_tests(), + EnvOverride::Enabled, + ) + .unwrap(); + activated.record(EventData::Activated).unwrap(); + activated + .record(EventData::StepViewed { step: Step::Model }) + .unwrap(); + activated.end_setup_session().unwrap(); + assert_eq!(activated.snapshot().unwrap().last_step, Some(Step::Model)); + assert_eq!(activated.last_step_shown().unwrap(), Some(Step::Model)); + } + #[test] fn quit_abandonment_is_not_duplicated_on_next_launch() { let dir = temp_dir("quit-reopen"); diff --git a/desktop/src/App.test.tsx b/desktop/src/App.test.tsx index 9525ef50f1..024c85e460 100644 --- a/desktop/src/App.test.tsx +++ b/desktop/src/App.test.tsx @@ -2439,6 +2439,10 @@ test("asked from Settings to choose where OpenBot runs, the first screen opens o "connection", "take_connection_notice", ]); + // The first screen shown again is counted once, as a Sign in again is. + expect(setupEvents()).toEqual([ + { event: { kind: "step_viewed", step: "connect_openbot" } }, + ]); // Picking Self-Contained switches the saved choice, then setup carries on as it does today. await userEvent.click( view.getByRole("radio", { name: /^OpenBot \(Self-Contained\)/ }), @@ -2593,6 +2597,10 @@ test("Stop reconnecting shows the connect screen with why, and Try again opens i "show_connected", "show_connected", ]); + // The connect screen it said why on is counted once, as a Sign in again is. + expect(setupEvents()).toEqual([ + { event: { kind: "step_viewed", step: "connect_openbot" } }, + ]); // Opened with the sign-in this computer had: not a go at connecting, so nothing is counted. expect(connectEvents()).toEqual([]); expect(strays).toEqual([]); From 2958bcfdfc8ffaba4e12d497c89f6a0a2c1742c0 Mon Sep 17 00:00:00 2001 From: Alexander Clarke Date: Wed, 2 Dec 2026 09:38:51 +0000 Subject: [PATCH 02/14] A window signed in at OpenBot itself ends setup, and its Sign in again is not abandoned Since the window can sign in at OpenBot's own origin with OpenBot's own session cookie, there are two more ways through setup's end. Connecting there keeps the choice to be connected (with the window's origin), which ends setup as any kept connection does. And the window's sign-in can be let go with the choice still connected: OpenBot's page could not trade its code, or a saved window sign-in that OpenBot no longer publishes. The first screen then shows Sign in again, which is counted and starts no setup session, so neither a quit nor the next launch says setup_abandoned. Tests, through the shell's own commands against the window stand-in: a first launch that connects through the window, then a code the page could not trade, then Sign in again, then quit and the next launch; and a launch whose saved window sign-in is no longer published. The first fails with setup_abandoned when either the kept connection's end of setup or record_setup_event's after-setup rule is turned off; the second fails when the after-setup rule is turned off (its launch already knew setup had ended). desktop/TELEMETRY.md names both ways. --- desktop/TELEMETRY.md | 2 +- desktop/src-tauri/src/window_ipc_tests.rs | 110 ++++++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) diff --git a/desktop/TELEMETRY.md b/desktop/TELEMETRY.md index 0a26f59466..89d1f53f85 100644 --- a/desktop/TELEMETRY.md +++ b/desktop/TELEMETRY.md @@ -64,7 +64,7 @@ For `model_chosen`, providers are `openai`, `anthropic`, `google`, `xai`, `compa `ui_stalled` is a setup window that stopped taking what the desktop sends it. While the setup, start or update screens show, the page invokes `setup_heartbeat` every five seconds, and as soon as a row's progress reaches it, with the highest progress number it has taken (`setup:progress` carries one). The heartbeat is never awaited and runs off the window's thread. Progress left untaken for over 30 seconds while the window is shown, not minimised and, on macOS, not covered is a stall. The Desktop log says `[ui] the window has not answered for 31s during start_machine` when it is noticed and `[ui] the window stopped answering for 42s during start_machine` when it ends, and that end sends one `ui_stalled` with `stalled_seconds` and `step`, the setup row the desktop was reporting, by the same names as `failing_step`. It ends when the page catches up, the window leaves the screen, the window loads another page, or OpenBot quits. A page that has just loaded counts what was sent before it listened as taken, and a page that sends no heartbeat (OpenBot itself) is not watched. -`setup_abandoned` is setup ending before activation, or before a connection from the first screen completed (`openbot_connect`): Quit during setup, or, on the next launch, a crash. Once the app keeps a connection to an OpenBot that runs elsewhere (kept once signed in and that OpenBot answered, just before `openbot_connect` `completed` is counted when the first screen named its way; or by Move to Cloud), setup has ended: keeping it closes any setup session still open, whether or not a `completed` was sent, and nothing starts one while it is kept. Each launch, and the first screen whenever it shows again (Sign in again once a sign-in ended, at launch or while OpenBot shows; a saved OpenBot that cannot be reached; the choice made again from Settings), is still counted as `step_viewed`, but neither a quit nor a crash then sends `setup_abandoned`, even after a Sign in again that started, failed or was cancelled. A setup session the last run left open (a crash, or an earlier version, which started one at every launch) is closed without a `setup_abandoned` by a launch that finds the connection kept. Releases before this counted a quit or a crash of a connected app as `setup_abandoned`, at `welcome` or `connect_openbot`, and one that such a release recorded on quit but had not yet sent is still sent after the update, so compare `setup_abandoned` across this change by `openbot_version` (the app version every event carries). Choosing this computer there starts a setup on this computer at its first screen, as a first launch does: one `step_viewed` `welcome` is sent at once, before the window shows anything and even when the window then resumes past Welcome, and a quit or a crash before `activated` abandons it as any other. A screen said twice in a row is counted once, as every `step_viewed` is; usage data turned off and back on in Settings starts afresh, so the first screen after it is counted, and a setup failure before any screen is placed at `install`. `setup_restart_required` is setup ending for the Windows restart that turning on Windows Subsystem for Linux needs, at the step it was on: Restart now, or Windows ending the app while that restart is owed (a restart from the Start menu). It is saved before Windows ends the app and sent by the launch after the restart, which carries on the same setup under the same installation UUID; that exit is never a `setup_abandoned`. A Quit while the restart is owed is still `setup_abandoned`. +`setup_abandoned` is setup ending before activation, or before a connection from the first screen completed (`openbot_connect`): Quit during setup, or, on the next launch, a crash. Once the app keeps a connection to an OpenBot that runs elsewhere (kept once signed in and that OpenBot answered, just before `openbot_connect` `completed` is counted when the first screen named its way; once the window signed in at that OpenBot itself; or by Move to Cloud), setup has ended: keeping it closes any setup session still open, whether or not a `completed` was sent, and nothing starts one while it is kept. Each launch, and the first screen whenever it shows again (Sign in again once a sign-in ended, at launch or while OpenBot shows, or once the window's own sign-in was let go: OpenBot's page could not trade its code, or that OpenBot no longer signs the window in; a saved OpenBot that cannot be reached; the choice made again from Settings), is still counted as `step_viewed`, but neither a quit nor a crash then sends `setup_abandoned`, even after a Sign in again that started, failed or was cancelled. A setup session the last run left open (a crash, or an earlier version, which started one at every launch) is closed without a `setup_abandoned` by a launch that finds the connection kept. Releases before this counted a quit or a crash of a connected app as `setup_abandoned`, at `welcome` or `connect_openbot`, and one that such a release recorded on quit but had not yet sent is still sent after the update, so compare `setup_abandoned` across this change by `openbot_version` (the app version every event carries). Choosing this computer there starts a setup on this computer at its first screen, as a first launch does: one `step_viewed` `welcome` is sent at once, before the window shows anything and even when the window then resumes past Welcome, and a quit or a crash before `activated` abandons it as any other. A screen said twice in a row is counted once, as every `step_viewed` is; usage data turned off and back on in Settings starts afresh, so the first screen after it is counted, and a setup failure before any screen is placed at `install`. `setup_restart_required` is setup ending for the Windows restart that turning on Windows Subsystem for Linux needs, at the step it was on: Restart now, or Windows ending the app while that restart is owed (a restart from the Start menu). It is saved before Windows ends the app and sent by the launch after the restart, which carries on the same setup under the same installation UUID; that exit is never a `setup_abandoned`. A Quit while the restart is owed is still `setup_abandoned`. `windows_probe` is one of the Windows readiness check's probes, which the setup window waits on before it shows its first screen, that ran long or was stopped at its limit. Sent by the desktop itself, once per such probe, on Windows only. `probe` is which one, by what it asks: `virtualization`, `administrator`, `wsl_feature`, `wsl_service`, `virtual_machine_platform_feature`, `wsl_version`, `wsl_system_start` (`wsl.exe --system`, which starts WSL's own VM) or `docker`. `outcome` is `slow` (it answered, after the probe's slow mark) or `timed_out` (it was stopped at its limit and counted as no answer). `duration_ms` is how long it ran. Slow marks are well under the limits: 5 seconds for the PowerShell probes and `wsl_version` (limit 30), 3 for `docker` (limit 10), and 20 for `wsl_system_start` (limit 60; a cold start measured about 6). A probe that answers in good time sends nothing. Never the command, its output, its error or a path. diff --git a/desktop/src-tauri/src/window_ipc_tests.rs b/desktop/src-tauri/src/window_ipc_tests.rs index 84f567eaec..2963076a22 100644 --- a/desktop/src-tauri/src/window_ipc_tests.rs +++ b/desktop/src-tauri/src/window_ipc_tests.rs @@ -739,3 +739,113 @@ fn an_older_openbot_and_a_sign_in_from_before_go_on_through_the_relay() { Some(address.as_str()) ); } + +/** +Setup ends with a connection through the window's own sign-in too (`connect_window_now` keeps the +choice), and a first screen the window's sign-in puts back (the page could not trade its code: +Sign in again, the choice still connected) starts no setup session: no `setup_abandoned` on quit, +or at the next launch. +*/ +#[test] +fn a_window_sign_in_ends_setup_and_its_sign_in_again_is_not_abandoned() { + use openbot_desktop_lib::telemetry::{EventData, Step}; + let data = temp_root("openbot-window-sign-in-not-abandoned"); + let address = window_stand_in(WindowStand::new(true)); + let shell = window_shell(); + let (_browser, _opened) = approving_browser(); + desktop_telemetry::initialize_for_test(shell.handle(), data.to_path_buf()); + window_says( + &shell, + &serde_json::json!({ "kind": "step_viewed", "step": "connect_openbot" }), + ); + shell + .ask_with(SETUP, "connect_to_openbot", serde_json::json!({ "address": address })) + .expect("connected"); + assert_eq!( + choice::read(&shell.config).window_origin(), + Some(address.as_str()) + ); + shell + .ask_with( + &format!("{address}/desktop/signed-in"), + "plugin:openbot-desktop|window_sign_in_failed", + serde_json::json!({ "reason": "invalid_code" }), + ) + .expect("put back"); + assert_eq!(shell.window.url().unwrap().as_str(), SETUP); + assert_eq!( + choice::read(&shell.config).connected_to(), + Some(address.as_str()), + "the choice kept" + ); + window_says( + &shell, + &serde_json::json!({ "kind": "step_viewed", "step": "connect_openbot" }), + ); + let shown = vec![ + EventData::StepViewed { + step: Step::Welcome, + }, + EventData::StepViewed { + step: Step::ConnectOpenbot, + }, + EventData::StepViewed { + step: Step::ConnectOpenbot, + }, + ]; + desktop_telemetry::shutdown(shell.handle()); + assert_eq!(queued(&shell), shown, "on quit"); + let next = relaunched(&shell, &data); + let mut expected = shown; + expected.push(EventData::StepViewed { + step: Step::Welcome, + }); + assert_eq!(queued(&next), expected, "next launch"); + drop(next); + drop(shell); + let _ = std::fs::remove_dir_all(&data); +} + +/** +A launch whose saved window sign-in that OpenBot no longer publishes (`show_window_saved`) lets +the window's sign-in go and puts Sign in again up, the choice still connected: that screen starts +no setup session, so no `setup_abandoned` on quit, or at the next launch. +*/ +#[test] +fn a_saved_window_sign_in_no_longer_published_is_not_abandoned() { + use openbot_desktop_lib::telemetry::{EventData, Step}; + let data = temp_root("openbot-window-no-longer-published"); + let stand = WindowStand::new(false); + let address = window_stand_in(stand); + let shell = window_shell(); + choice::write(&shell.config, &choice::window_signed_in_at(&address, &address)).unwrap(); + desktop_telemetry::initialize_for_test(shell.handle(), data.to_path_buf()); + let refused = shell.ask(SETUP, "show_connected").unwrap_err(); + assert_eq!(refused["kind"], "session-ended", "{refused}"); + let kept = choice::read(&shell.config); + assert_eq!(kept.window, None, "the window's sign-in let go"); + assert_eq!(kept.connected_to(), Some(address.as_str()), "the choice kept"); + window_says( + &shell, + &serde_json::json!({ "kind": "step_viewed", "step": "connect_openbot" }), + ); + let shown = vec![ + EventData::StepViewed { + step: Step::Welcome, + }, + EventData::StepViewed { + step: Step::ConnectOpenbot, + }, + ]; + desktop_telemetry::shutdown(shell.handle()); + assert_eq!(queued(&shell), shown, "on quit"); + let next = relaunched(&shell, &data); + let mut expected = shown; + expected.push(EventData::StepViewed { + step: Step::Welcome, + }); + assert_eq!(queued(&next), expected, "next launch"); + drop(next); + drop(shell); + let _ = std::fs::remove_dir_all(&data); +} From 8a8679de0079bfb59a83c9de329539ef0c3ed2fa Mon Sep 17 00:00:00 2001 From: Alexander Clarke Date: Wed, 2 Dec 2026 10:16:39 +0000 Subject: [PATCH 03/14] Telemetry docs: when the window's sign-in keeps the connection, and a repeated screen after setup ends The window's own sign-in keeps the connection once the browser sign-in comes back, just before the window trades its code for its session at that OpenBot, so setup has ended from then; a trade that fails then shows Sign in again, which is not abandoned. And a screen said twice in a row counts once unless setup ended between the two: ending setup forgets the last screen, so the same screen shown again after it is counted again. --- desktop/TELEMETRY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop/TELEMETRY.md b/desktop/TELEMETRY.md index 89d1f53f85..15dbc203c4 100644 --- a/desktop/TELEMETRY.md +++ b/desktop/TELEMETRY.md @@ -64,7 +64,7 @@ For `model_chosen`, providers are `openai`, `anthropic`, `google`, `xai`, `compa `ui_stalled` is a setup window that stopped taking what the desktop sends it. While the setup, start or update screens show, the page invokes `setup_heartbeat` every five seconds, and as soon as a row's progress reaches it, with the highest progress number it has taken (`setup:progress` carries one). The heartbeat is never awaited and runs off the window's thread. Progress left untaken for over 30 seconds while the window is shown, not minimised and, on macOS, not covered is a stall. The Desktop log says `[ui] the window has not answered for 31s during start_machine` when it is noticed and `[ui] the window stopped answering for 42s during start_machine` when it ends, and that end sends one `ui_stalled` with `stalled_seconds` and `step`, the setup row the desktop was reporting, by the same names as `failing_step`. It ends when the page catches up, the window leaves the screen, the window loads another page, or OpenBot quits. A page that has just loaded counts what was sent before it listened as taken, and a page that sends no heartbeat (OpenBot itself) is not watched. -`setup_abandoned` is setup ending before activation, or before a connection from the first screen completed (`openbot_connect`): Quit during setup, or, on the next launch, a crash. Once the app keeps a connection to an OpenBot that runs elsewhere (kept once signed in and that OpenBot answered, just before `openbot_connect` `completed` is counted when the first screen named its way; once the window signed in at that OpenBot itself; or by Move to Cloud), setup has ended: keeping it closes any setup session still open, whether or not a `completed` was sent, and nothing starts one while it is kept. Each launch, and the first screen whenever it shows again (Sign in again once a sign-in ended, at launch or while OpenBot shows, or once the window's own sign-in was let go: OpenBot's page could not trade its code, or that OpenBot no longer signs the window in; a saved OpenBot that cannot be reached; the choice made again from Settings), is still counted as `step_viewed`, but neither a quit nor a crash then sends `setup_abandoned`, even after a Sign in again that started, failed or was cancelled. A setup session the last run left open (a crash, or an earlier version, which started one at every launch) is closed without a `setup_abandoned` by a launch that finds the connection kept. Releases before this counted a quit or a crash of a connected app as `setup_abandoned`, at `welcome` or `connect_openbot`, and one that such a release recorded on quit but had not yet sent is still sent after the update, so compare `setup_abandoned` across this change by `openbot_version` (the app version every event carries). Choosing this computer there starts a setup on this computer at its first screen, as a first launch does: one `step_viewed` `welcome` is sent at once, before the window shows anything and even when the window then resumes past Welcome, and a quit or a crash before `activated` abandons it as any other. A screen said twice in a row is counted once, as every `step_viewed` is; usage data turned off and back on in Settings starts afresh, so the first screen after it is counted, and a setup failure before any screen is placed at `install`. `setup_restart_required` is setup ending for the Windows restart that turning on Windows Subsystem for Linux needs, at the step it was on: Restart now, or Windows ending the app while that restart is owed (a restart from the Start menu). It is saved before Windows ends the app and sent by the launch after the restart, which carries on the same setup under the same installation UUID; that exit is never a `setup_abandoned`. A Quit while the restart is owed is still `setup_abandoned`. +`setup_abandoned` is setup ending before activation, or before a connection from the first screen completed (`openbot_connect`): Quit during setup, or, on the next launch, a crash. Once the app keeps a connection to an OpenBot that runs elsewhere (kept once signed in and that OpenBot answered, just before `openbot_connect` `completed` is counted when the first screen named its way; once the window's own sign-in at that OpenBot came back from the browser, just before the window trades its code for its session there; or by Move to Cloud), setup has ended: keeping it closes any setup session still open, whether or not a `completed` was sent, and nothing starts one while it is kept. Each launch, and the first screen whenever it shows again (Sign in again once a sign-in ended, at launch or while OpenBot shows, or once the window's own sign-in was let go: OpenBot's page could not trade its code, or that OpenBot no longer signs the window in; a saved OpenBot that cannot be reached; the choice made again from Settings), is still counted as `step_viewed`, but neither a quit nor a crash then sends `setup_abandoned`, even after a Sign in again that started, failed or was cancelled. A setup session the last run left open (a crash, or an earlier version, which started one at every launch) is closed without a `setup_abandoned` by a launch that finds the connection kept. Releases before this counted a quit or a crash of a connected app as `setup_abandoned`, at `welcome` or `connect_openbot`, and one that such a release recorded on quit but had not yet sent is still sent after the update, so compare `setup_abandoned` across this change by `openbot_version` (the app version every event carries). Choosing this computer there starts a setup on this computer at its first screen, as a first launch does: one `step_viewed` `welcome` is sent at once, before the window shows anything and even when the window then resumes past Welcome, and a quit or a crash before `activated` abandons it as any other. A screen said twice in a row is counted once, as every `step_viewed` is, unless setup ended between the two; usage data turned off and back on in Settings starts afresh, so the first screen after it is counted, and a setup failure before any screen is placed at `install`. `setup_restart_required` is setup ending for the Windows restart that turning on Windows Subsystem for Linux needs, at the step it was on: Restart now, or Windows ending the app while that restart is owed (a restart from the Start menu). It is saved before Windows ends the app and sent by the launch after the restart, which carries on the same setup under the same installation UUID; that exit is never a `setup_abandoned`. A Quit while the restart is owed is still `setup_abandoned`. `windows_probe` is one of the Windows readiness check's probes, which the setup window waits on before it shows its first screen, that ran long or was stopped at its limit. Sent by the desktop itself, once per such probe, on Windows only. `probe` is which one, by what it asks: `virtualization`, `administrator`, `wsl_feature`, `wsl_service`, `virtual_machine_platform_feature`, `wsl_version`, `wsl_system_start` (`wsl.exe --system`, which starts WSL's own VM) or `docker`. `outcome` is `slow` (it answered, after the probe's slow mark) or `timed_out` (it was stopped at its limit and counted as no answer). `duration_ms` is how long it ran. Slow marks are well under the limits: 5 seconds for the PowerShell probes and `wsl_version` (limit 30), 3 for `docker` (limit 10), and 20 for `wsl_system_start` (limit 60; a cold start measured about 6). A probe that answers in good time sends nothing. Never the command, its output, its error or a path. From c53dea7b7a6754c110e700c5f0b2ab7e6fffcbec Mon Sep 17 00:00:00 2001 From: Alexander Clarke Date: Wed, 2 Dec 2026 10:41:47 +0000 Subject: [PATCH 04/14] Comments and telemetry docs name the window's own sign-in as a kept connection The comments on keep and setup_ended_with_connection also name connect_window_now, which keeps the connected choice once the window's own sign-in came back from the browser, just before the page trades its code. open_then_launch's comment names first_screen, which records the launch's first screen by the same reading of the choice. The comment on a screen shown after setup, then the same screen starting a setup, says no current window flow puts the two side by side. desktop/TELEMETRY.md says completed is counted when the window named the screen it was pressed on (screen). --- desktop/TELEMETRY.md | 2 +- desktop/src-tauri/src/desktop_connected.rs | 15 +++++++++------ desktop/src-tauri/src/desktop_telemetry.rs | 2 +- desktop/src-tauri/src/telemetry.rs | 5 +++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/desktop/TELEMETRY.md b/desktop/TELEMETRY.md index 15dbc203c4..35727c13c6 100644 --- a/desktop/TELEMETRY.md +++ b/desktop/TELEMETRY.md @@ -64,7 +64,7 @@ For `model_chosen`, providers are `openai`, `anthropic`, `google`, `xai`, `compa `ui_stalled` is a setup window that stopped taking what the desktop sends it. While the setup, start or update screens show, the page invokes `setup_heartbeat` every five seconds, and as soon as a row's progress reaches it, with the highest progress number it has taken (`setup:progress` carries one). The heartbeat is never awaited and runs off the window's thread. Progress left untaken for over 30 seconds while the window is shown, not minimised and, on macOS, not covered is a stall. The Desktop log says `[ui] the window has not answered for 31s during start_machine` when it is noticed and `[ui] the window stopped answering for 42s during start_machine` when it ends, and that end sends one `ui_stalled` with `stalled_seconds` and `step`, the setup row the desktop was reporting, by the same names as `failing_step`. It ends when the page catches up, the window leaves the screen, the window loads another page, or OpenBot quits. A page that has just loaded counts what was sent before it listened as taken, and a page that sends no heartbeat (OpenBot itself) is not watched. -`setup_abandoned` is setup ending before activation, or before a connection from the first screen completed (`openbot_connect`): Quit during setup, or, on the next launch, a crash. Once the app keeps a connection to an OpenBot that runs elsewhere (kept once signed in and that OpenBot answered, just before `openbot_connect` `completed` is counted when the first screen named its way; once the window's own sign-in at that OpenBot came back from the browser, just before the window trades its code for its session there; or by Move to Cloud), setup has ended: keeping it closes any setup session still open, whether or not a `completed` was sent, and nothing starts one while it is kept. Each launch, and the first screen whenever it shows again (Sign in again once a sign-in ended, at launch or while OpenBot shows, or once the window's own sign-in was let go: OpenBot's page could not trade its code, or that OpenBot no longer signs the window in; a saved OpenBot that cannot be reached; the choice made again from Settings), is still counted as `step_viewed`, but neither a quit nor a crash then sends `setup_abandoned`, even after a Sign in again that started, failed or was cancelled. A setup session the last run left open (a crash, or an earlier version, which started one at every launch) is closed without a `setup_abandoned` by a launch that finds the connection kept. Releases before this counted a quit or a crash of a connected app as `setup_abandoned`, at `welcome` or `connect_openbot`, and one that such a release recorded on quit but had not yet sent is still sent after the update, so compare `setup_abandoned` across this change by `openbot_version` (the app version every event carries). Choosing this computer there starts a setup on this computer at its first screen, as a first launch does: one `step_viewed` `welcome` is sent at once, before the window shows anything and even when the window then resumes past Welcome, and a quit or a crash before `activated` abandons it as any other. A screen said twice in a row is counted once, as every `step_viewed` is, unless setup ended between the two; usage data turned off and back on in Settings starts afresh, so the first screen after it is counted, and a setup failure before any screen is placed at `install`. `setup_restart_required` is setup ending for the Windows restart that turning on Windows Subsystem for Linux needs, at the step it was on: Restart now, or Windows ending the app while that restart is owed (a restart from the Start menu). It is saved before Windows ends the app and sent by the launch after the restart, which carries on the same setup under the same installation UUID; that exit is never a `setup_abandoned`. A Quit while the restart is owed is still `setup_abandoned`. +`setup_abandoned` is setup ending before activation, or before a connection from the first screen completed (`openbot_connect`): Quit during setup, or, on the next launch, a crash. Once the app keeps a connection to an OpenBot that runs elsewhere (kept once signed in and that OpenBot answered, just before `openbot_connect` `completed` is counted when the window named the screen it was pressed on (`screen`); once the window's own sign-in at that OpenBot came back from the browser, just before the window trades its code for its session there; or by Move to Cloud), setup has ended: keeping it closes any setup session still open, whether or not a `completed` was sent, and nothing starts one while it is kept. Each launch, and the first screen whenever it shows again (Sign in again once a sign-in ended, at launch or while OpenBot shows, or once the window's own sign-in was let go: OpenBot's page could not trade its code, or that OpenBot no longer signs the window in; a saved OpenBot that cannot be reached; the choice made again from Settings), is still counted as `step_viewed`, but neither a quit nor a crash then sends `setup_abandoned`, even after a Sign in again that started, failed or was cancelled. A setup session the last run left open (a crash, or an earlier version, which started one at every launch) is closed without a `setup_abandoned` by a launch that finds the connection kept. Releases before this counted a quit or a crash of a connected app as `setup_abandoned`, at `welcome` or `connect_openbot`, and one that such a release recorded on quit but had not yet sent is still sent after the update, so compare `setup_abandoned` across this change by `openbot_version` (the app version every event carries). Choosing this computer there starts a setup on this computer at its first screen, as a first launch does: one `step_viewed` `welcome` is sent at once, before the window shows anything and even when the window then resumes past Welcome, and a quit or a crash before `activated` abandons it as any other. A screen said twice in a row is counted once, as every `step_viewed` is, unless setup ended between the two; usage data turned off and back on in Settings starts afresh, so the first screen after it is counted, and a setup failure before any screen is placed at `install`. `setup_restart_required` is setup ending for the Windows restart that turning on Windows Subsystem for Linux needs, at the step it was on: Restart now, or Windows ending the app while that restart is owed (a restart from the Start menu). It is saved before Windows ends the app and sent by the launch after the restart, which carries on the same setup under the same installation UUID; that exit is never a `setup_abandoned`. A Quit while the restart is owed is still `setup_abandoned`. `windows_probe` is one of the Windows readiness check's probes, which the setup window waits on before it shows its first screen, that ran long or was stopped at its limit. Sent by the desktop itself, once per such probe, on Windows only. `probe` is which one, by what it asks: `virtualization`, `administrator`, `wsl_feature`, `wsl_service`, `virtual_machine_platform_feature`, `wsl_version`, `wsl_system_start` (`wsl.exe --system`, which starts WSL's own VM) or `docker`. `outcome` is `slow` (it answered, after the probe's slow mark) or `timed_out` (it was stopped at its limit and counted as no answer). `duration_ms` is how long it ran. Slow marks are well under the limits: 5 seconds for the PowerShell probes and `wsl_version` (limit 30), 3 for `docker` (limit 10), and 20 for `wsl_system_start` (limit 60; a cold start measured about 6). A probe that answers in good time sends nothing. Never the command, its output, its error or a path. diff --git a/desktop/src-tauri/src/desktop_connected.rs b/desktop/src-tauri/src/desktop_connected.rs index 2e63c651c8..2dbd9c5b37 100644 --- a/desktop/src-tauri/src/desktop_connected.rs +++ b/desktop/src-tauri/src/desktop_connected.rs @@ -152,8 +152,9 @@ fn keep( let written = config_dir(app) .ok_or_else(|| "the app has no configuration folder".to_owned()) .and_then(|dir| choice::write(&dir, chosen).map_err(|error| error.to_string())); - // Connected is kept only once a connection worked: setup on this computer ended with it, - // whether or not the connection was counted (`openbot_connect` `completed`, Move to Cloud). + // Connected is first kept once a connection worked, or once the window's own sign-in came + // back from the browser: setup on this computer ended with it, whether or not the connection + // was counted (`openbot_connect` `completed`, Move to Cloud). if written.is_ok() && chosen.mode == choice::Mode::Connected { crate::desktop_telemetry::setup_ended(app); } @@ -196,10 +197,12 @@ pub fn shown_origin(app: &tauri::AppHandle) -> Option(app: &tauri::AppHandle) -> bool { app.try_state::().is_some() && chosen(app).mode == choice::Mode::Connected diff --git a/desktop/src-tauri/src/desktop_telemetry.rs b/desktop/src-tauri/src/desktop_telemetry.rs index e56c8578fe..9c75861dd0 100644 --- a/desktop/src-tauri/src/desktop_telemetry.rs +++ b/desktop/src-tauri/src/desktop_telemetry.rs @@ -155,7 +155,7 @@ pub fn initialize(app: &tauri::AppHandle) { } /// The emitter opened in `data_dir`, sending to `endpoint`, knowing whether setup already ended -/// with a connection, then this launch's first screen (`launched`). +/// with a connection, then this launch's first screen (`first_screen`, by the same reading). fn open_then_launch( app: &tauri::AppHandle, data_dir: Option, diff --git a/desktop/src-tauri/src/telemetry.rs b/desktop/src-tauri/src/telemetry.rs index 041bf8d4bb..5801844041 100644 --- a/desktop/src-tauri/src/telemetry.rs +++ b/desktop/src-tauri/src/telemetry.rs @@ -576,8 +576,9 @@ impl Telemetry { .last_step_shown .lock() .map_err(|_| TelemetryError::Poisoned)? = Some(*step); - // A screen shown after setup ended, then the same screen starting a setup (This - // computer chosen there): the setup starts even though the view is not said twice. + // A screen shown after setup ended, then the same screen starting a setup + // (defensive: no current window flow puts these two side by side): the setup + // starts even though the view is not said twice. let starts = starts_setup && state.last_step != Some(*step); if starts { state.last_step = Some(*step); From 9c36986a18968fa94ab172fcc98cb57afcdbe538 Mon Sep 17 00:00:00 2001 From: Alexander Clarke Date: Wed, 2 Dec 2026 10:41:47 +0000 Subject: [PATCH 05/14] The opt-out deletes the saved state even with a step lock poisoned stop_sharing cleared the last screen shown and the duplicate rule's last view with ? before it deleted the state file, so a lock poisoned by a panic returned an error and left the file behind until the next launch with sharing off. Each is now cleared only if its lock can be taken, and the file is always deleted. Test: both locks poisoned, then the opt-out deletes the file; it failed with Poisoned before. The test of a screen shown after setup, then the same screen starting a setup, now also crashes after the two views and asserts that the next launch says that setup abandoned, so the saved write on that path is tested: it fails when that write is skipped. --- desktop/src-tauri/src/telemetry.rs | 88 ++++++++++++++++++++++++++---- 1 file changed, 78 insertions(+), 10 deletions(-) diff --git a/desktop/src-tauri/src/telemetry.rs b/desktop/src-tauri/src/telemetry.rs index 5801844041..f0a454b16e 100644 --- a/desktop/src-tauri/src/telemetry.rs +++ b/desktop/src-tauri/src/telemetry.rs @@ -417,15 +417,14 @@ impl Telemetry { pub fn stop_sharing(&self) -> Result<()> { let mut guard = self.state.lock().map_err(|_| TelemetryError::Poisoned)?; *guard = None; - // Nothing from before the opt-out names a step for what is said after it. - *self - .last_step_shown - .lock() - .map_err(|_| TelemetryError::Poisoned)? = None; - *self - .session_last_step_viewed - .lock() - .map_err(|_| TelemetryError::Poisoned)? = None; + // Nothing from before the opt-out names a step for what is said after it. A poisoned lock + // never stops the state file being deleted. + if let Ok(mut shown) = self.last_step_shown.lock() { + *shown = None; + } + if let Ok(mut viewed) = self.session_last_step_viewed.lock() { + *viewed = None; + } match fs::remove_file(&self.state_path) { Ok(()) => Ok(()), Err(error) if error.kind() == io::ErrorKind::NotFound => Ok(()), @@ -3738,7 +3737,7 @@ mod tests { /// A screen shown after setup ended, then the same screen starting a setup on this computer: /// counted once, as any view said twice in a row, and the setup it starts is still abandoned - /// by a quit. Where a setup failure happened is the last screen shown either way, until setup + /// by a quit, or by the next launch after a crash. Where a setup failure happened is the last screen shown either way, until setup /// ends. With usage data off, nothing is recorded or kept. #[test] fn a_step_shown_after_setup_then_starting_one_is_counted_once_and_abandoned() { @@ -3784,6 +3783,49 @@ mod tests { ); assert_eq!(telemetry.last_step_shown().unwrap(), None, "setup ended"); + // The same two views, then a crash: the setup they started is saved, so the next launch + // says it abandoned. + let crash_dir = temp_dir("shown-after-then-starting-crash"); + let crashed = Telemetry::open_with_env( + &crash_dir, + context("1.2.3", Engine::None), + Config::disabled_for_tests(), + EnvOverride::Enabled, + ) + .unwrap(); + crashed.record_step_after_setup(Step::Welcome).unwrap(); + crashed + .record(EventData::StepViewed { + step: Step::Welcome, + }) + .unwrap(); + drop(crashed); + let next_launch = Telemetry::open_with_env( + &crash_dir, + context("1.2.3", Engine::None), + Config::disabled_for_tests(), + EnvOverride::Enabled, + ) + .unwrap(); + let queue: Vec = next_launch + .snapshot() + .unwrap() + .queue + .into_iter() + .map(|event| event.data) + .collect(); + assert_eq!( + queue, + vec![ + EventData::StepViewed { + step: Step::Welcome + }, + EventData::SetupAbandoned { + step: Step::Welcome + }, + ] + ); + let shown = Telemetry::open_with_env( temp_dir("shown-after-then-connected"), context("1.2.3", Engine::None), @@ -3840,6 +3882,32 @@ mod tests { ); } + /// Usage data turned off deletes the saved state even when a panic poisoned the locks on the + /// last screen shown: the opt-out never leaves the file behind. + #[test] + fn an_opt_out_deletes_the_saved_state_even_with_the_step_locks_poisoned() { + let dir = temp_dir("opt-out-poisoned-steps"); + let telemetry = Telemetry::open_with_env( + &dir, + context("1.2.3", Engine::None), + Config::disabled_for_tests(), + EnvOverride::Enabled, + ) + .unwrap(); + telemetry.record_step_after_setup(Step::Welcome).unwrap(); + assert!(state_path(&dir).exists()); + let poisoned = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + let _shown = telemetry.last_step_shown.lock().unwrap(); + let _viewed = telemetry.session_last_step_viewed.lock().unwrap(); + panic!("a panic while the step locks are held"); + })); + assert!(poisoned.is_err()); + assert!(telemetry.last_step_shown.is_poisoned()); + assert!(telemetry.session_last_step_viewed.is_poisoned()); + telemetry.stop_sharing().unwrap(); + assert!(!state_path(&dir).exists(), "the opt-out deleted the state"); + } + /// A launch that knows setup already ended (a connection kept) closes the setup session the /// last run left open (a crash) without a `setup_abandoned`, in the write that opens the state: /// nothing is queued for it, so nothing is pushed out of a full queue, and what was queued From 9e99aafd8dbf69846671412b2e32e61ed3df96d7 Mon Sep 17 00:00:00 2001 From: Alexander Clarke Date: Wed, 2 Dec 2026 14:24:59 +0000 Subject: [PATCH 06/14] The release note goes in the description, not CHANGELOG.md CHANGELOG.md is written by the release from the notes in pull requests' descriptions, so this change leaves it as it is on main and carries its note under the description's Changelog heading instead. --- CHANGELOG.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 64a22dd409..8998635947 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -39,14 +39,6 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged. permission, `openbot`, which stands for all of them, decided on each request, including ones added later. An OpenBot that doesn't offer `openbot` is asked for every permission it lists, as before. -- **OpenBot Desktop connected to an OpenBot elsewhere no longer counts as setup abandoned.** While - you share usage data, quitting OpenBot Desktop, or a crash, once it is connected to an OpenBot - that runs elsewhere no longer counts as setup abandoned, at any launch or at its first screen - shown again (Sign in again, or Change from Settings): setup ended with that connection. The screen - is still counted. A first setup left at the same screen still counts. Choosing This computer - there now counts its first screen, `welcome`, at once, even when the window then resumes past - Welcome, and usage data turned off and back on in Settings counts the first screen after it - again ([desktop/TELEMETRY.md](desktop/TELEMETRY.md)). **API.** From a0494bcaa018836b3d4c8689e2469ca4a8a935c2 Mon Sep 17 00:00:00 2001 From: Alexander Clarke Date: Wed, 2 Dec 2026 20:59:37 +0000 Subject: [PATCH 07/14] Test: a Connect through the relay ends setup, so its quit is not abandoned A first launch's Connect from the first screen, through the relay, with and without the screen named, then a quit and the next launch: no setup_abandoned either way, and completed only when the screen is named. The window stand-in now also answers an authorization of the app's own sign-in, sending the browser back with a code. --- desktop/src-tauri/src/connected_ipc_tests.rs | 81 ++++++++++++++++++++ desktop/src-tauri/src/window_ipc_tests.rs | 8 +- 2 files changed, 85 insertions(+), 4 deletions(-) diff --git a/desktop/src-tauri/src/connected_ipc_tests.rs b/desktop/src-tauri/src/connected_ipc_tests.rs index 018c10c8ff..34f9b0a65a 100644 --- a/desktop/src-tauri/src/connected_ipc_tests.rs +++ b/desktop/src-tauri/src/connected_ipc_tests.rs @@ -555,6 +555,87 @@ mod connected_ipc { let _ = std::fs::remove_dir_all(&data); } + /// A first launch's Connect through the relay, from the first screen: the connection it keeps + /// ends the setup session the launch opened, whether or not the window named its screen (only + /// then is it counted `completed`), so neither the quit nor the next launch says + /// `setup_abandoned`. The window's events are its own JSON (`ConnectToOpenBot.tsx`: `started` + /// only with a screen, and the screen and the wait sent with Connect). + #[test] + fn a_first_launchs_connect_through_the_relay_ends_setup_so_its_quit_is_not_abandoned() { + use openbot_desktop_lib::telemetry::{ConnectOutcome, ConnectScreen, EventData, Step}; + for named in [true, false] { + let data = temp_root("openbot-relay-connect-telemetry"); + let address = window_stand_in(WindowStand::new(false)); + let shell = launched_with_usage_data(false, &data); + let (_browser, _opened) = approving_browser(); + window_says( + &shell, + &serde_json::json!({ "kind": "step_viewed", "step": "connect_openbot" }), + ); + let mut asked = serde_json::json!({ "address": address }); + if named { + window_says( + &shell, + &serde_json::json!({ + "kind": "openbot_connect", "screen": "connect_openbot", "outcome": "started" + }), + ); + asked["screen"] = "connect_openbot".into(); + asked["waitedMs"] = 400.into(); + } + shell + .ask_with(SETUP, "connect_to_openbot", asked) + .expect("connected"); + assert!(desktop_connected::relay_origin(shell.handle()).is_some()); + assert_eq!( + choice::read(&shell.config).connected_to(), + Some(address.as_str()), + "named {named}: the choice kept" + ); + let mut shown = vec![ + EventData::StepViewed { + step: Step::Welcome, + }, + EventData::StepViewed { + step: Step::ConnectOpenbot, + }, + ]; + if named { + shown.push(EventData::OpenbotConnect { + screen: ConnectScreen::ConnectOpenbot, + outcome: ConnectOutcome::Started, + duration_ms: None, + }); + // From the press: the window's 400 ms, then the sign-in's own time. + let took = queued(&shell).last().and_then(|event| match event { + EventData::OpenbotConnect { + outcome: ConnectOutcome::Completed, + duration_ms, + .. + } => *duration_ms, + _ => None, + }); + assert!(took.is_some_and(|ms| ms >= 400), "{:?}", queued(&shell)); + shown.push(EventData::OpenbotConnect { + screen: ConnectScreen::ConnectOpenbot, + outcome: ConnectOutcome::Completed, + duration_ms: took, + }); + } + desktop_telemetry::shutdown(shell.handle()); + assert_eq!(queued(&shell), shown, "named {named}: on quit"); + let next = relaunched(&shell, &data); + let mut expected = shown; + expected.push(EventData::StepViewed { + step: Step::Welcome, + }); + assert_eq!(queued(&next), expected, "named {named}: next launch"); + drop(next); + drop(shell); + let _ = std::fs::remove_dir_all(&data); + } + } + /// The first screen shown again by the desktop itself, then said by the window: a sign-in that /// ends while OpenBot shows (`session_ended`, which puts setup back) when `ended`, otherwise a /// saved OpenBot that cannot be reached (`show_connected`, asked by the window, failing). diff --git a/desktop/src-tauri/src/window_ipc_tests.rs b/desktop/src-tauri/src/window_ipc_tests.rs index 2963076a22..fdca2cefbd 100644 --- a/desktop/src-tauri/src/window_ipc_tests.rs +++ b/desktop/src-tauri/src/window_ipc_tests.rs @@ -36,9 +36,9 @@ impl WindowStand { } /// An OpenBot stand-in on 127.0.0.1: the two public questions (with or without the window's -/// sign-in), the window sign-in sending the browser back with a code, Better Auth's sign-out, the -/// token endpoint for a sign-in of the app's own, and the person's organizations and email to the -/// window's session cookie only. +/// sign-in), the window sign-in and the authorization of a sign-in of the app's own each sending +/// the browser back with a code, Better Auth's sign-out, the token endpoint for a sign-in of the +/// app's own, and the person's organizations and email to the window's session cookie only. fn window_stand_in(stand: Arc>) -> String { let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); let address = format!("http://{}", listener.local_addr().unwrap()); @@ -105,7 +105,7 @@ fn window_stand_in(stand: Arc>) -> String { } (200, None, metadata.to_string()) } - ("GET", "/api/auth/window/sign-in") => { + ("GET", "/api/auth/window/sign-in" | "/api/auth/oauth2/authorize") => { let asked: std::collections::HashMap<_, _> = url.query_pairs().into_owned().collect(); let mut back = reqwest::Url::parse(&asked["redirect_uri"]).unwrap(); From 5dd8fc6bdc0e435d649632b892e49acbe022f230 Mon Sep 17 00:00:00 2001 From: Alexander Clarke Date: Wed, 2 Dec 2026 21:02:22 +0000 Subject: [PATCH 08/14] Telemetry docs: setup_failed's step, and setup_abandoned in short paragraphs setup_failed's step is the last screen shown, which setup ending clears; a connection kept with no setup session open, such as an organization switch, leaves it as it was (end_setup_session returns before clearing it). The same in the comments on last_step_shown and end_setup_session. setup_abandoned's paragraph is split into short ones with the same facts, and a test's comment is wrapped to the file's width. --- desktop/TELEMETRY.md | 14 ++++++++++++-- desktop/src-tauri/src/telemetry.rs | 18 ++++++++++-------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/desktop/TELEMETRY.md b/desktop/TELEMETRY.md index 35727c13c6..67ac6549b2 100644 --- a/desktop/TELEMETRY.md +++ b/desktop/TELEMETRY.md @@ -56,7 +56,7 @@ All desktop event names begin with `oss.desktop.`. The Rust `EventData` enum and For `model_chosen`, providers are `openai`, `anthropic`, `google`, `xai`, `compatible`, or `none`; credential paths are `subscription`, `api_key`, `oauth`, or `none`. OpenAI and Anthropic plan sign-ins use `subscription`. xAI's native sign-in uses its named provider with `oauth` (Google's did, before Gemini took an API key only); Google's and xAI's API-key routes use `compatible`, matching the picker’s endpoint choice. A compatible endpoint uses `api_key` only when a nonblank key is supplied or its saved key is explicitly selected; keyless endpoints use `none`. Skipping model setup uses provider and credential path `none`. `custom_base_url` records only whether a nonblank base URL was selected, never its value. -`setup_failed` is sent by the desktop itself, never by the window, from every failed install or Start (once: a step that already said it failed is not counted again, and a Start cancelled by Stop is not a failure), and from every failed `local setup`, `local start`, `local update`, `local connect`, the Learning model's setup after Start, and an Account-step check that stops setup (an engine too small, or one local setup does not run on). `step` is the last screen shown since setup last ended, one shown once a connection is kept included (`install` when none); `failing_step` names the part that failed by the setup rows' step names (`install_engine`, `services`, `local_setup`, `account_check`, ...). `error_class` comes from the step, or where the step says nothing, from the failure's words, of which only the class is kept. `cli_reason` and `cli_failure` are the CLI's closed reason and the desktop's closed failure category. `resources`, for an engine too small, has `cpu_short`, `memory_short` and `disk_short`, and what setup needs against what was measured: CPUs in thousandths, memory and disk in MiB; anything not measured is absent. +`setup_failed` is sent by the desktop itself, never by the window, from every failed install or Start (once: a step that already said it failed is not counted again, and a Start cancelled by Stop is not a failure), and from every failed `local setup`, `local start`, `local update`, `local connect`, the Learning model's setup after Start, and an Account-step check that stops setup (an engine too small, or one local setup does not run on). `step` is the last screen shown, one shown once a connection is kept included (`install` when none). Setup ending clears it (`activated`, `completed`, `setup_abandoned`, `setup_restart_required`, or a kept connection that closes an open setup session); a connection kept with no setup session open, such as an organization switch, leaves it as it was; `failing_step` names the part that failed by the setup rows' step names (`install_engine`, `services`, `local_setup`, `account_check`, ...). `error_class` comes from the step, or where the step says nothing, from the failure's words, of which only the class is kept. `cli_reason` and `cli_failure` are the CLI's closed reason and the desktop's closed failure category. `resources`, for an engine too small, has `cpu_short`, `memory_short` and `disk_short`, and what setup needs against what was measured: CPUs in thousandths, memory and disk in MiB; anything not measured is absent. `setup_stalled` and `ui_stalled` report a hang, which is not a failure and so is never a `setup_failed`. Both are sent by the desktop itself, never by the window, with closed names and seconds only: never what the window showed, a log line, or what the step was working on. @@ -64,7 +64,17 @@ For `model_chosen`, providers are `openai`, `anthropic`, `google`, `xai`, `compa `ui_stalled` is a setup window that stopped taking what the desktop sends it. While the setup, start or update screens show, the page invokes `setup_heartbeat` every five seconds, and as soon as a row's progress reaches it, with the highest progress number it has taken (`setup:progress` carries one). The heartbeat is never awaited and runs off the window's thread. Progress left untaken for over 30 seconds while the window is shown, not minimised and, on macOS, not covered is a stall. The Desktop log says `[ui] the window has not answered for 31s during start_machine` when it is noticed and `[ui] the window stopped answering for 42s during start_machine` when it ends, and that end sends one `ui_stalled` with `stalled_seconds` and `step`, the setup row the desktop was reporting, by the same names as `failing_step`. It ends when the page catches up, the window leaves the screen, the window loads another page, or OpenBot quits. A page that has just loaded counts what was sent before it listened as taken, and a page that sends no heartbeat (OpenBot itself) is not watched. -`setup_abandoned` is setup ending before activation, or before a connection from the first screen completed (`openbot_connect`): Quit during setup, or, on the next launch, a crash. Once the app keeps a connection to an OpenBot that runs elsewhere (kept once signed in and that OpenBot answered, just before `openbot_connect` `completed` is counted when the window named the screen it was pressed on (`screen`); once the window's own sign-in at that OpenBot came back from the browser, just before the window trades its code for its session there; or by Move to Cloud), setup has ended: keeping it closes any setup session still open, whether or not a `completed` was sent, and nothing starts one while it is kept. Each launch, and the first screen whenever it shows again (Sign in again once a sign-in ended, at launch or while OpenBot shows, or once the window's own sign-in was let go: OpenBot's page could not trade its code, or that OpenBot no longer signs the window in; a saved OpenBot that cannot be reached; the choice made again from Settings), is still counted as `step_viewed`, but neither a quit nor a crash then sends `setup_abandoned`, even after a Sign in again that started, failed or was cancelled. A setup session the last run left open (a crash, or an earlier version, which started one at every launch) is closed without a `setup_abandoned` by a launch that finds the connection kept. Releases before this counted a quit or a crash of a connected app as `setup_abandoned`, at `welcome` or `connect_openbot`, and one that such a release recorded on quit but had not yet sent is still sent after the update, so compare `setup_abandoned` across this change by `openbot_version` (the app version every event carries). Choosing this computer there starts a setup on this computer at its first screen, as a first launch does: one `step_viewed` `welcome` is sent at once, before the window shows anything and even when the window then resumes past Welcome, and a quit or a crash before `activated` abandons it as any other. A screen said twice in a row is counted once, as every `step_viewed` is, unless setup ended between the two; usage data turned off and back on in Settings starts afresh, so the first screen after it is counted, and a setup failure before any screen is placed at `install`. `setup_restart_required` is setup ending for the Windows restart that turning on Windows Subsystem for Linux needs, at the step it was on: Restart now, or Windows ending the app while that restart is owed (a restart from the Start menu). It is saved before Windows ends the app and sent by the launch after the restart, which carries on the same setup under the same installation UUID; that exit is never a `setup_abandoned`. A Quit while the restart is owed is still `setup_abandoned`. +`setup_abandoned` is setup ending before activation, or before a connection from the first screen completed (`openbot_connect`): Quit during setup, or, on the next launch, a crash. + +Keeping a connection to an OpenBot that runs elsewhere ends setup too. The app keeps one once signed in and that OpenBot answered, just before `openbot_connect` `completed` is counted when the window named the screen it was pressed on (`screen`); once the window's own sign-in at that OpenBot came back from the browser, just before the window trades its code for its session there; or by Move to Cloud. Keeping it closes any setup session still open, whether or not a `completed` was sent, and nothing starts one while it is kept. + +While it is kept, each launch and the first screen whenever it shows again are still counted as `step_viewed`, but neither a quit nor a crash then sends `setup_abandoned`, even after a Sign in again that started, failed or was cancelled. The first screen shows again for Sign in again once a sign-in ended, at launch or while OpenBot shows, or once the window's own sign-in was let go (OpenBot's page could not trade its code, or that OpenBot no longer signs the window in); for a saved OpenBot that cannot be reached; and for the choice made again from Settings. A setup session the last run left open (a crash, or an earlier version, which started one at every launch) is closed without a `setup_abandoned` by a launch that finds the connection kept. + +Releases before this counted a quit or a crash of a connected app as `setup_abandoned`, at `welcome` or `connect_openbot`, and one that such a release recorded on quit but had not yet sent is still sent after the update, so compare `setup_abandoned` across this change by `openbot_version` (the app version every event carries). + +Choosing this computer on a first screen shown again starts a setup on this computer at its first screen, as a first launch does: one `step_viewed` `welcome` is sent at once, before the window shows anything and even when the window then resumes past Welcome, and a quit or a crash before `activated` abandons it as any other. A screen said twice in a row is counted once, as every `step_viewed` is, unless setup ended between the two; usage data turned off and back on in Settings starts afresh, so the first screen after it is counted, and a setup failure before any screen is placed at `install`. + +`setup_restart_required` is setup ending for the Windows restart that turning on Windows Subsystem for Linux needs, at the step it was on: Restart now, or Windows ending the app while that restart is owed (a restart from the Start menu). It is saved before Windows ends the app and sent by the launch after the restart, which carries on the same setup under the same installation UUID; that exit is never a `setup_abandoned`. A Quit while the restart is owed is still `setup_abandoned`. `windows_probe` is one of the Windows readiness check's probes, which the setup window waits on before it shows its first screen, that ran long or was stopped at its limit. Sent by the desktop itself, once per such probe, on Windows only. `probe` is which one, by what it asks: `virtualization`, `administrator`, `wsl_feature`, `wsl_service`, `virtual_machine_platform_feature`, `wsl_version`, `wsl_system_start` (`wsl.exe --system`, which starts WSL's own VM) or `docker`. `outcome` is `slow` (it answered, after the probe's slow mark) or `timed_out` (it was stopped at its limit and counted as no answer). `duration_ms` is how long it ran. Slow marks are well under the limits: 5 seconds for the PowerShell probes and `wsl_version` (limit 30), 3 for `docker` (limit 10), and 20 for `wsl_system_start` (limit 60; a cold start measured about 6). A probe that answers in good time sends nothing. Never the command, its output, its error or a path. diff --git a/desktop/src-tauri/src/telemetry.rs b/desktop/src-tauri/src/telemetry.rs index f0a454b16e..b78120f498 100644 --- a/desktop/src-tauri/src/telemetry.rs +++ b/desktop/src-tauri/src/telemetry.rs @@ -105,8 +105,8 @@ pub struct Telemetry { config: Config, state: Mutex>, session_last_step_viewed: Mutex>, - /// The last setup screen shown since setup last ended, whether or not it started a setup - /// session: where a setup failure happened (`last_step_shown`). + /// The last setup screen shown, whether or not it started a setup session: where a setup + /// failure happened (`last_step_shown` says when it is cleared). last_step_shown: Mutex>, flush_lock: Mutex<()>, client: Client, @@ -797,7 +797,8 @@ impl Telemetry { /** Setup ended with a connection to an OpenBot that runs elsewhere, kept by the app, whether or not that connection was counted (`openbot_connect` `completed`): the setup session open now closes - without a `setup_abandoned`, and nothing is sent for it. + without a `setup_abandoned`, and nothing is sent for it. With none open it changes nothing, and + the last screen shown stays (`last_step_shown`). */ pub fn end_setup_session(&self) -> Result<()> { let mut guard = self.state.lock().map_err(|_| TelemetryError::Poisoned)?; @@ -818,8 +819,9 @@ impl Telemetry { write_state(&self.state_path, state) } - /// The last setup screen shown since setup last ended, whether or not it started a setup - /// session: where a setup failure is said to have happened. + /// The last setup screen shown, whether or not it started a setup session: where a setup + /// failure is said to have happened. Setup ending clears it, and a kept connection only when + /// it closes an open setup session (`end_setup_session`). pub fn last_step_shown(&self) -> Result> { Ok(*self .last_step_shown @@ -3736,9 +3738,9 @@ mod tests { } /// A screen shown after setup ended, then the same screen starting a setup on this computer: - /// counted once, as any view said twice in a row, and the setup it starts is still abandoned - /// by a quit, or by the next launch after a crash. Where a setup failure happened is the last screen shown either way, until setup - /// ends. With usage data off, nothing is recorded or kept. + /// counted once, as any view said twice in a row, and the setup it starts is still abandoned by + /// a quit, or by the next launch after a crash. Where a setup failure happened is the last + /// screen shown either way, until setup ends. With usage data off, nothing is recorded or kept. #[test] fn a_step_shown_after_setup_then_starting_one_is_counted_once_and_abandoned() { let dir = temp_dir("shown-after-then-starting"); From 7a983323bcbec43769818bbb5a38afa0422ce337 Mon Sep 17 00:00:00 2001 From: Alexander Clarke Date: Wed, 2 Dec 2026 21:26:19 +0000 Subject: [PATCH 09/14] Test: a Sign out, and a window sign-in Connect with its screen named, are not abandoned Sign out keeps the address, so the first screen it puts up is shown again: no setup_abandoned on quit or at the next launch. The window sign-in test now runs Connect as the window asks it, with the screen named (started and completed before the trade), and without, the defensive case; the relay test shares the same Connect. App.test.tsx pins the welcome the window says after OpenBot (Self-Contained) is chosen on the first screen shown again. The file's header and one test's doc say what the tests run. --- desktop/src-tauri/src/connected_ipc_tests.rs | 201 ++++++++++++------- desktop/src-tauri/src/window_ipc_tests.rs | 113 ++++++----- desktop/src/App.test.tsx | 6 + 3 files changed, 194 insertions(+), 126 deletions(-) diff --git a/desktop/src-tauri/src/connected_ipc_tests.rs b/desktop/src-tauri/src/connected_ipc_tests.rs index 34f9b0a65a..70930791f0 100644 --- a/desktop/src-tauri/src/connected_ipc_tests.rs +++ b/desktop/src-tauri/src/connected_ipc_tests.rs @@ -1,7 +1,8 @@ // Included by main.rs: the app connected to an OpenBot that runs elsewhere, through the shell's own // registered commands, its window rules and its Stop and Quit. The sign-in and the relay themselves -// are tested in the library (`connected`), against a full OpenBot stand-in; here only a `/health` -// stand-in is used. +// are tested in the library (`connected`), against a full OpenBot stand-in; here small stand-ins +// answer only what the shell asks: `/health`, the token endpoint and, for a sign-in through the +// browser, the window stand-in (`window_ipc_tests.rs`). mod connected_ipc { use super::*; use openbot_desktop_lib::connected::{choice, credentials}; @@ -326,15 +327,67 @@ mod connected_ipc { ); } + /// Connect pressed on the first screen's address, through `connect_to_openbot` from the setup + /// window, as the window asks it: when `named`, after its own `started` and with the screen and + /// its wait (`ConnectToOpenBot.tsx`, which always names the screen today); otherwise with the + /// address alone, the defensive case. What it adds to usage data: `started` and the shell's + /// `completed`, from the press, when named; nothing otherwise. + fn connect_from_the_first_screen( + shell: &Connected, + address: &str, + named: bool, + ) -> Vec { + use openbot_desktop_lib::telemetry::{ConnectOutcome, ConnectScreen, EventData}; + let mut asked = serde_json::json!({ "address": address }); + if named { + window_says( + shell, + &serde_json::json!({ + "kind": "openbot_connect", "screen": "connect_openbot", "outcome": "started" + }), + ); + asked["screen"] = "connect_openbot".into(); + asked["waitedMs"] = 400.into(); + } + shell + .ask_with(SETUP, "connect_to_openbot", asked) + .expect("connected"); + if !named { + return Vec::new(); + } + // From the press: the window's 400 ms, then the sign-in's own time. + let took = queued(shell).last().and_then(|event| match event { + EventData::OpenbotConnect { + outcome: ConnectOutcome::Completed, + duration_ms, + .. + } => *duration_ms, + _ => None, + }); + assert!(took.is_some_and(|ms| ms >= 400), "{:?}", queued(shell)); + vec![ + EventData::OpenbotConnect { + screen: ConnectScreen::ConnectOpenbot, + outcome: ConnectOutcome::Started, + duration_ms: None, + }, + EventData::OpenbotConnect { + screen: ConnectScreen::ConnectOpenbot, + outcome: ConnectOutcome::Completed, + duration_ms: took, + }, + ] + } + /// Once setup ended with a connection (the choice on record is connected), every launch and - /// every first screen shown again is counted and starts no setup session: a launch that opens - /// that OpenBot, a Sign in again, a Change from Settings, a sign-in that ends while OpenBot - /// shows. Neither a quit nor a crash then says `setup_abandoned`, at once or at the next launch, - /// also after a Sign in again that only started or failed. With no connection on record the - /// same launch and screens are a first setup, which a quit or a crash abandons at the last - /// step. Choosing This computer on the screen shown again (`use_this_computer`) starts a setup - /// on this computer at its first screen, before the window shows anything, which a quit or a - /// crash abandons; the window's own first view then is not counted twice. + /// every first screen shown again is counted and starts no setup session: here a launch that + /// opens that OpenBot, and a Sign in again or a Change from Settings (the same view). Neither a + /// quit nor a crash then says `setup_abandoned`, at once or at the next launch, also after a + /// Sign in again that started and failed. With no connection on record the same launch and + /// screens are a first setup, which a quit or a crash abandons at the last step. Choosing + /// OpenBot (Self-Contained) on the screen shown again (`use_this_computer`) starts a setup on + /// this computer at its first screen, before the window shows anything, which a quit or a crash + /// abandons; the window's own first view then is not counted twice. /// /// Each launch goes through `open_then_launch`, as `initialize` does, the window's events are /// its own JSON (`App.tsx`, `useConnectToOpenBot`; pinned in `App.test.tsx`), and what is kept @@ -556,13 +609,13 @@ mod connected_ipc { } /// A first launch's Connect through the relay, from the first screen: the connection it keeps - /// ends the setup session the launch opened, whether or not the window named its screen (only - /// then is it counted `completed`), so neither the quit nor the next launch says - /// `setup_abandoned`. The window's events are its own JSON (`ConnectToOpenBot.tsx`: `started` - /// only with a screen, and the screen and the wait sent with Connect). + /// ends the setup session the launch opened, whether or not the window named its screen (it + /// always does today, and only then is it counted `completed`; without it, keeping the + /// connection alone ends the session), so neither the quit nor the next launch says + /// `setup_abandoned`. #[test] fn a_first_launchs_connect_through_the_relay_ends_setup_so_its_quit_is_not_abandoned() { - use openbot_desktop_lib::telemetry::{ConnectOutcome, ConnectScreen, EventData, Step}; + use openbot_desktop_lib::telemetry::{EventData, Step}; for named in [true, false] { let data = temp_root("openbot-relay-connect-telemetry"); let address = window_stand_in(WindowStand::new(false)); @@ -572,20 +625,7 @@ mod connected_ipc { &shell, &serde_json::json!({ "kind": "step_viewed", "step": "connect_openbot" }), ); - let mut asked = serde_json::json!({ "address": address }); - if named { - window_says( - &shell, - &serde_json::json!({ - "kind": "openbot_connect", "screen": "connect_openbot", "outcome": "started" - }), - ); - asked["screen"] = "connect_openbot".into(); - asked["waitedMs"] = 400.into(); - } - shell - .ask_with(SETUP, "connect_to_openbot", asked) - .expect("connected"); + let connected = connect_from_the_first_screen(&shell, &address, named); assert!(desktop_connected::relay_origin(shell.handle()).is_some()); assert_eq!( choice::read(&shell.config).connected_to(), @@ -600,28 +640,7 @@ mod connected_ipc { step: Step::ConnectOpenbot, }, ]; - if named { - shown.push(EventData::OpenbotConnect { - screen: ConnectScreen::ConnectOpenbot, - outcome: ConnectOutcome::Started, - duration_ms: None, - }); - // From the press: the window's 400 ms, then the sign-in's own time. - let took = queued(&shell).last().and_then(|event| match event { - EventData::OpenbotConnect { - outcome: ConnectOutcome::Completed, - duration_ms, - .. - } => *duration_ms, - _ => None, - }); - assert!(took.is_some_and(|ms| ms >= 400), "{:?}", queued(&shell)); - shown.push(EventData::OpenbotConnect { - screen: ConnectScreen::ConnectOpenbot, - outcome: ConnectOutcome::Completed, - duration_ms: took, - }); - } + shown.extend(connected); desktop_telemetry::shutdown(shell.handle()); assert_eq!(queued(&shell), shown, "named {named}: on quit"); let next = relaunched(&shell, &data); @@ -636,40 +655,73 @@ mod connected_ipc { } } - /// The first screen shown again by the desktop itself, then said by the window: a sign-in that - /// ends while OpenBot shows (`session_ended`, which puts setup back) when `ended`, otherwise a - /// saved OpenBot that cannot be reached (`show_connected`, asked by the window, failing). - /// Neither touches the choice on record, so the screen is counted and starts no setup session: + /// What put the first screen up again, the choice on record still connected. + #[derive(Clone, Copy, Debug)] + enum ShownAgainBy { + /// A sign-in that ended while OpenBot showed (`session_ended`, which puts setup back). + EndedSignIn, + /// A saved OpenBot that cannot be reached (`show_connected`, asked by the window, failing). + Unreachable, + /// Sign out, from a menu or the setup window (`sign_out_of_openbot`): the sign-in is + /// forgotten and the address kept. + SignOut, + } + + /// The first screen shown again by the desktop itself (`by`), then said by the window. None of + /// these changes the choice on record, so the screen is counted and starts no setup session: /// no `setup_abandoned` on quit, or at the next launch. - fn shown_again_by_the_desktop_is_not_abandoned(ended: bool) { + fn shown_again_by_the_desktop_is_not_abandoned(by: ShownAgainBy) { use openbot_desktop_lib::telemetry::{EventData, Step}; // An address where nothing answers: a loopback port just closed. let unreachable = { let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap(); format!("http://{}", listener.local_addr().unwrap()) }; + let address = match by { + ShownAgainBy::EndedSignIn => ADDRESS.to_owned(), + ShownAgainBy::Unreachable | ShownAgainBy::SignOut => unreachable, + }; let data = temp_root("openbot-shown-again-by-the-desktop"); let shell = Connected::new(); - shell.choose( - choice::Mode::Connected, - if ended { ADDRESS } else { &unreachable }, - None, - ); + shell.choose(choice::Mode::Connected, &address, None); desktop_telemetry::initialize_for_test(shell.handle(), data.to_path_buf()); - if ended { - desktop_connected::session_ended(shell.handle(), "openbot.example.com"); - } else { - let refused = shell.ask(SETUP, "show_connected").unwrap_err(); - assert_eq!(refused["kind"], "unreachable", "{refused}"); + match by { + ShownAgainBy::EndedSignIn => { + desktop_connected::session_ended(shell.handle(), "openbot.example.com"); + } + ShownAgainBy::Unreachable => { + let refused = shell.ask(SETUP, "show_connected").unwrap_err(); + assert_eq!(refused["kind"], "unreachable", "{refused}"); + } + ShownAgainBy::SignOut => { + // Nothing answers there, so no browser is sent to end a session at it. + let opened = Arc::new(Mutex::new(Vec::::new())); + let noting = opened.clone(); + let _browser = desktop_connected::use_browser_for_test(move |to: &str| { + noting.lock().unwrap().push(to.to_owned()); + Ok(()) + }); + shell + .store + .set(&address, &format!("obr_saved{}", "s".repeat(32))) + .unwrap(); + assert_eq!( + shell.ask(SETUP, "sign_out_of_openbot"), + Ok(serde_json::Value::Null) + ); + assert_eq!(shell.store.get(&address).unwrap(), None, "signed out"); + assert_eq!(shell.window.url().unwrap().as_str(), SETUP); + assert_eq!(*opened.lock().unwrap(), Vec::::new()); + } } window_says( &shell, &serde_json::json!({ "kind": "step_viewed", "step": "connect_openbot" }), ); assert_eq!( - choice::read(&shell.config).mode, - choice::Mode::Connected, - "the choice kept" + choice::read(&shell.config).connected_to(), + Some(address.as_str()), + "{by:?}: the choice kept" ); let shown = vec![ EventData::StepViewed { @@ -696,14 +748,21 @@ mod connected_ipc { /// not abandoned on quit or at the next launch. #[test] fn a_first_screen_shown_again_by_an_ended_sign_in_is_not_abandoned() { - shown_again_by_the_desktop_is_not_abandoned(true); + shown_again_by_the_desktop_is_not_abandoned(ShownAgainBy::EndedSignIn); } /// A saved OpenBot that cannot be reached keeps the connection: the screen that says so is not /// abandoned on quit or at the next launch. #[test] fn a_first_screen_shown_again_by_an_unreachable_openbot_is_not_abandoned() { - shown_again_by_the_desktop_is_not_abandoned(false); + shown_again_by_the_desktop_is_not_abandoned(ShownAgainBy::Unreachable); + } + + /// Sign out keeps the address, so the choice stays connected: Sign in again, shown then, is not + /// abandoned on quit or at the next launch. + #[test] + fn a_first_screen_shown_again_by_a_sign_out_is_not_abandoned() { + shown_again_by_the_desktop_is_not_abandoned(ShownAgainBy::SignOut); } /// A setup failure is said at the last screen shown, a screen shown once setup ended with a diff --git a/desktop/src-tauri/src/window_ipc_tests.rs b/desktop/src-tauri/src/window_ipc_tests.rs index fdca2cefbd..5417b231b9 100644 --- a/desktop/src-tauri/src/window_ipc_tests.rs +++ b/desktop/src-tauri/src/window_ipc_tests.rs @@ -744,66 +744,69 @@ fn an_older_openbot_and_a_sign_in_from_before_go_on_through_the_relay() { Setup ends with a connection through the window's own sign-in too (`connect_window_now` keeps the choice), and a first screen the window's sign-in puts back (the page could not trade its code: Sign in again, the choice still connected) starts no setup session: no `setup_abandoned` on quit, -or at the next launch. +or at the next launch. Connect is asked as the window asks it, with the screen named (then counted +`started` and `completed` before the trade) and, the defensive case, without +(`connect_from_the_first_screen`). */ #[test] fn a_window_sign_in_ends_setup_and_its_sign_in_again_is_not_abandoned() { use openbot_desktop_lib::telemetry::{EventData, Step}; - let data = temp_root("openbot-window-sign-in-not-abandoned"); - let address = window_stand_in(WindowStand::new(true)); - let shell = window_shell(); - let (_browser, _opened) = approving_browser(); - desktop_telemetry::initialize_for_test(shell.handle(), data.to_path_buf()); - window_says( - &shell, - &serde_json::json!({ "kind": "step_viewed", "step": "connect_openbot" }), - ); - shell - .ask_with(SETUP, "connect_to_openbot", serde_json::json!({ "address": address })) - .expect("connected"); - assert_eq!( - choice::read(&shell.config).window_origin(), - Some(address.as_str()) - ); - shell - .ask_with( - &format!("{address}/desktop/signed-in"), - "plugin:openbot-desktop|window_sign_in_failed", - serde_json::json!({ "reason": "invalid_code" }), - ) - .expect("put back"); - assert_eq!(shell.window.url().unwrap().as_str(), SETUP); - assert_eq!( - choice::read(&shell.config).connected_to(), - Some(address.as_str()), - "the choice kept" - ); - window_says( - &shell, - &serde_json::json!({ "kind": "step_viewed", "step": "connect_openbot" }), - ); - let shown = vec![ - EventData::StepViewed { - step: Step::Welcome, - }, - EventData::StepViewed { - step: Step::ConnectOpenbot, - }, - EventData::StepViewed { + for named in [true, false] { + let data = temp_root("openbot-window-sign-in-not-abandoned"); + let address = window_stand_in(WindowStand::new(true)); + let shell = window_shell(); + let (_browser, _opened) = approving_browser(); + desktop_telemetry::initialize_for_test(shell.handle(), data.to_path_buf()); + window_says( + &shell, + &serde_json::json!({ "kind": "step_viewed", "step": "connect_openbot" }), + ); + let connected = connect_from_the_first_screen(&shell, &address, named); + assert_eq!( + choice::read(&shell.config).window_origin(), + Some(address.as_str()) + ); + shell + .ask_with( + &format!("{address}/desktop/signed-in"), + "plugin:openbot-desktop|window_sign_in_failed", + serde_json::json!({ "reason": "invalid_code" }), + ) + .expect("put back"); + assert_eq!(shell.window.url().unwrap().as_str(), SETUP); + assert_eq!( + choice::read(&shell.config).connected_to(), + Some(address.as_str()), + "named {named}: the choice kept" + ); + window_says( + &shell, + &serde_json::json!({ "kind": "step_viewed", "step": "connect_openbot" }), + ); + let mut shown = vec![ + EventData::StepViewed { + step: Step::Welcome, + }, + EventData::StepViewed { + step: Step::ConnectOpenbot, + }, + ]; + shown.extend(connected); + shown.push(EventData::StepViewed { step: Step::ConnectOpenbot, - }, - ]; - desktop_telemetry::shutdown(shell.handle()); - assert_eq!(queued(&shell), shown, "on quit"); - let next = relaunched(&shell, &data); - let mut expected = shown; - expected.push(EventData::StepViewed { - step: Step::Welcome, - }); - assert_eq!(queued(&next), expected, "next launch"); - drop(next); - drop(shell); - let _ = std::fs::remove_dir_all(&data); + }); + desktop_telemetry::shutdown(shell.handle()); + assert_eq!(queued(&shell), shown, "named {named}: on quit"); + let next = relaunched(&shell, &data); + let mut expected = shown; + expected.push(EventData::StepViewed { + step: Step::Welcome, + }); + assert_eq!(queued(&next), expected, "named {named}: next launch"); + drop(next); + drop(shell); + let _ = std::fs::remove_dir_all(&data); + } } /** diff --git a/desktop/src/App.test.tsx b/desktop/src/App.test.tsx index 024c85e460..c90d1b0fa6 100644 --- a/desktop/src/App.test.tsx +++ b/desktop/src/App.test.tsx @@ -2451,6 +2451,12 @@ test("asked from Settings to choose where OpenBot runs, the first screen opens o const commands = asked().map((call) => call.command); expect(commands.indexOf("use_this_computer")).toBe(2); expect(commands).toContain("already_configured"); + // The window then says the first screen of the setup this computer starts, as the shell's own + // IPC test of `use_this_computer` takes it to. + expect(setupEvents()).toEqual([ + { event: { kind: "step_viewed", step: "connect_openbot" } }, + { event: { kind: "step_viewed", step: "welcome" } }, + ]); }); /* From d071880ede5d704632b23a9e0ed01aa62447fd2b Mon Sep 17 00:00:00 2001 From: Alexander Clarke Date: Wed, 2 Dec 2026 21:26:19 +0000 Subject: [PATCH 10/14] Telemetry docs: a kept connection ends setup, in paragraphs that open with their event setup_abandoned is setup ending before activation or before a connection is kept, and each paragraph after it opens with the event it is about. setup_failed's step names openbot_connect completed in full. use_this_computer's comment says it starts a setup, and two comments are wrapped to 100 columns. --- desktop/TELEMETRY.md | 12 +++++------- desktop/src-tauri/src/desktop_connected.rs | 3 ++- desktop/src-tauri/src/desktop_telemetry.rs | 14 ++++++++------ 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/desktop/TELEMETRY.md b/desktop/TELEMETRY.md index 67ac6549b2..d2c3d2bc23 100644 --- a/desktop/TELEMETRY.md +++ b/desktop/TELEMETRY.md @@ -56,7 +56,7 @@ All desktop event names begin with `oss.desktop.`. The Rust `EventData` enum and For `model_chosen`, providers are `openai`, `anthropic`, `google`, `xai`, `compatible`, or `none`; credential paths are `subscription`, `api_key`, `oauth`, or `none`. OpenAI and Anthropic plan sign-ins use `subscription`. xAI's native sign-in uses its named provider with `oauth` (Google's did, before Gemini took an API key only); Google's and xAI's API-key routes use `compatible`, matching the picker’s endpoint choice. A compatible endpoint uses `api_key` only when a nonblank key is supplied or its saved key is explicitly selected; keyless endpoints use `none`. Skipping model setup uses provider and credential path `none`. `custom_base_url` records only whether a nonblank base URL was selected, never its value. -`setup_failed` is sent by the desktop itself, never by the window, from every failed install or Start (once: a step that already said it failed is not counted again, and a Start cancelled by Stop is not a failure), and from every failed `local setup`, `local start`, `local update`, `local connect`, the Learning model's setup after Start, and an Account-step check that stops setup (an engine too small, or one local setup does not run on). `step` is the last screen shown, one shown once a connection is kept included (`install` when none). Setup ending clears it (`activated`, `completed`, `setup_abandoned`, `setup_restart_required`, or a kept connection that closes an open setup session); a connection kept with no setup session open, such as an organization switch, leaves it as it was; `failing_step` names the part that failed by the setup rows' step names (`install_engine`, `services`, `local_setup`, `account_check`, ...). `error_class` comes from the step, or where the step says nothing, from the failure's words, of which only the class is kept. `cli_reason` and `cli_failure` are the CLI's closed reason and the desktop's closed failure category. `resources`, for an engine too small, has `cpu_short`, `memory_short` and `disk_short`, and what setup needs against what was measured: CPUs in thousandths, memory and disk in MiB; anything not measured is absent. +`setup_failed` is sent by the desktop itself, never by the window, from every failed install or Start (once: a step that already said it failed is not counted again, and a Start cancelled by Stop is not a failure), and from every failed `local setup`, `local start`, `local update`, `local connect`, the Learning model's setup after Start, and an Account-step check that stops setup (an engine too small, or one local setup does not run on). `step` is the last screen shown, including one shown after a connection is kept (`install` when none). Setup ending clears it (`activated`, `openbot_connect` `completed`, `setup_abandoned`, `setup_restart_required`, or a kept connection that closes an open setup session); a connection kept with no setup session open, such as an organization switch, leaves it as it was. `failing_step` names the part that failed by the setup rows' step names (`install_engine`, `services`, `local_setup`, `account_check`, ...). `error_class` comes from the step, or where the step says nothing, from the failure's words, of which only the class is kept. `cli_reason` and `cli_failure` are the CLI's closed reason and the desktop's closed failure category. `resources`, for an engine too small, has `cpu_short`, `memory_short` and `disk_short`, and what setup needs against what was measured: CPUs in thousandths, memory and disk in MiB; anything not measured is absent. `setup_stalled` and `ui_stalled` report a hang, which is not a failure and so is never a `setup_failed`. Both are sent by the desktop itself, never by the window, with closed names and seconds only: never what the window showed, a log line, or what the step was working on. @@ -64,15 +64,13 @@ For `model_chosen`, providers are `openai`, `anthropic`, `google`, `xai`, `compa `ui_stalled` is a setup window that stopped taking what the desktop sends it. While the setup, start or update screens show, the page invokes `setup_heartbeat` every five seconds, and as soon as a row's progress reaches it, with the highest progress number it has taken (`setup:progress` carries one). The heartbeat is never awaited and runs off the window's thread. Progress left untaken for over 30 seconds while the window is shown, not minimised and, on macOS, not covered is a stall. The Desktop log says `[ui] the window has not answered for 31s during start_machine` when it is noticed and `[ui] the window stopped answering for 42s during start_machine` when it ends, and that end sends one `ui_stalled` with `stalled_seconds` and `step`, the setup row the desktop was reporting, by the same names as `failing_step`. It ends when the page catches up, the window leaves the screen, the window loads another page, or OpenBot quits. A page that has just loaded counts what was sent before it listened as taken, and a page that sends no heartbeat (OpenBot itself) is not watched. -`setup_abandoned` is setup ending before activation, or before a connection from the first screen completed (`openbot_connect`): Quit during setup, or, on the next launch, a crash. +`setup_abandoned` is setup ending before activation, or before a connection to an OpenBot that runs elsewhere is kept: Quit during setup, or, on the next launch, a crash. The app keeps a connection once signed in and that OpenBot answered, just before `openbot_connect` `completed` is counted when the window named the screen it was pressed on (`screen`); once the window's own sign-in at that OpenBot came back from the browser, just before the window trades its code for its session there; or by Move to Cloud. Keeping it closes any setup session still open, whether or not a `completed` was sent, and nothing starts one while it is kept. -Keeping a connection to an OpenBot that runs elsewhere ends setup too. The app keeps one once signed in and that OpenBot answered, just before `openbot_connect` `completed` is counted when the window named the screen it was pressed on (`screen`); once the window's own sign-in at that OpenBot came back from the browser, just before the window trades its code for its session there; or by Move to Cloud. Keeping it closes any setup session still open, whether or not a `completed` was sent, and nothing starts one while it is kept. +`step_viewed` still counts each launch, and the first screen whenever it shows again, while a connection is kept, but neither a quit nor a crash then sends `setup_abandoned`, even after a Sign in again that started, failed or was cancelled. The first screen shows again for Sign in again once a sign-in ended, at launch or while OpenBot shows, or once the window's own sign-in was let go (OpenBot's page could not trade its code, or that OpenBot no longer signs the window in); for a saved OpenBot that cannot be reached; and for the choice made again from Settings. A setup session the last run left open (a crash, or an earlier version, which started one at every launch) is closed without a `setup_abandoned` by a launch that finds the connection kept. -While it is kept, each launch and the first screen whenever it shows again are still counted as `step_viewed`, but neither a quit nor a crash then sends `setup_abandoned`, even after a Sign in again that started, failed or was cancelled. The first screen shows again for Sign in again once a sign-in ended, at launch or while OpenBot shows, or once the window's own sign-in was let go (OpenBot's page could not trade its code, or that OpenBot no longer signs the window in); for a saved OpenBot that cannot be reached; and for the choice made again from Settings. A setup session the last run left open (a crash, or an earlier version, which started one at every launch) is closed without a `setup_abandoned` by a launch that finds the connection kept. +`setup_abandoned` was also sent for a quit or a crash of a connected app by releases before this rule, at `welcome` or `connect_openbot`, and one that such a release recorded on quit but had not yet sent is still sent after the update, so compare `setup_abandoned` from before and after the rule by `openbot_version` (the app version every event carries). -Releases before this counted a quit or a crash of a connected app as `setup_abandoned`, at `welcome` or `connect_openbot`, and one that such a release recorded on quit but had not yet sent is still sent after the update, so compare `setup_abandoned` across this change by `openbot_version` (the app version every event carries). - -Choosing this computer on a first screen shown again starts a setup on this computer at its first screen, as a first launch does: one `step_viewed` `welcome` is sent at once, before the window shows anything and even when the window then resumes past Welcome, and a quit or a crash before `activated` abandons it as any other. A screen said twice in a row is counted once, as every `step_viewed` is, unless setup ended between the two; usage data turned off and back on in Settings starts afresh, so the first screen after it is counted, and a setup failure before any screen is placed at `install`. +`step_viewed` `welcome` is sent at once when OpenBot (Self-Contained) is chosen on a first screen shown again, before the window shows anything and even when the window then resumes past Welcome: the choice starts a setup on this computer at its first screen, as a first launch does, and a quit or a crash before `activated` abandons it as any other. A screen said twice in a row is counted once, as every `step_viewed` is, unless setup ended between the two; usage data turned off and back on in Settings starts afresh, so the first screen after it is counted, and a setup failure before any screen is placed at `install`. `setup_restart_required` is setup ending for the Windows restart that turning on Windows Subsystem for Linux needs, at the step it was on: Restart now, or Windows ending the app while that restart is owed (a restart from the Start menu). It is saved before Windows ends the app and sent by the launch after the restart, which carries on the same setup under the same installation UUID; that exit is never a `setup_abandoned`. A Quit while the restart is owed is still `setup_abandoned`. diff --git a/desktop/src-tauri/src/desktop_connected.rs b/desktop/src-tauri/src/desktop_connected.rs index 2dbd9c5b37..033e923c24 100644 --- a/desktop/src-tauri/src/desktop_connected.rs +++ b/desktop/src-tauri/src/desktop_connected.rs @@ -749,7 +749,8 @@ pub async fn sign_out_of_openbot( } /// Back to OpenBot on this computer: signed out, the choice switched, and the setup window, which -/// carries on as it does for an installation here. +/// carries on as it does for an installation here. A setup starts at its first screen, as at a +/// first launch (`desktop_telemetry::launched`), so a quit before `activated` is `setup_abandoned`. #[tauri::command] pub async fn use_this_computer(app: tauri::AppHandle) -> Result<(), Problem> { blocking(move || { diff --git a/desktop/src-tauri/src/desktop_telemetry.rs b/desktop/src-tauri/src/desktop_telemetry.rs index 9c75861dd0..7c785da098 100644 --- a/desktop/src-tauri/src/desktop_telemetry.rs +++ b/desktop/src-tauri/src/desktop_telemetry.rs @@ -201,12 +201,13 @@ pub(crate) fn initialize_for_test( } /** -The first screen viewed: at every launch, and when This computer is chosen once connected +The first screen viewed: at every launch, and when OpenBot (Self-Contained) is chosen once connected (`desktop_connected::use_this_computer`), before the window has shown anything. Once setup ended -with a connection to an OpenBot that runs elsewhere (`desktop_connected::setup_ended_with_connection`) -it starts no setup session: a launch that opens that OpenBot, or shows the first screen to sign in -again, and is then quit is not `setup_abandoned`. Otherwise it is where a setup starts, as it always -was, so a quit before the window shows anything still abandons it. +with a connection to an OpenBot that runs elsewhere +(`desktop_connected::setup_ended_with_connection`) it starts no setup session: a launch that opens +that OpenBot, or shows the first screen to sign in again, and is then quit is not `setup_abandoned`. +Otherwise it is where a setup starts, as it always was, so a quit before the window shows anything +still abandons it. */ pub fn launched(app: &tauri::AppHandle) { first_screen( @@ -591,7 +592,8 @@ pub fn setup_ended(app: &tauri::AppHandle) { } } -/// A setup step shown again once setup ended with a connection (`Telemetry::record_step_after_setup`). +/// A setup step shown again once setup ended with a connection +/// (`Telemetry::record_step_after_setup`). pub fn record_step_after_setup( app: &tauri::AppHandle, step: telemetry::Step, From 4173506da738c2e24ee7d59d12cf4faff61ebf20 Mon Sep 17 00:00:00 2001 From: Alexander Clarke Date: Wed, 2 Dec 2026 21:50:15 +0000 Subject: [PATCH 11/14] Test: Settings' Change is not abandoned, and a switch with no setup open keeps the step Settings' Change while connected keeps the address, so the first screen it opens is shown again: no setup_abandoned on quit or at the next launch. A connection kept with no setup session open, such as an organization switch, leaves the last screen shown, in the library and through set_organization_now before a setup failure. The quit and next-launch checks are one helper, and a launch connected to any address another. --- desktop/src-tauri/src/connected_ipc_tests.rs | 110 +++++++++++-------- desktop/src-tauri/src/telemetry.rs | 21 +++- desktop/src-tauri/src/window_ipc_tests.rs | 24 +--- 3 files changed, 89 insertions(+), 66 deletions(-) diff --git a/desktop/src-tauri/src/connected_ipc_tests.rs b/desktop/src-tauri/src/connected_ipc_tests.rs index 70930791f0..fc58a1b589 100644 --- a/desktop/src-tauri/src/connected_ipc_tests.rs +++ b/desktop/src-tauri/src/connected_ipc_tests.rs @@ -294,9 +294,14 @@ mod connected_ipc { /// usage data kept in `data`, launched as `desktop_telemetry::initialize` launches it once it /// has read the usage-data setting (`open_then_launch`), sending nowhere. fn launched_with_usage_data(connected: bool, data: &std::path::Path) -> Connected { + launched_connected_to(connected.then_some(ADDRESS), data) + } + + /// The same, connected to `address` when one is given. + fn launched_connected_to(address: Option<&str>, data: &std::path::Path) -> Connected { let shell = Connected::new(); - if connected { - shell.choose(choice::Mode::Connected, ADDRESS, None); + if let Some(address) = address { + shell.choose(choice::Mode::Connected, address, None); } desktop_telemetry::initialize_for_test(shell.handle(), data.to_path_buf()); shell @@ -327,6 +332,29 @@ mod connected_ipc { ); } + /// A quit of `shell`, then the next launch of an app on the same files: the quit leaves `shown` + /// queued and nothing more (no `setup_abandoned`), and the next launch adds only its own + /// `welcome`. The usage data in `data` is removed afterwards. + fn quit_and_relaunch_without_abandonment( + shell: Connected, + data: &std::path::Path, + shown: Vec, + what: &str, + ) { + use openbot_desktop_lib::telemetry::{EventData, Step}; + desktop_telemetry::shutdown(shell.handle()); + assert_eq!(queued(&shell), shown, "{what}: on quit"); + let next = relaunched(&shell, data); + let mut expected = shown; + expected.push(EventData::StepViewed { + step: Step::Welcome, + }); + assert_eq!(queued(&next), expected, "{what}: next launch"); + drop(next); + drop(shell); + let _ = std::fs::remove_dir_all(data); + } + /// Connect pressed on the first screen's address, through `connect_to_openbot` from the setup /// window, as the window asks it: when `named`, after its own `started` and with the screen and /// its wait (`ConnectToOpenBot.tsx`, which always names the screen today); otherwise with the @@ -589,23 +617,18 @@ mod connected_ipc { /// Move to Cloud from an OpenBot on this computer whose activation was never recorded (usage /// data was off when it started): the connection it keeps ends the setup session this launch /// opened, though the move says no `openbot_connect`, so neither the quit nor the next launch - /// says `setup_abandoned`. + /// says `setup_abandoned`. The move keeps it through `keep_moved_choice` once it is saved + /// (`ThisComputer::moved`), which is called here directly. #[test] fn a_connection_kept_by_move_to_cloud_ends_the_setup_session() { use openbot_desktop_lib::telemetry::{EventData, Step}; let data = temp_root("openbot-moved-telemetry"); let shell = launched_with_usage_data(false, &data); desktop_connected::keep_moved_choice(shell.handle(), ADDRESS, "org_moved").unwrap(); - desktop_telemetry::shutdown(shell.handle()); let welcome = EventData::StepViewed { step: Step::Welcome, }; - assert_eq!(queued(&shell), vec![welcome.clone()]); - let next = relaunched(&shell, &data); - assert_eq!(queued(&next), vec![welcome.clone(), welcome]); - drop(next); - drop(shell); - let _ = std::fs::remove_dir_all(&data); + quit_and_relaunch_without_abandonment(shell, &data, vec![welcome], "moved"); } /// A first launch's Connect through the relay, from the first screen: the connection it keeps @@ -641,17 +664,7 @@ mod connected_ipc { }, ]; shown.extend(connected); - desktop_telemetry::shutdown(shell.handle()); - assert_eq!(queued(&shell), shown, "named {named}: on quit"); - let next = relaunched(&shell, &data); - let mut expected = shown; - expected.push(EventData::StepViewed { - step: Step::Welcome, - }); - assert_eq!(queued(&next), expected, "named {named}: next launch"); - drop(next); - drop(shell); - let _ = std::fs::remove_dir_all(&data); + quit_and_relaunch_without_abandonment(shell, &data, shown, &format!("named {named}")); } } @@ -665,6 +678,9 @@ mod connected_ipc { /// Sign out, from a menu or the setup window (`sign_out_of_openbot`): the sign-in is /// forgotten and the address kept. SignOut, + /// Settings' Change while connected (`change_connection_now`): signed out, and setup asked + /// to open at the choice of where OpenBot runs. + SettingsChange, } /// The first screen shown again by the desktop itself (`by`), then said by the window. None of @@ -679,12 +695,12 @@ mod connected_ipc { }; let address = match by { ShownAgainBy::EndedSignIn => ADDRESS.to_owned(), - ShownAgainBy::Unreachable | ShownAgainBy::SignOut => unreachable, + ShownAgainBy::Unreachable | ShownAgainBy::SignOut | ShownAgainBy::SettingsChange => { + unreachable + } }; let data = temp_root("openbot-shown-again-by-the-desktop"); - let shell = Connected::new(); - shell.choose(choice::Mode::Connected, &address, None); - desktop_telemetry::initialize_for_test(shell.handle(), data.to_path_buf()); + let shell = launched_connected_to(Some(&address), &data); match by { ShownAgainBy::EndedSignIn => { desktop_connected::session_ended(shell.handle(), "openbot.example.com"); @@ -693,7 +709,7 @@ mod connected_ipc { let refused = shell.ask(SETUP, "show_connected").unwrap_err(); assert_eq!(refused["kind"], "unreachable", "{refused}"); } - ShownAgainBy::SignOut => { + ShownAgainBy::SignOut | ShownAgainBy::SettingsChange => { // Nothing answers there, so no browser is sent to end a session at it. let opened = Arc::new(Mutex::new(Vec::::new())); let noting = opened.clone(); @@ -705,10 +721,18 @@ mod connected_ipc { .store .set(&address, &format!("obr_saved{}", "s".repeat(32))) .unwrap(); - assert_eq!( - shell.ask(SETUP, "sign_out_of_openbot"), - Ok(serde_json::Value::Null) - ); + if matches!(by, ShownAgainBy::SignOut) { + assert_eq!( + shell.ask(SETUP, "sign_out_of_openbot"), + Ok(serde_json::Value::Null) + ); + } else { + desktop_connected::change_connection_now(shell.handle()).unwrap(); + assert_eq!( + shell.ask(SETUP, "take_connection_notice"), + Ok(serde_json::json!({ "kind": "choose", "message": null })) + ); + } assert_eq!(shell.store.get(&address).unwrap(), None, "signed out"); assert_eq!(shell.window.url().unwrap().as_str(), SETUP); assert_eq!(*opened.lock().unwrap(), Vec::::new()); @@ -731,17 +755,7 @@ mod connected_ipc { step: Step::ConnectOpenbot, }, ]; - desktop_telemetry::shutdown(shell.handle()); - assert_eq!(queued(&shell), shown, "on quit"); - let next = relaunched(&shell, &data); - let mut expected = shown; - expected.push(EventData::StepViewed { - step: Step::Welcome, - }); - assert_eq!(queued(&next), expected, "next launch"); - drop(next); - drop(shell); - let _ = std::fs::remove_dir_all(&data); + quit_and_relaunch_without_abandonment(shell, &data, shown, &format!("{by:?}")); } /// A sign-in that ends while OpenBot shows keeps the connection: Sign in again, shown then, is @@ -765,9 +779,17 @@ mod connected_ipc { shown_again_by_the_desktop_is_not_abandoned(ShownAgainBy::SignOut); } + /// Settings' Change while connected signs out and keeps the address, so the choice stays + /// connected: the first screen it opens is not abandoned on quit or at the next launch. + #[test] + fn a_first_screen_shown_again_by_settings_change_is_not_abandoned() { + shown_again_by_the_desktop_is_not_abandoned(ShownAgainBy::SettingsChange); + } + /// A setup failure is said at the last screen shown, a screen shown once setup ended with a - /// connection included, though that screen starts no setup session. Which part failed is - /// arbitrary here: the test is about where the failure is placed. + /// connection included, though that screen starts no setup session, and also after an + /// organization switch, which keeps the connection with no setup session open. Which part + /// failed is arbitrary here: the test is about where the failure is placed. #[test] fn a_setup_failure_after_a_screen_shown_again_names_that_screen() { use openbot_desktop_lib::telemetry::{EventData, FailingStep, SetupErrorClass, Step}; @@ -777,6 +799,8 @@ mod connected_ipc { &shell, &serde_json::json!({ "kind": "step_viewed", "step": "connect_openbot" }), ); + desktop_connected::set_organization_now(shell.handle(), Some("org_switched".into())) + .unwrap(); desktop_telemetry::setup_failed( shell.handle(), desktop_telemetry::SetupFailure::new( diff --git a/desktop/src-tauri/src/telemetry.rs b/desktop/src-tauri/src/telemetry.rs index b78120f498..037bb62fcd 100644 --- a/desktop/src-tauri/src/telemetry.rs +++ b/desktop/src-tauri/src/telemetry.rs @@ -3977,7 +3977,7 @@ mod tests { /// A connection kept ends the setup session open now, whether or not the connection was /// counted: no `setup_abandoned` on quit or at the next launch, and nothing sent for it. With - /// no session open, or once activated, it changes nothing. + /// no session open, or once activated, it changes nothing, the last screen shown included. #[test] fn a_connection_kept_ends_the_open_setup_session_and_sends_nothing() { let dir = temp_dir("connection-kept-ends-setup"); @@ -4033,6 +4033,25 @@ mod tests { activated.end_setup_session().unwrap(); assert_eq!(activated.snapshot().unwrap().last_step, Some(Step::Model)); assert_eq!(activated.last_step_shown().unwrap(), Some(Step::Model)); + + // With no session open (a screen shown once setup ended, then an organization switch), + // the last screen shown stays, so a setup failure after it is placed there. + let after_setup = Telemetry::open_with_env( + temp_dir("connection-kept-with-no-session"), + context("1.2.3", Engine::None), + Config::disabled_for_tests(), + EnvOverride::Enabled, + ) + .unwrap(); + after_setup + .record_step_after_setup(Step::ConnectOpenbot) + .unwrap(); + after_setup.end_setup_session().unwrap(); + assert_eq!(after_setup.snapshot().unwrap().last_step, None); + assert_eq!( + after_setup.last_step_shown().unwrap(), + Some(Step::ConnectOpenbot) + ); } #[test] diff --git a/desktop/src-tauri/src/window_ipc_tests.rs b/desktop/src-tauri/src/window_ipc_tests.rs index 5417b231b9..122b4d2895 100644 --- a/desktop/src-tauri/src/window_ipc_tests.rs +++ b/desktop/src-tauri/src/window_ipc_tests.rs @@ -795,17 +795,7 @@ fn a_window_sign_in_ends_setup_and_its_sign_in_again_is_not_abandoned() { shown.push(EventData::StepViewed { step: Step::ConnectOpenbot, }); - desktop_telemetry::shutdown(shell.handle()); - assert_eq!(queued(&shell), shown, "named {named}: on quit"); - let next = relaunched(&shell, &data); - let mut expected = shown; - expected.push(EventData::StepViewed { - step: Step::Welcome, - }); - assert_eq!(queued(&next), expected, "named {named}: next launch"); - drop(next); - drop(shell); - let _ = std::fs::remove_dir_all(&data); + quit_and_relaunch_without_abandonment(shell, &data, shown, &format!("named {named}")); } } @@ -840,15 +830,5 @@ fn a_saved_window_sign_in_no_longer_published_is_not_abandoned() { step: Step::ConnectOpenbot, }, ]; - desktop_telemetry::shutdown(shell.handle()); - assert_eq!(queued(&shell), shown, "on quit"); - let next = relaunched(&shell, &data); - let mut expected = shown; - expected.push(EventData::StepViewed { - step: Step::Welcome, - }); - assert_eq!(queued(&next), expected, "next launch"); - drop(next); - drop(shell); - let _ = std::fs::remove_dir_all(&data); + quit_and_relaunch_without_abandonment(shell, &data, shown, "no longer published"); } From 220fc029553ba154c1c293d269b3aab83c982adc Mon Sep 17 00:00:00 2001 From: Alexander Clarke Date: Wed, 2 Dec 2026 21:50:15 +0000 Subject: [PATCH 12/14] Telemetry docs: the three ways a connection is kept, and when the window's completed is counted setup_abandoned names Connect through the relay, the window's own sign-in and Move to Cloud in a sentence each. openbot_connect's completed, through the window's own sign-in, is counted once the window goes to the page that trades its code, before the trade. launched's comment says it is use_this_computer's view, as a launch views it. --- desktop/TELEMETRY.md | 4 ++-- desktop/src-tauri/src/desktop_telemetry.rs | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/desktop/TELEMETRY.md b/desktop/TELEMETRY.md index d2c3d2bc23..b3a713578a 100644 --- a/desktop/TELEMETRY.md +++ b/desktop/TELEMETRY.md @@ -64,7 +64,7 @@ For `model_chosen`, providers are `openai`, `anthropic`, `google`, `xai`, `compa `ui_stalled` is a setup window that stopped taking what the desktop sends it. While the setup, start or update screens show, the page invokes `setup_heartbeat` every five seconds, and as soon as a row's progress reaches it, with the highest progress number it has taken (`setup:progress` carries one). The heartbeat is never awaited and runs off the window's thread. Progress left untaken for over 30 seconds while the window is shown, not minimised and, on macOS, not covered is a stall. The Desktop log says `[ui] the window has not answered for 31s during start_machine` when it is noticed and `[ui] the window stopped answering for 42s during start_machine` when it ends, and that end sends one `ui_stalled` with `stalled_seconds` and `step`, the setup row the desktop was reporting, by the same names as `failing_step`. It ends when the page catches up, the window leaves the screen, the window loads another page, or OpenBot quits. A page that has just loaded counts what was sent before it listened as taken, and a page that sends no heartbeat (OpenBot itself) is not watched. -`setup_abandoned` is setup ending before activation, or before a connection to an OpenBot that runs elsewhere is kept: Quit during setup, or, on the next launch, a crash. The app keeps a connection once signed in and that OpenBot answered, just before `openbot_connect` `completed` is counted when the window named the screen it was pressed on (`screen`); once the window's own sign-in at that OpenBot came back from the browser, just before the window trades its code for its session there; or by Move to Cloud. Keeping it closes any setup session still open, whether or not a `completed` was sent, and nothing starts one while it is kept. +`setup_abandoned` is setup ending before activation, or before a connection to an OpenBot that runs elsewhere is kept: Quit during setup, or, on the next launch, a crash. The app keeps a connection in three ways. Connect through the relay keeps it once signed in and that OpenBot answered, just before `openbot_connect` `completed` is counted when the window named the screen it was pressed on (`screen`). The window's own sign-in keeps it once the browser sign-in came back, just before the window trades its code for its session at that OpenBot. Move to Cloud keeps it once the move is saved. Keeping it closes any setup session still open, whether or not a `completed` was sent, and nothing starts one while it is kept. `step_viewed` still counts each launch, and the first screen whenever it shows again, while a connection is kept, but neither a quit nor a crash then sends `setup_abandoned`, even after a Sign in again that started, failed or was cancelled. The first screen shows again for Sign in again once a sign-in ended, at launch or while OpenBot shows, or once the window's own sign-in was let go (OpenBot's page could not trade its code, or that OpenBot no longer signs the window in); for a saved OpenBot that cannot be reached; and for the choice made again from Settings. A setup session the last run left open (a crash, or an earlier version, which started one at every launch) is closed without a `setup_abandoned` by a launch that finds the connection kept. @@ -78,7 +78,7 @@ For `model_chosen`, providers are `openai`, `anthropic`, `google`, `xai`, `compa `business_opened` is OpenBot for Business's booker coming on screen because it was picked: on the first screen (`welcome`) or in Move to Cloud (`move_to_cloud`), once for each place each time the setup window's page loads (coming back to setup from OpenBot loads it again), however often it is picked again there. `business_booked` is a call booked in its calendar, said by Calendly from its own origin and the calendar's frame. The window sends both, with the place and nothing else: never the time booked or anything typed into the calendar. The calendar's address carries the same place as `utm_content` beside `utm_source=openbot_app` and `utm_medium=in_app`, which Calendly keeps on the booking, so a booking and these events name the same screen. -`openbot_connect` is the first screen's connection to an OpenBot that runs elsewhere, by the screen it was made on: OpenBot Cloud's sign-in (`cloud`) or a company's OpenBot by its address (`connect_openbot`). It counts that screen whenever it shows: on a first setup, and on a later launch that shows it again, such as a saved connection whose sign-in ended (Sign in again) or the choice of where OpenBot runs made again from Settings. Shown again once a connection is kept, its `step_viewed` starts no setup session (see `setup_abandoned`). The window sends `started` when the person presses Sign in, Connect, Try again or Sign in again, then `failed` when the address check or the browser sign-in fails, or `cancelled` when the person presses Cancel. The desktop itself sends `completed` once signed in and that OpenBot is shown, since the window has gone to it by then. Each ending has `duration_ms` from the press, and the outcomes are `sign_in`'s. A Cancel pressed just as the sign-in completes can give `cancelled` and then `completed` for one go: it did connect. `completed` also ends the setup session, as `activated` does for OpenBot on this computer, so a quit afterwards is not `setup_abandoned`; it is not `activated`, since nothing started here. Move to Cloud signs in its own way and never sends it. Opening a connection again with the sign-in this computer already has sends nothing, and a sign-in left behind when the screen goes says nothing when it ends. Never the address, its host or the sentence about what went wrong. It is not `sign_in`, which stays the Account step's CopilotKit sign-in. +`openbot_connect` is the first screen's connection to an OpenBot that runs elsewhere, by the screen it was made on: OpenBot Cloud's sign-in (`cloud`) or a company's OpenBot by its address (`connect_openbot`). It counts that screen whenever it shows: on a first setup, and on a later launch that shows it again, such as a saved connection whose sign-in ended (Sign in again) or the choice of where OpenBot runs made again from Settings. Shown again once a connection is kept, its `step_viewed` starts no setup session (see `setup_abandoned`). The window sends `started` when the person presses Sign in, Connect, Try again or Sign in again, then `failed` when the address check or the browser sign-in fails, or `cancelled` when the person presses Cancel. The desktop itself sends `completed` once signed in and the window has gone to that OpenBot: through the relay, once that OpenBot is shown; through the window's own sign-in, once the window goes to the page that trades its code, so before the trade. Each ending has `duration_ms` from the press, and the outcomes are `sign_in`'s. A Cancel pressed just as the sign-in completes can give `cancelled` and then `completed` for one go: it did connect. `completed` also ends the setup session, as `activated` does for OpenBot on this computer, so a quit afterwards is not `setup_abandoned`; it is not `activated`, since nothing started here. Move to Cloud signs in its own way and never sends it. Opening a connection again with the sign-in this computer already has sends nothing, and a sign-in left behind when the screen goes says nothing when it ends. Never the address, its host or the sentence about what went wrong. It is not `sign_in`, which stays the Account step's CopilotKit sign-in. `engine_measured` is what the Account step's check measured of the engine local setup runs on, too small or not: `resources` as `setup_failed` carries it for an engine too small, CPUs in thousandths and memory and free disk in MiB, against what setup needs. Sent by the desktop itself, never by the window, once a launch and again only when the engine's CPUs or memory change (a Podman machine made bigger). Free disk is sent with them, but a change in it alone, as the downloads fill the disk, sends nothing new. Every install that goes through the Account step runs that check, so each one whose engine answers it sends one; an engine not known yet, or one that does not answer, is not measured and sends nothing, and neither does a reinstall that goes straight to Install. Nothing is kept while usage data is off, so turning it on again in the same launch still sends the size. OpenBot Cloud and a company's OpenBot run nothing on this computer, so a connection never sends it. Never the engine's name, a drive, a path or a hostname. diff --git a/desktop/src-tauri/src/desktop_telemetry.rs b/desktop/src-tauri/src/desktop_telemetry.rs index 7c785da098..4c61cc45a0 100644 --- a/desktop/src-tauri/src/desktop_telemetry.rs +++ b/desktop/src-tauri/src/desktop_telemetry.rs @@ -201,13 +201,13 @@ pub(crate) fn initialize_for_test( } /** -The first screen viewed: at every launch, and when OpenBot (Self-Contained) is chosen once connected -(`desktop_connected::use_this_computer`), before the window has shown anything. Once setup ended -with a connection to an OpenBot that runs elsewhere -(`desktop_connected::setup_ended_with_connection`) it starts no setup session: a launch that opens -that OpenBot, or shows the first screen to sign in again, and is then quit is not `setup_abandoned`. -Otherwise it is where a setup starts, as it always was, so a quit before the window shows anything -still abandons it. +The first screen viewed when OpenBot (Self-Contained) is chosen once connected +(`desktop_connected::use_this_computer`), before the window has shown anything, as a launch views +it (`open_then_launch`, through `first_screen`). Once setup ended with a connection to an OpenBot +that runs elsewhere (`desktop_connected::setup_ended_with_connection`), that view starts no setup +session, so a launch that opens that OpenBot, or shows the first screen to sign in again, and is +then quit is not `setup_abandoned`. `use_this_computer` calls it once the choice is this computer, +so there it starts a setup, and a quit before the window shows anything abandons it. */ pub fn launched(app: &tauri::AppHandle) { first_screen( From 01670c096ed9345f32c7ab0a2bd64a18501e133c Mon Sep 17 00:00:00 2001 From: Alexander Clarke Date: Wed, 2 Dec 2026 22:27:10 +0000 Subject: [PATCH 13/14] keep's comment names the other two callers that keep a connected choice An organization switch (set_organization_now) and a window sign-in let go (forget_window_sign_in) also keep a Connected choice. Both run only once the choice is already connected, so setup had already ended there, and ending it again changes nothing. Comment only. --- desktop/src-tauri/src/desktop_connected.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/desktop/src-tauri/src/desktop_connected.rs b/desktop/src-tauri/src/desktop_connected.rs index 033e923c24..6b2d4c2a7a 100644 --- a/desktop/src-tauri/src/desktop_connected.rs +++ b/desktop/src-tauri/src/desktop_connected.rs @@ -154,7 +154,9 @@ fn keep( .and_then(|dir| choice::write(&dir, chosen).map_err(|error| error.to_string())); // Connected is first kept once a connection worked, or once the window's own sign-in came // back from the browser: setup on this computer ended with it, whether or not the connection - // was counted (`openbot_connect` `completed`, Move to Cloud). + // was counted (`openbot_connect` `completed`, Move to Cloud). An organization switch + // (`set_organization_now`) and a window sign-in let go (`forget_window_sign_in`) keep a choice + // that was already connected, so setup had already ended, and ending it again changes nothing. if written.is_ok() && chosen.mode == choice::Mode::Connected { crate::desktop_telemetry::setup_ended(app); } From b93c18dc21f7270ba3bc464c238aba8d3e389ca2 Mon Sep 17 00:00:00 2001 From: Alexander Clarke Date: Thu, 3 Dec 2026 17:22:43 +0000 Subject: [PATCH 14/14] Telemetry docs: choosing this computer again keeps an earlier activation, so a quit then is not setup_abandoned --- desktop/TELEMETRY.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/desktop/TELEMETRY.md b/desktop/TELEMETRY.md index a42590fab4..16b13249ed 100644 --- a/desktop/TELEMETRY.md +++ b/desktop/TELEMETRY.md @@ -70,7 +70,7 @@ For `model_chosen`, providers are `openai`, `anthropic`, `google`, `xai`, `cloud `setup_abandoned` was also sent for a quit or a crash of a connected app by releases before this rule, at `welcome` or `connect_openbot`, and one that such a release recorded on quit but had not yet sent is still sent after the update, so compare `setup_abandoned` from before and after the rule by `openbot_version` (the app version every event carries). -`step_viewed` `welcome` is sent at once when OpenBot (Self-Contained) is chosen on a first screen shown again, before the window shows anything and even when the window then resumes past Welcome: the choice starts a setup on this computer at its first screen, as a first launch does, and a quit or a crash before `activated` abandons it as any other. A screen said twice in a row is counted once, as every `step_viewed` is, unless setup ended between the two; usage data turned off and back on in Settings starts afresh, so the first screen after it is counted, and a setup failure before any screen is placed at `install`. +`step_viewed` `welcome` is sent at once when OpenBot (Self-Contained) is chosen on a first screen shown again, before the window shows anything and even when the window then resumes past Welcome: the choice starts a setup on this computer at its first screen, as a first launch does, and a quit or a crash before `activated` abandons it as any other; an installation that was activated before stays activated, so a quit or a crash then sends no `setup_abandoned`. A screen said twice in a row is counted once, as every `step_viewed` is, unless setup ended between the two; usage data turned off and back on in Settings starts afresh, so the first screen after it is counted, and a setup failure before any screen is placed at `install`. `setup_restart_required` is setup ending for the Windows restart that turning on Windows Subsystem for Linux needs, at the step it was on: Restart now, or Windows ending the app while that restart is owed (a restart from the Start menu). It is saved before Windows ends the app and sent by the launch after the restart, which carries on the same setup under the same installation UUID; that exit is never a `setup_abandoned`. A Quit while the restart is owed is still `setup_abandoned`.