Skip to content

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.

fix(win): der Motor stirbt jetzt mit der App, und ein Absturz hinterlaesst eine Spur

David6254f959f137
diff --git a/src-tauri/src/commands/engine.rs b/src-tauri/src/commands/engine.rs
index 02d28d4e..0d649cac 100644
--- a/src-tauri/src/commands/engine.rs
+++ b/src-tauri/src/commands/engine.rs
@@ -1,4 +1,5 @@
use crate::os_error;
+use super::process::tie_child_to_app_lifetime;
// P1 — Built-in inference engine (bundled llama.cpp `llama-server`).
//
@@ -953,6 +954,15 @@ fn spawn_engine_attempt(
})
}
};
+ // Tie the engine to the app's lifetime BEFORE anything else can go wrong.
+ // The graceful shutdown path in `AppState::shutdown_subprocesses` kills this
+ // child on a normal quit, but nothing runs on a hard kill or a crash, and
+ // this is the single most expensive orphan the app can leave: a whole GGUF
+ // resident in VRAM with no owner left to free it. Proved on the Windows box
+ // on 2026-08-29 (app terminated 09:48:19, lu-llama-server still holding
+ // 3633 MiB afterwards). ComfyUI survived the same event correctly because
+ // it was already in the job and the engine was not.
+ tie_child_to_app_lifetime(child.id());
let diagnostics = child.stderr.take().map(super::shell::drain);
*state.bundled_engine.lock().unwrap() = Some(BundledEngine {
@@ -1487,6 +1497,8 @@ fn start_bundled_embed_blocking(
let mut child = cmd
.spawn()
.map_err(|e| format!("Failed to spawn embeddings server: {}", os_error::english(&e)))?;
+ // Same orphan rule as the chat engine above.
+ tie_child_to_app_lifetime(child.id());
let diagnostics = child.stderr.take().map(super::shell::drain);
*state.bundled_embed.lock().unwrap() = Some(BundledEngine {
diff --git a/src-tauri/src/commands/process.rs b/src-tauri/src/commands/process.rs
index 58cb310a..25a4ac61 100644
--- a/src-tauri/src/commands/process.rs
+++ b/src-tauri/src/commands/process.rs
@@ -29,38 +29,66 @@ pub fn comfy_supported_here() -> bool {
#[cfg(target_os = "windows")]
const CREATE_NO_WINDOW: u32 = 0x08000000;
-/// Assign a child process to a Windows Job Object with KILL_ON_JOB_CLOSE.
-/// When the Tauri parent process dies (even via Task Manager), the OS kernel
-/// automatically terminates all processes in the job — no Drop needed.
+/// Assign a child process to the app-wide Windows Job Object with
+/// KILL_ON_JOB_CLOSE. When the Tauri parent process dies (even via Task
+/// Manager, even via a hard kill from a build script), the OS kernel
+/// automatically terminates every process in the job, with no Drop needed.
#[cfg(target_os = "windows")]
fn assign_to_kill_on_close_job(child: &std::process::Child) {
assign_pid_to_kill_on_close_job(child.id());
}
-/// PID-based variant of [`assign_to_kill_on_close_job`]. Usable from spawn paths
-/// that don't own a `std::process::Child` — notably `tokio::process::Child`
-/// (whose `id()` is `Option<u32>`) in the background-task runner (bg_tasks.rs).
-/// Same KILL_ON_JOB_CLOSE semantics; a pid of 0 is ignored.
+/// The ONE kill-on-close job object of this process, created on first use.
+///
+/// It used to be one fresh job per child, with the handle leaked on purpose so
+/// the job outlived the call. That is correct for a child spawned once, and a
+/// slow leak for one spawned again and again: the built-in engine is restarted
+/// on every model swap, and a session that switches models a few dozen times
+/// (measured on the Windows box on 2026-08-29: 30 restarts in eleven minutes)
+/// leaked a kernel job handle every single time. A process may belong to
+/// several jobs on Windows 8 and later, so one shared job holds every child
+/// just as well and leaks exactly one handle for the whole run.
#[cfg(target_os = "windows")]
-pub(crate) fn assign_pid_to_kill_on_close_job(pid: u32) {
+fn kill_on_close_job() -> isize {
+ use std::sync::OnceLock;
use windows_sys::Win32::System::JobObjects::*;
- use windows_sys::Win32::Foundation::*;
- if pid == 0 { return; }
- unsafe {
+ // The raw HANDLE is a pointer and therefore not `Sync`; the numeric value
+ // is, and it is what every call site needs.
+ static JOB: OnceLock<isize> = OnceLock::new();
+ *JOB.get_or_init(|| unsafe {
let job = CreateJobObjectW(std::ptr::null(), std::ptr::null());
- if job.is_null() { return; }
-
+ if job.is_null() {
+ return 0;
+ }
let mut info: JOBOBJECT_EXTENDED_LIMIT_INFORMATION = std::mem::zeroed();
info.BasicLimitInformation.LimitFlags = JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE;
-
SetInformationJobObject(
job,
JobObjectExtendedLimitInformation,
&info as *const _ as *const _,
std::mem::size_of::<JOBOBJECT_EXTENDED_LIMIT_INFORMATION>() as u32,
);
+ // Intentionally never closed. The handle must stay alive for the
+ // lifetime of the app. When the app dies the OS closes it and
+ // KILL_ON_JOB_CLOSE takes the children with it.
+ job as isize
+ })
+}
+
+/// PID-based variant of [`assign_to_kill_on_close_job`]. Usable from spawn paths
+/// that don't own a `std::process::Child`, notably `tokio::process::Child`
+/// (whose `id()` is `Option<u32>`) in the background-task runner (bg_tasks.rs).
+/// Same KILL_ON_JOB_CLOSE semantics; a pid of 0 is ignored.
+#[cfg(target_os = "windows")]
+pub(crate) fn assign_pid_to_kill_on_close_job(pid: u32) {
+ use windows_sys::Win32::System::JobObjects::*;
+ use windows_sys::Win32::Foundation::*;
+ if pid == 0 { return; }
+ let job = kill_on_close_job();
+ if job == 0 { return; }
+ unsafe {
let handle = windows_sys::Win32::System::Threading::OpenProcess(
windows_sys::Win32::System::Threading::PROCESS_SET_QUOTA
| windows_sys::Win32::System::Threading::PROCESS_TERMINATE,
@@ -68,15 +96,34 @@ pub(crate) fn assign_pid_to_kill_on_close_job(pid: u32) {
pid,
);
if !handle.is_null() {
- AssignProcessToJobObject(job, handle);
+ AssignProcessToJobObject(job as _, handle);
CloseHandle(handle);
}
- // Intentionally leak the job handle — it must stay alive for the duration
- // of the parent process. When the parent dies, the handle is closed by the
- // OS and KILL_ON_JOB_CLOSE triggers.
}
}
+/// Tie a spawned child to the lifetime of the app: on Windows it joins the
+/// kill-on-close job object, everywhere else this is a no-op (Unix children of
+/// a dead parent are reparented, and the graceful shutdown path plus the
+/// process-group kill in `process_util` cover what matters there).
+///
+/// Every long lived child goes through here: the bundled llama-server (chat
+/// and embeddings), Ollama, the whisper server, the trainer, ComfyUI. Before
+/// 2.6.7 only ComfyUI, Ollama-by-Drop and the background-task runner were
+/// covered, so an app that died without running its shutdown path left a
+/// llama-server behind holding the whole model in VRAM. Proved on the Windows
+/// box on 2026-08-29: the app was terminated at 09:48:19, both ComfyUI
+/// processes went with it, and lu-llama-server stayed up on 3633 MiB.
+///
+/// Cross platform on purpose (no `#[cfg]` at the call sites) so the call is
+/// visible and testable on every platform, not only the one that needs it.
+pub(crate) fn tie_child_to_app_lifetime(pid: u32) {
+ #[cfg(target_os = "windows")]
+ assign_pid_to_kill_on_close_job(pid);
+ #[cfg(not(target_os = "windows"))]
+ let _ = pid;
+}
+
/// Show the main window (called from frontend after React renders)
#[tauri::command]
pub fn show_window(app: tauri::AppHandle) {
@@ -1065,6 +1112,10 @@ fn start_ollama_blocking(state: &AppState) -> Result<serde_json::Value, String>
// shutdown (kj103x — Discord 2026-05-23 #help-chat 1507756765612216411).
// Note: tasklist check above means we only get here if WE start it,
// so we never kill a user-managed ollama serve.
+ //
+ // The Drop only covers a shutdown that runs. A hard kill of the app
+ // does not run one, so the child also joins the kill-on-close job.
+ tie_child_to_app_lifetime(child.id());
*state.ollama_process.lock().unwrap() = Some(child);
println!("[Ollama] Started");
info!("ollama spawned");
@@ -2024,6 +2075,7 @@ pub fn auto_start_ollama(state: &AppState) {
match cmd.spawn() {
Ok(child) => {
// Same orphan-prevention rationale as `start_ollama` above.
+ tie_child_to_app_lifetime(child.id());
*state.ollama_process.lock().unwrap() = Some(child);
println!("[Ollama] Started");
}
@@ -2672,3 +2724,125 @@ mod ollama_probe_tests {
drop(listener);
}
}
+
+/// Orphan safety: every long lived child the app spawns has to die with the
+/// app, including the deaths that never reach `shutdown_subprocesses` (a hard
+/// kill, Task Manager, a build script that clears the way for itself).
+///
+/// The evidence these tests were written from, Windows box 2026-08-29: the app
+/// was terminated at 09:48:19, both ComfyUI processes went with it because
+/// ComfyUI was in the kill-on-close job, and lu-llama-server survived holding
+/// 3633 MiB of VRAM because the engine spawn was not.
+#[cfg(test)]
+mod orphan_safety_tests {
+ use super::*;
+
+ /// Source of the files that spawn a long lived child, read at compile
+ /// time. A grep in a test is a blunt instrument, but it is the only guard
+ /// available for a Windows kernel behaviour that cannot be exercised on
+ /// this machine, and it fails loudly when a NEW spawn path forgets the
+ /// call rather than after the next VRAM leak in the field.
+ const ENGINE_RS: &str = include_str!("engine.rs");
+ const WHISPER_RS: &str = include_str!("whisper.rs");
+ const TRAINER_RS: &str = include_str!("trainer.rs");
+ const PROCESS_RS: &str = include_str!("process.rs");
+
+ fn ties(src: &str) -> usize {
+ src.matches("tie_child_to_app_lifetime(").count()
+ - src.matches("fn tie_child_to_app_lifetime(").count()
+ }
+
+ #[test]
+ fn the_bundled_engine_and_the_embeddings_server_are_both_tied_to_the_app() {
+ // Two spawns in engine.rs: the chat server and the embeddings server.
+ // Neither was tied before 2.6.7, and the chat one is the orphan that
+ // was measured holding 3633 MiB after the app was gone.
+ assert!(
+ ENGINE_RS.contains("tie_child_to_app_lifetime(child.id())"),
+ "the bundled engine spawn must tie its child to the app lifetime"
+ );
+ assert_eq!(
+ ties(ENGINE_RS),
+ 2,
+ "engine.rs has two long lived spawns (chat + embeddings); both must be tied"
+ );
+ }
+
+ /// process.rs up to this test module. The assertions below mention the
+ /// call by name many times over, and counting those as call sites would
+ /// make the guard meaningless.
+ fn process_rs_production_code() -> &'static str {
+ PROCESS_RS
+ .split_once("mod orphan_safety_tests {")
+ .map(|(head, _)| head)
+ .expect("this module is part of process.rs")
+ }
+
+ #[test]
+ fn the_other_long_lived_children_are_tied_too() {
+ assert_eq!(ties(WHISPER_RS), 1, "the persistent whisper server must be tied");
+ assert_eq!(ties(TRAINER_RS), 1, "the trainer must be tied");
+ // Ollama is spawned twice: the command and the auto-start path.
+ assert_eq!(
+ ties(process_rs_production_code()),
+ 2,
+ "both ollama spawns must be tied"
+ );
+ }
+
+ #[test]
+ fn comfyui_keeps_the_job_it_already_had() {
+ // Negative control: the fix must not have moved ComfyUI off the
+ // mechanism that demonstrably worked on 2026-08-29.
+ assert_eq!(
+ process_rs_production_code()
+ .matches("assign_to_kill_on_close_job(&child)")
+ .count(),
+ 2,
+ "both ComfyUI spawns must stay on the kill-on-close job"
+ );
+ }
+
+ #[test]
+ fn tying_a_child_leaves_it_running_and_a_zero_pid_is_ignored() {
+ // The call is a no-op off Windows and must never be a way to kill
+ // something by accident. A pid of 0 means "no process" on both
+ // families and must not be handed to the OS at all.
+ tie_child_to_app_lifetime(0);
+
+ #[cfg(not(target_os = "windows"))]
+ {
+ let mut child = std::process::Command::new("sleep")
+ .arg("5")
+ .stdin(Stdio::null())
+ .stdout(Stdio::null())
+ .stderr(Stdio::null())
+ .spawn()
+ .expect("spawn a sleeper");
+ tie_child_to_app_lifetime(child.id());
+ std::thread::sleep(std::time::Duration::from_millis(200));
+ assert!(
+ child.try_wait().expect("try_wait").is_none(),
+ "tying a child must not disturb it"
+ );
+ let _ = child.kill();
+ let _ = child.wait();
+ }
+ }
+
+ #[test]
+ fn the_job_object_is_created_once_and_shared() {
+ // The old code made a fresh job per child and leaked the handle every
+ // time; the engine restarts on every model swap (30 restarts in eleven
+ // minutes were logged on 2026-08-29), so that leaked 30 handles.
+ assert_eq!(
+ process_rs_production_code().matches("CreateJobObjectW(").count(),
+ 1,
+ "there must be exactly one place that creates the job object"
+ );
+ assert!(
+ PROCESS_RS.contains("static JOB: OnceLock<isize>"),
+ "the job handle must be created once and reused"
+ );
+ }
+}
diff --git a/src-tauri/src/commands/trainer.rs b/src-tauri/src/commands/trainer.rs
index e8d0899b..2c48f5e1 100644
--- a/src-tauri/src/commands/trainer.rs
+++ b/src-tauri/src/commands/trainer.rs
@@ -586,6 +586,10 @@ fn run_streamed(
let mut child = cmd
.spawn()
.map_err(|e| format!("{label} could not start: {}", os_error::english(&e)))?;
+ // The trainer is the longest lived and most VRAM hungry child the app
+ // spawns. `shutdown_subprocesses` kills it on a clean quit; the job object
+ // covers the quits that never reach that code.
+ crate::commands::process::tie_child_to_app_lifetime(child.id());
if let Ok(mut slot) = pid_slot.lock() {
*slot = Some(child.id());
}
diff --git a/src-tauri/src/commands/whisper.rs b/src-tauri/src/commands/whisper.rs
index 73a37357..492060eb 100644
--- a/src-tauri/src/commands/whisper.rs
+++ b/src-tauri/src/commands/whisper.rs
@@ -99,6 +99,8 @@ impl WhisperServer {
cmd.creation_flags(CREATE_NO_WINDOW);
let mut child = cmd.spawn()
.map_err(|e| format!("Failed to start whisper server: {}", os_error::english(&e)))?;
+ // Long lived Python server: it must not outlive the app on a hard kill.
+ crate::commands::process::tie_child_to_app_lifetime(child.id());
let stdin = child.stdin.take().ok_or("Failed to get stdin")?;
let stdout = child.stdout.take().ok_or("Failed to get stdout")?;
diff --git a/src-tauri/src/crash_report.rs b/src-tauri/src/crash_report.rs
new file mode 100644
index 00000000..f7466b13
--- /dev/null
+++ b/src-tauri/src/crash_report.rs
@@ -0,0 +1,214 @@
+//! Last words. A record of an unexpected process death, written where a
+//! support request can find it.
+//!
+//! Why this exists: the release profile builds with `panic = "abort"`
+//! (Cargo.toml). A panic on ANY thread therefore takes the whole app down at
+//! once, and `catch_unwind` cannot stop it, so "no unhandled panic in the
+//! timer paths" cannot be delivered by catching. What can be delivered is a
+//! trace. A shipped Windows build has no console: it is started from the
+//! Start menu, `windows_subsystem = "windows"` is set, and stdout and stderr
+//! go nowhere a user will ever look. Until now a panic in a background thread
+//! ended the app with an empty screen and an empty log, which is exactly the
+//! shape of the "it just died on its own" reports.
+//!
+//! What is written is deliberately small: one line per death, appended, with
+//! a hard cap on the file so it can never grow without bound. Everything the
+//! user might see is English (house rule), and the payload is what Rust
+//! already prints for a panic, so it holds no user content beyond whatever a
+//! panic message carries by itself.
+
+use std::io::Write;
+
+/// The name of the file, in the app data directory.
+pub(crate) const CRASH_LOG: &str = "crash.log";
+
+/// Keep the newest entries and no more than this many bytes. A panic line is
+/// a few hundred bytes, so this is thousands of deaths, and the cap matters
+/// only against a boot loop that panics on every start.
+pub(crate) const MAX_BYTES: u64 = 256 * 1024;
+
+/// One line for one death. Pure, so the format is testable without panicking
+/// a test process.
+///
+/// `when` is passed in rather than read from the clock so the test can pin it.
+pub(crate) fn crash_line(when: &str, thread: &str, location: &str, payload: &str) -> String {
+ // Newlines in a panic payload would break "one death, one line" and make
+ // the file unparseable, so they are folded. Runs of whitespace collapse to
+ // a single space, otherwise a CRLF payload leaves double gaps and the line
+ // reads worse than the panic it reports.
+ let flat = |s: &str| s.split_whitespace().collect::<Vec<_>>().join(" ");
+ format!(
+ "{} FATAL thread={} at={} panic: {}\n",
+ flat(when),
+ flat(thread),
+ flat(location),
+ flat(payload)
+ )
+}
+
+/// What Rust hands a panic hook, reduced to the two strings we can print.
+/// `PanicHookInfo::payload` is `&str` for `panic!("...")` and `String` for a
+/// formatted one; anything else has no text at all and says so rather than
+/// being dropped silently.
+pub(crate) fn payload_text(payload: &(dyn std::any::Any + Send)) -> String {
+ if let Some(s) = payload.downcast_ref::<&str>() {
+ (*s).to_string()
+ } else if let Some(s) = payload.downcast_ref::<String>() {
+ s.clone()
+ } else {
+ "panic payload is not a string".to_string()
+ }
+}
+
+/// Append one line, trimming the file first if it has grown past the cap.
+///
+/// Best effort throughout. This runs while the process is already dying: a
+/// read-only directory, a full disk, or a file another process holds open
+/// must not turn a panic into a second failure, and there is nobody left to
+/// report an error to anyway.
+pub(crate) fn append_capped(path: &std::path::Path, line: &str) {
+ if let Some(parent) = path.parent() {
+ let _ = std::fs::create_dir_all(parent);
+ }
+ let too_big = std::fs::metadata(path).map(|m| m.len() > MAX_BYTES).unwrap_or(false);
+ if too_big {
+ // Keep the newest half. Reading the whole file is fine at this size,
+ // and a partial line at the front is cut at the first newline so the
+ // file stays one-record-per-line.
+ if let Ok(old) = std::fs::read_to_string(path) {
+ let keep_from = old.len().saturating_sub(MAX_BYTES as usize / 2);
+ let tail = &old[keep_from..];
+ let tail = match tail.find('\n') {
+ Some(i) => &tail[i + 1..],
+ None => "",
+ };
+ let _ = std::fs::write(path, tail);
+ }
+ }
+ if let Ok(mut f) = std::fs::OpenOptions::new().create(true).append(true).open(path) {
+ let _ = f.write_all(line.as_bytes());
+ let _ = f.flush();
+ }
+}
+
+/// Where the crash log lives.
+pub(crate) fn crash_log_path() -> std::path::PathBuf {
+ crate::os_paths::data_dir().join(CRASH_LOG)
+}
+
+/// Install the hook. Called once from `main`, before anything can panic.
+///
+/// The previous hook is kept and still runs, so the familiar
+/// `thread '...' panicked at ...` line still reaches stderr for anyone who
+/// started the app from a terminal.
+pub fn install_panic_hook() {
+ let previous = std::panic::take_hook();
+ std::panic::set_hook(Box::new(move |info| {
+ let when = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .map(|d| format!("unix={}", d.as_secs()))
+ .unwrap_or_else(|_| "unix=unknown".to_string());
+ let thread = std::thread::current().name().unwrap_or("unnamed").to_string();
+ let location = info
+ .location()
+ .map(|l| format!("{}:{}:{}", l.file(), l.line(), l.column()))
+ .unwrap_or_else(|| "unknown".to_string());
+ let payload = payload_text(info.payload());
+ let line = crash_line(&when, &thread, &location, &payload);
+ append_capped(&crash_log_path(), &line);
+ // Also on stderr, where a debug launcher that redirects it will catch
+ // it. The release profile aborts right after this hook returns, so
+ // this is the last chance either sink gets.
+ eprint!("{line}");
+ previous(info);
+ }));
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn a_death_is_one_line_that_names_thread_place_and_reason() {
+ let line = crash_line("unix=1", "backup-ring", "src/commands/system.rs:42:9", "index out of bounds");
+ assert!(line.ends_with('\n'));
+ assert_eq!(line.matches('\n').count(), 1);
+ assert!(line.contains("FATAL"));
+ assert!(line.contains("thread=backup-ring"));
+ assert!(line.contains("at=src/commands/system.rs:42:9"));
+ assert!(line.contains("index out of bounds"));
+ }
+
+ #[test]
+ fn a_multi_line_panic_message_is_folded_into_the_one_line() {
+ // Negative control for the check above: a payload with newlines used
+ // to be able to forge extra records in the file.
+ let line = crash_line("unix=1", "main", "a.rs:1:1", "first\nsecond\r\nthird");
+ assert_eq!(line.matches('\n').count(), 1);
+ assert!(line.contains("first second third"));
+ }
+
+ #[test]
+ fn both_panic_payload_shapes_keep_their_text() {
+ let borrowed: Box<dyn std::any::Any + Send> = Box::new("a literal panic");
+ let owned: Box<dyn std::any::Any + Send> = Box::new(String::from("a formatted panic"));
+ assert_eq!(payload_text(&*borrowed), "a literal panic");
+ assert_eq!(payload_text(&*owned), "a formatted panic");
+ }
+
+ #[test]
+ fn a_payload_that_is_not_text_still_reports_something() {
+ // Negative control: `panic_any(42)` carries no string, and dropping it
+ // silently would leave the same empty log this module exists to end.
+ let odd: Box<dyn std::any::Any + Send> = Box::new(42u8);
+ assert_eq!(payload_text(&*odd), "panic payload is not a string");
+ }
+
+ #[test]
+ fn every_line_is_english() {
+ // House rule: nothing the user or support reads is localised, and no
+ // OS string in any language is passed through here.
+ let line = crash_line("unix=1", "main", "a.rs:1:1", "attempt to divide by zero");
+ assert!(line.is_ascii(), "crash line must stay plain English ASCII: {line}");
+ }
+
+ #[test]
+ fn appending_creates_the_file_and_keeps_the_records_in_order() {
+ let dir = tempfile::tempdir().expect("tempdir");
+ let path = dir.path().join("nested").join(CRASH_LOG);
+ append_capped(&path, "first\n");
+ append_capped(&path, "second\n");
+ let got = std::fs::read_to_string(&path).expect("crash log exists");
+ assert_eq!(got, "first\nsecond\n");
+ }
+
+ #[test]
+ fn a_log_past_the_cap_is_trimmed_but_the_newest_record_survives() {
+ let dir = tempfile::tempdir().expect("tempdir");
+ let path = dir.path().join(CRASH_LOG);
+ let filler = format!("{}\n", "x".repeat(1023));
+ let mut bulk = String::new();
+ while (bulk.len() as u64) < MAX_BYTES + 4096 {
+ bulk.push_str(&filler);
+ }
+ std::fs::write(&path, &bulk).expect("write bulk");
+ append_capped(&path, "the newest death\n");
+ let got = std::fs::read_to_string(&path).expect("read back");
+ assert!(got.len() < bulk.len(), "file was not trimmed: {} bytes", got.len());
+ assert!(got.ends_with("the newest death\n"));
+ assert!(got.starts_with("xxx"), "trim must cut at a record boundary");
+ }
+
+ #[test]
+ fn a_log_under_the_cap_is_never_trimmed() {
+ // Negative control for the trim above.
+ let dir = tempfile::tempdir().expect("tempdir");
+ let path = dir.path().join(CRASH_LOG);
+ std::fs::write(&path, "old record\n").expect("write");
+ append_capped(&path, "new record\n");
+ assert_eq!(
+ std::fs::read_to_string(&path).expect("read back"),
+ "old record\nnew record\n"
+ );
+ }
+}
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index d6bf7113..85c69990 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -2,6 +2,7 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
mod commands;
+mod crash_report;
mod install_state;
mod os_error;
mod os_paths;
@@ -107,6 +108,14 @@ where
}
fn main() {
+ // First thing of all: a panic anywhere must leave a trace. The release
+ // profile is `panic = "abort"`, so a panic on any thread ends the process
+ // immediately, and a shipped Windows build has no console to print to.
+ // Without this hook such a death is indistinguishable from the app being
+ // killed from outside, which is exactly the confusion the 2026-08-29
+ // Windows investigation had to untangle by hand.
+ crash_report::install_panic_hook();
+
#[cfg(target_os = "linux")]
apply_linux_webkit_workarounds();
// Before anything can spawn a child: an AppImage exports PYTHONHOME and