Skip to content

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.

Studio: never walk init's descendants when stopping a server (#14486)

Daniel Han6446636f8a59
diff --git a/studio/backend/tests/test_process_lifetime_never_signals_init.py b/studio/backend/tests/test_process_lifetime_never_signals_init.py
index 4e9483fb06e..3ba3316f0a9 100644
--- a/studio/backend/tests/test_process_lifetime_never_signals_init.py
+++ b/studio/backend/tests/test_process_lifetime_never_signals_init.py
@@ -135,6 +135,38 @@ def test_terminate_descendants_skips_init(recorded_signals, monkeypatch):
assert recorded_signals == []
+# Every process on the host descends from init. A walk rooted at pid 1 is the whole
+# machine, and the llama-server unload SIGTERMs whatever the walk returns: a stand-in
+# process with pid 1 in a test took down every process the user owned that way.
+_INIT_OWNS_EVERYTHING = {1: [4242], 4242: [4243]}
+
+
[email protected](not IS_POSIX, reason = "POSIX process table")
[email protected]("pid", [1, True])
+def test_collect_descendants_never_walks_init(monkeypatch, pid):
+ monkeypatch.setattr(pl, "_child_pid_map", lambda: _INIT_OWNS_EVERYTHING)
+ monkeypatch.setattr(pl, "_pid_identity", lambda p: "start")
+ assert pl.collect_descendants_known(pid) == ([], True)
+ assert pl.collect_descendants(pid) == []
+
+
[email protected](not IS_POSIX, reason = "POSIX process table")
+def test_collect_descendants_still_walks_a_real_pid(monkeypatch):
+ """The floor must not disarm the walk it guards."""
+ monkeypatch.setattr(pl, "_child_pid_map", lambda: _INIT_OWNS_EVERYTHING)
+ monkeypatch.setattr(pl, "_pid_identity", lambda p: "start")
+ assert pl.collect_descendants_known(4242) == ([(4243, "start")], True)
+
+
[email protected](not IS_POSIX, reason = "POSIX process table")
+def test_llama_unload_walk_never_names_inits_children(monkeypatch):
+ from core.inference.llama_cpp import LlamaCppBackend
+
+ monkeypatch.setattr(pl, "_child_pid_map", lambda: _INIT_OWNS_EVERYTHING)
+ monkeypatch.setattr(pl, "_pid_identity", lambda p: "start")
+ assert LlamaCppBackend._collect_descendants(1) == ([], True)
+
+
# --- the end to end case that actually happened ----------------------------
diff --git a/studio/backend/utils/process_lifetime.py b/studio/backend/utils/process_lifetime.py
index 2a88ee977e7..c61a44ac529 100644
--- a/studio/backend/utils/process_lifetime.py
+++ b/studio/backend/utils/process_lifetime.py
@@ -950,6 +950,12 @@ def collect_descendants_known(
if not pid:
# Not a question about a process, so there is nothing indeterminate about it.
return [], True
+ if not is_signalable_pid(pid):
+ # Below the floor. Every process on the host descends from init, so walking pid 1
+ # hands the whole machine to a caller that is about to SIGTERM what it gets back:
+ # a stand-in process with pid 1 in a test did exactly that and took the user's
+ # session down. Nothing under init is ours by descent.
+ return [], True
# Windows records the creating pid on a process and never clears it, not even when
# that parent exits and its number is handed to something else, so the raw table
# lists strangers created by an earlier holder of this pid as children of it. A real