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(missions): start a Windows worker command without PowerShell module discovery (#608)
Ruben Lütkecd6473a893c1
diff --git a/jarvis/missions/workers/api_agent_tools.py b/jarvis/missions/workers/api_agent_tools.pyindex 7c1d2b9e3a..4b5cfbea69 100644--- a/jarvis/missions/workers/api_agent_tools.py+++ b/jarvis/missions/workers/api_agent_tools.py@@ -22,7 +22,7 @@ worktree, process containment, and post-run diff/path review remain mandatory.from __future__ import annotationsimport asyncio-import json+import base64import loggingimport osimport re@@ -42,27 +42,37 @@ from .process_utils import create_worker_subprocess, resolve_node_executablelogger = logging.getLogger(__name__)+# The launcher names no cmdlet, only language keywords and .NET calls. Resolving+# a cmdlet that is not loaded yet makes PowerShell analyse every module on the+# machine's module path before it reaches its own built-in ones, and the+# mission-scoped profile gives it no analysis cache to reuse: a machine with+# many installed modules paid tens of seconds for that before each command._WINDOWS_GATE_SCRIPT = """param([Parameter(Mandatory=$true)][string]$GatePath,[Parameter(Mandatory=$true)][string]$PayloadPath)$deadline = [DateTime]::UtcNow.AddSeconds(30)-while (-not (Test-Path -LiteralPath $GatePath -PathType Leaf)) {+while (-not [System.IO.File]::Exists($GatePath)) {if ([DateTime]::UtcNow -ge $deadline) {- Write-Error "Containment gate did not open before its deadline."+ [Console]::Error.WriteLine("Containment gate did not open before its deadline.")exit 125}- Start-Sleep -Milliseconds 10+ [System.Threading.Thread]::Sleep(10)}try {- $payload = Get-Content -LiteralPath $PayloadPath -Raw | ConvertFrom-Json+ $words = @()+ foreach ($line in [System.IO.File]::ReadAllLines($PayloadPath)) {+ $bytes = [System.Convert]::FromBase64String($line)+ $words += [System.Text.Encoding]::UTF8.GetString($bytes)+ }+ $executable = $words[0]$commandArgs = @()- foreach ($item in $payload.arguments) { $commandArgs += [string]$item }- & ([string]$payload.executable) @commandArgs+ for ($index = 1; $index -lt $words.Count; $index++) { $commandArgs += $words[$index] }+ & $executable @commandArgsif ($null -eq $LASTEXITCODE) { exit 1 }exit [int]$LASTEXITCODE} catch {- Write-Error $_+ [Console]::Error.WriteLine([string]$_)exit 1}"""@@ -637,8 +647,8 @@ def _prepare_windows_gated_launch(launcher therefore waits on a random gate file. Jarvis assigns that waitinglauncher to a non-breakaway Job Object first and creates the gate only afterassignment succeeds. The trusted launcher self-exits after 30 seconds if- Jarvis crashes in that narrow pre-assignment window. Target argv is JSON- data, never interpolated into PowerShell source.+ Jarvis crashes in that narrow pre-assignment window. Target argv is data,+ one base64 line per word, never interpolated into PowerShell source."""powershell = (shutil.which("powershell.exe", path=env.get("PATH"))@@ -667,17 +677,17 @@ def _prepare_windows_gated_launch(launch_dir.mkdir(parents=True, exist_ok=True)token = uuid.uuid4().hexscript_path = launch_dir / "contained-command.ps1"- payload_path = launch_dir / f"payload-{token}.json"+ payload_path = launch_dir / f"payload-{token}.txt"gate_path = launch_dir / f"gate-{token}"with contextlib_suppress(FileNotFoundError):gate_path.unlink()script_path.write_text(_WINDOWS_GATE_SCRIPT, encoding="utf-8")payload_path.write_text(- json.dumps(- {"executable": executable, "arguments": list(args)},- ensure_ascii=True,+ "".join(+ base64.b64encode(word.encode("utf-8")).decode("ascii") + "\n"+ for word in (executable, *args)),- encoding="utf-8",+ encoding="ascii",)command = [powershell,diff --git a/tests/missions/workers/test_api_agent_tools.py b/tests/missions/workers/test_api_agent_tools.pyindex a6bd3c3e50..cdb02ef3cb 100644--- a/tests/missions/workers/test_api_agent_tools.py+++ b/tests/missions/workers/test_api_agent_tools.py@@ -2,7 +2,9 @@from __future__ import annotationsimport asyncio+import jsonimport os+import reimport sysimport timefrom pathlib import Path@@ -96,6 +98,30 @@ async def test_command_nonzero_exit_is_error(tmp_path: Path) -> None:assert "exit 3" in out+async def test_command_arguments_reach_the_program_as_separate_words(tmp_path: Path) -> None:+ (tmp_path / "show_args.py").write_text(+ "import json, sys\nprint(json.dumps(sys.argv[1:]))\n", encoding="utf-8"+ )+ words = ["two words", "se\u00f1al", "--label=caf\u00e9 au lait", "-x"]+ out, err = await execute_worker_tool_async(+ "RunCommand",+ {"program": "python", "args": ["show_args.py", *words]},+ worktree=tmp_path,+ )+ assert err is False, out+ assert json.loads(out) == words+++def test_windows_launcher_names_no_cmdlet() -> None:+ """A cmdlet sends PowerShell through module discovery before every command.++ With the mission-scoped profile there is no analysis cache, so on a machine+ with many installed modules that lookup cost tens of seconds per command.+ """+ assert re.findall(r"\b[A-Za-z]+-[A-Za-z]+\b", aat._WINDOWS_GATE_SCRIPT) == []++def test_path_escape_is_rejected_on_write(tmp_path: Path) -> None:"""The model must never write outside the worktree (../ escape)."""out, err = execute_worker_tool(@@ -321,9 +347,8 @@ def _tree_script(tmp_path: Path, *, fast_leader: bool = False) -> Path:# Bounds for event-driven waits below; each returns as soon as its condition# holds. On Windows a command runs behind a PowerShell containment launcher,-# whose start-up alone took 10-20 s per command on the loaded CI runner (this-# file ran 116-233 s there against ~10 s on a desktop), so a short bound-# measures the runner, not the containment.+# and a hosted runner starts a process far slower than a desktop does, so a+# short bound measures the runner, not the containment._TREE_START_TIMEOUT_S = 120.0_TREE_REAP_TIMEOUT_S = 30.0