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(pets): keep the last thought and a new pet when Windows timers or scanners interfere
rubenluetke10-beep25e48614e0d7
diff --git a/jarvis/ui/pets/status_line.py b/jarvis/ui/pets/status_line.pyindex 3ef75af351..3c122b0c9e 100644--- a/jarvis/ui/pets/status_line.py+++ b/jarvis/ui/pets/status_line.py@@ -274,6 +274,19 @@ class StatusFeed:return Nonereturn self._show(self._pending, now)+ def wait_s(self) -> float | None:+ """Seconds until :meth:`flush` can show the held-back pair, or ``None``.++ ``None`` means nothing is held back. A caller that slept the full+ interval may still get a small positive value: a timer can wake a few+ milliseconds before the clock says the interval is over.+ """+ if self._pending is None:+ return None+ if self._last_at is None:+ return 0.0+ return max(0.0, self._min_interval - (self._clock() - self._last_at))+def reset(self) -> None:"""Forget the last shown and the throttled pair."""self._last = Nonediff --git a/jarvis/ui/pets/store.py b/jarvis/ui/pets/store.pyindex 17a28c2a7c..c6b189a42d 100644--- a/jarvis/ui/pets/store.py+++ b/jarvis/ui/pets/store.py@@ -201,12 +201,31 @@ class PetStore:_write_atomic(staging / SHEET_NAME, _encode_png(sheet))text = json.dumps(manifest.to_json(), indent=2, ensure_ascii=False) + "\n"_write_atomic(staging / MANIFEST_NAME, text.encode("utf-8"))- os.replace(staging, self.root / manifest.id)+ _replace_with_retry(staging, self.root / manifest.id)except OSError as exc:shutil.rmtree(staging, ignore_errors=True)raise PetManifestError("The pet could not be saved.") from exc+#: Attempts and pause for the final rename. On Windows a virus scanner or the+#: search indexer briefly holds a file it just saw written, and renaming its+#: folder fails with "access denied" until it lets go.+_REPLACE_ATTEMPTS = 5+_REPLACE_PAUSE_S = 0.1+++def _replace_with_retry(src: Path, dst: Path) -> None:+ for attempt in range(_REPLACE_ATTEMPTS):+ try:+ os.replace(src, dst)+ return+ except PermissionError:+ if attempt == _REPLACE_ATTEMPTS - 1:+ raise+ _log.debug("pet folder rename held by another process, retrying: %s", src)+ time.sleep(_REPLACE_PAUSE_S * (attempt + 1))++def _decode_sheet(sheet_bytes: bytes) -> Image.Image:if not isinstance(sheet_bytes, bytes | bytearray) or not sheet_bytes:raise PetManifestError("The sprite sheet is empty.")diff --git a/tests/unit/ui/pets/test_status_line.py b/tests/unit/ui/pets/test_status_line.pyindex 430f0bb162..d5a4dffbcd 100644--- a/tests/unit/ui/pets/test_status_line.py+++ b/tests/unit/ui/pets/test_status_line.py@@ -95,6 +95,22 @@ def test_feed_dedupes_and_rate_limits() -> None:assert feed.flush() is None+def test_feed_says_how_long_a_held_back_pair_still_waits() -> None:+ clock = FakeClock()+ clock.now = 1.0+ feed = StatusFeed(clock=clock, min_interval_s=0.3)+ assert feed.wait_s() is None # nothing held back+ feed.offer("Plan", "First.")+ feed.offer("Plan", "Second.")+ clock.now = 1.29 # a timer that woke just before the interval ended+ assert feed.flush() is None+ assert feed.wait_s() == pytest.approx(0.01)+ clock.now = 1.3+ assert feed.wait_s() == 0.0+ assert feed.flush() == ("Plan", "Second.")+ assert feed.wait_s() is None++def test_feed_force_bypasses_interval_not_dedupe() -> None:clock = FakeClock()feed = StatusFeed(clock=clock)diff --git a/ui/orb/bus_bridge.py b/ui/orb/bus_bridge.pyindex 3ecd290762..43165b5603 100644--- a/ui/orb/bus_bridge.py+++ b/ui/orb/bus_bridge.py@@ -979,12 +979,21 @@ class OrbBusBridge:returnasync def _flush() -> None:- try:- await asyncio.sleep(PET_STATUS_MIN_INTERVAL_S)- except asyncio.CancelledError:- return- if not self._wants_card():- return+ # A timer can wake a few milliseconds before the feed's clock+ # says the interval is over (coarse Windows timers); then the+ # feed still holds the pair back, so sleep the rest instead of+ # dropping the last thought of the burst.+ delay: float | None = PET_STATUS_MIN_INTERVAL_S+ while delay is not None:+ try:+ await asyncio.sleep(delay + 0.005 if delay else 0)+ except asyncio.CancelledError:+ return+ if not self._wants_card():+ return+ delay = self._status_feed.wait_s()+ if delay == 0.0:+ breakshown = self._status_feed.flush()if shown is not None:self._card_visible = True