Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: treat unknown parent liveness as alive in the llama-server reaper (#15921)
Daniel Hanec7aba0c6cb9
diff --git a/studio/backend/core/inference/llama_cpp.py b/studio/backend/core/inference/llama_cpp.pyindex 480818103b8..f371a2ae56a 100644--- a/studio/backend/core/inference/llama_cpp.py+++ b/studio/backend/core/inference/llama_cpp.py@@ -33865,7 +33865,7 @@ class LlamaCppBackend:@staticmethoddef _pid_start_identity(pid: int) -> str:- """True when the parent still runs, so the server is not orphaned; uncertainty reads as alive so a live server is never mistakenly reaped"""+ """Process start time as a string ('' when unknown); a recycled PID will not match it."""try:import psutiltry:@@ -33886,7 +33886,7 @@ class LlamaCppBackend:@staticmethoddef _pid_parent_is_alive(pid: int) -> bool:- """Reaps only true orphans so a second backend cannot kill a live server; recycled PIDs are rejected by start time and name; SIGKILL becomes SIGTERM on Windows"""+ """True when the parent still runs, so the server is not orphaned; uncertainty reads as alive."""try:import psutil@@ -33911,7 +33911,7 @@ class LlamaCppBackend:if ppid <= 1:return Falsereturn Path(f"/proc/{ppid}").exists()- return False+ return True # no psutil and no /proc: unknown@staticmethoddef _unlink_pidfile(path: Path) -> None:@@ -33944,7 +33944,6 @@ class LlamaCppBackend:return 0 # never our own pid; leave the record aloneif cls._pid_parent_is_alive(pid):- # Kills only Unsloth-root or env-override servers, gathering all candidates first so a failed scan kills none; a positive count arms the VRAM settle waitreturn 0# Parent is gone: candidate orphan. Reject a PID recycled to something else.@@ -34160,7 +34159,6 @@ class LlamaCppBackend:# -- Ownership check, orphan check, kill ---------------------------for pid, binary, kill in candidates:- # atexit: log streams may be closed, so log nothing; stdlib loggers need raiseExceptions off, while the except covers structlog; neither alone is enoughif not _is_signalable_pid(pid):continue# Ownership: exact match OR binary under a known root.diff --git a/studio/backend/tests/test_llama_cpp_wait_for_vram_settle.py b/studio/backend/tests/test_llama_cpp_wait_for_vram_settle.pyindex 7a79659e07b..b05aef81982 100644--- a/studio/backend/tests/test_llama_cpp_wait_for_vram_settle.py+++ b/studio/backend/tests/test_llama_cpp_wait_for_vram_settle.py@@ -596,6 +596,29 @@ def test_reap_recorded_pid_spares_live_server(tmp_path):proc.wait(timeout = 5)[email protected]("platform", ["win32", "darwin"])+def test_reap_recorded_pid_spares_live_server_without_psutil(tmp_path, monkeypatch, platform):+ """Unknown parent liveness (no psutil, no /proc) must never reap a live server."""+ proc = subprocess.Popen([sys.executable, "-c", "import time; time.sleep(30)"])+ pidfile = tmp_path / "llama-server.pid"+ pidfile.write_text(str(proc.pid))+ monkeypatch.setitem(sys.modules, "psutil", None)+ monkeypatch.setattr(sys, "platform", platform)+ try:+ assert LlamaCppBackend._pid_parent_is_alive(proc.pid) is True+ with (+ patch.object(LlamaCppBackend, "_server_pidfile_path", staticmethod(lambda: pidfile)),+ patch.object(LlamaCppBackend, "_pid_is_llama_server", staticmethod(lambda pid: True)),+ ):+ n = LlamaCppBackend._reap_recorded_pid()+ assert n == 0, "unknown parent liveness must not reap a server"+ assert proc.poll() is None+ assert pidfile.exists()+ finally:+ proc.kill()+ proc.wait(timeout = 5)++def test_reap_recorded_pid_skips_pid_reuse(tmp_path):"""A recorded PID recycled to a non-llama-server must NOT be killed (only thestale pidfile is cleaned), so the user's vllm/games are never touched."""