the runtime your coding agents live on
Rust agentagent-orchestrationaiai-agentsclaude-codeclicodexcoding-agentsdeveloper-toolsdevtoolsmultiplexerrustterminalterminal-multiplexerterminal-uitmuxtuiworkspace-manager
fix: explain Windows local server permission failures (#4769)
JJ Liebigda5881eaff77
diff --git a/src/cli.rs b/src/cli.rsindex fead33b6b..3dbdceafc 100644--- a/src/cli.rs+++ b/src/cli.rs@@ -998,7 +998,9 @@ fn print_session_table(sessions: &[crate::session::SessionInfo]) {println!("{:<20} {:<8} {:<48} {}",session.name,- if session.running {+ if session.connection_error.is_some() {+ "unavailable"+ } else if session.running {"running"} else {"stopped"@@ -1006,6 +1008,9 @@ fn print_session_table(sessions: &[crate::session::SessionInfo]) {session.session_dir,session.socket_path);+ if let Some(error) = &session.connection_error {+ println!(" {error}");+ }}}diff --git a/src/ipc.rs b/src/ipc.rsindex 291b6ca24..eee623ef5 100644--- a/src/ipc.rs+++ b/src/ipc.rs@@ -47,7 +47,7 @@ pub(crate) fn connect_local_stream(path: &Path) -> io::Result<LocalStream> {let name = path.to_string_lossy().to_string();let name = name.to_ns_name::<GenericNamespaced>()?;- LocalStream::connect(name)+ LocalStream::connect(name).map_err(crate::platform::local_server_connection_error)}}diff --git a/src/platform/windows.rs b/src/platform/windows.rsindex 867701aac..c61d2f3f8 100644--- a/src/platform/windows.rs+++ b/src/platform/windows.rs@@ -16,6 +16,19 @@ use std::{mod clipboard_image;mod config_backup;+pub(crate) fn local_server_connection_error(error: std::io::Error) -> std::io::Error {+ if error.kind() != std::io::ErrorKind::PermissionDenied {+ return error;+ }+ std::io::Error::new(+ error.kind(),+ format!(+ "If this server is elevated, stop it in an admin shell; \+ reopen Herdr normally (closes panes). {error}"+ ),+ )+}+pub(crate) fn windows_virtual_terminal_input_active() -> bool {use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE;use windows_sys::Win32::System::Console::{diff --git a/src/session.rs b/src/session.rsindex 29e3e17e9..b2cb7a4eb 100644--- a/src/session.rs+++ b/src/session.rs@@ -22,6 +22,8 @@ pub struct SessionInfo {pub name: String,pub default: bool,pub running: bool,+ #[serde(skip_serializing_if = "Option::is_none")]+ pub connection_error: Option<String>,pub socket_path: String,pub session_dir: String,}@@ -216,10 +218,17 @@ pub fn session_info(name: Option<&str>) -> SessionInfo {let display_name = name.unwrap_or(DEFAULT_SESSION_NAME).to_string();let socket_path = api_socket_path_for(name);let session_dir = data_dir_for(name);+ let connection = crate::ipc::connect_local_stream(&socket_path);+ let running = connection.is_ok();+ let connection_error = connection+ .err()+ .filter(|error| !crate::cli::server_not_running_error(error))+ .map(|error| error.to_string());SessionInfo {name: display_name,default,- running: is_running_at(&socket_path),+ running,+ connection_error,socket_path: socket_path.display().to_string(),session_dir: session_dir.display().to_string(),}@@ -496,11 +505,78 @@ mod tests {use super::*;#[cfg(unix)]use interprocess::local_socket::traits::Listener as _;- use std::sync::{Mutex, OnceLock};+ use std::sync::Mutex;fn env_lock() -> &'static Mutex<()> {- static LOCK: OnceLock<Mutex<()>> = OnceLock::new();- LOCK.get_or_init(|| Mutex::new(()))+ crate::config::test_config_env_lock()+ }++ #[cfg(windows)]+ #[test]+ fn session_discovery_distinguishes_denied_running_and_stopped_servers() {+ use interprocess::local_socket::{prelude::*, GenericNamespaced, ListenerOptions};+ use interprocess::os::windows::local_socket::ListenerOptionsExt as _;+ use interprocess::os::windows::security_descriptor::SecurityDescriptor;+ use widestring::U16CString;++ let _guard = env_lock().lock().unwrap();+ let config_home =+ std::env::temp_dir().join(format!("herdr-session-denied-{}", std::process::id()));+ let previous_config_home = std::env::var_os("XDG_CONFIG_HOME");+ std::env::set_var("XDG_CONFIG_HOME", &config_home);+ let denied_path = api_socket_path_for(Some("denied"));+ let running_path = api_socket_path_for(Some("running"));+ std::fs::create_dir_all(denied_path.parent().unwrap()).unwrap();+ std::fs::create_dir_all(running_path.parent().unwrap()).unwrap();++ // A SYSTEM-only pipe reproduces access denial without requiring elevation in CI.+ let sddl = U16CString::from_str("D:P(A;;GA;;;SY)").unwrap();+ let denied_listener = ListenerOptions::new()+ .name(+ denied_path+ .to_string_lossy()+ .to_ns_name::<GenericNamespaced>()+ .unwrap(),+ )+ .security_descriptor(SecurityDescriptor::deserialize(&sddl).unwrap())+ .create_sync()+ .unwrap();+ let running_listener = crate::ipc::bind_local_listener(&running_path).unwrap();+ let error = crate::ipc::connect_local_stream(&denied_path).unwrap_err();+ assert_eq!(error.kind(), std::io::ErrorKind::PermissionDenied);+ assert!(error.to_string().contains("admin shell"));++ let sessions = list_sessions().unwrap();+ let denied = sessions+ .iter()+ .find(|session| session.name == "denied")+ .unwrap();+ assert!(!denied.running);+ assert!(denied.connection_error.is_some());+ let running = sessions+ .iter()+ .find(|session| session.name == "running")+ .unwrap();+ assert!(running.running);+ assert!(running.connection_error.is_none());+ let stopped = sessions.iter().find(|session| session.default).unwrap();+ assert!(!stopped.running);+ assert!(stopped.connection_error.is_none());+ for session in [running, stopped] {+ assert!(serde_json::to_value(session)+ .unwrap()+ .get("connection_error")+ .is_none());+ }+ assert!(serde_json::to_value(denied).unwrap()["connection_error"].is_string());++ drop(denied_listener);+ drop(running_listener);+ match previous_config_home {+ Some(value) => std::env::set_var("XDG_CONFIG_HOME", value),+ None => std::env::remove_var("XDG_CONFIG_HOME"),+ }+ std::fs::remove_dir_all(config_home).unwrap();}#[cfg(unix)]