diff --git a/desktop/src-tauri/src/client_version.rs b/desktop/src-tauri/src/client_version.rs index b77ab64e5a..f45615ed99 100644 --- a/desktop/src-tauri/src/client_version.rs +++ b/desktop/src-tauri/src/client_version.rs @@ -284,6 +284,15 @@ pub fn why(deployment: &Deployment, fit: &Fit) -> String { pub const LOCAL_APP_TOO_OLD: &str = "The OpenBot on this computer needs a newer version of this app. Update OpenBot to keep going."; +/// The OpenBot on this computer needs a newer version of this app, for `why` in the log: whether its +/// `deployment` said so, or its release needs a launcher contract this app does not speak +/// (`deployment_release::start_problem`). The window says "Update OpenBot" with this app's update. +pub fn local_app_too_old(why: String) -> Problem { + let mut problem = Problem::with(LOCAL_APP_TOO_OLD, why); + problem.kind = Some(APP_TOO_OLD); + problem +} + /** Whether the OpenBot on this computer, at `base` (`http://127.0.0.1:` of its server), needs a newer version of this app: its `deployment` read the way every app reads it, with the install's @@ -319,13 +328,12 @@ pub fn local_problem(base: &str, install_token: Option<&str>) -> Option let Fit::App { security, .. } = decided else { return None; }; - let (said, kind) = if security { - (SECURITY_UPDATE, APP_TOO_OLD_SECURITY) - } else { - (LOCAL_APP_TOO_OLD, APP_TOO_OLD) - }; - let mut problem = Problem::with(said, why(&deployment, &decided)); - problem.kind = Some(kind); + let why = why(&deployment, &decided); + if !security { + return Some(local_app_too_old(why)); + } + let mut problem = Problem::with(SECURITY_UPDATE, why); + problem.kind = Some(APP_TOO_OLD_SECURITY); Some(problem) } diff --git a/desktop/src-tauri/src/deployment_release.rs b/desktop/src-tauri/src/deployment_release.rs index b08e41739f..cb7f9f9c20 100644 --- a/desktop/src-tauri/src/deployment_release.rs +++ b/desktop/src-tauri/src/deployment_release.rs @@ -1,12 +1,24 @@ //! Choose a release for a deployment: the release a deployment already has, otherwise the exact //! build a pinned app was cut with, otherwise the latest public release, or the app's own when the -//! app is newer. And where releases come from: the distribution this installation follows. +//! app is newer or when the latest needs a newer app to start it. And where releases come from: the +//! distribution this installation follows. +//! +//! WHAT STARTS A RELEASE IS A CONTRACT WITH A NUMBER. This app starts the back end from the +//! release's Compose file, with settings it writes into `.env` and secrets it hands Compose: the +//! launcher's side of the contract, numbered `compatibility.launcherApi` in `release-policy.json` +//! and in every release's `release-manifest.json`. A release whose number is above the one this app +//! was built with needs something this app does not write. It is never laid out for a first install +//! (the app's own release is) and never started (the window says "Update OpenBot"); see +//! [`launcher_api`]. A release one number behind starts as it always has: the app still writes +//! what that release reads (`install_token`, for one, is read back from a server that predates it). use std::path::Path; +use std::sync::OnceLock; use serde::{Deserialize, Serialize}; use crate::deployment; +use crate::problem::Problem; /// Where an installation's releases come from, when it names a distributor of its own. pub const DISTRIBUTION: &str = ".openbot-distribution.json"; @@ -97,28 +109,158 @@ pub fn latest_url(policy: &Distribution) -> String { /// (`deployment::predates_containers`, which this app cannot run), or one of the other kind /// (pinned or followed) that never finished laying out gets a fresh release: the one a pinned build /// was cut with, otherwise the latest the distribution has published, or this app's own release -/// when the app is newer (`newer`). The fetcher records the exact tag after the source and image -/// manifest have both downloaded. +/// when the app is newer (`newer`) or the latest needs a newer app ([`launcher_api`]). The fetcher +/// records the exact tag after the source and image manifest have both downloaded. pub fn resolve_version(root: &Path) -> Result { let own = crate::upgrade::app_release(); - resolve_version_with(root, deployment::pinned().as_ref(), &own, || { - let policy = distribution(root)?; - // OpenBot's own releases: the app update feed on downloads.copilotkit.ai names the same - // Latest release, and GitHub is asked only when it cannot be read. - if policy.repository == "CopilotKit/OpenBot" { - match deployment::get_from_mirror(LATEST_FEED).and_then(|body| feed_tag(&body)) { - Ok(tag) => return Ok(tag), - Err(error) => { - log::warn!("[download] {error}; asking GitHub for the latest release") + resolve_version_with( + root, + deployment::pinned().as_ref(), + &own, + || { + let policy = distribution(root)?; + // OpenBot's own releases: the app update feed on downloads.copilotkit.ai names the same + // Latest release, and GitHub is asked only when it cannot be read. + if policy.repository == "CopilotKit/OpenBot" { + match deployment::get_from_mirror(LATEST_FEED).and_then(|body| feed_tag(&body)) { + Ok(tag) => return Ok(tag), + Err(error) => { + log::warn!("[download] {error}; asking GitHub for the latest release") + } } } - } - let body = deployment::get(&latest_url(&policy)) - .map_err(|error| format!("could not find the latest OpenBot release: {error}"))?; - release_tag(&body) + let body = deployment::get(&latest_url(&policy)) + .map_err(|error| format!("could not find the latest OpenBot release: {error}"))?; + release_tag(&body) + }, + launcher_api(), + |version| release_launcher_api(root, version, &deployment::get), + ) +} + +/// What this app writes and hands the back end it starts: `compatibility.launcherApi` of the +/// `release-policy.json` it was built from, which its own release publishes too. +pub fn launcher_api() -> u32 { + static SPOKEN: OnceLock = OnceLock::new(); + *SPOKEN.get_or_init(|| { + launcher_api_of(include_bytes!("../../../release-policy.json")) + .expect("release-policy.json names compatibility.launcherApi") }) } +/// The release asset that says what a release is compatible with, `launcherApi` among it. +pub const RELEASE_MANIFEST: &str = "release-manifest.json"; + +/// Where `version` of `policy`'s distribution publishes its [`RELEASE_MANIFEST`]. +pub fn release_manifest_url(policy: &Distribution, version: &str) -> String { + format!( + "https://github.com/{}/releases/download/{version}/{RELEASE_MANIFEST}", + policy.repository + ) +} + +/// `compatibility.launcherApi` of a release manifest, or of `release-policy.json`, which carries it +/// in the same place. Everything else in either is not read here. +pub fn launcher_api_of(body: &[u8]) -> Result { + #[derive(Deserialize)] + struct Compatibility { + #[serde(rename = "launcherApi")] + launcher_api: u32, + } + #[derive(Deserialize)] + struct Manifest { + compatibility: Compatibility, + } + let read: Manifest = serde_json::from_slice(body) + .map_err(|error| format!("names no compatibility.launcherApi: {error}"))?; + if read.compatibility.launcher_api == 0 { + return Err("names launcherApi 0, which no release is".into()); + } + Ok(read.compatibility.launcher_api) +} + +/// The launcher contract `version` of the distribution `root` follows needs, from the manifest it +/// published, downloaded through `get`. +pub fn release_launcher_api( + root: &Path, + version: &str, + get: deployment::Download, +) -> Result { + let url = release_manifest_url(&distribution(root)?, version); + let body = get(&url).map_err(|error| format!("could not read {url}: {error}"))?; + launcher_api_of(&body).map_err(|error| format!("{url} {error}")) +} + +/// Whether this app, speaking launcher contract `speaks`, can start a release that needs `needs`. +/// The same number starts. A lower one starts too: the app keeps writing what an older release +/// reads, and Start moves a release older than the app to the app's own anyway. Only a higher one +/// needs a newer app. +pub fn starts(needs: u32, speaks: u32) -> bool { + needs <= speaks +} + +/** +Whether the release laid out in `root` needs a newer app than this one to start: a release newer +than the app (one an earlier, newer app laid out, or one a first install from an app that did not +read this number took), whose manifest names a launcher contract above this app's. Then Start +leaves it as it is, stopped, and the window says "Update OpenBot" with this app's update: never moved +back to the app's own, whose database it is already past (`upgrade`). + +Only a release newer than the app is asked about, since the number never goes down from one release +to the next, and asked once, with no retries: offline, or with no answer, it starts as it did before +this check, and a server too new for this app then says so itself. Blocking HTTP: from a blocking task. +*/ +pub fn start_problem(root: &Path) -> Option { + start_problem_with( + root, + &crate::upgrade::app_release(), + launcher_api(), + &get_once, + ) +} + +/// [`start_problem`] for an app of release `own` speaking `speaks`, downloading through `get`. +pub fn start_problem_with( + root: &Path, + own: &str, + speaks: u32, + get: deployment::Download, +) -> Option { + let installed = deployment::installed(root)?; + let version = |tag: &str| semver::Version::parse(tag.strip_prefix('v').unwrap_or(tag)).ok(); + match (version(&installed.version), version(own)) { + (Some(laid_out), Some(app)) if laid_out > app => {} + _ => return None, + } + match release_launcher_api(root, &installed.version, get) { + Ok(needs) if !starts(needs, speaks) => Some(crate::client_version::local_app_too_old( + format!( + "OpenBot {} needs launcherApi {needs}; this app is {own} and speaks launcherApi {speaks}", + installed.version + ), + )), + Ok(_) => None, + Err(error) => { + log::warn!( + "[start] could not tell which launcher contract {} needs, so it starts as before: {error}", + installed.version + ); + None + } + } +} + +/// One try at each copy of a download, downloads.copilotkit.ai's and then GitHub's, with no retries. +fn get_once(url: &str) -> Result, String> { + if let Some(copy) = deployment::mirrored(url) { + match deployment::get_from_mirror(©) { + Ok(body) => return Ok(body), + Err(error) => log::warn!("[download] {error}; asking for {url} instead"), + } + } + deployment::get_from_mirror(url) +} + /// The app update feed for the Latest release, copied to downloads.copilotkit.ai as each stable /// release becomes Latest. const LATEST_FEED: &str = "https://downloads.copilotkit.ai/latest/latest.json"; @@ -140,12 +282,18 @@ fn feed_tag(body: &[u8]) -> Result { /// With an installed deployment of this build's kind, or one laid out completely, its own version. /// Otherwise the pin's version when there is one, and the newer of `latest` and `own` (the app's -/// own release) only when there is not. +/// own release) only when there is not, as long as this app, speaking launcher contract `speaks`, +/// can start it: a latest release that needs a newer app, or whose need cannot be read +/// (`launcher_api_of`), gives way to `own`, which this app always can. The person is offered the +/// newer app as every launch offers it (`app_update`), and Start moves the installation on once +/// they take it. fn resolve_version_with( root: &Path, pinned: Option<&deployment::Pin>, own: &str, latest: impl FnOnce() -> Result, + speaks: u32, + launcher_api_of: impl FnOnce(&str) -> Result, ) -> Result { match deployment::installed(root) { Some(installed) @@ -157,7 +305,27 @@ fn resolve_version_with( } _ => match pinned { Some(pin) => Ok(pin.version.clone()), - None => latest().map(|latest| newer(latest, own)), + None => { + let chosen = newer(latest()?, own); + if chosen == own { + return Ok(chosen); + } + match launcher_api_of(&chosen) { + Ok(needs) if starts(needs, speaks) => Ok(chosen), + Ok(needs) => { + log::warn!( + "[download] OpenBot {chosen} needs launcherApi {needs} and this app speaks {speaks}: laying out this app's own {own}, and offering the app's update" + ); + Ok(own.to_string()) + } + Err(error) => { + log::warn!( + "[download] could not tell which launcher contract OpenBot {chosen} needs ({error}): laying out this app's own {own}" + ); + Ok(own.to_string()) + } + } + } }, } } @@ -205,6 +373,208 @@ mod tests { root } + /// [`resolve_version_with`] where every release needs the launcher contract this app speaks, + /// for the choices that are not about that. + fn resolve( + root: &Path, + pinned: Option<&deployment::Pin>, + own: &str, + latest: impl FnOnce() -> Result, + ) -> Result { + resolve_version_with(root, pinned, own, latest, launcher_api(), |_| { + Ok(launcher_api()) + }) + } + + /// v1.1.0's own release manifest, as GitHub serves it, and the same with another launcherApi: + /// what a later release that raised it would publish. + const V1_1_0_MANIFEST: &[u8] = include_bytes!("../test-fixtures/release-manifest-v1.1.0.json"); + fn manifest_needing(launcher_api: u32) -> Vec { + let mut manifest: serde_json::Value = serde_json::from_slice(V1_1_0_MANIFEST).unwrap(); + manifest["compatibility"]["launcherApi"] = launcher_api.into(); + serde_json::to_vec(&manifest).unwrap() + } + + /// The distribution's releases, as a download: each version's manifest by its address, and + /// every address asked for, in order. + struct Releases { + manifests: Vec<(&'static str, Vec)>, + asked: std::cell::RefCell>, + } + impl Releases { + fn get(&self, url: &str) -> Result, String> { + self.asked.borrow_mut().push(url.to_string()); + self.manifests + .iter() + .find(|(version, _)| { + url == format!( + "https://github.com/CopilotKit/OpenBot/releases/download/{version}/release-manifest.json" + ) + }) + .map(|(_, body)| body.clone()) + .ok_or_else(|| format!("{url} answered 404")) + } + } + + #[test] + fn this_app_speaks_the_launcher_contract_its_release_policy_names() { + let policy: serde_json::Value = + serde_json::from_slice(include_bytes!("../../../release-policy.json")).unwrap(); + assert_eq!( + u64::from(launcher_api()), + policy["compatibility"]["launcherApi"].as_u64().unwrap() + ); + // And reads it out of a real release's manifest the same way. + assert_eq!(launcher_api_of(V1_1_0_MANIFEST), Ok(1)); + assert!(launcher_api_of(b"{}").is_err()); + assert!(launcher_api_of(br#"{"compatibility":{"launcherApi":0}}"#).is_err()); + assert_eq!( + release_manifest_url(&distribution_defaults(None, None, None), "v1.1.0"), + "https://github.com/CopilotKit/OpenBot/releases/download/v1.1.0/release-manifest.json" + ); + } + + /// Design 6.5, step 2: an app meeting a latest release whose launcher contract is above its own + /// lays out its own release for a first install, and the latest one only once it is updated. + #[test] + fn a_first_install_lays_out_the_apps_own_release_when_the_latest_needs_a_newer_app() { + let root = scratch("release-launcher-ahead"); + let releases = Releases { + manifests: vec![ + ("v1.3.0", manifest_needing(2)), + ("v1.2.0", manifest_needing(1)), + ], + asked: Default::default(), + }; + let get = |url: &str| releases.get(url); + let from = |latest: &'static str, speaks: u32| { + resolve_version_with( + &root, + None, + "v1.1.1", + || Ok(latest.into()), + speaks, + |version| release_launcher_api(&root, version, &get), + ) + .unwrap() + }; + // Beyond this app: its own release, which it can start. + assert_eq!(from("v1.3.0", 1), "v1.1.1"); + // The same contract: the latest, as before. + assert_eq!(from("v1.2.0", 1), "v1.2.0"); + // An app of the newer contract takes the latest. + assert_eq!(from("v1.3.0", 2), "v1.3.0"); + // A latest release whose manifest cannot be read: the app's own, which it knows it can start. + assert_eq!(from("v1.4.0", 1), "v1.1.1"); + // Nothing was laid out or recorded by choosing. + assert!(deployment::installed(&root).is_none()); + assert_eq!( + releases.asked.borrow().as_slice(), + [ + "https://github.com/CopilotKit/OpenBot/releases/download/v1.3.0/release-manifest.json", + "https://github.com/CopilotKit/OpenBot/releases/download/v1.2.0/release-manifest.json", + "https://github.com/CopilotKit/OpenBot/releases/download/v1.3.0/release-manifest.json", + "https://github.com/CopilotKit/OpenBot/releases/download/v1.4.0/release-manifest.json", + ] + ); + // An app newer than the latest never asks: its own release is the one it takes. + assert_eq!( + resolve_version_with( + &root, + None, + "v1.5.0", + || Ok("v1.3.0".into()), + 1, + |_| panic!("the app's own release needs no question"), + ) + .unwrap(), + "v1.5.0" + ); + std::fs::remove_dir_all(root).unwrap(); + } + + /// Design 7.1: an installation whose release needs a newer app is not started, and is never + /// moved back. Start says "Update OpenBot", the window's sentence, with this app's update. + #[test] + fn a_release_that_needs_a_newer_app_is_not_started_and_says_update_openbot() { + let releases = Releases { + manifests: vec![ + ("v1.3.0", manifest_needing(2)), + ("v1.2.0", manifest_needing(1)), + ("v1.1.0", V1_1_0_MANIFEST.to_vec()), + ], + asked: Default::default(), + }; + let get = |url: &str| releases.get(url); + let laid_out = |label: &str, version: &str| { + let root = scratch(label); + std::fs::write(root.join("docker-compose.yml"), "services:\n server: {}\n").unwrap(); + std::fs::write(deployment::images_path(&root), "{}").unwrap(); + deployment::record(&root, version, false).unwrap(); + root + }; + + // A release beyond this app's contract: not started, with the sentence and the update. + let ahead = laid_out("start-launcher-ahead", "v1.3.0"); + let problem = start_problem_with(&ahead, "v1.1.1", 1, &get) + .expect("a release that needs a newer app is not started"); + assert_eq!(problem.kind, Some(crate::client_version::APP_TOO_OLD)); + assert_eq!( + problem.said, + "The OpenBot on this computer needs a newer version of this app. Update OpenBot to keep going." + ); + assert!( + problem.detail.as_deref().is_some_and(|detail| detail + .contains("OpenBot v1.3.0 needs launcherApi 2; this app is v1.1.1 and speaks launcherApi 1")), + "{problem:?}" + ); + // Never moved back: Start has no upgrade to make, and the release is as it was laid out. + let own = crate::upgrade::Own { + version: "v1.1.1".into(), + pinned: false, + }; + assert_eq!(crate::upgrade::due(&ahead, &own), None); + assert_eq!(deployment::installed(&ahead).unwrap().version, "v1.3.0"); + + // Newer, at this app's contract: starts as before. + let same = laid_out("start-launcher-same", "v1.2.0"); + assert!(start_problem_with(&same, "v1.1.1", 1, &get).is_none()); + // An app of the newer contract starts the release that needs it. + assert!(start_problem_with(&ahead, "v1.3.0", 2, &get).is_none()); + + // A release older than this app is never asked about: Start moves it to the app's own. + let older = laid_out("start-launcher-older", "v1.1.0"); + let asked = releases.asked.borrow().len(); + assert!(start_problem_with(&older, "v1.1.1", 1, &get).is_none()); + assert!(start_problem_with(&older, "v1.1.1", 1, &|_| panic!("offline")).is_none()); + assert_eq!(releases.asked.borrow().len(), asked); + + // Newer, and no answer about it: it starts as it did before this check. + let unknown = laid_out("start-launcher-unknown", "v1.4.0"); + assert!(start_problem_with(&unknown, "v1.1.1", 1, &get).is_none()); + // Nothing laid out, or a pinned build's tag: nothing to ask. + let empty = scratch("start-launcher-empty"); + assert!(start_problem_with(&empty, "v1.1.1", 1, &|_| panic!("nothing laid out")).is_none()); + let internal = laid_out("start-launcher-internal", "internal-abc"); + assert!( + start_problem_with(&internal, "v1.1.1", 1, &|_| panic!("a pinned build")).is_none() + ); + + for root in [ahead, same, older, unknown, empty, internal] { + std::fs::remove_dir_all(root).unwrap(); + } + } + + /// The rule itself: the same contract starts, one behind starts (1.1.0 keeps starting a server + /// from before the install token, `install_token`), and only a higher one needs a newer app. + #[test] + fn only_a_higher_launcher_contract_needs_a_newer_app() { + assert!(starts(1, 1)); + assert!(starts(1, 2)); + assert!(!starts(2, 1)); + assert!(!starts(3, 1)); + } + #[test] fn reads_the_latest_release_from_the_update_feed() { // The shape downloads.copilotkit.ai/latest/latest.json had for v0.3.3. @@ -217,7 +587,7 @@ mod tests { #[test] fn a_fresh_install_selects_latest_without_recording_an_unfinished_download() { let root = scratch("release-fresh"); - let version = resolve_version_with(&root, None, OLDER, || Ok("v0.0.9".into())).unwrap(); + let version = resolve(&root, None, OLDER, || Ok("v0.0.9".into())).unwrap(); assert_eq!(version, "v0.0.9"); assert!(deployment::installed(&root).is_none()); assert!(deployment::needs_fetch(&root, &version)); @@ -236,8 +606,7 @@ mod tests { version: "v1.0.1".into(), pinned: false, }; - let version = - resolve_version_with(&root, None, &own.version, || Ok("v1.0.0".into())).unwrap(); + let version = resolve(&root, None, &own.version, || Ok("v1.0.0".into())).unwrap(); assert_eq!(version, "v1.0.1"); // Laid out as Install lays it out, Start has nothing to move. std::fs::write(root.join("docker-compose.yml"), "services:\n server: {}\n").unwrap(); @@ -250,7 +619,7 @@ mod tests { #[test] fn a_fresh_install_still_takes_a_latest_release_newer_than_the_app() { let root = scratch("release-app-behind"); - let version = resolve_version_with(&root, None, "v1.0.0", || Ok("v1.0.1".into())).unwrap(); + let version = resolve(&root, None, "v1.0.0", || Ok("v1.0.1".into())).unwrap(); assert_eq!(version, "v1.0.1"); std::fs::remove_dir_all(root).unwrap(); } @@ -260,8 +629,7 @@ mod tests { let root = scratch("release-installed"); deployment::record(&root, "v0.0.7", false).unwrap(); std::fs::write(deployment::images_path(&root), "{}").unwrap(); - let version = - resolve_version_with(&root, None, OLDER, || panic!("must work offline")).unwrap(); + let version = resolve(&root, None, OLDER, || panic!("must work offline")).unwrap(); assert_eq!(version, "v0.0.7"); assert!(!deployment::needs_fetch(&root, &version)); std::fs::remove_dir_all(root).unwrap(); @@ -277,7 +645,7 @@ mod tests { .unwrap(); std::fs::write(deployment::images_path(&root), "{}").unwrap(); deployment::record(&root, "v0.0.15", false).unwrap(); - let version = resolve_version_with(&root, None, OLDER, || Ok("v0.0.16".into())).unwrap(); + let version = resolve(&root, None, OLDER, || Ok("v0.0.16".into())).unwrap(); assert_eq!(version, "v0.0.16"); assert!(deployment::needs_fetch(&root, &version)); std::fs::remove_dir_all(root).unwrap(); @@ -287,8 +655,7 @@ mod tests { fn a_missing_manifest_repairs_the_pinned_version() { let root = scratch("release-repair"); deployment::record(&root, "v0.0.7", false).unwrap(); - let version = - resolve_version_with(&root, None, OLDER, || panic!("keep the installed pin")).unwrap(); + let version = resolve(&root, None, OLDER, || panic!("keep the installed pin")).unwrap(); assert_eq!(version, "v0.0.7"); assert!(deployment::needs_fetch(&root, &version)); std::fs::remove_dir_all(root).unwrap(); @@ -297,7 +664,7 @@ mod tests { #[test] fn a_failed_lookup_is_reported_without_recording_a_version() { let root = scratch("release-lookup-failed"); - let error = resolve_version_with(&root, None, OLDER, || Err("GitHub answered 403".into())) + let error = resolve(&root, None, OLDER, || Err("GitHub answered 403".into())) .expect_err("a failed lookup must not fall back to an old release"); assert!(error.contains("403")); assert!(deployment::installed(&root).is_none()); @@ -317,7 +684,7 @@ mod tests { let root = scratch("release-pinned-keeps"); deployment::record(&root, "v0.3.0", false).unwrap(); std::fs::write(deployment::images_path(&root), "{}").unwrap(); - let version = resolve_version_with(&root, Some(&pin("internal-abc")), OLDER, || { + let version = resolve(&root, Some(&pin("internal-abc")), OLDER, || { panic!("a pinned build is offline") }) .unwrap(); @@ -351,7 +718,7 @@ mod tests { let root = scratch("release-pinned-build"); deployment::record(&root, "v0.0.7", false).unwrap(); let pin = pin("internal-abc"); - let version = resolve_version_with(&root, Some(&pin), OLDER, || { + let version = resolve(&root, Some(&pin), OLDER, || { panic!("a pinned build is offline") }) .unwrap(); @@ -363,7 +730,7 @@ mod tests { fn a_customer_build_moves_a_pinned_deployment_to_the_latest_release() { let root = scratch("release-unpin"); deployment::record(&root, "internal-abc", true).unwrap(); - let version = resolve_version_with(&root, None, OLDER, || Ok("v0.2.0".into())).unwrap(); + let version = resolve(&root, None, OLDER, || Ok("v0.2.0".into())).unwrap(); assert_eq!(version, "v0.2.0"); std::fs::remove_dir_all(root).unwrap(); } @@ -372,7 +739,7 @@ mod tests { fn a_customer_build_keeps_its_own_release() { let root = scratch("release-keep"); deployment::record(&root, "v0.2.0", false).unwrap(); - let version = resolve_version_with(&root, None, OLDER, || { + let version = resolve(&root, None, OLDER, || { panic!("must keep the followed release") }) .unwrap(); @@ -412,7 +779,7 @@ mod tests { assert!(root.join(path).exists(), "missing {path}"); } assert_eq!( - resolve_version_with(&root, None, OLDER, || panic!( + resolve(&root, None, OLDER, || panic!( "restart must not need GitHub" )) .unwrap(), diff --git a/desktop/src-tauri/src/main.rs b/desktop/src-tauri/src/main.rs index 36ac8d156f..9febea3b5c 100644 --- a/desktop/src-tauri/src/main.rs +++ b/desktop/src-tauri/src/main.rs @@ -4845,6 +4845,22 @@ async fn start_stack_inner( remember_selected_root(&shell, &root); *shell.leftover_database.lock().unwrap() = None; } + /* + * A release that needs a newer app than this one is not started, and nothing is woken or + * written for it: the window says "Update OpenBot" with this app's update, and the release stays + * as it was laid out (`deployment_release::start_problem`). Off the async thread, because it can + * ask the release's manifest over blocking HTTP. + */ + let laid_out = root.clone(); + if let Some(problem) = + tauri::async_runtime::spawn_blocking(move || deployment_release::start_problem(&laid_out)) + .await + .ok() + .flatten() + { + log::warn!("[start] {}", logging::Failure::described(&problem)); + return Err(problem); + } /* * Resolved from the catalogue rather than taken from the window. * diff --git a/desktop/src-tauri/test-fixtures/release-manifest-v1.1.0.json b/desktop/src-tauri/test-fixtures/release-manifest-v1.1.0.json new file mode 100644 index 0000000000..c69837d139 --- /dev/null +++ b/desktop/src-tauri/test-fixtures/release-manifest-v1.1.0.json @@ -0,0 +1,117 @@ +{ + "schemaVersion": 1, + "distribution": { + "id": "CopilotKit/OpenBot", + "repository": "CopilotKit/OpenBot", + "channel": "stable" + }, + "version": "v1.1.0", + "source": { + "commit": "e373655cc7d506d11bc99e4165935bf6f8f98fd7", + "upstreamRepository": "CopilotKit/openbot", + "upstreamCommit": "e373655cc7d506d11bc99e4165935bf6f8f98fd7", + "modified": false + }, + "artifacts": { + "source": { + "url": "https://github.com/CopilotKit/OpenBot/releases/download/v1.1.0/openbot-source.tar.gz", + "sha256": "918b0b474247927d6bcc223f723cedb249e087ecb89d57e7a576b0a404e7876b" + }, + "images": { + "agent-adk": { + "reference": "ghcr.io/copilotkit/openbot-agent-adk@sha256:5f50c88244b5589ae1706fc13548d927fc38bb751bb980819479dbc98a0e12e3" + }, + "agent-ag2": { + "reference": "ghcr.io/copilotkit/openbot-agent-ag2@sha256:5099b4b775217429e47b76c7d4b4d2422bc8c36c74ef5b0b7b668081c2b70966" + }, + "agent-agno": { + "reference": "ghcr.io/copilotkit/openbot-agent-agno@sha256:3d3ea615ebe955a5b27d4d252386a99c51d3eeb6a821ebfa454477152ac8de46" + }, + "agent-antigravity": { + "reference": "ghcr.io/copilotkit/openbot-agent-antigravity@sha256:ca2d525a733b51d93b02de5acdbaf662be8a2a0ff1811e6d1c20a532bce79407" + }, + "agent-claude-sdk": { + "reference": "ghcr.io/copilotkit/openbot-agent-claude-sdk@sha256:0db7da223b3eba7ab8afd3dc3d3ebc2ef96ae9441ce90ae406c76a53465cd9c2" + }, + "agent-crewai": { + "reference": "ghcr.io/copilotkit/openbot-agent-crewai@sha256:bfbb629a1e0a4d1959f75c9df7eaac5a67d74024ec8a443417d3a8f9f69fe999" + }, + "agent-langgraph-agui": { + "reference": "ghcr.io/copilotkit/openbot-agent-langgraph-agui@sha256:3e9557439f204c131c5c0d52b7b8076e7c46686bbd2ebf2b40f75f3adba5fa7e" + }, + "agent-langroid": { + "reference": "ghcr.io/copilotkit/openbot-agent-langroid@sha256:215aa800336d4cf0348823ff703c2a29dbca064819ee2925878180be42f4291e" + }, + "agent-llamaindex": { + "reference": "ghcr.io/copilotkit/openbot-agent-llamaindex@sha256:35722d8666b953946ca7adb643791f522c000491b9e979a850c2dd218b18fa04" + }, + "agent-mastra": { + "reference": "ghcr.io/copilotkit/openbot-agent-mastra@sha256:fcf42c7ad901f7f06381ecac8c4a76e1a21e3ade388e6bb7a4a9a64fe58f3344" + }, + "agent-microsoft": { + "reference": "ghcr.io/copilotkit/openbot-agent-microsoft@sha256:248a0440f5f7cbc2331b1e9040aadf38eeb136a8fb1b2d680559dab45e22d623" + }, + "agent-pydantic-ai": { + "reference": "ghcr.io/copilotkit/openbot-agent-pydantic-ai@sha256:e13d1bb218879031f3ac70fd06c31885f6c00ff81a81b26127634e615e0fea93" + }, + "agent-strands": { + "reference": "ghcr.io/copilotkit/openbot-agent-strands@sha256:11053b61e961edb2877f0b42912f6c9ed56acca9cd5c48bf166f8ec8703643a8" + }, + "openbot": { + "reference": "ghcr.io/copilotkit/openbot@sha256:479cccd42fc8942c98c7f326b065ca53cfd58f91d78fd1d5a2680b684e1a5f70" + }, + "supervisor": { + "reference": "ghcr.io/copilotkit/openbot-supervisor@sha256:ef25e8829606478a412345f3f63e041f827359c1f9759008e32341ce4f81e0e0" + }, + "server": { + "reference": "ghcr.io/copilotkit/openbot@sha256:479cccd42fc8942c98c7f326b065ca53cfd58f91d78fd1d5a2680b684e1a5f70" + }, + "agent-computer": { + "reference": "ghcr.io/copilotkit/openbot@sha256:479cccd42fc8942c98c7f326b065ca53cfd58f91d78fd1d5a2680b684e1a5f70" + }, + "agent-bot": { + "reference": "ghcr.io/copilotkit/openbot@sha256:479cccd42fc8942c98c7f326b065ca53cfd58f91d78fd1d5a2680b684e1a5f70" + }, + "agent-langgraph": { + "reference": "ghcr.io/copilotkit/openbot@sha256:479cccd42fc8942c98c7f326b065ca53cfd58f91d78fd1d5a2680b684e1a5f70" + } + }, + "chart": { + "version": "0.3.0", + "url": "https://github.com/CopilotKit/OpenBot/releases/download/v1.1.0/openbot-0.3.0.tgz", + "sha256": "267fa687d676b8feb191ad1c5ceea229a4872a2dfc2148d2dadee295a8fcda8a" + } + }, + "compatibility": { + "launcherApi": 1, + "configSchema": 1, + "extensionApi": 1, + "database": { + "from": [ + "0088_approval_reviewer_guidance", + "0085_approval_rule_account", + "0083_learning_skill_approvals", + "0082_routine_goal", + "0077_channel_opening" + ], + "to": "0132_bot_task_runs", + "rollbackCompatible": false + }, + "intelligenceCapabilities": [] + }, + "upgrade": { + "fromVersions": [ + "v1.0.3", + "v1.0.2", + "v1.0.1", + "v1.0.0", + "v0.3.4", + "v0.3.3", + "v0.3.2", + "v0.3.1", + "v0.3.0" + ], + "requiresDowntime": true, + "recovery": "restore-backup" + } +} diff --git a/desktop/src/App.test.tsx b/desktop/src/App.test.tsx index ae0383a432..64e763eff2 100644 --- a/desktop/src/App.test.tsx +++ b/desktop/src/App.test.tsx @@ -4052,6 +4052,66 @@ test("an OpenBot on this computer that raised this app's minimum for a security expect(view.getByRole("button", { name: "Stop OpenBot" })).toBeTruthy(); }); +/* + * The release laid out on this computer needs a launcher contract newer than this app speaks (a + * newer app laid it out, and this one is older): Start does not start it + * (`deployment_release::start_problem`). The window says "Update OpenBot" with the same sentence and + * Update and restart, not that OpenBot stopped or that setup failed, and Update and restart installs + * this app's update. + */ +test("a release that needs a newer app is not started, and the window says Update OpenBot with its update", async () => { + setupConnectedLocalStack( + "/tmp/local-eval-launcher-ahead", + localStatus("ready", "valid"), + ); + const said = + "The OpenBot on this computer needs a newer version of this app. Update OpenBot to keep going."; + const previous = invokeHandler; + invokeHandler = async (command, args) => { + if (command === "start_stack") + throw { + said, + detail: + "OpenBot v1.3.0 needs launcherApi 2; this app is v1.1.1 and speaks launcherApi 1", + kind: "app-too-old", + }; + if (command === "app_update_offer") + return { + version: null, + current: "1.1.1", + installing: null, + updatesItself: true, + }; + if (command === "check_app_update") + return { found: "available", version: "1.3.0", current: "1.1.1" }; + if (command === "install_app_update") return new Promise(() => {}); + return previous(command, args); + }; + const view = await renderApp(); + await waitFor(() => expect(localSequence()).toContain("start_stack")); + const heading = await view.findByRole("heading", { + level: 1, + name: "Update OpenBot", + }); + expect(view.queryByRole("heading", { name: "OpenBot stopped" })).toBeNull(); + expect(view.queryByText("That didn’t finish")).toBeNull(); + expect(view.queryByRole("list", { name: "Setup progress" })).toBeNull(); + const card = view.getByRole("alert"); + expect(card.textContent).toContain(said); + expect(within(card).queryByRole("heading")).toBeNull(); + expect(heading.closest(".sheet")?.contains(card)).toBe(true); + // Nothing was shown: the release that needs a newer app is not opened. + expect(localSequence()).not.toContain("show_openbot"); + const update = view.getByRole("button", { name: "Update and restart" }); + await waitFor(() => expect(update).toHaveProperty("disabled", false)); + await userEvent.click(update); + await waitFor(() => + expect(invokeCalls.map((call) => call.command)).toContain( + "install_app_update", + ), + ); +}); + /* * The same OpenBot, found already running by a launch that did not start it: the app was quit or * killed and opened again while OpenBot kept running. Seen on a Mac and on Windows: the window said diff --git a/desktop/src/App.tsx b/desktop/src/App.tsx index ad0d584fa9..2fb47dfd2e 100644 --- a/desktop/src/App.tsx +++ b/desktop/src/App.tsx @@ -1583,6 +1583,14 @@ function LocalSetup({ address, choose }: { address: string; choose: boolean }) { displayedFailure?.shortfall, local.stopped ? local.blocked?.shortfall : undefined, ); + /* + * The release on this computer needs a newer version of this app, so Start did not start it + * (`deployment_release::start_problem`). Nothing failed and nothing is stopped for good: the + * heading says what to do, and the card under it says why and offers this app's update. No + * failed row, Retry, logs or Repair, which would each say something broke. + */ + const appBehind = + !localStarting && !installingAfresh && appTooOld(displayedFailure); return (
@@ -1591,20 +1599,26 @@ function LocalSetup({ address, choose }: { address: string; choose: boolean }) { ? UPDATING_SELF_CONTAINED : localStarting || installingAfresh ? "Starting OpenBot" - : roomShort - ? ROOM_HEADING - : "OpenBot is stopped"} + : appBehind + ? forSecurity(displayedFailure) && displayedFailure + ? displayedFailure.said + : "Update OpenBot" + : roomShort + ? ROOM_HEADING + : "OpenBot is stopped"} -

