Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
afc2db4
Desktop connected to an OpenBot elsewhere is not setup abandoned on quit
ACl365 Dec 1, 2026
2958bcf
A window signed in at OpenBot itself ends setup, and its Sign in agai…
ACl365 Dec 2, 2026
8a8679d
Telemetry docs: when the window's sign-in keeps the connection, and a…
ACl365 Dec 2, 2026
c53dea7
Comments and telemetry docs name the window's own sign-in as a kept c…
ACl365 Dec 2, 2026
9c36986
The opt-out deletes the saved state even with a step lock poisoned
ACl365 Dec 2, 2026
9e99aaf
The release note goes in the description, not CHANGELOG.md
ACl365 Dec 2, 2026
5e17a85
Merge main into alex/2026-12-01/reshown-first-screen-not-abandoned
ACl365 Dec 2, 2026
a0494bc
Test: a Connect through the relay ends setup, so its quit is not aban…
ACl365 Dec 2, 2026
5dd8fc6
Telemetry docs: setup_failed's step, and setup_abandoned in short par…
ACl365 Dec 2, 2026
7a98332
Test: a Sign out, and a window sign-in Connect with its screen named,…
ACl365 Dec 2, 2026
d071880
Telemetry docs: a kept connection ends setup, in paragraphs that open…
ACl365 Dec 2, 2026
03b485f
Merge main into alex/2026-12-01/reshown-first-screen-not-abandoned
ACl365 Dec 2, 2026
4173506
Test: Settings' Change is not abandoned, and a switch with no setup o…
ACl365 Dec 2, 2026
220fc02
Telemetry docs: the three ways a connection is kept, and when the win…
ACl365 Dec 2, 2026
e1f3e03
Merge main into alex/2026-12-01/reshown-first-screen-not-abandoned
ACl365 Dec 2, 2026
01670c0
keep's comment names the other two callers that keep a connected choice
ACl365 Dec 2, 2026
aa2cd17
Merge main into alex/2026-12-01/reshown-first-screen-not-abandoned
ACl365 Dec 3, 2026
c7a2d07
Merge main into alex/2026-12-01/reshown-first-screen-not-abandoned
ACl365 Dec 3, 2026
b93c18d
Telemetry docs: choosing this computer again keeps an earlier activat…
ACl365 Dec 3, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions desktop/TELEMETRY.md

Large diffs are not rendered by default.

539 changes: 537 additions & 2 deletions desktop/src-tauri/src/connected_ipc_tests.rs

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion desktop/src-tauri/src/desktop_connected.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ fn keep<R: tauri::Runtime>(
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 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). 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);
}
written.map_err(|detail| {
Problem::with(
"OpenBot couldn't save your choice on this computer. Try again.",
Expand Down Expand Up @@ -189,6 +197,19 @@ pub fn shown_origin<R: tauri::Runtime>(app: &tauri::AppHandle<R>) -> Option<Stri
relay_origin(app).or_else(|| window_origin(app))
}

/**
Whether setup on this computer already ended with a connection to an OpenBot that runs elsewhere:
the choice on record is to be connected, which is first kept only once a connection has worked
(`connect_now`, and the move to OpenBot Cloud's `keep_moved_choice`) or, for the window's own
sign-in, once the browser sign-in came back, just before the page trades its code
(`connect_window_now`). The first screen shown in that state (Sign in again, or the choice asked
for again from Settings) is shown again, not a setup starting. False with no shell state, as in a
test of the telemetry command alone.
*/
pub fn setup_ended_with_connection<R: tauri::Runtime>(app: &tauri::AppHandle<R>) -> bool {
app.try_state::<Shell>().is_some() && chosen(app).mode == choice::Mode::Connected
}

/// The relay's origin, `http://127.0.0.1:<port>`, while the window shows OpenBot through it.
pub fn relay_origin<R: tauri::Runtime>(app: &tauri::AppHandle<R>) -> Option<String> {
#[cfg(test)]
Expand Down Expand Up @@ -730,7 +751,8 @@ pub async fn sign_out_of_openbot<R: tauri::Runtime>(
}

/// 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<R: tauri::Runtime>(app: tauri::AppHandle<R>) -> Result<(), Problem> {
blocking(move || {
Expand All @@ -740,6 +762,8 @@ pub async fn use_this_computer<R: tauri::Runtime>(app: tauri::AppHandle<R>) -> 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)
})
Expand Down
125 changes: 107 additions & 18 deletions desktop/src-tauri/src/desktop_telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -130,24 +136,47 @@ pub fn initialize<R: tauri::Runtime>(app: &tauri::AppHandle<R>) {
.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 (`first_screen`, by the same reading).
fn open_then_launch<R: tauri::Runtime>(
app: &tauri::AppHandle<R>,
data_dir: Option<std::path::PathBuf>,
endpoint: Option<String>,
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));
Expand All @@ -157,14 +186,46 @@ pub fn initialize<R: tauri::Runtime>(app: &tauri::AppHandle<R>) {
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<R: tauri::Runtime>(
app: &tauri::AppHandle<R>,
data_dir: std::path::PathBuf,
) {
open_then_launch(app, Some(data_dir), None, telemetry::EnvOverride::Enabled);
}

/**
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<R: tauri::Runtime>(app: &tauri::AppHandle<R>) {
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<R: tauri::Runtime>(app: &tauri::AppHandle<R>, 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<telemetry::Context> {
use telemetry::{
AppVersion, Architecture, Distribution, Engine, NumericVersion, Platform, RuntimeEnv,
Expand Down Expand Up @@ -517,10 +578,38 @@ fn link_account_unlocked(
}

pub fn record<R: tauri::Runtime>(app: &tauri::AppHandle<R>, 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<R: tauri::Runtime>(app: &tauri::AppHandle<R>) {
let Some(state) = app.try_state::<DesktopTelemetry>() 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<R: tauri::Runtime>(
app: &tauri::AppHandle<R>,
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<R: tauri::Runtime>(
app: &tauri::AppHandle<R>,
save: impl FnOnce(&telemetry::Telemetry) -> telemetry::Result<()>,
) {
let Some(state) = app.try_state::<DesktopTelemetry>() 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;
}
Expand Down Expand Up @@ -613,9 +702,9 @@ pub fn setup_failed<R: tauri::Runtime>(app: &tauri::AppHandle<R>, 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));
}
Expand Down
11 changes: 10 additions & 1 deletion desktop/src-tauri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1961,7 +1961,16 @@ fn record_setup_event<R: tauri::Runtime>(app: tauri::AppHandle<R>, 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),
}
}
}

Expand Down
Loading
Loading