Skip to content

Commit eae70f1

Browse files
committed
AI: Quite llama-server on app force quit
1 parent ffcbc81 commit eae70f1

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

apps/desktop/src-tauri/src/ai/CLAUDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ Frontend manager.rs process.rs / download.rs / c
8080
**Decision**: `SIGTERM` then 5s wait then `SIGKILL` for process shutdown.
8181
**Why**: llama-server may be mid-inference holding GPU memory. `SIGTERM` gives it a chance to release resources cleanly. The 5s timeout prevents hanging on app quit if the server is stuck.
8282

83+
**Decision**: `shutdown()` called from both `on_window_event` (CloseRequested/Destroyed) and `RunEvent::Exit`.
84+
**Why**: `on_window_event` handles normal quit, but force-quit/crash/SIGTERM bypass it. `RunEvent::Exit` fires on app-level exit regardless of how it was triggered. `shutdown()` is idempotent (`child_pid.take()` returns `None` on subsequent calls), so double-calling is safe.
85+
8386
**Decision**: Context window (`-c 4096`) explicitly set on llama-server.
8487
**Why**: Without `-c`, llama-server defaults to the model's trained max context (256K for Ministral), creating a ~27 GB KV cache. Folder suggestions need at most 2K context. 4K is generous and keeps memory under ~400 MB.
8588

apps/desktop/src-tauri/src/lib.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,13 @@ pub fn run() {
872872
network::mdns_discovery::stop_discovery();
873873
}
874874
})
875-
.run(tauri::generate_context!())
876-
.expect("error while running tauri application");
875+
.build(tauri::generate_context!())
876+
.expect("error while building tauri application")
877+
.run(|_app, event| {
878+
if let tauri::RunEvent::Exit = event {
879+
ai::manager::shutdown();
880+
#[cfg(any(target_os = "macos", target_os = "linux"))]
881+
network::mdns_discovery::stop_discovery();
882+
}
883+
});
877884
}

0 commit comments

Comments
 (0)