The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(shell): der Beweis bekommt die Startzeit als Eingabe
purpledf7b86d6002a
diff --git a/src-tauri/src/commands/shell.rs b/src-tauri/src/commands/shell.rsindex 895a7a9d..653c6912 100644--- a/src-tauri/src/commands/shell.rs+++ b/src-tauri/src/commands/shell.rs@@ -230,6 +230,18 @@ const TREE_KILL_POLL: Duration = Duration::from_millis(50);/// mlx_video job and an adopted ComfyUI get the same sweep the shell gets.#[cfg(windows)]pub(crate) fn kill_tree(root: u32) {+ kill_tree_with(root, start_time_of(root));+}++/// Same as [`kill_tree`], with the root's start time injected.+///+/// The real code path always comes through [`kill_tree`], which reads the+/// token itself while the root is still alive. It is separated so the sweep+/// can be tested against the state it exists for, a live worker under a dead+/// root, which cannot be reached any other way: producing that state means+/// felling the root first, and after that its start time is unreadable.+#[cfg(windows)]+pub(crate) fn kill_tree_with(root: u32, root_start: Option<u64>) {if root == 0 { return; }// sysinfo0.33 kills each snapshot member with a separate taskkill /PID.// During shell startup a new child can appear between those calls and@@ -250,7 +262,6 @@ pub(crate) fn kill_tree(root: u32) {// is already dead, which is why each leftover is felled as a root of its// own. The loop ends as soon as nothing is left, and otherwise after// TREE_KILL_SETTLE, for as long as taskkill itself returns.- let root_start = start_time_of(root);taskkill_tree(root);let deadline = Instant::now() + TREE_KILL_SETTLE;loop {@@ -449,7 +460,12 @@ mod windows_stop_tests {std::thread::sleep(Duration::from_millis(20));};- // The shell only. Nothing walks the tree, so the worker stays.+ // Read while the shell is alive, exactly as `kill_tree` reads it, and+ // before the incomplete kill below makes it unreadable.+ let root_start = start_time_of(shell.id());++ // The shell only. Nothing walks the tree, so the worker stays: this+ // is the sweep that missed a worker started one instant behind it.let mut lonely = Command::new("taskkill.exe");lonely.args(["/PID", &shell.id().to_string(), "/F"]).stdin(Stdio::null()).stdout(Stdio::null()).stderr(Stdio::null());@@ -465,7 +481,7 @@ mod windows_stop_tests {"the worker was gone before the sweep was even asked: {workers:?}");- kill_tree(shell.id());+ kill_tree_with(shell.id(), root_start);let _ = shell.wait();settle(&out_done, &err_done, Duration::from_millis(1500));diff --git a/src-tauri/src/process_util.rs b/src-tauri/src/process_util.rsindex 7ee48ce3..8f2108f5 100644--- a/src-tauri/src/process_util.rs+++ b/src-tauri/src/process_util.rs@@ -866,52 +866,42 @@ mod libc {}}-#[cfg(all(test, windows))]-mod windows_kill_tree_tests {- use super::*;- use crate::test_support::{is_alive, worker_descendants_of};- use std::time::{Duration, Instant};-- /// NB4: this module's own tree kill had the identical Windows gap the- /// shell's had, and the tunnel and the video job cancel through it. The- /// state is reproduced the same way as in `commands::shell`: fell the- /// shell alone, which leaves a live worker under a dead parent, exactly- /// what a `CreateProcess` one instant behind the sweep produces. Whatever- /// this function does about it, it must not be a second answer to the- /// question the shell already answers.+#[cfg(test)]+mod one_windows_tree_kill_guard {+ /// NB4: this module used to carry its OWN `taskkill /T /F`, a second+ /// answer to a question `commands::shell::kill_tree` already answers, and+ /// it had the identical gap: one enumeration, so a worker the tree starts+ /// while the sweep runs survives. `remote::kill_tunnel_child` (cloudflared)+ /// and `video::video_cancel` cancel through here, so the bug would have had+ /// to be found twice and fixed twice.+ ///+ /// A behaviour test cannot stand guard over that from here: the sweep+ /// itself is proven in `commands::shell`, and both branches would look the+ /// same from outside on a tree with nothing left over. What has to stay+ /// true is that there is only ONE of them, and that is what this reads.+ /// Same shape as `command_new_coverage_guard` below.#[test]- fn a_worker_left_under_a_dead_root_is_still_felled() {- let mut shell = Command::new("powershell.exe");- shell.args(["-NoProfile", "-NonInteractive", "-Command", "ping -n 31 127.0.0.1"]);- let mut shell = spawn_piped(shell).expect("start test shell");- let ready = Instant::now();- let workers = loop {- let workers = worker_descendants_of(shell.id());- if !workers.is_empty() { break workers; }- if ready.elapsed() >= Duration::from_secs(30) {- let _ = kill_tree(&mut shell);- panic!("test shell did not start its child");- }- std::thread::sleep(Duration::from_millis(20));- };-- let mut lonely = Command::new("taskkill.exe");- lonely.args(["/PID", &shell.id().to_string(), "/F"])- .stdout(Stdio::null()).stderr(Stdio::null());- suppress_window(&mut lonely);- if let Ok(mut lonely) = lonely.spawn() {- let _ = lonely.wait();- }- assert!(- workers.iter().all(|pid| is_alive(*pid)),- "the worker was gone before the sweep was even asked: {workers:?}"+ fn the_windows_tree_kill_is_not_written_a_second_time() {+ let path = concat!(env!("CARGO_MANIFEST_DIR"), "/src/process_util.rs");+ let src = std::fs::read_to_string(path).expect("read this file");+ // The two Windows branches that fell a tree: `kill_tree` and+ // `kill_pid_tree`. Comment lines are skipped so the prose above them+ // can name the call without standing in for it. The `taskkill /F` in+ // `free_port` is a different job (one stranger holding a port, no+ // tree) and is deliberately not counted here.+ // Spelled in two halves so this line is not itself one of the hits.+ let needle = format!("crate::commands::shell::{}(pid)", "kill_tree");+ let delegations = src+ .lines()+ .filter(|l| !l.trim_start().starts_with("//"))+ .filter(|l| l.contains(&needle))+ .count();+ assert_eq!(+ delegations, 2,+ "both Windows tree kills here have to reach the one sweep in commands::shell; \+ a copy of taskkill in their place would have to be found and fixed twice, \+ and a cancelled tunnel or video job would keep the worker it started late");-- let _ = kill_tree(&mut shell);-- let survivors: Vec<_> = workers.into_iter().filter(|pid| is_alive(*pid)).collect();- for pid in &survivors { crate::commands::shell::kill_tree(*pid); }- assert!(survivors.is_empty(), "a worker under a dead root survived the sweep: {survivors:?}");}}