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(parity): close the small macOS/Linux gaps from the os-parity register
Ruben Lütke5db06c590034
diff --git a/.gitattributes b/.gitattributesindex 288c434d38..a679b8e6cd 100644--- a/.gitattributes+++ b/.gitattributes@@ -29,6 +29,9 @@ verify-wave6.sh text eol=lf# Git hooks run through a POSIX shell and must never be checked out as CRLF..githooks/* text eol=lf+# POSIX launcher (parity twin of run.bat) — CRLF breaks the shebang.+run.sh text eol=lf+# The supply-chain documentation, workflows, and in-toto layout are# also pinned to LF so any future inclusion in the signed-artifact# set does not require revisiting this file.diff --git a/jarvis/audio/capture.py b/jarvis/audio/capture.pyindex e3bc8c7c87..720648ee5b 100644--- a/jarvis/audio/capture.py+++ b/jarvis/audio/capture.py@@ -151,6 +151,10 @@ _INPUT_DEPRIORITIZE = (# Forensics 2026-04-26: Logitech PRO X on WASAPI silently killed the wake# loop (exception swallowed in the asyncio task), which is why# "Hey Jarvis" had no effect. Prioritising MME fixes this.+# Cross-platform note: WINDOWS host-API names by design — on macOS ("Core+# Audio") and Linux ("ALSA"/"JACK") nothing matches, so ranking falls through+# to the OS default enumeration order. Intentionally inert-by-data; add+# macOS/Linux preferences as new entries if ever needed, don't platform-gate._HOSTAPI_PREFERENCE = {"MME": 0,"Windows DirectSound": 1,diff --git a/jarvis/audio/player.py b/jarvis/audio/player.pyindex e198e572c0..0016762b20 100644--- a/jarvis/audio/player.py+++ b/jarvis/audio/player.py@@ -91,6 +91,13 @@ _HEADSET_PRIORITY = (#: WDM-KS now receives the default rank of 99 (effective last) and is also#: actively filtered out in ``_resolve_output_device`` when the same physical#: device is available on another host API.+#:+#: Cross-platform note: these keys are WINDOWS host-API names by design. On+#: macOS ("Core Audio") and Linux ("ALSA"/"JACK") nothing matches, every host+#: API gets the default rank 99, and PortAudio's enumeration order (= the OS+#: default) wins. That inert-by-data behavior is intentional — do not "fix"+#: it by adding a platform guard, and keep any future macOS/Linux preference+#: as new table entries, never as a rewrite of the ranking logic._HOSTAPI_PREFERENCE = {"Windows WASAPI": 0, # modern, reliable mono routing, blocking OK"Windows DirectSound": 1,@@ -986,4 +993,7 @@ class AudioPlayer:stream.close()except Exception: # noqa: BLE001log.debug("Output stream close during shutdown failed", exc_info=True)- sd.stop()+ # sounddevice is None on hosts without PortAudio (headless server) —+ # stop() must stay callable there instead of raising AttributeError.+ if sd is not None:+ sd.stop()diff --git a/jarvis/ui/shell/single_instance.py b/jarvis/ui/shell/single_instance.pyindex bd1c6d81d1..6ce7af100a 100644--- a/jarvis/ui/shell/single_instance.py+++ b/jarvis/ui/shell/single_instance.py@@ -2,11 +2,13 @@**Two-layer strategy:**-1. **Named mutex via pywin32** — atomic primary claim. OS-guaranteed- cleanup on crash (the kernel releases the handle), no stale- lock files. More robust than `filelock` on Windows.+1. **Atomic primary claim with kernel-guaranteed crash cleanup:**+ a named mutex via pywin32 on Windows, an exclusive non-blocking+ ``flock`` on ``instance.lock`` on POSIX. In both cases the OS releases+ the claim when the process dies (handle close / fd close), so there are+ no stale locks to garbage-collect.-2. **Session file** (`%LOCALAPPDATA%\\Jarvis\\session.json`) — stores the port ++2. **Session file** (``<user-app-dir>/session.json``) — stores the port +token of the running primary instance, so a secondary can ping it on``/internal/activate``. Token-protected: owner-only 0600 on POSIX(explicit), per-user profile ACL on Windows.@@ -37,6 +39,10 @@ logger = logging.getLogger(__name__)MUTEX_NAME = "Global\\PersonalJarvis_v1"SESSION_FILENAME = "session.json"+#: POSIX primary-claim lock file (flock'd exclusively by the primary). Distinct+#: from the launcher's ``acquire_single_instance_lock`` file so the two+#: mechanisms can never contend for the same path.+LOCK_FILENAME = "instance.lock"def _app_data_dir() -> Path:@@ -50,12 +56,13 @@ def _app_data_dir() -> Path:@dataclass(slots=True)class InstanceClaim:- """Handle to the active mutex — call `release()` on shutdown."""+ """Handle to the active claim — call `release()` on shutdown."""_mutex: Any = None+ _lock_fd: int | None = None_session_file: Path | None = Nonedef release(self) -> None:- # Release the mutex+ # Release the Windows mutexif self._mutex is not None:try:import win32api # type: ignore[import-not-found]@@ -66,6 +73,13 @@ class InstanceClaim:except Exception: # noqa: BLE001passself._mutex = None+ # Release the POSIX flock (closing the fd drops the kernel lock)+ if self._lock_fd is not None:+ try:+ os.close(self._lock_fd)+ except OSError:+ pass+ self._lock_fd = None# Clean up the session fileif self._session_file is not None:try:@@ -103,11 +117,14 @@ class SingleInstance:"""Primary claim — returns an `InstanceClaim`, or None if anotherprocess is already active."""+ if os.name != "nt":+ return self._try_claim_posix()try:import win32event # type: ignore[import-not-found]import winerror # type: ignore[import-not-found]except ImportError:- # Not Windows — no mutex, just report as primary.+ # Windows without pywin32 — no mutex available, report as primary+ # (the load-bearing launcher lock still enforces exclusivity).self._on_primary_claim()return InstanceClaim(_mutex=None, _session_file=self.session_file)@@ -125,6 +142,36 @@ class SingleInstance:self._on_primary_claim()return InstanceClaim(_mutex=mutex, _session_file=self.session_file)+ def _try_claim_posix(self) -> InstanceClaim | None:+ """POSIX primary claim via an exclusive non-blocking ``flock``.++ Same guarantee class as the Windows named mutex: the kernel drops the+ lock when the holding process dies (fd close), so a crashed primary+ never leaves a stale claim behind.+ """+ try:+ import fcntl+ except ImportError: # pragma: no cover — fcntl exists on all POSIX+ self._on_primary_claim()+ return InstanceClaim(_session_file=self.session_file)++ lock_path = self._app_dir / LOCK_FILENAME+ try:+ fd = os.open(lock_path, os.O_RDWR | os.O_CREAT, 0o600)+ except OSError:+ # Unwritable app dir — claiming must not crash the boot; report+ # primary like the historic (no-op) behavior did.+ logger.warning("single-instance lock file unavailable: %s", lock_path)+ self._on_primary_claim()+ return InstanceClaim(_session_file=self.session_file)+ try:+ fcntl.flock(fd, fcntl.LOCK_EX | fcntl.LOCK_NB)+ except OSError:+ os.close(fd)+ return None+ self._on_primary_claim()+ return InstanceClaim(_lock_fd=fd, _session_file=self.session_file)+def write_session(self, *, port: int, token: str) -> None:data = {"port": port, "token": token, "pid": os.getpid()}path = self.session_filediff --git a/jarvis/ui/web/launcher.py b/jarvis/ui/web/launcher.pyindex 5fd5c7a397..e73f14d7bd 100644--- a/jarvis/ui/web/launcher.py+++ b/jarvis/ui/web/launcher.py@@ -713,7 +713,10 @@ async def _run_headless(args) -> int:except (ValueError, AttributeError):pass- print(f"Jarvis backend is running at http://127.0.0.1:{cfg.ui.admin_api_port}")+ # Show the actual bind host (JARVIS_BIND_HOST may be 0.0.0.0 on a VPS);+ # bracket IPv6 literals so the printed URL stays valid.+ _url_host = f"[{_host}]" if ":" in _host else _host+ print(f"Jarvis backend is running at http://{_url_host}:{cfg.ui.admin_api_port}")print("Ctrl+C to quit.")try:diff --git a/run.sh b/run.shnew file mode 100644index 0000000000..296539f258--- /dev/null+++ b/run.sh@@ -0,0 +1,50 @@+#!/usr/bin/env sh+# Personal Jarvis - POSIX launcher (macOS + Linux). Parity twin of run.bat.+#+# Usage: ./run.sh [--debug|--headless|--dev]+# --debug verbose logging, foreground console+# --headless API/WS backend only, no desktop window or voice+# --dev frontend served from the Vite dev server (port 5173)+#+# Runs in the foreground (Ctrl+C stops Jarvis); append `&` to detach.+set -u+cd "$(dirname "$0")" || exit 1++# Activate the project venv when present (mirrors run.bat).+if [ -f ".venv/bin/activate" ]; then+ # shellcheck disable=SC1091+ . ".venv/bin/activate"+fi++# Pick the interpreter - Debian/Ubuntu ship python3 without a python alias.+if command -v python >/dev/null 2>&1; then+ PY=python+elif command -v python3 >/dev/null 2>&1; then+ PY=python3+else+ echo "error: no Python interpreter found on PATH" >&2+ exit 1+fi++# Pre-boot drift check (optional, needs PowerShell 7+). Mirrors run.bat:+# always continues on failure, never blocks boot, skipped without pwsh.+if [ -f "scripts/check-working-tree.ps1" ] && command -v pwsh >/dev/null 2>&1; then+ pwsh -NoProfile -File "scripts/check-working-tree.ps1" || true+fi++case "${1:-}" in+ --debug)+ # --debug is launcher-local: visible console + verbose logging.+ # Forwarding it to the launcher would trip argparse (see run.bat).+ JARVIS_DEBUG=1 exec "$PY" -m jarvis.ui.web.launcher+ ;;+ --headless)+ exec "$PY" -m jarvis.ui.web.launcher --headless+ ;;+ --dev)+ JARVIS_DEV=1 exec "$PY" -m jarvis.ui.web.launcher --dev+ ;;+ *)+ exec "$PY" -m jarvis.ui.web.launcher+ ;;+esacdiff --git a/tests/unit/ui/test_session_file_permissions.py b/tests/unit/ui/test_session_file_permissions.pyindex 5d6dae27ac..46c4d28223 100644--- a/tests/unit/ui/test_session_file_permissions.py+++ b/tests/unit/ui/test_session_file_permissions.py@@ -41,3 +41,22 @@ def test_write_session_repairs_preexisting_loose_permissions(tmp_path):os.chmod(loose, 0o644) # what older builds left behindSingleInstance(app_dir=tmp_path).write_session(port=1, token="t")assert stat.S_IMODE(loose.stat().st_mode) == 0o600++[email protected](sys.platform == "win32", reason="flock is POSIX-only")+def test_posix_claim_is_exclusive_and_released(tmp_path):+ """The POSIX flock claim must actually enforce single-instance semantics:+ a second claim on the same app dir fails while the first is held and+ succeeds again after release()."""+ first = SingleInstance(app_dir=tmp_path).try_claim()+ assert first is not None++ # flock is per-(process, fd); a second fd in the SAME process still+ # observes the exclusivity because we use LOCK_NB on a fresh descriptor.+ second = SingleInstance(app_dir=tmp_path).try_claim()+ assert second is None++ first.release()+ third = SingleInstance(app_dir=tmp_path).try_claim()+ assert third is not None+ third.release()