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(computers): a cancelled turn on a Windows computer ends its CLI there
rubenluetke10-beep6cd03bfeeb23
diff --git a/docs/os-parity.md b/docs/os-parity.mdindex 0ad8819c86..8f76f8b07d 100644--- a/docs/os-parity.md+++ b/docs/os-parity.md@@ -16,7 +16,7 @@ once (one `echo` that sh, cmd and PowerShell answer differently) and then:| Health check and facts | POSIX probe | PowerShell probe on stdin, same sections; no load average || Planting the app's key (password login) | `~/.ssh/authorized_keys` | PowerShell: `administrators_authorized_keys` for admins, ACL by SID (works on a German Windows), UTF-8 without BOM || Readiness and install | tmux, git, Node, CLIs; apt/dnf/yum/apk/pacman/brew | git (Git for Windows), Node, CLIs; winget and npm; "admin" instead of root |-| Society agent's CLI turn | `exec env … <cli>` on the command line | system prompt uploaded as a file, CLI started by a Git Bash launcher uploaded over SFTP |+| Society agent's CLI turn | `exec env … <cli>` on the command line; cancel = hang up | system prompt uploaded as a file, CLI started by a Git Bash launcher uploaded over SFTP; cancel ends the launcher's process tree with `taskkill /T` first, because hanging up ends only cmd and bash and left the CLI running (measured) || Society agent's shell tool | sh in `~/jarvis-agents/<id>` | Git Bash in the same folder; PowerShell when Git for Windows is missing || IDE panes | tmux session; survives app close and network loss, re-attached | no tmux: the agent runs in the SSH terminal (ConPTY) and ends with the channel; a plain terminal is PowerShell || IDE folder sync, conversation copy | POSIX scripts | the same scripts in Git Bash; SFTP paths as `/C:/…` |@@ -25,8 +25,10 @@ once (one `echo` that sh, cmd and PowerShell answer differently) and then:Git for Windows is the one prerequisite beyond the SSH server, and everyfeature that needs it says so in one sentence. Verified live against aWindows 11 Pro VM (German locale): facts, readiness, a CLI start through the-launcher, an agent shell command with non-ASCII output, a PowerShell pane,-and a git folder sent over and brought back with an edit made there. Covered+launcher, a cancelled turn leaving no process behind, an agent shell command+with non-ASCII output, a PowerShell pane (closing it, or the app, ends its+program there), and a git folder sent over and brought back with an edit made+there. Coveredby `tests/unit/computers/test_windows_remote.py` against a scripted WindowsSSH server. Not verified live: planting the key with a password (unit-testedonly; the VM already had the key), a Windows computer whose `DefaultShell` isdiff --git a/jarvis/agent_chat/remote_cli.py b/jarvis/agent_chat/remote_cli.pyindex 812eebcde0..e13bb1283f 100644--- a/jarvis/agent_chat/remote_cli.py+++ b/jarvis/agent_chat/remote_cli.py@@ -26,10 +26,11 @@ small Git Bash launcher uploaded next to it (``jarvis.computers.remote_os``).from __future__ import annotations+import asyncioimport contextlibimport loggingimport shlex-from collections.abc import Sequence+from collections.abc import Awaitable, Callable, Sequencefrom typing import Any, Finallog = logging.getLogger(__name__)@@ -165,13 +166,22 @@ class RemoteCliProcess:pid: int | None = None- def __init__(self, process: Any, stack: contextlib.AsyncExitStack) -> None:+ def __init__(+ self,+ process: Any,+ stack: contextlib.AsyncExitStack,+ *,+ stop: Callable[[], Awaitable[None]] | None = None,+ ) -> None:self._process = processself._stack = stackself.stdin = _Stdin(process.stdin)self.stdout = process.stdoutself.stderr = process.stderrself._closed = False+ #: Ends the remote process tree on a computer where hanging up does not.+ self._stop = stop+ self._stopping: asyncio.Task[None] | None = None@propertydef returncode(self) -> int | None:@@ -179,12 +189,25 @@ class RemoteCliProcess:return None if code is None else int(code)async def wait(self) -> int | None:+ if self._stopping is not None:+ # Shielded: a caller giving up on the wait must not cut the stop short.+ with contextlib.suppress(Exception):+ await asyncio.shield(self._stopping)with contextlib.suppress(Exception): # a torn-down channel reports no statusawait self._process.wait_closed()await self._release()return self.returncodedef kill(self) -> None:+ if self._stop is not None:+ if self._stopping is None:+ self._stopping = asyncio.get_running_loop().create_task(+ self._stop_then_hang_up(), name="remote-cli-stop"+ )+ return+ self._hang_up()++ def _hang_up(self) -> None:# Many sshd builds ignore signal requests; closing the channel hangs# up the remote command's terminal-less session instead.with contextlib.suppress(Exception):@@ -192,6 +215,24 @@ class RemoteCliProcess:with contextlib.suppress(Exception):self._process.close()+ async def _stop_then_hang_up(self) -> None:+ """Windows: hanging up ends only cmd and bash; the CLI below them lived on.++ So the process tree is ended first, on the same connection, and only+ then is the channel closed — and the connection released even when+ nobody waits for the process any more.+ """+ assert self._stop is not None+ try:+ await self._stop()+ except Exception as exc: # noqa: BLE001 — logged; hanging up below still runs+ log.warning("agent chat: stopping the remote CLI failed: %s", exc)+ finally:+ self._hang_up()+ with contextlib.suppress(Exception):+ await asyncio.wait_for(self._process.wait_closed(), timeout=15)+ await self._release()+async def _release(self) -> None:if self._closed:return@@ -253,11 +294,19 @@ async def _windows_launch(uploaded_prompt_files=uploaded,)launcher = f"{remote_os.LAUNCH_DIR}/{remote_os.launcher_name(agent_id)}"- script = remote_os.launcher_script(remote_cwd, command_argv, remote_env(env))+ script = remote_os.launcher_script(+ remote_cwd, command_argv, remote_env(env), pid_file=_pid_file(agent_id)+ )await remote_os.upload_text(opened, host, launcher, script)return host.launcher_command(launcher)+def _pid_file(agent_id: str) -> str:+ from jarvis.computers import remote_os++ return f"{remote_os.LAUNCH_DIR}/{remote_os.launcher_name(agent_id, '.pid')}"++async def spawn(computer_id: str,*,@@ -334,4 +383,11 @@ async def spawn(except BaseException:await stack.aclose()raise- return RemoteCliProcess(process, stack)+ stop = None+ if host.windows:+ stop_command = remote_os.stop_script(_pid_file(agent_id))++ async def stop() -> None:+ await remote_os.run_bash(opened, host, stop_command, timeout_s=30)++ return RemoteCliProcess(process, stack, stop=stop)diff --git a/jarvis/computers/remote_os.py b/jarvis/computers/remote_os.pyindex c48aa0175e..9d95964f4a 100644--- a/jarvis/computers/remote_os.py+++ b/jarvis/computers/remote_os.py@@ -192,9 +192,22 @@ def forget(computer_id: str) -> None:_CACHE.pop(computer_id, None)-def launcher_script(cwd: str, argv: Sequence[str], env: Mapping[str, str] | None = None) -> str:- """The Git Bash file that starts ``argv`` in ``cwd`` with stdin and terminal intact."""+def launcher_script(+ cwd: str,+ argv: Sequence[str],+ env: Mapping[str, str] | None = None,+ *,+ pid_file: str | None = None,+) -> str:+ """The Git Bash file that starts ``argv`` in ``cwd`` with stdin and terminal intact.++ ``pid_file`` (relative to the home folder) receives the Windows id of the+ bash that becomes ``argv``'s parent: hanging up the SSH channel ends that+ bash but not the program below it, so :func:`stop_script` ends the tree.+ """lines = [f"cd -- {shlex.quote(cwd)} || exit 97"]+ if pid_file:+ lines.append(f'cat /proc/$$/winpid > "$HOME"/{shlex.quote(pid_file)} 2>/dev/null || true')for key, value in (env or {}).items():lines.append(f"export {key}={shlex.quote(value)}")lines.append(_NO_PATH_CONVERSION)@@ -202,6 +215,17 @@ def launcher_script(cwd: str, argv: Sequence[str], env: Mapping[str, str] | Nonereturn "\n".join(lines) + "\n"+def stop_script(pid_file: str) -> str:+ """The Git Bash script that ends a launcher's whole process tree (Windows)."""+ return (+ f'f="$HOME"/{shlex.quote(pid_file)}\n'+ '[ -f "$f" ] || exit 0\n'+ 'p=$(cat "$f"); rm -f "$f"\n'+ '[ -n "$p" ] && MSYS_NO_PATHCONV=1 taskkill /PID "$p" /T /F >/dev/null 2>&1\n'+ "exit 0\n"+ )++def launcher_name(identity: str, suffix: str = ".sh") -> str:"""A file name (under :data:`LAUNCH_DIR`) that is safe on every shell."""return re.sub(r"[^A-Za-z0-9_.-]", "-", identity)[:64] + suffixdiff --git a/tests/unit/computers/test_windows_remote.py b/tests/unit/computers/test_windows_remote.pyindex fc26c4c9ba..8d64079c49 100644--- a/tests/unit/computers/test_windows_remote.py+++ b/tests/unit/computers/test_windows_remote.py@@ -441,3 +441,47 @@ async def test_keep_working_never_moves_panes_to_windows(assert await offload_on_quit.offload_before_quit(registry) == []assert placed == []+++async def test_cancelling_a_turn_ends_the_remote_process_tree(+ desk, # noqa: ANN001+ box: WindowsBox,+ ssh_server: FakeSshServer,+ tmp_path: Path,+) -> None:+ """Hanging up ends only cmd and bash on Windows; the CLI below them lived on."""+ stopped = asyncio.Event()++ async def handler(command: str, process: Any) -> bool:+ if "--noprofile --norc" in command:+ await stopped.wait() # the CLI runs until its tree is ended+ process.exit(1)+ return True+ if "-l -s" in command and GIT_BASH in command:+ script = await process.stdin.read()+ box.scripts.append(("bash", script))+ if "taskkill" in script:+ stopped.set()+ elif "pwd -W" in script:+ process.stdout.write(f"{HOME}/jarvis-agents/scout\nfound\n")+ process.exit(0)+ return True+ return await box(command, process)++ ssh_server.state.handler = handler+ proc = await remote_cli.spawn(+ desk.id,+ agent_id="scout",+ runner="claude-cli",+ binary="claude",+ argv=["claude", "--print"],+ local_cwd="/ws",+ env={},+ )+ launcher = (tmp_path / "remote-home/jarvis-agents/.launch/scout.sh").read_text(encoding="utf-8")+ assert 'cat /proc/$$/winpid > "$HOME"/jarvis-agents/.launch/scout.pid' in launcher++ proc.kill()+ assert await asyncio.wait_for(proc.wait(), timeout=30) == 1+ stop = next(script for _kind, script in box.scripts if "taskkill" in script)+ assert "jarvis-agents/.launch/scout.pid" in stop and "/T /F" in stop