Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(windows): repair PATH at Codex spawn boundaries (#844)
IdeeWirdApp0a87b76240cc
diff --git a/dodaios/agent_chat/runner_cli.py b/dodaios/agent_chat/runner_cli.pyindex 588bf7b6ab..b2fafa7382 100644--- a/dodaios/agent_chat/runner_cli.py+++ b/dodaios/agent_chat/runner_cli.py@@ -3785,6 +3785,11 @@ async def _spawn_child(plan.env[TURN_MARKER_ENV] = uuid4().hextry:+ if runner == "codex-cli" and os.name == "nt":+ from dodaios.core.path_augment import ensure_cli_paths++ ensure_cli_paths()+ plan.env["PATH"] = os.environ.get("PATH", "")proc = await asyncio.create_subprocess_exec(*plan.argv,cwd=str(cwd),diff --git a/dodaios/agent_chat/turn_host.py b/dodaios/agent_chat/turn_host.pyindex e7d6216be8..e1a9b000c5 100644--- a/dodaios/agent_chat/turn_host.py+++ b/dodaios/agent_chat/turn_host.py@@ -370,11 +370,18 @@ class TurnHost:# ------------------------------------------------------------ requestsasync def _spawn(self, frame: dict[str, Any]) -> dict[str, Any]:+ from dodaios.core.path_augment import ensure_cli_pathsfrom dodaios.core.process_utils import NO_WINDOW_CREATIONFLAGSargv = [str(part) for part in frame.get("argv") or ()]if not argv:return {"ok": False, "error": "empty argv"}+ # A turn host can outlive and be reattached by the desktop process that+ # created it. In particular, an older host may still carry the PATH it+ # inherited before the Windows length guard was added. Repair the+ # caller's PATH immediately before CreateProcess: changing only the+ # child environment is too late for WinError 8.+ ensure_cli_paths()env = frame.get("env")stdin_data = frame.get("stdin")proc = await asyncio.create_subprocess_exec(diff --git a/tests/unit/agent_chat/test_runner_cli_path.py b/tests/unit/agent_chat/test_runner_cli_path.pynew file mode 100644index 0000000000..2a30982833--- /dev/null+++ b/tests/unit/agent_chat/test_runner_cli_path.py@@ -0,0 +1,60 @@+"""Windows PATH repair at the direct Codex CLI spawn boundary."""++from __future__ import annotations++import os+from pathlib import Path+from typing import Any++import pytest++from dodaios.agent_chat import runner_cli+from dodaios.core import path_augment++[email protected](os.name != "nt", reason="Windows CreateProcess PATH limit")+async def test_direct_codex_spawn_repairs_parent_and_child_path(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ """A normal text chat must repair both PATH copies before CreateProcess."""+ existing = tmp_path / "existing"+ cli_dir = tmp_path / "cli"+ existing.mkdir()+ cli_dir.mkdir()+ for name in ("node.exe", "npm.cmd", "codex.cmd"):+ (cli_dir / name).touch()++ budget = len(os.pathsep.join((str(existing), str(cli_dir))))+ bloated = os.pathsep.join([str(existing)] * 40)+ assert len(bloated) > budget+ monkeypatch.setenv("PATH", bloated)+ monkeypatch.setattr(path_augment, "candidate_dirs", lambda: [str(cli_dir)])+ monkeypatch.setattr(path_augment, "_path_budget", lambda: budget)+ monkeypatch.setattr(path_augment, "_settled_overflow", None)++ observed: list[tuple[str, str]] = []++ async def capture_spawn(*_argv: str, **kwargs: Any) -> object:+ parent_path = os.environ["PATH"]+ child_path = kwargs["env"]["PATH"]+ observed.append((parent_path, child_path))+ assert parent_path == child_path == os.pathsep.join((str(existing), str(cli_dir)))+ assert len(parent_path) <= budget+ assert all((cli_dir / name).is_file() for name in ("node.exe", "npm.cmd", "codex.cmd"))+ return object()++ monkeypatch.setattr(runner_cli.asyncio, "create_subprocess_exec", capture_spawn)+ for _ in range(2):+ plan = runner_cli.CliPlan(+ argv=[str(cli_dir / "codex.cmd"), "exec", "--json", "-"],+ env={"PATH": bloated},+ stdin_text="test",+ shape="codex",+ vendor_session=None,+ )+ result = await runner_cli._spawn_child(plan, tmp_path, None, "codex-cli")+ assert not isinstance(result, runner_cli._Outcome)++ assert len(observed) == 2+ assert observed[0] == observed[1]+ assert path_augment.ensure_cli_paths() == []diff --git a/tests/unit/agent_chat/test_turn_host_path.py b/tests/unit/agent_chat/test_turn_host_path.pynew file mode 100644index 0000000000..9408de75ba--- /dev/null+++ b/tests/unit/agent_chat/test_turn_host_path.py@@ -0,0 +1,62 @@+"""PATH repair at the persistent coding-CLI turn host boundary."""++from __future__ import annotations++import os+from pathlib import Path+from typing import Any++import pytest++from dodaios.agent_chat import turn_host+from dodaios.core import path_augment+++async def test_codex_spawn_repairs_an_inherited_oversized_path_before_create_process(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch+) -> None:+ """A surviving turn host must repair its own PATH before the first CLI spawn."""+ host = turn_host.TurnHost("test-token", tmp_path / "spool")+ existing = tmp_path / "existing"+ cli_dir = tmp_path / "cli"+ existing.mkdir()+ cli_dir.mkdir()+ for name in ("node.exe", "npm.cmd", "codex.cmd"):+ (cli_dir / name).touch()++ budget = len(os.pathsep.join((str(existing), str(cli_dir))))+ bloated = os.pathsep.join([str(existing)] * 40)+ assert len(bloated) > budget+ monkeypatch.setenv("PATH", bloated)+ monkeypatch.setattr(path_augment, "candidate_dirs", lambda: [str(cli_dir)])+ monkeypatch.setattr(path_augment, "_path_budget", lambda: budget)+ monkeypatch.setattr(path_augment, "_settled_overflow", None)++ observed_paths: list[str] = []++ async def stop_at_create_process(*_argv: str, **_kwargs: Any) -> None:+ current = os.environ["PATH"]+ observed_paths.append(current)+ entries = current.split(os.pathsep)+ assert entries == [str(existing), str(cli_dir)]+ assert len(current) <= budget+ assert all((cli_dir / name).is_file() for name in ("node.exe", "npm.cmd", "codex.cmd"))+ raise OSError("test stops at CreateProcess")++ monkeypatch.setattr(turn_host.asyncio, "create_subprocess_exec", stop_at_create_process)+ frame = {+ "argv": [str(cli_dir / "codex.cmd"), "exec", "--json", "-"],+ "cwd": str(tmp_path),+ "env": {"PATH": bloated},+ "meta": {"runner": "codex-cli"},+ }++ with pytest.raises(OSError, match="test stops at CreateProcess"):+ await host._spawn(frame)+ repaired = os.environ["PATH"]+ with pytest.raises(OSError, match="test stops at CreateProcess"):+ await host._spawn(frame)++ assert observed_paths == [repaired, repaired]+ assert path_augment.ensure_cli_paths() == []+ assert os.environ["PATH"] == repaired