Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(plugins): let cancelInstall run during a download
vastsa322dffb0f7ab
diff --git a/crates/host-core/src/plugins.rs b/crates/host-core/src/plugins.rsindex 7c22dd4d1..53e2794df 100644--- a/crates/host-core/src/plugins.rs+++ b/crates/host-core/src/plugins.rs@@ -23,7 +23,7 @@ mod manifest;pub mod marketplace;mod model;mod permissions;-mod progress;+pub(crate) mod progress;mod providers;mod registry;mod resolve;diff --git a/crates/host-core/src/plugins/install.rs b/crates/host-core/src/plugins/install.rsindex 687609bd8..8ec766dc0 100644--- a/crates/host-core/src/plugins/install.rs+++ b/crates/host-core/src/plugins/install.rs@@ -353,6 +353,24 @@ impl PluginManager {if url.is_empty() {continue;}+ // Resolve mirrors are hosts the platform named, not local catalog+ // fixtures: file:// and bare paths skip the allowlist on the+ // backup path and must not do so here.+ if let Err(error) = super::package_host_allowed(url, &catalog_url) {+ tracing::warn!(+ source = %mirror.source,+ %url,+ %error,+ "this mirror is not an allowed package host"+ );+ tried.push(TriedMirror {+ source: mirror.source.clone(),+ url: url.to_string(),+ error: Some(error.to_string()),+ });+ last_error = Some(error);+ continue;+ }report.mirror(Some(&mirror.source), index as u32 + 1, attempts);match self.download_market_package(info, url, &expected, resolved.size_bytes, report) {Ok(path) => return Ok((path, expected)),diff --git a/crates/host-core/src/plugins/marketplace.rs b/crates/host-core/src/plugins/marketplace.rsindex 689416c4f..33d7fced7 100644--- a/crates/host-core/src/plugins/marketplace.rs+++ b/crates/host-core/src/plugins/marketplace.rs@@ -155,18 +155,11 @@ impl PluginManager {/// The token is held here rather than passed around, because the cancel/// action arrives as its own RPC while the install is still running.pub(crate) fn set_install_cancel(&mut self, token: Option<CancelToken>) {- self.install_cancel = token;- }-- /// Ask the running install to stop. Answers whether one was running.- pub(crate) fn cancel_install(&self) -> bool {- match self.install_cancel.as_ref() {- Some(token) => {- token.cancel();- true- }- None => false,+ match &token {+ Some(value) => super::progress::arm_active_cancel(value),+ None => super::progress::disarm_active_cancel(),}+ self.install_cancel = token;}pub(crate) fn market_cache_meta_path(&self) -> PathBuf {diff --git a/crates/host-core/src/plugins/progress.rs b/crates/host-core/src/plugins/progress.rsindex f0c57562c..dfe280fd3 100644--- a/crates/host-core/src/plugins/progress.rs+++ b/crates/host-core/src/plugins/progress.rs@@ -12,7 +12,7 @@use super::*;use std::sync::atomic::{AtomicBool, Ordering};-use std::sync::Arc;+use std::sync::{Arc, Mutex, OnceLock};/// What an install is doing right now.#[derive(Clone, Copy, Debug, PartialEq, Eq)]@@ -122,6 +122,43 @@ impl CancelToken {}}+/// Slot the cancel RPC flips without taking the AppState lock.+///+/// `market.install` holds that lock for the whole download, so a cancel that+/// waited on it would only run after the install finished. The token is an+/// `Arc`, so this is a second handle to the same flag.+static ACTIVE_CANCEL: OnceLock<Mutex<Option<CancelToken>>> = OnceLock::new();++fn active_cancel_slot() -> &'static Mutex<Option<CancelToken>> {+ ACTIVE_CANCEL.get_or_init(|| Mutex::new(None))+}++pub(crate) fn arm_active_cancel(token: &CancelToken) {+ *active_cancel_slot()+ .lock()+ .unwrap_or_else(|e| e.into_inner()) = Some(token.clone());+}++pub(crate) fn disarm_active_cancel() {+ *active_cancel_slot()+ .lock()+ .unwrap_or_else(|e| e.into_inner()) = None;+}++/// Flip the running install's cancel flag. Does not take AppState.+pub(crate) fn cancel_active_install() -> bool {+ let guard = active_cancel_slot()+ .lock()+ .unwrap_or_else(|e| e.into_inner());+ match guard.as_ref() {+ Some(token) => {+ token.cancel();+ true+ }+ None => false,+ }+}+/// The error a cancelled install ends with.////// Its own marker, so the RPC layer can answer "you cancelled this" instead of@@ -280,4 +317,16 @@ mod tests {"PLUGIN_INTEGRITY: checksum mismatch")));}++ #[test]+ fn cancel_active_install_flips_the_armed_token() {+ disarm_active_cancel();+ assert!(!cancel_active_install(), "nothing is running");+ let token = CancelToken::default();+ arm_active_cancel(&token);+ assert!(cancel_active_install());+ assert!(token.is_cancelled());+ disarm_active_cancel();+ assert!(!cancel_active_install());+ }}diff --git a/crates/host-core/src/rpc/mod.rs b/crates/host-core/src/rpc/mod.rsindex c51666a63..22570fd72 100644--- a/crates/host-core/src/rpc/mod.rs+++ b/crates/host-core/src/rpc/mod.rs@@ -4437,6 +4437,9 @@ async fn handle_request(// those steps is worth showing, which is what the observer does,// and the token is what the cancel channel flips.let cancel = crate::plugins::CancelToken::default();+ // Armed outside AppState: cancelInstall must flip this flag while+ // install still holds the state lock for the download.+ crate::plugins::progress::arm_active_cancel(&cancel);let mut observer = RpcInstallObserver {tx: tx.clone(),cancel: cancel.clone(),@@ -4465,10 +4468,9 @@ async fn handle_request(.get("id").and_then(|v| v.as_str()).ok_or_else(|| rpc_err(1002, "id required", "INVALID_PARAMS"))?;- let st = state.lock().await;- // Answer whether an install was actually cancelled rather than- // letting the surface assume the click did something.- let cancelled = st.plugins.cancel_install();+ // Do not take AppState: the install holds that lock while bytes+ // arrive, and waiting on it would make cancel a no-op.+ let cancelled = crate::plugins::progress::cancel_active_install();Ok(json!({ "cancelled": cancelled, "id": id }))}"market.checkUpdates" => {