From 226ece0c9e0e671a22e6efcd250fab27c9dbad97 Mon Sep 17 00:00:00 2001 From: Daniel Han Date: Sun, 15 Mar 2026 07:06:10 +0000 Subject: [PATCH] studio: fix cancel to actually kill llama-server during loading The unload endpoint checked is_loaded (requires healthy=True), but during initial loading the server is not yet healthy. Cancel had no effect because the unload route fell through to the Unsloth backend. Fix: add is_active property (process exists, loading or loaded) and check it in the unload route so cancel kills llama-server even during the download/loading phase. Also: toast cancel button now properly triggers the backend unload. --- studio/backend/core/inference/llama_cpp.py | 5 +++++ studio/backend/routes/inference.py | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.py index c222b43a9f..d1c943ee16 100644 --- a/studio/backend/core/inference/llama_cpp.py +++ b/studio/backend/core/inference/llama_cpp.py @@ -58,6 +58,11 @@ class LlamaCppBackend: def is_loaded(self) -> bool: return self._process is not None and self._healthy + @property + def is_active(self) -> bool: + """True if a llama-server process exists (loading or loaded).""" + return self._process is not None + @property def base_url(self) -> str: return f"http://127.0.0.1:{self._port}" diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py index e9ad9a6995..5299d168f5 100644 --- a/studio/backend/routes/inference.py +++ b/studio/backend/routes/inference.py @@ -343,11 +343,11 @@ async def unload_model( Routes to the correct backend (llama-server for GGUF, Unsloth otherwise). """ try: - # Check if the GGUF backend has this model loaded + # Check if the GGUF backend has this model loaded or is loading it llama_backend = get_llama_cpp_backend() - if ( - llama_backend.is_loaded - and llama_backend.model_identifier == request.model_path + if llama_backend.is_active and ( + llama_backend.model_identifier == request.model_path + or not llama_backend.is_loaded ): llama_backend.unload_model() logger.info(f"Unloaded GGUF model: {request.model_path}")