Skip to content

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.

chore: auto-save WIP via Claude stop-hook safety net (2026-07-01 14:00)

Ruben Lütkeb8844b4f33dd
diff --git a/jarvis/plugins/tool/_http_pool.py b/jarvis/plugins/tool/_http_pool.py
index 6a4b55d2fd..88682af0af 100644
--- a/jarvis/plugins/tool/_http_pool.py
+++ b/jarvis/plugins/tool/_http_pool.py
@@ -12,6 +12,7 @@ client is never reused across loops — each ``pytest-asyncio`` test runs in its
own loop, and a tool instance reused across loops would otherwise raise
``RuntimeError: Event loop is closed``.
"""
+
from __future__ import annotations
from typing import Any
@@ -24,9 +25,7 @@ class HttpClientPool:
``httpx.MockTransport`` exactly as they did with the per-request clients.
"""
- def __init__(
- self, *, timeout_s: float = 20.0, transport: Any | None = None
- ) -> None:
+ def __init__(self, *, timeout_s: float = 20.0, transport: Any | None = None) -> None:
self._timeout_s = timeout_s
self._transport = transport
self._client: Any | None = None
@@ -41,9 +40,7 @@ class HttpClientPool:
loop = asyncio.get_running_loop()
client = self._client
if client is None or self._loop is not loop or client.is_closed:
- client = httpx.AsyncClient(
- timeout=self._timeout_s, transport=self._transport
- )
+ client = httpx.AsyncClient(timeout=self._timeout_s, transport=self._transport)
self._client = client
self._loop = loop
return client
diff --git a/jarvis/ui/jarvisbar/overlay.py b/jarvis/ui/jarvisbar/overlay.py
index f0c0510752..e0346acd94 100644
--- a/jarvis/ui/jarvisbar/overlay.py
+++ b/jarvis/ui/jarvisbar/overlay.py
@@ -91,6 +91,48 @@ def _primary_work_area() -> tuple[int, int, int, int] | None:
return None
+def _pin_bar_window_unaware() -> None:
+ """Pin the bar's Tk window to per-window DPI-UNAWARE (Windows only).
+
+ The bar must keep the exact size + look it has always had: a small pill that
+ Windows bitmap-UPSCALES to a comfortable physical size on a scaled display.
+ That upscaling only happens for a DPI-UNAWARE window. The recurring bug: the
+ process is made DPI-AWARE — by ``ensure_dpi_awareness`` above and, at runtime,
+ by pywebview's ``SetProcessDPIAware`` inside ``webview.start()`` — and an
+ awareness change strips the upscaling off any window that merely INHERITS the
+ process default. The already-visible bar then snaps to raw pixels (~2/3 size)
+ and jumps position mid-session; only a restart cures it.
+
+ Giving THIS thread an EXPLICIT ``DPI_AWARENESS_CONTEXT_UNAWARE`` before
+ ``tk.Tk()`` bakes that context into the bar window for its lifetime. Because
+ the process is already aware (``ensure_dpi_awareness`` ran first), the
+ window's context genuinely DIFFERS from the process, so the upscaling is
+ pinned: a later process-wide flip can no longer strip it. Verified live — a
+ 107x48 window pinned this way sits at 161x72 physical and STAYS 161x72 across
+ ``SetProcessDPIAware``. Geometry and pointer events both stay in the one
+ virtualized space, so dragging stays glued to the cursor. The renderer is not
+ touched: the bar looks identical, it just stops shrinking.
+
+ No-op off Windows, under pytest (never mutate the test runner's thread), and
+ on any Windows without the per-thread API; never blocks the bar on failure.
+ """
+ if sys.platform != "win32":
+ return
+ if "pytest" in sys.modules: # don't mutate the test runner thread's DPI context
+ return
+ try:
+ import ctypes
+ from ctypes import wintypes
+
+ user32 = ctypes.windll.user32
+ user32.SetThreadDpiAwarenessContext.restype = wintypes.HANDLE
+ user32.SetThreadDpiAwarenessContext.argtypes = [wintypes.HANDLE]
+ # DPI_AWARENESS_CONTEXT_UNAWARE is the sentinel handle value ((HANDLE)-1).
+ user32.SetThreadDpiAwarenessContext(wintypes.HANDLE(-1))
+ except Exception: # noqa: BLE001 — never block the bar on a DPI hiccup
+ log.debug("jarvisbar DPI unaware-pin skipped", exc_info=True)
+
+
class JarvisBarOverlay:
def __init__(
self,
diff --git a/tests/unit/plugins/tool/test_http_pool.py b/tests/unit/plugins/tool/test_http_pool.py
new file mode 100644
index 0000000000..c7e2145f10
--- /dev/null
+++ b/tests/unit/plugins/tool/test_http_pool.py
@@ -0,0 +1,55 @@
+"""Tests for the shared HTTP keep-alive pool used by the REST router tools.
+
+Regression guard for the plugin-latency fix: the gmail/vercel tools must reuse
+ONE warm ``httpx.AsyncClient`` across calls instead of opening a fresh client
+(new TLS handshake) per request.
+"""
+
+from __future__ import annotations
+
+import httpx
+import pytest
+
+from jarvis.plugins.tool._http_pool import HttpClientPool
+from jarvis.plugins.tool.gmail_rest import GmailRestTool
+
+
+async def test_pool_returns_same_client_within_a_loop() -> None:
+ pool = HttpClientPool()
+ try:
+ assert pool.client() is pool.client()
+ finally:
+ await pool.aclose()
+
+
+async def test_pool_rebinds_after_close() -> None:
+ pool = HttpClientPool()
+ first = pool.client()
+ await pool.aclose()
+ second = pool.client()
+ try:
+ assert first is not second # closed → a fresh client is created
+ finally:
+ await pool.aclose()
+
+
+async def test_gmail_reuses_one_client_across_calls() -> None:
+ """list_messages twice must ride the SAME pooled client — the second call
+ reuses the warm connection rather than re-handshaking."""
+
+ def handler(_req: httpx.Request) -> httpx.Response:
+ return httpx.Response(200, json={"messages": []})
+
+ tool = GmailRestTool(
+ access_token_provider=lambda: "at_1",
+ transport=httpx.MockTransport(handler),
+ )
+ await tool.list_messages(max_results=1)
+ first = tool._pool._client
+ assert first is not None
+
+ await tool.list_messages(max_results=1)
+ assert tool._pool._client is first