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 08:59)

Ruben Lütkeff1fa294c71b
diff --git a/jarvis/cu/geometry.py b/jarvis/cu/geometry.py
index 57e333c530..3e455a832f 100644
--- a/jarvis/cu/geometry.py
+++ b/jarvis/cu/geometry.py
@@ -230,23 +230,35 @@ class CoordinateMapper:
Input is clamped to the image so a slightly-out-of-range model
estimate cannot escape the captured monitor. ``+0.5`` centers the
mapping on the pixel so a 1:1 frame maps pixel N to pixel N.
+
+ The local offset is computed non-negative and floored BEFORE the
+ (possibly negative) capture origin is added — ``int()`` on a negative
+ float truncates toward zero and shifted every left-of-primary monitor
+ click by one unit toward the primary.
"""
ix = min(max(float(ix), 0.0), float(self.image_width - 1))
iy = min(max(float(iy), 0.0), float(self.image_height - 1))
- sx = self.capture_left + (ix + 0.5) * self.capture_width / self.image_width
- sy = self.capture_top + (iy + 0.5) * self.capture_height / self.image_height
- return (int(sx), int(sy))
+ lx = int((ix + 0.5) * self.capture_width / self.image_width)
+ ly = int((iy + 0.5) * self.capture_height / self.image_height)
+ lx = min(lx, self.capture_width - 1)
+ ly = min(ly, self.capture_height - 1)
+ return (self.capture_left + lx, self.capture_top + ly)
def normalized_to_screen(self, nx: float, ny: float) -> tuple[int, int]:
- """Map a 0..1000 normalized coordinate (Gemini grid) to screen units."""
+ """Map a 0..1000 normalized coordinate (Gemini grid) to screen units.
+
+ Uses ``round`` on the local offset — the exact math the legacy engine
+ live-proved (norm 636 on the 3840px monitor at -3840 -> abs -1398) —
+ then adds the origin as an exact integer.
+ """
nx = min(max(float(nx), 0.0), float(_NORM_MAX))
ny = min(max(float(ny), 0.0), float(_NORM_MAX))
- sx = self.capture_left + nx / _NORM_MAX * self.capture_width
- sy = self.capture_top + ny / _NORM_MAX * self.capture_height
+ lx = round(nx / _NORM_MAX * self.capture_width)
+ ly = round(ny / _NORM_MAX * self.capture_height)
# Clamp inside the capture rect (1000/1000 is the bottom-right EDGE).
- sx = min(sx, self.capture_left + self.capture_width - 1)
- sy = min(sy, self.capture_top + self.capture_height - 1)
- return (int(sx), int(sy))
+ lx = min(lx, self.capture_width - 1)
+ ly = min(ly, self.capture_height - 1)
+ return (self.capture_left + lx, self.capture_top + ly)
def model_to_screen(
self, x: float, y: float, convention: CoordinateConvention,
diff --git a/jarvis/speech/rolling_whisper_wake.py b/jarvis/speech/rolling_whisper_wake.py
index 9c2ba0594a..15ae4cbbb1 100644
--- a/jarvis/speech/rolling_whisper_wake.py
+++ b/jarvis/speech/rolling_whisper_wake.py
@@ -380,33 +380,53 @@ class RollingWhisperWake:
consumer = asyncio.create_task(_consume(), name="rolling-whisper-consume")
last_trigger_t = 0.0
# Self-heal counter: consecutive transcribe failures with no success.
- # Reset on any successful transcription; a run of these triggers a fresh
- # model rebuild (see _WEDGE_RECOVER_AFTER_FAILS) so a wedged local Whisper
- # can never leave the wake permanently dead.
+ # Reset on any successful transcription. Only failures of DISTINCT
+ # calls count — a TranscribeBusy right after an abandoned timeout is
+ # the SAME in-flight call still running, tracked separately via
+ # ``busy_since`` (see the busy handler below and _BUSY_HANG_RECOVER_S).
consecutive_fail = 0
+ # Start of the current continuous TranscribeBusy streak (None = the
+ # last poll was not busy). A streak longer than
+ # ``self._busy_hang_recover_s`` is a TRUE hang -> rebuild.
+ busy_since: float | None = None
# Boot serialisation state — see the warm gate inside the poll loop.
warm_wait_t0 = time.time()
warm_wait_logged = False
fallback_warmed = False
+ # Set when recover() dropped the model MID-SESSION: the warm gate then
+ # re-warms immediately (this loop owns it — the boot deferred loader
+ # only runs once) instead of lazily rebuilding INSIDE the next poll's
+ # transcribe timeout, which under load re-wedged and cascaded (live
+ # log 2026-07-02 08:21-08:26).
+ rewarm_owed = False
+
+ def _recover_wedged(reason: str) -> None:
+ nonlocal busy_since, consecutive_fail, rewarm_owed
+ recover = getattr(self._stt, "recover", None)
+ if callable(recover):
+ log.error(
+ "rolling-whisper: %s — rebuilding the wedged wake model "
+ "(self-heal, no restart).",
+ reason,
+ )
+ try:
+ recover()
+ except Exception as exc: # noqa: BLE001 — heal must never crash
+ log.warning("rolling-whisper: model recover() failed: %s", exc)
+ rewarm_owed = True
+ busy_since = None
+ consecutive_fail = 0
def _note_transcribe_fail() -> int:
nonlocal consecutive_fail
consecutive_fail += 1
+ failed = consecutive_fail
if consecutive_fail >= _WEDGE_RECOVER_AFTER_FAILS:
- recover = getattr(self._stt, "recover", None)
- if callable(recover):
- log.error(
- "rolling-whisper: %d consecutive transcribe failures — "
- "rebuilding the wedged wake model (self-heal, no restart).",
- consecutive_fail,
- )
- try:
- recover()
- except Exception as exc: # noqa: BLE001 — heal must never crash
- log.warning("rolling-whisper: model recover() failed: %s", exc)
- consecutive_fail = 0
- return consecutive_fail
+ _recover_wedged(
+ f"{consecutive_fail} consecutive transcribe failures"
+ )
+ return failed
try:
while not stopped.is_set():
@@ -427,7 +447,33 @@ class RollingWhisperWake:
# without the flag (fakes, cloud STT) count as warm. The
# audio consumer keeps the rolling buffer live throughout.
if not getattr(self._stt, "is_warm", True):
- if (
+ if rewarm_owed:
+ # Mid-session self-heal: recover() just dropped the
+ # model. Rebuild + prime it HERE, off the transcribe
+ # timeout, so the next poll meets a hot model instead
+ # of a cold load racing an 8 s deadline (the cascade).
+ rewarm_owed = False
+ warm = getattr(self._stt, "warm_up", None)
+ if callable(warm):
+ t_rewarm = time.time()
+ log.info(
+ "rolling-whisper: re-warming the rebuilt wake "
+ "model off the poll path (mid-session self-heal)."
+ )
+ try:
+ await asyncio.to_thread(warm)
+ log.info(
+ "rolling-whisper: rebuilt wake model warm "
+ "in %.1f s — polling resumes.",
+ time.time() - t_rewarm,
+ )
+ except Exception as exc: # noqa: BLE001
+ log.warning(
+ "rolling-whisper: re-warm failed (%s) — "
+ "lazy load on the next poll.",
+ exc,
+ )
+ elif (
not fallback_warmed
and time.time() - warm_wait_t0 > self._warm_wait_fallback_s
):