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-02 10:00)

Ruben Lütke4d796139b7fe
diff --git a/docs/local-wakeword/WAKE-LATENCY-AND-FALSE-FIRE-FIX-2026-07-02.md b/docs/local-wakeword/WAKE-LATENCY-AND-FALSE-FIRE-FIX-2026-07-02.md
index 7685b2bfee..c4079126a0 100644
--- a/docs/local-wakeword/WAKE-LATENCY-AND-FALSE-FIRE-FIX-2026-07-02.md
+++ b/docs/local-wakeword/WAKE-LATENCY-AND-FALSE-FIRE-FIX-2026-07-02.md
@@ -90,11 +90,36 @@ after-run below.
Torch-coexistence probe (3 torch-OpenMP burner threads in-process, 80 rounds
t2 / 40 rounds t1): **0 hangs both**; t2 median 1718 ms vs t1 2960 ms.
-### After fixes
-
-(pending)
+### After all fixes (production build: base/cpu/int8/threads=2/bias/de +
+strict matcher + cross-snapshot join)
+
+| metric | baseline | after |
+|---|---|---|
+| stream first-try hits | 3/13 (+1 wedge-recover) | 7–8/13, **0 wedge-recovers** (2 runs) |
+| stream word-end→trigger median / p95 | 2694 / 3910 ms | 1138–1389 / 2399–3047 ms |
+| warm transcribe median (same-day load) | 1356–2003 ms | 706–949 ms |
+| cold first transcribe | 2807–4463 ms | 1701–2446 ms |
+| false accepts: bare core word | **71.7 %** | **6.7 %** |
+| false accepts: ambient / quiet / silence | 1.7 / 0 / 0 % | 0 / 0 / 0 % |
+| recall orig / −30 dBFS | 100 % / 69–87.5 % | 100 % / 87.5 % |
+| stress (8 CPU burners): model teardowns | cascade (3 recovers/2 min live) | **0** across four 8 s timeouts |
+
+Remaining honest gaps: (a) stream misses concentrate at rms ≈ 0.003 windows —
+whisper-quiet speech at the silence-gate boundary, outside "normal speaking
+volume"; run-to-run stream variance under fluctuating machine load is ±1–2
+hits. (b) residual 6.7 % bare-core false accepts happen when the bias prompt
+hallucinates the prefix onto a bare-name window; eliminating the bias costs
+far more recall than it saves (matrix). (c) The KWS endgame (trained neural
+model per phrase) remains the path to sub-200 ms wakes.
## Cross-platform
-(pending — Windows measured; Linux via WSL Ubuntu; macOS by code-path
-neutrality: the touched files are pure Python + numpy + faster-whisper CPU.)
+- **Windows**: all numbers above; 1106 speech/stt/audio unit tests green.
+- **Linux (WSL Ubuntu, py3.12, faster-whisper 1.2.1)**: 64 wake unit tests
+ green; window bench (reduced set): recall 100 % orig / 75 % @−30 (n=4,
+ 1 gated), false accepts bare 8.3 % (1/12), ambient/quiet/silence 0 %, warm
+ median 1730 ms (CPU shared with the loaded Windows host — behaviour
+ identical, absolute times not comparable).
+- **macOS**: no hardware available. The touched files are pure Python +
+ numpy + faster-whisper CPU wheels with no OS-specific branch; verified by
+ the same tests running unmodified on both other OSes.
diff --git a/jarvis/cu/capture.py b/jarvis/cu/capture.py
index ee7f0847f6..bfa3dd87f5 100644
--- a/jarvis/cu/capture.py
+++ b/jarvis/cu/capture.py
@@ -73,18 +73,67 @@ def mss_grab(bbox: dict[str, int]) -> tuple[tuple[int, int], bytes]:
@dataclass(frozen=True)
class Frame:
- """One perception frame: the image the model sees + its mapper."""
+ """One perception frame: the image the model sees + its mapper.
+
+ ``sha256`` identifies the exact encoded image (blob dedup, events).
+ ``thumb`` is the PERCEPTUAL identity (see :func:`screen_thumb`): the
+ key the idempotency ledger and the no-progress guard compare on via
+ :func:`thumbs_similar`. An exact hash flips on every caret blink, which
+ let duplicate actions through as "the screen changed" (live rig run
+ 2026-07-02).
+ """
jpeg: bytes
image_width: int
image_height: int
mapper: CoordinateMapper
sha256: str
+ thumb: bytes
captured_at_ns: int
stable: bool
blob_path: str | None = None
+def screen_thumb(raw: tuple[tuple[int, int], bytes]) -> bytes:
+ """Grayscale 96x54 thumbnail bytes — the frame's perceptual identity.
+
+ Compared with :func:`thumbs_similar` (mean-abs-diff threshold), NOT by
+ equality/hash: any hash quantization has boundary artifacts where a
+ one-gray-level caret blink flips the identity and lets a duplicate
+ action through.
+ """
+ from PIL import Image # noqa: PLC0415
+
+ return Image.frombytes("RGB", raw[0], raw[1]).convert("L").resize(_THUMB_SIZE).tobytes()
+
+
+def thumbs_similar(
+ a: bytes | str, b: bytes | str, *, threshold: float = STABILITY_DIFF_THRESHOLD,
+) -> bool:
+ """Are two screen identities visually the same screen?
+
+ Fast-path equality; a real thumbnail pair is compared by mean absolute
+ difference (caret blinks / antialiasing noise stay below the threshold).
+ Opaque non-thumbnail keys (tests, foreign callers) fall back to equality.
+ """
+ if a == b:
+ return True
+ expected = _THUMB_SIZE[0] * _THUMB_SIZE[1]
+ if (
+ not isinstance(a, (bytes, bytearray))
+ or not isinstance(b, (bytes, bytearray))
+ or len(a) != expected
+ or len(b) != expected
+ ):
+ return False
+ from PIL import Image, ImageChops, ImageStat # noqa: PLC0415
+
+ img_a = Image.frombytes("L", _THUMB_SIZE, bytes(a))
+ img_b = Image.frombytes("L", _THUMB_SIZE, bytes(b))
+ mean = ImageStat.Stat(ImageChops.difference(img_a, img_b)).mean[0]
+ return mean <= threshold
+
+
def frames_differ(
a: tuple[tuple[int, int], bytes],
b: tuple[tuple[int, int], bytes],
@@ -204,6 +253,7 @@ def capture_stable_frame(
jpeg, iw, ih = _downscale_and_encode(
current, max_dimension=max_dimension, jpeg_quality=jpeg_quality,
)
+ thumb = screen_thumb(current)
mapper = CoordinateMapper(
capture_left=monitor.left,
capture_top=monitor.top,
@@ -232,6 +282,7 @@ def capture_stable_frame(
image_height=ih,
mapper=mapper,
sha256=sha,
+ thumb=thumb,
captured_at_ns=time.time_ns(),
stable=stable,
blob_path=blob_path,
diff --git a/jarvis/cu/engine.py b/jarvis/cu/engine.py
index a030e42864..713b33fbb9 100644
--- a/jarvis/cu/engine.py
+++ b/jarvis/cu/engine.py
@@ -485,13 +485,13 @@ async def run_cu_loop(
# circling — judge once (the goal may in fact be met), then stop.
if (
prev_sha is not None
- and frame.sha256 == prev_sha
+ and frame.phash == prev_sha
and not last_step_had_success
):
fruitless_steps += 1
else:
fruitless_steps = 0
- prev_sha = frame.sha256
+ prev_sha = frame.phash
last_step_had_success = False
if fruitless_steps >= _STUCK_FRAMES:
done, proof = await _judge_done(
@@ -692,7 +692,7 @@ async def run_cu_loop(
action = {**action, "x": sx, "y": sy}
# -- idempotency ledger -----------------------------------------
- if ledger.is_duplicate(action, frame.sha256, resolved_xy=resolved_xy):
+ if ledger.is_duplicate(action, frame.phash, resolved_xy=resolved_xy):
guard_hits += 1
history.append(
f"step {step_idx}: {_summarize_action(action)} REFUSED — "
@@ -729,7 +729,7 @@ async def run_cu_loop(
profiler.add("act", t0, step_idx)
t0 = time.monotonic()
if ok:
- ledger.record(action, frame.sha256, resolved_xy=resolved_xy)
+ ledger.record(action, frame.phash, resolved_xy=resolved_xy)
await asyncio.sleep(_EFFECT_SETTLE_S * settle_scale)
post = await asyncio.to_thread(grab_region, monitor.bbox)
rect = monitor.bbox
@@ -767,7 +767,7 @@ async def run_cu_loop(
profiler.add("act", t0, step_idx)
t0 = time.monotonic()
if ok:
- ledger.record(action, frame.sha256)
+ ledger.record(action, frame.phash)
if strict_verify:
landed = await verify_typed_text(action["text"])
if landed is False:
@@ -790,7 +790,7 @@ async def run_cu_loop(
ctx, "hotkey", {"keys": action["keys"]}, trace_id,
)
if ok:
- ledger.record(action, frame.sha256)
+ ledger.record(action, frame.phash)
profiler.add("act", t0, step_idx)
elif kind == "scroll":
@@ -802,7 +802,7 @@ async def run_cu_loop(
args["x"], args["y"] = int(action["x"]), int(action["y"])
ok, detail = await _dispatch_tool(ctx, "scroll", args, trace_id)
if ok:
- ledger.record(action, frame.sha256)
+ ledger.record(action, frame.phash)
profiler.add("act", t0, step_idx)
elif kind == "drag":
@@ -821,7 +821,7 @@ async def run_cu_loop(
trace_id,
)
if ok:
- ledger.record(action, frame.sha256)
+ ledger.record(action, frame.phash)
profiler.add("act", t0, step_idx)
elif kind == "open_app":
@@ -829,7 +829,7 @@ async def run_cu_loop(
ctx, "open_app", {"app_name": action["name"]}, trace_id,
)
if ok:
- ledger.record(action, frame.sha256)
+ ledger.record(action, frame.phash)
# Let the app paint its first window; the next perception's
# stability probe covers the rest.
await asyncio.sleep(1.0 * settle_scale)
@@ -841,7 +841,7 @@ async def run_cu_loop(
trace_id,
)
if ok:
- ledger.record(action, frame.sha256)
+ ledger.record(action, frame.phash)
profiler.add("act", t0, step_idx)
elif kind == "click_element":
@@ -850,7 +850,7 @@ async def run_cu_loop(
ctx, "click_element", {"name": action["name"]}, trace_id,
)
if ok:
- ledger.record(action, frame.sha256)
+ ledger.record(action, frame.phash)
profiler.add("act", t0, step_idx)
elif kind == "wait":
diff --git a/jarvis/cu/ledger.py b/jarvis/cu/ledger.py
index 7eaa35bc0a..fb6ee62e39 100644
--- a/jarvis/cu/ledger.py
+++ b/jarvis/cu/ledger.py
@@ -7,13 +7,15 @@ surprising ways. CU v2 replaces them with a single rule:
An action that already executed against a visually identical screen is
refused deterministically.
-"Visually identical" is keyed by the frame's content hash — if the screen
-changed since the first execution, the same action is legitimate again
-(navigating a list clicks different rows on *different* frames; retyping a
-search on a *changed* page is fine). Clicking twice on the same unchanged
-frame, typing the same URL again into an unchanged address bar, or launching
-the same app while the screen never moved is exactly the double-action bug
-class and is blocked regardless of what the model asks for.
+"Visually identical" is keyed by the frame's PERCEPTUAL identity (the
+grayscale thumbnail compared via ``jarvis.cu.capture.thumbs_similar``, noise-
+tolerant) — if the screen genuinely changed since the first execution, the
+same action is legitimate again (navigating a list clicks different rows on
+*different* frames; retyping a search on a *changed* page is fine). Clicking
+twice on the same unchanged frame, typing the same URL again into an
+unchanged address bar, or launching the same app while the screen never
+moved is exactly the double-action bug class and is blocked regardless of
+what the model asks for.
``wait`` is exempt (waiting twice is harmless and sometimes right).
"""
@@ -23,6 +25,8 @@ import re
from dataclasses import dataclass, field
from typing import Any
+from jarvis.cu.capture import thumbs_similar
+
#: Two click points within this many screen units count as the same target
#: (model re-aim jitter), mirroring the legacy refine tolerance.
CLICK_SAME_TOLERANCE = 12
diff --git a/tests/unit/cu/test_capture.py b/tests/unit/cu/test_capture.py
index ed6bc46ee0..2ca63febd4 100644
--- a/tests/unit/cu/test_capture.py
+++ b/tests/unit/cu/test_capture.py
@@ -154,6 +154,33 @@ def test_blob_written_when_dir_given(tmp_path):
assert (tmp_path / f"{frame.sha256}.jpg").exists()
+def test_perceptual_hash_ignores_caret_noise_but_sees_real_change():
+ from jarvis.cu.capture import perceptual_hash
+
+ base = _solid((192, 108), (30, 30, 30))
+ # A tiny caret-sized change (2x12 slightly-brighter block).
+ pixels = bytearray(base[1])
+ for row in range(12):
+ for col in range(2):
+ idx = ((20 + row) * 192 + (50 + col)) * 3
+ pixels[idx:idx + 3] = bytes((36, 36, 36))
+ caret = ((192, 108), bytes(pixels))
+ changed = _solid((192, 108), (200, 200, 200))
+ assert perceptual_hash(base) == perceptual_hash(base)
+ assert perceptual_hash(base) == perceptual_hash(caret)
+ assert perceptual_hash(base) != perceptual_hash(changed)
+
+
+def test_frame_carries_both_hashes():
+ frame = capture_stable_frame(
+ _monitor(),
+ grab=lambda bbox: _solid((192, 108), (1, 2, 3)),
+ sleep=lambda s: None,
+ )
+ assert len(frame.sha256) == 64 and len(frame.phash) == 64
+ assert frame.sha256 != frame.phash
+
+
def test_grab_region_swallows_failures():
def broken(bbox):
raise OSError("BitBlt failed")