- {localStarting || installingAfresh - ? // No time of its own: the card under it says how long is left, from how long each - // part takes. "This usually takes a minute or two" sat over "About 3 minutes left" - // on Windows G, and the start took four. - "OpenBot is getting ready and opens by itself." - : roomShort - ? resourcesShortSaid(roomShort) - : "Your installation and saved connections are ready to reopen."} -

+ {!appBehind && ( +

+ {localStarting || installingAfresh + ? // No time of its own: the card under it says how long is left, from how long each + // part takes. "This usually takes a minute or two" sat over "About 3 minutes left" + // on Windows G, and the start took four. + "OpenBot is getting ready and opens by itself." + : roomShort + ? resourcesShortSaid(roomShort) + : "Your installation and saved connections are ready to reopen."} +

+ )} {roomShort && (
)} - {freshInstall || ( + {freshInstall || appBehind || ( } {pauseCard} {updatingLine} - {displayedFailure && !roomShort && ( - - )} + {displayedFailure && + !roomShort && + (appBehind ? ( + + ) : ( + + ))} {updatingSelf && } {/* While a local step runs, its Cancel is the only control. */} {!localStarting && !installingAfresh && ( @@ -1650,8 +1668,9 @@ function LocalSetup({ address, choose }: { address: string; choose: boolean }) { > Change AI connection - {/* Room is what is short: a repair installs again, and needs room too. */} - {displayedFailure && !roomShort && ( + {/* Room is what is short: a repair installs again, and needs room too. And a + release that needs a newer app is not broken: a repair lays the same one out. */} + {displayedFailure && !roomShort && !appBehind && (