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(overlay): gate every off-main-thread Tk creator off on macOS (BUG-057)
Ruben Lütke28390b2ac5a1
diff --git a/docs/BUGS.md b/docs/BUGS.mdindex f4fa967acb..f93ce6b34a 100644--- a/docs/BUGS.md+++ b/docs/BUGS.md@@ -3719,14 +3719,12 @@ user-audible dead air.**Fix.** A dispatch-time dead-air bridge in the deterministic delegate path(`jarvis/realtime/session.py`). When the delegated action is still pending-`_DELEGATE_BRIDGE_DELAY_S` (2 s) after dispatch, `_run_delegate_bridge`-injects `_delegate_bridge_prompt` into the LIVE model — one voice per call-(BUG-049) — ordering exactly one short interim sentence in the conversation-language, with outcome claims, answer content, and function calls forbidden-(the line is contextual, never a canned pool). The withhold gate opens only-for this instruction-bounded response (`bridge_delivery_started`), and the-held `turn_complete` path flushes the bridge audio tail instead of draining-it. Necessity-gated: a result faster than the delay (`result_ready`) skips+`_DELEGATE_BRIDGE_DELAY_S` (now 6 s) after dispatch, `_run_delegate_bridge`+asks the LIVE model to voice one fixed localized progress template — one voice+per call (BUG-049). The complete bridge transcript and audio stay withheld+until the transcript deterministically matches that exact template. A ready+trusted result preempts an active bridge so it never waits behind interim+speech. Necessity-gated: a result faster than the delay (`result_ready`) skipsthe bridge entirely. The bridge task is deliberately NOT a tracked delegatetask, so a sleeping timer can never hold a turn open, defer a VAD edge, orrefuse an announcement. Secondary lever (still open): the ~10 s OpenRouter@@ -3740,10 +3738,10 @@ the result is still delivered live, not as a late follow-up) andchatter-free).**Class rule.** An interim ack that waits for the completion of the decision-it is meant to cover is not an ack. The bridge over dead air needs a latency-budget bounded by user patience (~2–3 s), independent of any model round —-and it must be a bystander: a helper task that merely waits must never feed-the liveness signals (turn hold, endpoint protection) that real work feeds.+it is meant to cover is not an ack. A realtime bridge must be late enough not+to serialize an ordinary result behind a second provider response, and it must+be a bystander: a helper task that merely waits must never feed the liveness+signals (turn hold, endpoint protection) that real work feeds.## BUG-052: Realtime records an empty response as success and returns to listening (HIGH, 2026-07-14)@@ -3883,7 +3881,7 @@ user lifecycle action, configured inactivity, shutdown, or a genuinelyunrecoverable failure; recoverable control-plane races must never masquerade ashang-up.-## BUG-054: The realtime dead-air bridge invents a connected-tool result before the tool runs (HIGH, OPEN, 2026-07-14)+## BUG-054: The realtime dead-air bridge invents a connected-tool result before the tool runs (HIGH, FIXED 2026-07-14)**Symptom.** In the same 09:04 session as BUG-053, the user asked Jarvis to listtheir notebooks. Jarvis spoke five plausible-looking notebook names as though@@ -3930,25 +3928,26 @@ prompt compliance became a correctness boundary again. Starting a real missionproves that work exists, but it does not prove any result that the interim modelchooses to state.-**Required correction.** This incident is diagnosed and recorded; the runtime-repair has not yet been applied. The bridge must become structurally incapable-of supplying answer content:--1. Keep bridge audio withheld until the full bridge transcript passes a strict,- deterministic progress-only contract. The safest contract is an exact- localized status template (rendered in the already resolved turn language),- not an open-ended instruction to invent a sentence. A non-conforming bridge- is dropped without affecting the running action.+**Fix.** The bridge is now structurally incapable of supplying answer content:++1. Bridge audio stays withheld until the full transcript exactly matches a+ fixed localized status template rendered in the resolved turn language. A+ non-conforming bridge is dropped without affecting the running action.2. Never publish bridge text as `ResponseGenerated` or ordinary assistant turncontent. It is `SpeechSpoken(progress)` only and must be excluded from factextraction, personal-memory journaling, and answer history.3. Keep the real answer gate closed until the delegated result is complete andits trusted payload is being delivered. Mission-start evidence may authorizeonly a progress status, never a factual result.-4. Add a hostile-provider regression test whose bridge ignores the prompt and- emits a plausible list. Assert zero leaked PCM, no authoritative response or- memory candidate, a still-live delegated action, and later delivery of only- the grounded tool outcome.+4. A hostile-provider regression test makes the bridge ignore its prompt and+ emit a plausible list. It asserts zero leaked PCM, no authoritative response,+ a still-live delegated action, and later delivery of only the grounded tool+ outcome. A separate regression proves that a ready result interrupts an+ active bridge instead of queueing behind it.++The bridge threshold moved from 2 s to 6 s for realtime only. The classic+speech pipeline keeps its existing grounded tool acknowledgement; realtime+delegate calls explicitly suppress that duplicate manager-level event.**Class rule.** "Work started" and "result known" are different evidencelevels. An interim surface may report only the former, and its data must never@@ -4142,3 +4141,45 @@ Guards: `tests/unit/realtime/test_openai_realtime.py` (recoverable + skip),`tests/unit/realtime/test_scrub_gate.py` (detector diagnosis),`tests/unit/realtime/test_session.py` (withheld recording),`tests/unit/sessions/test_spoken_kind_parity.py`.++## BUG-057: Second macOS first-boot abort — JarvisBar/Orb Tk root created off the main thread (HIGH, FIXED 2026-07-14)++**Symptom.** After the BUG-056 tray fix shipped, a fresh macOS install still+died at first launch with the identical "Python quit unexpectedly" dialog.+The dialog is the generic macOS crash reporter — same look, DIFFERENT crash+site: with the tray gated off, boot now reached the on-screen overlay.++**Root cause.** The desktop backend runs on the ``jarvis-backend`` worker+thread; its boot task builds the default overlay surface via+``DesktopApp._build_overlay_surface`` → ``JarvisBarOverlay.start_in_thread()``+which creates the Tk root + mainloop on the daemon thread+``jarvisbar-tk-mainloop``. Aqua-Tk is AppKit-backed and main-thread-only on+macOS: a worker-thread Tk root aborts the whole process with a native,+uncatchable assertion — exactly the BUG-056 class, one layer further into+boot. Same defect in three siblings: the mascot ``OrbOverlay`` (thread+``orb-tk-mainloop``), the opt-in ``TkVirtualCursor`` (thread+``virtual-cursor``), and ``make_overlay_surface`` which handed darwin a+``TkColorKeyOverlay``. A full boot-path audit confirmed the remaining AppKit+touchpoints are safe (Dock icon + pywebview window run on the main thread).++**Fix (2026-07-14).** darwin gates at every off-main-thread Tk creator, all+degrading to logged English no-ops (AD-6/AD-11):+``_build_overlay_surface`` returns the existing ``NullOverlay`` (bridge+wiring stays intact), ``JarvisBarOverlay.start_in_thread`` /+``OrbOverlay.start_in_thread`` / ``TkVirtualCursor.start`` no-op as+backstops for any other caller, and ``make_overlay_surface`` sends darwin to+the tray floor. macOS keeps the desktop window + Dock icon. Guards:+``tests/unit/ui/test_macos_ui_main_thread_gates.py`` (incl. an AD-7+windows-still-spawns test),+``tests/overlay/test_overlay_surface.py::test_factory_selects_tray_floor_on_macos``.++**Follow-up (needs real Mac hardware).** A visible macOS bar/orb needs a+main-thread or own-process host — same follow-up as the BUG-056 menu-bar+icon, tracked in the cross-platform FIX-TRACKER.++**Class rule.** BUG-056 generalizes: on macOS EVERY UI toolkit in the+process (AppKit, Aqua-Tk, pystray) is main-thread-only, and the "Python+quit unexpectedly" dialog looks identical for every native abort — fixing+one crash site just reveals the next one down the boot path. Audit the+WHOLE boot path for off-main-thread UI creation at once (as done here),+never one dialog at a time.diff --git a/jarvis/overlay/surface.py b/jarvis/overlay/surface.pyindex 7da4b457ed..6a39f0f43f 100644--- a/jarvis/overlay/surface.py+++ b/jarvis/overlay/surface.py@@ -177,7 +177,9 @@ class TkColorKeyOverlay:def make_overlay_surface(*, capabilities: Any = None) -> OverlaySurface:"""Select the orb surface for this host (AD-11). **Never raises** (AD-6).- * ``win32`` / ``darwin`` with ``capabilities.has_overlay`` → :class:`TkColorKeyOverlay`.+ * ``win32`` with ``capabilities.has_overlay`` → :class:`TkColorKeyOverlay`.+ * ``darwin`` → tray floor (Aqua-Tk is main-thread-only; a worker-thread+ Tk root aborts the process natively — BUG-057).* ``linux`` with a display and not Wayland → :class:`LinuxBestEffortOverlay`(which itself degrades to the tray when the color-key probe fails).* everything else (``not has_overlay``, no display, Wayland, headless) →@@ -197,7 +199,11 @@ def make_overlay_surface(*, capabilities: Any = None) -> OverlaySurface:# re-detect when the snapshot somehow lacks a platform field.plat = getattr(caps, "platform", None) or detect_platform()- if plat in ("win32", "darwin") and getattr(caps, "has_overlay", False):+ # darwin deliberately falls through to the tray floor: this factory's+ # surfaces run their Tk mainloop on a worker thread, and Aqua-Tk (like+ # AppKit) is main-thread-only on macOS — a Tk root there aborts the+ # process natively (BUG-057, same class as the BUG-056 tray).+ if plat == "win32" and getattr(caps, "has_overlay", False):return TkColorKeyOverlay()if plat == "linux":diff --git a/jarvis/ui/desktop_app.py b/jarvis/ui/desktop_app.pyindex 755c36b151..4c790bf7ba 100644--- a/jarvis/ui/desktop_app.py+++ b/jarvis/ui/desktop_app.py@@ -1918,6 +1918,24 @@ class DesktopApp:signal. Runtime surfaces keep their immediate behavior. A non-persistentbar / the mascot still starts withdrawn and pops on a real session."""+ if sys.platform == "darwin":+ # This runs on the jarvis-backend worker thread; Aqua-Tk (like+ # AppKit) is main-thread-only on macOS, so a bar/mascot Tk root+ # here aborts the WHOLE process natively — the second macOS+ # first-boot crash (BUG-057; the first was the BUG-056 tray).+ # NullOverlay keeps the bridge wiring intact; the desktop window+ # + Dock icon remain the macOS surface until the overlay is+ # hosted in its own process.+ from loguru import logger++ from jarvis.ui.jarvisbar import NullOverlay++ logger.info(+ "On-screen overlay disabled on macOS (style={}): Tk windows "+ "are main-thread-only there — using the no-op surface.",+ style,+ )+ return NullOverlay()if style == "none":from jarvis.ui.jarvisbar import NullOverlaydiff --git a/jarvis/ui/jarvisbar/overlay.py b/jarvis/ui/jarvisbar/overlay.pyindex 98ef85bffb..87fc7bccbf 100644--- a/jarvis/ui/jarvisbar/overlay.py+++ b/jarvis/ui/jarvisbar/overlay.py@@ -470,6 +470,19 @@ class JarvisBarOverlay:return (not self._persistent) or getattr(self, "_startup_gated", False)def start_in_thread(self, timeout: float = 3.0) -> None:+ if sys.platform == "darwin":+ # Aqua-Tk (like AppKit) is main-thread-only on macOS: creating the+ # Tk root on this worker thread aborts the WHOLE process with a+ # native, uncatchable assertion — the "Python quit unexpectedly"+ # first-boot crash (BUG-057, same class as the BUG-056 tray). The+ # desktop boot substitutes a NullOverlay before ever reaching+ # this; the gate is the backstop for any other caller.+ log.info(+ "JarvisBar not started: macOS allows Tk windows on the main "+ "thread only — running without the on-screen bar."+ )+ return+def _run() -> None:try:self.start()diff --git a/tests/overlay/test_overlay_surface.py b/tests/overlay/test_overlay_surface.pyindex c2def5e669..37fcce5bdb 100644--- a/tests/overlay/test_overlay_surface.py+++ b/tests/overlay/test_overlay_surface.py@@ -129,9 +129,15 @@ def test_factory_selects_tk_on_windows():assert isinstance(surface, OverlaySurface)-def test_factory_selects_tk_on_macos():+def test_factory_selects_tray_floor_on_macos():+ # NOT TkColorKeyOverlay: the factory's surfaces run Tk on a worker+ # thread, and Aqua-Tk is main-thread-only on macOS — a Tk root there+ # aborts the process natively (BUG-057). The tray floor is the degrade.+ from jarvis.overlay.tray_surface import TrayOnlySurface+surface = make_overlay_surface(capabilities=fake_macos_capabilities())- assert isinstance(surface, TkColorKeyOverlay)+ assert isinstance(surface, TrayOnlySurface)+ assert not isinstance(surface, TkColorKeyOverlay)def test_factory_selects_linux_best_effort_on_x11():diff --git a/tests/unit/ui/test_macos_ui_main_thread_gates.py b/tests/unit/ui/test_macos_ui_main_thread_gates.pynew file mode 100644index 0000000000..bb7b41eae1--- /dev/null+++ b/tests/unit/ui/test_macos_ui_main_thread_gates.py@@ -0,0 +1,123 @@+"""macOS main-thread gates for every off-main-thread Tk/AppKit UI creator.++AppKit and Aqua-Tk are main-thread-only on macOS: creating a Tk root (or an+NSStatusItem) on a worker thread aborts the WHOLE process with a native,+uncatchable assertion — the "Python quit unexpectedly" first-boot crash class+(BUG-056 tray, BUG-057 bar/orb). The desktop backend runs on a worker thread,+so on darwin every one of these creators must degrade to a logged no-op+instead of spawning its Tk thread.++Seam-level: sys.platform is forced via monkeypatch — proven on this Windows+host without real Mac hardware (same pattern as test_tray.py).+"""+from __future__ import annotations++import logging+import threading+from types import SimpleNamespace+++class _ThreadSpawnRecorder:+ """Fails the test if code under a darwin gate still spawns a thread."""++ def __init__(self) -> None:+ self.spawned: list[str] = []++ def __call__(self, *args, **kwargs): # noqa: ANN002, ANN003+ self.spawned.append(kwargs.get("name", "?"))+ raise AssertionError(+ f"threading.Thread spawned under the darwin gate: {kwargs.get('name')}"+ )+++def test_jarvisbar_start_in_thread_is_noop_on_macos(monkeypatch, caplog) -> None:+ from jarvis.ui.jarvisbar import overlay as bar_mod++ monkeypatch.setattr("sys.platform", "darwin")+ recorder = _ThreadSpawnRecorder()+ monkeypatch.setattr(bar_mod.threading, "Thread", recorder)+ bar = bar_mod.JarvisBarOverlay(persistent=True, accent="#e7c46e")+ with caplog.at_level(logging.INFO):+ bar.start_in_thread(timeout=0.1)+ assert recorder.spawned == []+ assert "main thread" in caplog.text.lower()+++def test_orb_overlay_start_in_thread_is_noop_on_macos(monkeypatch, caplog) -> None:+ from ui.orb import overlay as orb_mod++ monkeypatch.setattr("sys.platform", "darwin")+ recorder = _ThreadSpawnRecorder()+ monkeypatch.setattr(orb_mod.threading, "Thread", recorder)+ orb = orb_mod.OrbOverlay(sticky=False, mic_reactive=False)+ with caplog.at_level(logging.INFO):+ orb.start_in_thread(timeout=0.1)+ assert recorder.spawned == []+ assert "main thread" in caplog.text.lower()+++def test_virtual_cursor_start_returns_false_on_macos(monkeypatch, caplog) -> None:+ from ui.orb import virtual_cursor_window as vc_mod++ monkeypatch.setattr("sys.platform", "darwin")+ recorder = _ThreadSpawnRecorder()+ monkeypatch.setattr(vc_mod.threading, "Thread", recorder)+ cursor = vc_mod.TkVirtualCursor()+ with caplog.at_level(logging.INFO):+ assert cursor.start(timeout_s=0.1) is False+ assert recorder.spawned == []+++def test_desktop_build_overlay_surface_returns_nulloverlay_on_macos(+ monkeypatch,+) -> None:+ from jarvis.ui.desktop_app import DesktopApp+ from jarvis.ui.jarvisbar.null_overlay import NullOverlay++ monkeypatch.setattr("sys.platform", "darwin")+ app = DesktopApp.__new__(DesktopApp) # bypass heavy __init__+ app.cfg = SimpleNamespace(+ ui=SimpleNamespace(+ orb_style="jarvis_bar",+ bar_persistent=True,+ bar_accent="#e7c46e",+ orb_mascot_path="",+ )+ )+ for style in ("jarvis_bar", "mascot"):+ surface = app._build_overlay_surface(style)+ assert isinstance(surface, NullOverlay), style+++def test_overlay_factory_selects_tray_floor_on_macos() -> None:+ # make_overlay_surface runs on the desktop backend WORKER thread; a Tk+ # surface on darwin would abort the process natively. The tray floor is+ # the designed degrade (AD-11) — and the tray itself no-ops on darwin+ # (BUG-056), so macOS gets no crash and no stray window.+ from jarvis.overlay.surface import make_overlay_surface+ from jarvis.overlay.tray_surface import TrayOnlySurface+ from tests.fakes.fake_capabilities import fake_macos_capabilities++ surface = make_overlay_surface(capabilities=fake_macos_capabilities())+ assert isinstance(surface, TrayOnlySurface)+++def test_thread_spawners_still_run_on_windows(monkeypatch) -> None:+ # AD-7 guard: the darwin gates must not leak onto other platforms.+ from jarvis.ui.jarvisbar import overlay as bar_mod++ monkeypatch.setattr("sys.platform", "win32")+ spawned: list[str] = []++ class _FakeThread:+ def __init__(self, *args, **kwargs): # noqa: ANN002, ANN003+ spawned.append(kwargs.get("name", "?"))++ def start(self) -> None: ...++ monkeypatch.setattr(bar_mod.threading, "Thread", _FakeThread)+ bar = bar_mod.JarvisBarOverlay(persistent=True, accent="#e7c46e")+ bar._started = threading.Event()+ bar._started.set() # skip the wait — we only assert the spawn happened+ bar.start_in_thread(timeout=0.1)+ assert spawned == ["jarvisbar-tk-mainloop"]diff --git a/ui/orb/overlay.py b/ui/orb/overlay.pyindex 99ae5f338c..245b58f0cb 100644--- a/ui/orb/overlay.py+++ b/ui/orb/overlay.py@@ -2184,6 +2184,10 @@ class OrbOverlay:UI mutations are queued via `root.after(0, fn)` — ourshow/hide/set_mode/set_level methods already do this.+ On macOS this is a logged no-op: Aqua-Tk (like AppKit) is+ main-thread-only, and a Tk root on a worker thread aborts the whole+ process natively (BUG-057, same class as the BUG-056 tray).+Blocks until the window actually exists (self._started event),so the caller can safely call show()/hide() afterward withoutrunning into a None root.@@ -2191,6 +2195,13 @@ class OrbOverlay:import logging_log = logging.getLogger("jarvis.orb")+ if sys.platform == "darwin":+ _log.info(+ "Orb overlay not started: macOS allows Tk windows on the "+ "main thread only — running without the on-screen orb."+ )+ return+def _run():try:self.start(auto_demo=auto_demo)diff --git a/ui/orb/virtual_cursor_window.py b/ui/orb/virtual_cursor_window.pyindex 65028c7726..500e0adab2 100644--- a/ui/orb/virtual_cursor_window.py+++ b/ui/orb/virtual_cursor_window.py@@ -27,6 +27,7 @@ Cloud-first:from __future__ import annotationsimport logging+import sysimport threadingimport time@@ -159,6 +160,14 @@ class TkVirtualCursor:def start(self, *, timeout_s: float = 5.0) -> bool:"""Start the Tk thread. Returns True once the window is up."""+ if sys.platform == "darwin":+ # Aqua-Tk is main-thread-only on macOS; a Tk root on this worker+ # thread aborts the whole process natively (BUG-057 class).+ logger.info(+ "Virtual cursor overlay not started: macOS allows Tk windows "+ "on the main thread only — no-op."+ )+ return Falseif self._thread is not None:return self._ready.is_set()self._thread = threading.Thread(