Personal AI, On Personal Devices
Python
fix(cli): spawn the Windows daemon with CREATE_NO_WINDOW instead of DETACHED_PROCESS (#1120)
Ángel Baz Monteirof098e415cb9e
diff --git a/src/openjarvis/cli/daemon_cmd.py b/src/openjarvis/cli/daemon_cmd.pyindex b1342c17..f2324c89 100644--- a/src/openjarvis/cli/daemon_cmd.py+++ b/src/openjarvis/cli/daemon_cmd.py@@ -414,13 +414,18 @@ def start(# names the parameter ``unused_start_new_session`` and ignores it. Relying# on it there leaves the server sharing its parent's console, so closing# that console — or logging off — delivers CTRL_CLOSE_EVENT and kills the- # daemon. DETACHED_PROCESS gives it no console at all; the new process- # group additionally stops a Ctrl-C in the parent reaching it.+ # daemon. CREATE_NO_WINDOW gives it its own hidden console, which its+ # children inherit. DETACHED_PROCESS (no console at all) is not enough for a+ # venv install: ``jarvis.exe``/``python.exe`` there are launcher stubs that+ # spawn the real interpreter, and that child, finding no console to inherit,+ # allocates a NEW visible one (a terminal window) that kills the server when+ # closed. The new process group additionally stops a Ctrl-C in the parent+ # reaching it.DEFAULT_CONFIG_DIR.mkdir(parents=True, exist_ok=True)spawn_kwargs: dict = {}if sys.platform == "win32":spawn_kwargs["creationflags"] = (- subprocess.DETACHED_PROCESS | subprocess.CREATE_NEW_PROCESS_GROUP+ subprocess.CREATE_NO_WINDOW | subprocess.CREATE_NEW_PROCESS_GROUP)else:spawn_kwargs["start_new_session"] = Truediff --git a/tests/cli/test_daemon_cmd.py b/tests/cli/test_daemon_cmd.pyindex e0502530..d7005e33 100644--- a/tests/cli/test_daemon_cmd.py+++ b/tests/cli/test_daemon_cmd.py@@ -223,7 +223,7 @@ class TestDaemonDetachment:patch("openjarvis.cli.daemon_cmd._LOG_FILE", tmp_path / "server.log"),patch("openjarvis.cli.daemon_cmd.sys.platform", "win32"),patch("openjarvis.cli.daemon_cmd._write_pid_unlocked") as write_pid,- patch.object(subprocess, "DETACHED_PROCESS", 0x00000008, create=True),+ patch.object(subprocess, "CREATE_NO_WINDOW", 0x08000000, create=True),patch.object(subprocess, "CREATE_NEW_PROCESS_GROUP", 0x00000200, create=True),@@ -289,14 +289,15 @@ class TestDaemonDetachment:# Supply their documented values so the simulated Windows branch is# still exercised by the POSIX test job.detached_process = getattr(subprocess, "DETACHED_PROCESS", 0x00000008)+ create_no_window = getattr(subprocess, "CREATE_NO_WINDOW", 0x08000000)create_new_process_group = getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0x00000200)with (patch.object(subprocess,- "DETACHED_PROCESS",- detached_process,+ "CREATE_NO_WINDOW",+ create_no_window,create=True,),patch.object(@@ -309,9 +310,13 @@ class TestDaemonDetachment:kwargs = self._spawn_kwargs("win32")flags = kwargs.get("creationflags", 0)- assert flags & detached_process, (- "server must be spawned with DETACHED_PROCESS on Windows, otherwise "- "closing the launching console kills it"+ assert flags & create_no_window, (+ "server must be spawned with CREATE_NO_WINDOW on Windows: it gets its "+ "own hidden console, so closing the launching console does not kill it"+ )+ assert not flags & detached_process, (+ "DETACHED_PROCESS must not be used: with a venv launcher stub the real "+ "interpreter would allocate a new, visible console window")assert flags & create_new_process_group, ("server must be in its own process group so Ctrl-C in the parent "