Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.
fix(agent): address review — group-kill a hung Chrome, tighten setsid docs
James Dam5a61ec433f3a
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/handlers.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/handlers.rsindex ea10d1533..c3726f199 100644--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/handlers.rs+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/handlers.rs@@ -1679,7 +1679,19 @@ pub async fn render_html_png(}String::from_utf8_lossy(&buf).into_owned()});- let _ = tokio::time::timeout(std::time::Duration::from_secs(30), child.wait()).await;+ let pid = child.id();+ let waited = tokio::time::timeout(std::time::Duration::from_secs(30), child.wait()).await;+ // Still running: Chrome leads its own process group, so take its helper+ // processes down with it. Only while unreaped -- once `wait` returns, the+ // pid (and so the group id) may be reused.+ #[cfg(unix)]+ if waited.is_err() {+ if let Some(pid) = pid {+ proc::kill_tree(pid);+ }+ }+ #[cfg(not(unix))]+ let _ = (waited, pid);let _ = child.kill().await;let stderr = drain.await.unwrap_or_default();let _ = tokio::fs::remove_dir_all(&profile).await;diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/proc.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/proc.rsindex 1601dd4fe..0f865af00 100644--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/proc.rs+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/proc.rs@@ -732,9 +732,10 @@ fn set_process_group(cmd: &mut Command) {/// Once it exits, the foreground points at a dead group and the TUI's next/// read of the terminal stops Jan with SIGTTIN -- the shell then reports/// `suspended (tty input)` and the session looks dead. Without a controlling-/// terminal, opening `/dev/tty` fails (ENXIO), so a child can never take Jan's-/// terminal; a tool that insists on prompting there fails fast instead of-/// stopping or hanging.+/// terminal, opening `/dev/tty` fails (ENXIO) and `tcsetpgrp` has no terminal+/// to act on, so a child can never make itself the foreground group of Jan's+/// terminal; a tool that prompts on `/dev/tty` fails fast instead of stopping+/// or hanging.////// This replaces `process_group(0)` rather than adding to it: std applies the/// process group before the `pre_exec` hooks, and `setsid` refuses (EPERM) in a@@ -1325,7 +1326,10 @@ mod tests {/// The SIGTTIN stop behind a "dead" TUI session: a tool child that could/// open `/dev/tty` could also make itself the terminal's foreground group/// and leave Jan reading from the background. Without a controlling- /// terminal the open fails, whether or not Jan itself has one.+ /// terminal the open fails. Only meaningful when the test runner itself+ /// has a terminal (run it under a pty to see the old `process_group(0)`+ /// spawn print "opened"); without one it passes either way, and+ /// `spawned_child_leads_its_own_session` is the guard.#[tokio::test]async fn spawned_child_cannot_open_the_terminal() {let child = spawn(