Skip to content

A personal assistant that lives on your desktop, remembers what matters, and can use your Mac for you.

TypeScript

fix(daemon): release a stopped Windows assistant when another one holds the port

Marcelito62fc439ad824
diff --git a/apps/desktop/src-tauri/src/daemon.rs b/apps/desktop/src-tauri/src/daemon.rs
index 3c697c0..e5f8551 100644
--- a/apps/desktop/src-tauri/src/daemon.rs
+++ b/apps/desktop/src-tauri/src/daemon.rs
@@ -871,6 +871,7 @@ impl Daemon {
// Established launches must authenticate while fd3 remains open, otherwise
// daemon-side EOF aborts drain and prevents a clean managed root exit.
let close_first = child_slot.as_ref().map_or(true, |child| !child.shutdown_requires_channel());
+ let mut port_held = None;
if close_first {
if let Some(channel) = channel_slot.as_ref() {
if let Err(error) = channel.close() {
@@ -888,10 +889,10 @@ impl Daemon {
if let Err(error) = stop_child(child.as_mut(), grace) {
return self.windows_stop_failure(format!("owned Windows daemon shutdown/deletion is unfinished: {error}"));
}
- if let Err(reason) = self.windows_wait_port() {
- child.retain_failure();
- return self.windows_stop_failure(reason);
- }
+ // Checked shutdown confirmed our root exited and its Job is empty, so whatever still
+ // answers on the port is another assistant. Ours is finished, not a failed launch:
+ // release it like any stopped owner, then report the other one.
+ port_held = self.windows_wait_port().err();
}
if !close_first {
if let Some(channel) = channel_slot.as_ref() {
@@ -906,7 +907,10 @@ impl Daemon {
if has_recovered { self.windows_recovery_admission(&child_slot)?; }
drop(child_slot.take());
drop(channel_slot.take());
- Ok(())
+ match port_held {
+ Some(reason) => self.windows_stop_failure(reason),
+ None => Ok(()),
+ }
}
/// Blocking: call off the main thread.
@@ -917,7 +921,14 @@ impl Daemon {
#[cfg(unix)]
self.stop();
#[cfg(windows)]
- if let Err(reason) = self.stop() { return RestartOutcome::Failed(reason); }
+ if let Err(reason) = self.stop() {
+ // Stop finished what we owned, and another assistant answers on the port.
+ if reason == foreign_daemon_message(self.port) { return RestartOutcome::External; }
+ return RestartOutcome::Failed(reason);
+ }
+ // A second admission pass, deliberately: stop released both guards before returning,
+ // so another thread may have installed or failed an owner since. These are the states
+ // the windows_*_admission checks refuse, read again under the same child -> channel order.
#[cfg(windows)]
{
let child = self.child.lock().unwrap();