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): address review findings
rubenluetke10-beep82a7fb5dda11
diff --git a/docs/pets.md b/docs/pets.mdindex d1383a398f..a5bbc9c271 100644--- a/docs/pets.md+++ b/docs/pets.md@@ -29,7 +29,10 @@ one click.- **The status bubble** under the strip. It shows short, condensed lines ofwhat Jarvis is doing: the live transcript while listening, a "Thinking …"header with the current reason, tool or progress line while thinking, and- the condensed reply while talking. It collapses to two lines, expands to six+ the condensed reply while talking. Only spoken replies appear there (voice+ and realtime channels); typed-chat and background answers stay in the app+ window, so the always-on-top bubble never puts them on a shared screen. It+ collapses to two lines, expands to sixon click, and fades out six seconds after the last update while idle. It canbe switched off (`[ui] pet_bubble`).- **The pet "None"** (`pet_id = "none"`) shows the control strip and the@@ -37,8 +40,9 @@ one click.The pet stays on screen while Jarvis is idle. The global shortcut(`[trigger] hotkey_pet_toggle`, default `alt+win+p`) hides it or brings it-back and to the front; hiding lasts until the next app start. On Wayland,-global shortcuts are a no-op, as for every other shortcut.+back and to the front; hiding lasts until the next app start. The shortcut is+changed on the My Pets page (Customize); an empty value switches it off. On+Wayland, global shortcuts are a no-op, as for every other shortcut.## States@@ -52,14 +56,24 @@ equal.| `listening` | wake word, `VoiceSessionStarted`, `SystemStateChanged(LISTENING)`, dictation || `thinking` | `SystemStateChanged(THINKING)` || `talking` | `AudioOutFirst`, `SystemStateChanged(SPEAKING)` with audible output |-| `success` (one-shot, 1.5 s) | `ActionExecuted(success=True)`, `SpeechSpoken.spoken_kind` in `action_done`/`completion`, `JarvisAgentBackgroundCompleted(success=True)` |-| `error` (one-shot, 2 s) | `ErrorOccurred`, `ActionExecuted(success=False)`, `SpeechSpoken.spoken_kind` in `timeout`/`unavailable`/`stt_unavailable`, `VoiceSessionEnded(hangup_reason="error")` |+| `success` (one-shot, 1.5 s) | `SpeechSpoken.spoken_kind` in `action_done`/`completion`, `JarvisAgentBackgroundCompleted(success=True)`, `ActionExecuted(success=True)` while no turn is running |+| `error` (one-shot, 2 s) | `ErrorOccurred(recoverable=False)`, `SpeechSpoken.spoken_kind` in `timeout`/`unavailable`/`stt_unavailable`, `VoiceSessionEnded(hangup_reason="error")`, `ActionExecuted(success=False)` while no turn is running || `sleeping` | five minutes without any Jarvis event; any event wakes it |States come only from real bus events (`ui/orb/bus_bridge.py`); nothing issimulated. The classic voice pipeline does not publish `ErrorOccurred`, so onthat path an error shows through the `SpeechSpoken` kinds.+The one-shots report what the user experiences, not every internal step:++- a tool result inside a running voice or typed turn (any state other than+ `IDLE`, `ERROR` or `PAUSED`) is a step of that turn and plays nothing; the+ turn's own end reports how it went;+- a recoverable `ErrorOccurred` (a retry or fallback the user never notices)+ plays nothing;+- at most one one-shot plays per three seconds. The only exception is an error+ right after a success, because the failure is the news.+## Sprite format `jarvis-pet/1`A pet is a folder with two files:diff --git a/jarvis/ui/jarvisbar/subprocess_overlay.py b/jarvis/ui/jarvisbar/subprocess_overlay.pyindex fe83e23ff1..1c7254b649 100644--- a/jarvis/ui/jarvisbar/subprocess_overlay.py+++ b/jarvis/ui/jarvisbar/subprocess_overlay.py@@ -604,7 +604,10 @@ class SubprocessBarOverlay:returnfrom ui.orb.controls import toggle_speaker_mute- if toggle_speaker_mute() is None:+ # Same source names as the in-process orb window, so the pipeline's+ # VoiceSpeakerMuteChanged says which control the user pressed.+ source = "pet" if getattr(self, "_style", "") == "pet" else "orb"+ if toggle_speaker_mute(source=source) is None:log.debug("orb speaker toggle had no live pipeline in the parent")def _dispatch_talk_action(self) -> None:@@ -788,6 +791,9 @@ class SubprocessMascotOverlay(SubprocessBarOverlay):def toggle_visible(self) -> None:# The host knows whether the pet is on screen; this proxy only guesses.# The guess matters for one thing: a respawn replaying a hidden pet.+ # It is an optimistic mirror: the host sends no confirmation, so+ # ``pet_user_hidden`` (and the REST ``visible`` built on it) can drift+ # if the host drops the command; the next set_visible re-syncs it.self._user_visible = not self._user_visibleself._send({"op": "toggle_visible"})diff --git a/jarvis/ui/pets/status_line.py b/jarvis/ui/pets/status_line.pyindex 38872370d3..1a4bbb10f7 100644--- a/jarvis/ui/pets/status_line.py+++ b/jarvis/ui/pets/status_line.py@@ -50,6 +50,10 @@ _MAX_INLINE_CODE = 30#: A first sentence shorter than this borrows the next one (clipped if needed)._SHORT_SENTENCE = 20+#: Only the head of a text is condensed. The gist is its first sentence, and+#: running the markdown patterns over pages of reply on a bus handler is waste.+MAX_INPUT_CHARS = 600+_SENTENCE_MARKS = ".!?:" + ELLIPSIS@@ -125,7 +129,7 @@ def condense(text: str, *, max_chars: int = 90) -> str:"""if not isinstance(text, str) or not text.strip() or max_chars < 1:return ""- text = _strip_blocks(text)+ text = _strip_blocks(text[:MAX_INPUT_CHARS])headings: list[str] = []body: list[str] = []diff --git a/jarvis/ui/pets/store.py b/jarvis/ui/pets/store.pyindex 1885404763..17a28c2a7c 100644--- a/jarvis/ui/pets/store.py+++ b/jarvis/ui/pets/store.py@@ -15,6 +15,7 @@ import osimport secretsimport shutilimport tempfile+import timefrom pathlib import Pathfrom PIL import Image@@ -43,6 +44,15 @@ SHEET_NAME = "sheet.png"_PNG_SIGNATURE = b"\x89PNG\r\n\x1a\n"_MAX_MANIFEST_CHARS = 64 * 1024+#: Upper bound of user-created pets. Each one is up to 2 MB on disk, and the+#: settings grid shows them all; a cap keeps a scripted upload loop from+#: filling the data directory.+MAX_USER_PETS = 50++_STAGING_PREFIX = ".staging-"+#: A staging folder older than this is debris from a crash mid-save.+_STALE_STAGING_S = 3600.0+#: The frame size tried first when an upload does not name one (the template's)._PREFERRED_FRAME_SIZE = 48@@ -61,8 +71,23 @@ class PetStore:def list(self) -> list[PetManifest]:"""Every valid user pet; broken ones are skipped with a warning."""+ self._sweep_stale_staging()return list_custom(self.root)+ def count(self) -> int:+ """How many user pets exist (folders with a manifest), without decoding them."""+ if not self.root.is_dir():+ return 0+ try:+ return sum(+ 1+ for entry in self.root.iterdir()+ if USER_ID_RE.match(entry.name) and (entry / MANIFEST_NAME).is_file()+ )+ except OSError as exc:+ _log.warning("could not count user pets in %s: %s", self.root, exc)+ return 0+def directory(self, pet_id: str) -> Path | None:"""The folder of an existing user pet, or ``None``."""if not isinstance(pet_id, str) or not USER_ID_RE.match(pet_id):@@ -85,6 +110,10 @@ class PetStore:each row's frame count is its run of non-empty cells from the left.Raises :class:`PetManifestError` with a user-readable message."""+ if self.count() >= MAX_USER_PETS:+ raise PetManifestError(+ f"You already have {MAX_USER_PETS} pets. Delete one to add another."+ )sheet = _decode_sheet(sheet_bytes)width, height = sheet.sizepet_id = "u" + secrets.token_hex(8)@@ -137,9 +166,37 @@ class PetStore:# -- internals ------------------------------------------------------+ def _sweep_stale_staging(self, *, now: float | None = None) -> None:+ """Remove staging folders a crash left behind (older than an hour).++ A fresh one belongs to a save in progress (another thread, another+ request), so only old ones go.+ """+ if not self.root.is_dir():+ return+ cutoff = (time.time() if now is None else now) - _STALE_STAGING_S+ try:+ entries = list(self.root.iterdir())+ except OSError as exc:+ _log.debug("staging sweep skipped for %s: %s", self.root, exc)+ return+ for entry in entries:+ if not entry.name.startswith(_STAGING_PREFIX):+ continue+ try:+ if entry.is_symlink() or not entry.is_dir():+ continue+ if entry.stat().st_mtime >= cutoff:+ continue+ shutil.rmtree(entry)+ _log.info("removed a stale pet staging folder %s", entry.name)+ except OSError as exc:+ _log.debug("could not remove stale staging folder %s: %s", entry, exc)+def _write(self, manifest: PetManifest, sheet: Image.Image) -> None:self.root.mkdir(parents=True, exist_ok=True)- staging = Path(tempfile.mkdtemp(prefix=".staging-", dir=self.root))+ self._sweep_stale_staging()+ staging = Path(tempfile.mkdtemp(prefix=_STAGING_PREFIX, dir=self.root))try:_write_atomic(staging / SHEET_NAME, _encode_png(sheet))text = json.dumps(manifest.to_json(), indent=2, ensure_ascii=False) + "\n"diff --git a/jarvis/ui/web/pets_routes.py b/jarvis/ui/web/pets_routes.pyindex b9fdb98d5b..c6b20f1134 100644--- a/jarvis/ui/web/pets_routes.py+++ b/jarvis/ui/web/pets_routes.py@@ -33,19 +33,81 @@ from __future__ import annotationsimport asyncioimport logging+from collections.abc import Awaitable, Callablefrom pathlib import Pathfrom typing import Anyfrom fastapi import APIRouter, File, Form, HTTPException, Request, UploadFilefrom fastapi.responses import FileResponse+from fastapi.routing import APIRoutefrom pydantic import BaseModel, Field+from starlette.responses import Response+from starlette.types import Message, Receivefrom jarvis.core.config import clamp_pet_scale, normalize_pet_idfrom jarvis.ui.pets.states import DEFAULT_PET_ID, NO_PET_ID, PET_STATESlog = logging.getLogger(__name__)-router = APIRouter(prefix="/api/pets", tags=["pets"])+#: Ceiling of a whole request body on this router: the 2 MB sheet plus the+#: manifest and the form overhead. Checked BEFORE the multipart parser runs,+#: because Starlette spools an entire upload to disk before a handler (or a+#: FastAPI dependency) ever sees it — a per-handler read cap alone would still+#: accept a multi-gigabyte body.+MAX_REQUEST_BYTES = 3 * 1024 * 1024++_TOO_LARGE = "The upload is too large (the sprite sheet may be at most 2 MB)."+++def _limited_receive(receive: Receive, limit: int) -> Receive:+ """Wrap ``receive`` so a body without ``Content-Length`` stops at ``limit``."""+ seen = 0++ async def counting() -> Message:+ nonlocal seen+ message = await receive()+ if message.get("type") == "http.request":+ seen += len(message.get("body", b""))+ if seen > limit:+ raise HTTPException(status_code=413, detail=_TOO_LARGE)+ return message++ return counting+++class _BodyLimitRoute(APIRoute):+ """An ``APIRoute`` that refuses an oversized body before parsing it.++ A declared ``Content-Length`` above :data:`MAX_REQUEST_BYTES` is answered+ with 413 at once; a chunked body without one is counted while it streams+ and cut off at the same ceiling.+ """++ def get_route_handler(self) -> Callable[[Request], Awaitable[Response]]:+ handler = super().get_route_handler()++ async def limited(request: Request) -> Response:+ if request.method in ("POST", "PUT", "PATCH"):+ declared = request.headers.get("content-length")+ if declared is None:+ request = Request(+ request.scope, _limited_receive(request.receive, MAX_REQUEST_BYTES)+ )+ else:+ try:+ size = int(declared)+ except ValueError:+ raise HTTPException(+ status_code=400, detail="Invalid Content-Length header."+ ) from None+ if size > MAX_REQUEST_BYTES:+ raise HTTPException(status_code=413, detail=_TOO_LARGE)+ return await handler(request)++ return limited+++router = APIRouter(prefix="/api/pets", tags=["pets"], route_class=_BodyLimitRoute)#: A user-created pet's sheet never changes: a new upload gets a new id._IMMUTABLE_CACHE = {"Cache-Control": "public, max-age=31536000, immutable"}diff --git a/tests/unit/ui/pets/test_status_line.py b/tests/unit/ui/pets/test_status_line.pyindex 4b4a856bb7..1be4f2d370 100644--- a/tests/unit/ui/pets/test_status_line.py+++ b/tests/unit/ui/pets/test_status_line.py@@ -4,7 +4,7 @@ from __future__ import annotationsimport pytest-from jarvis.ui.pets.status_line import ELLIPSIS, StatusFeed, condense+from jarvis.ui.pets.status_line import ELLIPSIS, MAX_INPUT_CHARS, StatusFeed, condenseclass FakeClock:@@ -103,3 +103,15 @@ def test_feed_ignores_empty_pairs_and_resets() -> None:feed.offer("", "Same line.")feed.reset()assert feed.offer("", "Same line.") == ("", "Same line.")+++def test_only_the_head_of_a_long_text_is_condensed() -> None:+ # Pages of unpunctuated text (a table, a log) must not be worked through+ # on a bus handler; the gist comes from the head alone.+ text = "Here is the summary of the run " + "| cell " * 50_000+ assert len(text) > 10 * MAX_INPUT_CHARS+ line = condense(text)+ assert line.startswith("Here is the summary")+ assert len(line) <= 90+ # A sentence that starts after the cap is not part of the gist.+ assert "Tail" not in condense("x" * (MAX_INPUT_CHARS + 10) + " Tail sentence.")diff --git a/tests/unit/ui/pets/test_store.py b/tests/unit/ui/pets/test_store.pyindex f734701642..59896b6273 100644--- a/tests/unit/ui/pets/test_store.py+++ b/tests/unit/ui/pets/test_store.py@@ -4,12 +4,15 @@ from __future__ import annotationsimport ioimport json+import os+import timefrom pathlib import Pathimport pytestfrom PIL import Imagefrom PIL.PngImagePlugin import PngInfo+from jarvis.ui.pets import store as store_modulefrom jarvis.ui.pets.loader import load_petfrom jarvis.ui.pets.manifest import USER_ID_RE, PetManifestErrorfrom jarvis.ui.pets.states import PET_FORMAT@@ -179,3 +182,32 @@ def test_delete_never_leaves_the_root(store: PetStore, tmp_path: Path) -> None:def test_list_of_a_missing_root_is_empty(tmp_path: Path) -> None:assert PetStore(tmp_path / "nothing").list() == []+++def test_the_number_of_user_pets_is_capped(+ store: PetStore, monkeypatch: pytest.MonkeyPatch+) -> None:+ monkeypatch.setattr(store_module, "MAX_USER_PETS", 2)+ sheet = _png(_sheet([1], columns=1))+ _add(store, sheet)+ _add(store, sheet)+ assert store.count() == 2+ with pytest.raises(PetManifestError, match="already have 2 pets"):+ _add(store, sheet)+ assert store.count() == 2+++def test_stale_staging_folders_are_swept_and_fresh_ones_kept(store: PetStore) -> None:+ store.root.mkdir(parents=True)+ stale = store.root / ".staging-crashed"+ fresh = store.root / ".staging-in-progress"+ stale.mkdir()+ (stale / "sheet.png").write_bytes(b"half")+ fresh.mkdir()+ old = time.time() - 2 * 3600+ os.utime(stale, (old, old))++ assert store.list() == []++ assert not stale.exists()+ assert fresh.is_dir()diff --git a/tests/unit/ui/test_orb_bus_bridge_pet.py b/tests/unit/ui/test_orb_bus_bridge_pet.pyindex 5ce7ffec1c..6ff608a4b2 100644--- a/tests/unit/ui/test_orb_bus_bridge_pet.py+++ b/tests/unit/ui/test_orb_bus_bridge_pet.py@@ -32,6 +32,7 @@ from jarvis.core.events import (SystemStateChanged,TranscriptionUpdate,UiLanguageChanged,+ VoiceBootStatus,VoiceSessionEnded,VoiceSessionStarted,VoiceSpeakerMuteChanged,@@ -279,7 +280,7 @@ def test_a_swapped_in_surface_gets_every_callback_and_the_live_mutes(monkeypatch(SpeechSpoken(text="Offline.", spoken_kind="unavailable"), "error"),(SpeechSpoken(text="Can't hear.", spoken_kind="stt_unavailable"), "error"),(JarvisAgentBackgroundCompleted(success=True), "success"),- (ErrorOccurred(layer="brain", message="boom"), "error"),+ (ErrorOccurred(layer="brain", message="boom", recoverable=False), "error"),(VoiceSessionEnded(session_id="s", hangup_reason="error"), "error"),],)@@ -316,7 +317,7 @@ async def test_status_lines_reach_only_a_surface_that_wants_them() -> None:_bridge_, bus = _bridge(bar)await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))await bus.publish(ActionProposed(tool_name="web_search", rationale="Checking the news"))- await bus.publish(AssistantTextDelta(text="Here it is.", done=True))+ await bus.publish(AssistantTextDelta(channel="voice", text="Here it is.", done=True))assert bar.of("status") == []@@ -358,19 +359,21 @@ async def test_progress_announcements_are_thinking_lines(fast_status) -> None:async def test_a_streamed_reply_shows_its_latest_complete_sentence(fast_status) -> None:pet = _Pet()_bridge_, bus = _bridge(pet)- await bus.publish(AssistantTextDelta(text="It is sunny. Tomorrow it"))+ await bus.publish(AssistantTextDelta(channel="voice", text="It is sunny. Tomorrow it"))assert pet.of("status")[-1] == ("status", "Answer", "It is sunny.")await asyncio.sleep(0.03)- await bus.publish(AssistantTextDelta(text="It is sunny. Tomorrow it rains.", done=True))+ await bus.publish(+ AssistantTextDelta(channel="voice", text="It is sunny. Tomorrow it rains.", done=True)+ )assert pet.of("status")[-1] == ("status", "Answer", "Tomorrow it rains.")async def test_the_final_snapshot_beats_the_rate_limit() -> None:pet = _Pet()_bridge_, bus = _bridge(pet)- await bus.publish(AssistantTextDelta(text="First."))- await bus.publish(AssistantTextDelta(text="First. Second.", done=True))+ await bus.publish(AssistantTextDelta(channel="voice", text="First."))+ await bus.publish(AssistantTextDelta(channel="voice", text="First. Second.", done=True))assert [c[2] for c in pet.of("status")] == ["First.", "Second."]@@ -405,7 +408,7 @@ async def test_headers_follow_the_interface_language(fast_status) -> None:await bus.publish(UiLanguageChanged(language="es"))await asyncio.sleep(0.03)- await bus.publish(AssistantTextDelta(text="Hola.", done=True)) # i18n-allow+ await bus.publish(AssistantTextDelta(channel="voice", text="Hola.", done=True)) # i18n-allowassert pet.of("status")[-1][1] == "Respuesta" # i18n-allow@@ -442,3 +445,119 @@ async def test_a_mascot_still_hides_when_a_preview_is_retracted() -> None:await bus.publish(WakeCandidateDetected(active=True))await bus.publish(WakeCandidateDetected(active=False))assert mascot.calls[-1] == ("hide",)+++# ---------------------------------------------------------------------------+# outcomes report what the user experiences (review fixes)+# ---------------------------------------------------------------------------+++class _Clock:+ def __init__(self) -> None:+ self.now = 1000.0++ def __call__(self) -> float:+ return self.now+++async def test_a_recoverable_error_plays_nothing() -> None:+ pet = _Pet()+ _bridge_, bus = _bridge(pet)+ await bus.publish(ErrorOccurred(layer="brain", message="retrying", recoverable=True))+ assert pet.of("outcome") == []++[email protected]("success", [True, False])+async def test_a_tool_result_inside_a_turn_is_not_an_outcome(success: bool) -> None:+ pet = _Pet()+ _bridge_, bus = _bridge(pet)+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="THINKING"))+ await bus.publish(ActionExecuted(tool_name="web_search", success=success))+ assert pet.of("outcome") == []+++async def test_outcomes_are_throttled_but_an_error_after_a_success_shows() -> None:+ pet = _Pet()+ bridge, bus = _bridge(pet)+ clock = _Clock()+ bridge._clock = clock # noqa: SLF001 — the throttle's clock+ await bus.publish(JarvisAgentBackgroundCompleted(success=True))+ clock.now += 1.0+ await bus.publish(SpeechSpoken(text="Done.", spoken_kind="action_done"))+ clock.now += 0.5+ await bus.publish(SpeechSpoken(text="Too slow.", spoken_kind="timeout"))+ clock.now += 0.5+ await bus.publish(ErrorOccurred(layer="brain", message="x", recoverable=False))+ clock.now += 3.5+ await bus.publish(SpeechSpoken(text="Finished.", spoken_kind="completion"))+ assert [c[1] for c in pet.of("outcome")] == ["success", "error", "success"]+++# ---------------------------------------------------------------------------+# status lines: spoken replies only, every turn opens with its header+# ---------------------------------------------------------------------------+++async def test_typed_and_background_replies_stay_out_of_the_bubble(fast_status) -> None:+ pet = _Pet()+ _bridge_, bus = _bridge(pet)+ await bus.publish(AssistantTextDelta(channel="chat", text="Typed answer.", done=True))+ await bus.publish(AssistantTextDelta(channel="", text="Background answer.", done=True))+ assert pet.of("status") == []+ await bus.publish(AssistantTextDelta(channel="realtime", text="Spoken answer.", done=True))+ assert pet.of("status")[-1] == ("status", "Answer", "Spoken answer.")+++async def test_every_follow_up_turn_reopens_the_listening_header(fast_status) -> None:+ pet = _Pet()+ _bridge_, bus = _bridge(pet)+ await bus.publish(SystemStateChanged(previous="IDLE", new_state="LISTENING"))+ await bus.publish(SystemStateChanged(previous="LISTENING", new_state="THINKING"))+ await bus.publish(SystemStateChanged(previous="THINKING", new_state="SPEAKING"))+ await bus.publish(SystemStateChanged(previous="SPEAKING", new_state="LISTENING"))+ headers = [c[1] for c in pet.of("status")]+ assert headers.count("Listening …") == 2+ assert pet.of("status")[-1] == ("status", "Listening …", "")+++async def test_a_long_reply_is_cut_from_its_end() -> None:+ pet = _Pet()+ _bridge_, bus = _bridge(pet)+ reply = "Some words. " * 5_000 + "The last sentence."+ await bus.publish(AssistantTextDelta(channel="voice", text=reply, done=True))+ assert pet.of("status")[-1] == ("status", "Answer", "The last sentence.")+++# ---------------------------------------------------------------------------+# the backend loop: pinned early, never replaced by a throwaway one+# ---------------------------------------------------------------------------+++async def test_the_voice_ready_signal_pins_the_backend_loop() -> None:+ pet = _Pet()+ bridge, bus = _bridge(pet)+ bridge._loop = None # noqa: SLF001 — as if attach() had run off the loop+ await bus.publish(VoiceBootStatus(ready=True))+ assert bridge._loop is asyncio.get_running_loop() # noqa: SLF001+++def test_a_gesture_after_the_backend_loop_stopped_is_dropped() -> None:+ bus = EventBus()+ seen: list[ComposeRequested] = []++ async def _record(event: ComposeRequested) -> None:+ seen.append(event)++ bus.subscribe(ComposeRequested, _record)+ pet = _Pet()+ bridge = OrbBusBridge(bus=bus, orb=pet) # type: ignore[arg-type]+ bridge.attach()+ stopped = asyncio.new_event_loop()+ try:+ bridge._loop = stopped # noqa: SLF001 — captured once, no longer running+ pet.callbacks["compose"]()+ # Running the publish on a throwaway loop instead is the 2026-06-28+ # cross-loop crash; the gesture is dropped.+ assert seen == []+ finally:+ stopped.close()diff --git a/tests/unit/ui/test_orb_controls_pet.py b/tests/unit/ui/test_orb_controls_pet.pyindex 65efce15b5..9f0fdf89ad 100644--- a/tests/unit/ui/test_orb_controls_pet.py+++ b/tests/unit/ui/test_orb_controls_pet.py@@ -10,6 +10,8 @@ on to unmute again.from __future__ import annotations+import threading+import pytestfrom PIL import Image@@ -199,3 +201,47 @@ def test_the_speaker_toggle_mutes_and_then_unmutes_again(pipeline: _Pipeline) ->assert pipeline._volume == 0.0assert controls.toggle_speaker_mute() is Falseassert pipeline._volume == pytest.approx(0.7)+++class _ConfiguredPipeline(_Pipeline):+ """A pipeline whose voice was silenced elsewhere, with ``[tts].volume`` set."""++ def __init__(self, configured: float) -> None:+ super().__init__(0.0)++ class _Tts:+ volume = configured++ class _Config:+ tts = _Tts()++ self._config = _Config()++[email protected]("configured,expected", [(0.4, 0.4), (0.0, 1.0)])+def test_unmuting_a_voice_silenced_elsewhere_restores_the_configured_volume(+ monkeypatch: pytest.MonkeyPatch, configured: float, expected: float+) -> None:+ monkeypatch.setattr(controls, "_PRE_MUTE_VOLUME", {})+ live = _ConfiguredPipeline(configured)+ runtime_refs.set_speech_pipeline(live)+ try:+ assert controls.toggle_speaker_mute() is False+ assert live._volume == pytest.approx(expected)+ finally:+ runtime_refs.set_speech_pipeline(None)+++def test_concurrent_toggles_never_lose_the_remembered_volume(pipeline: _Pipeline) -> None:+ # The disc (Tk thread) and the in-app button (a REST worker) can toggle at+ # the same moment; an even number of toggles must end audible again.+ def _toggle_many() -> None:+ for _ in range(50):+ controls.toggle_speaker_mute()++ workers = [threading.Thread(target=_toggle_many) for _ in range(2)]+ for worker in workers:+ worker.start()+ for worker in workers:+ worker.join(timeout=10.0)+ assert pipeline._volume == pytest.approx(0.7)diff --git a/tests/unit/ui/test_pet_overlay_renderer.py b/tests/unit/ui/test_pet_overlay_renderer.pyindex 7912109c08..64281170f4 100644--- a/tests/unit/ui/test_pet_overlay_renderer.py+++ b/tests/unit/ui/test_pet_overlay_renderer.py@@ -304,3 +304,45 @@ def test_the_built_in_default_pet_loads_through_the_real_engine() -> None:assert renderer.state() in PET_STATESassert renderer.render().size == renderer.sizeassert pr.MIN_FRAME_DELAY_MS <= renderer.next_frame_delay_ms() <= pr.MAX_FRAME_DELAY_MS+++# --- memory and failure (review fixes) ------------------------------------------+++class _SharedRowPack(_Pack):+ """Like the real loader: fallback states share their source row's tuple."""++ def __init__(self) -> None:+ super().__init__()+ shared = self.frames["idle"]+ for state in ("thinking", "error", "sleeping"):+ self.frames[state] = shared+++def test_states_that_share_a_row_are_scaled_once() -> None:+ pack = _SharedRowPack()+ distinct = {id(sequence): sequence for sequence in pack.frames.values()}+ renderer, calls = _renderer(_Clock(), loader=_Loader({"fake": pack}))+ assert len(calls) == sum(len(sequence) for sequence in distinct.values())+ frames = renderer._frames # noqa: SLF001 — the scaled cache under test+ assert frames["sleeping"] is frames["idle"]+++def test_a_frame_that_will_not_scale_leaves_the_strip_only() -> None:+ clock = _Clock()++ def _broken(frame: Image.Image, scale: int, key: tuple[int, int, int]) -> Image.Image:+ raise ValueError("bad frame")++ renderer = pr.PetRenderer(+ "fake",+ clock=clock,+ loader=_Loader({"fake": _Pack()}),+ to_color_key=_broken,+ machine=PetStateMachine(clock),+ )+ assert renderer.has_figure is False+ assert renderer.pet_id == "none"+ assert renderer._frames == {} # noqa: SLF001 — nothing half-filled is kept+ assert renderer.size[1] == 1+ assert renderer.render().size == renderer.sizediff --git a/tests/unit/ui/test_pet_overlay_surface.py b/tests/unit/ui/test_pet_overlay_surface.pyindex b87af9b173..93646381f3 100644--- a/tests/unit/ui/test_pet_overlay_surface.py+++ b/tests/unit/ui/test_pet_overlay_surface.py@@ -18,7 +18,7 @@ from jarvis.ui.desktop_app import DesktopAppfrom jarvis.ui.jarvisbar.null_overlay import NullOverlayfrom jarvis.ui.jarvisbar.subprocess_overlay import SubprocessMascotOverlayfrom ui.orb import controls-from ui.orb.overlay import OrbOverlay+from ui.orb.overlay import OrbCommentBubble, OrbOverlay# --- OrbOverlay (never started: no Tk root under pytest) --------------------------@@ -278,3 +278,42 @@ def test_the_speaker_toggle_still_works_with_an_older_setter(live_pipeline) -> Nassert pipeline.volume == 0.0assert controls.toggle_speaker_mute() is Falseassert pipeline.volume == pytest.approx(0.8)+++[email protected]("style,source", [("pet", "pet"), ("voice_orb", "orb")])+def test_the_macos_speaker_disc_names_its_source(live_pipeline, style: str, source: str) -> None:+ pipeline = live_pipeline(_SourcePipeline())+ proxy = SubprocessMascotOverlay(style=style)+ proxy._dispatch_speaker_toggle() # noqa: SLF001 — the child's speaker event+ assert pipeline.sources == [source]+++# --- dragging moves the status bubble without repainting it ---------------------------+++class _RecordingTop:+ def __init__(self) -> None:+ self.geometries: list[str] = []++ def geometry(self, spec: str) -> None:+ self.geometries.append(spec)+++def test_a_drag_only_moves_the_painted_status_bubble() -> None:+ bubble = OrbCommentBubble.__new__(OrbCommentBubble) # no Tk: geometry only+ top = _RecordingTop()+ bubble._top = top # noqa: SLF001+ bubble._screen_w = 1920 # noqa: SLF001+ bubble._status_showing = True # noqa: SLF001+ bubble._status_size = (240, 60) # noqa: SLF001+ repaints: list[bool] = []+ bubble._render_status = lambda: repaints.append(True) or True # type: ignore[method-assign]++ # (center_x, below_y, above_y, limit_bottom): room below the strip.+ bubble.move_status((500, 300, 100, 1000))+ # No room below: the bubble sits over the figure instead.+ bubble.move_status((500, 980, 700, 1000))++ assert top.geometries == ["+380+300", "+380+640"]+ assert repaints == []diff --git a/tests/unit/ui/test_pets_routes.py b/tests/unit/ui/test_pets_routes.pyindex 4ede898950..d14e5f6cd1 100644--- a/tests/unit/ui/test_pets_routes.py+++ b/tests/unit/ui/test_pets_routes.py@@ -23,9 +23,10 @@ from jarvis.core import config as config_modulefrom jarvis.core.config import UIConfigfrom jarvis.core.events import PetChangedfrom jarvis.ui.pets import loader+from jarvis.ui.pets import store as store_modulefrom jarvis.ui.pets.manifest import MAX_SHEET_BYTESfrom jarvis.ui.pets.states import DEFAULT_PET_ID, PET_STATES-from jarvis.ui.web.pets_routes import router+from jarvis.ui.web.pets_routes import MAX_REQUEST_BYTES, routerFRAME = 32@@ -338,6 +339,42 @@ def test_upload_rejects_a_frame_size_that_is_not_a_number(env) -> None:assert _upload(env, frame_size="big").status_code == 400+def test_a_body_declared_too_large_is_refused_before_parsing(env) -> None:+ r = env.client.post(+ "/api/pets",+ content=b"x" * (MAX_REQUEST_BYTES + 1),+ headers={"content-type": "multipart/form-data; boundary=pets"},+ )+ assert r.status_code == 413+ assert "too large" in r.json()["detail"]+ assert not any(env.data.glob("pets/u*"))+++def test_a_chunked_body_is_cut_off_at_the_ceiling(env) -> None:+ chunk = b"y" * (64 * 1024)+ chunks = (MAX_REQUEST_BYTES // len(chunk)) + 4++ def _stream():+ for _ in range(chunks):+ yield chunk++ r = env.client.post(+ "/api/pets",+ content=_stream(),+ headers={"content-type": "multipart/form-data; boundary=pets"},+ )+ assert r.status_code == 413+ assert not any(env.data.glob("pets/u*"))+++def test_the_pet_cap_is_a_400_with_a_sentence(env, monkeypatch) -> None:+ monkeypatch.setattr(store_module, "MAX_USER_PETS", 1)+ assert _upload(env).status_code == 201+ r = _upload(env)+ assert r.status_code == 400+ assert "already have 1 pets" in r.json()["detail"]++def test_upload_rejects_a_manifest_that_is_not_json(env) -> None:r = _upload(env, manifest="{not json")assert r.status_code == 400diff --git a/ui/orb/bus_bridge.py b/ui/orb/bus_bridge.pyindex e28ae865cf..f5e73c1fd2 100644--- a/ui/orb/bus_bridge.py+++ b/ui/orb/bus_bridge.py@@ -259,6 +259,18 @@ PET_STATUS_LANGUAGES: tuple[str, ...] = ("en", "de", "es")# snapshots per second; repainting the bubble for each one is flicker.PET_STATUS_MIN_INTERVAL_S = 0.3+# Minimum spacing of two pet one-shots (success / error). A burst of results is+# one thing that happened; replaying the one-shot for each is flicker.+PET_OUTCOME_MIN_INTERVAL_S = 3.0++# Reply channels whose streamed text the pet shows. Typed chat and background+# work are read in the app window, not in an always-on-top bubble.+PET_STATUS_REPLY_CHANNELS = frozenset({"voice", "realtime"})++# The most text a status line is cut from. A reply can be pages long; only its+# end matters for the latest sentence, and condensing pages per update is waste.+PET_STATUS_INPUT_CHARS = 400+# Announcement kinds that describe work in progress (the pet's "thinking" line).# A completion or a sub-agent readback is an ANSWER, and it is spoken anyway._PET_THINKING_ANNOUNCEMENT_KINDS = frozenset({"preamble", "progress"})@@ -288,6 +300,11 @@ def _last_sentence(text: str, *, complete_only: bool = False) -> str:return pieces[-1]+def _tail_sentence(text: str, *, complete_only: bool = False) -> str:+ """:func:`_last_sentence` of the last ``PET_STATUS_INPUT_CHARS`` of ``text``."""+ return _last_sentence((text or "")[-PET_STATUS_INPUT_CHARS:], complete_only=complete_only)++def _humanize_tool_name(tool_name: str) -> str:"""``web_search`` → ``Web search``; ``mcp__github__create_issue`` → ``Create issue``."""name = str(tool_name or "").strip().split("__")[-1]@@ -333,6 +350,10 @@ class OrbBusBridge:# interval has passed, so the LAST update of a burst is never lost.self._status_feed = StatusFeed(time.monotonic, min_interval_s=PET_STATUS_MIN_INTERVAL_S)self._status_flush_task: asyncio.Task | None = None+ # Clock for the pet's outcome throttle (replaceable in tests) and the+ # last one-shot it played, as (kind, time).+ self._clock = time.monotonic+ self._last_outcome: tuple[str, float] | None = Noneself._mic_level_unsub = None # mic_level subscription (registered in attach)self._tts_recency_unsub = None # level_tap subscription (TTS-active tracker)# Monotonic time of the last TTS output level. The state label@@ -366,7 +387,7 @@ class OrbBusBridge:# forever with no way back — the "it never goes away and I can't tell# why" failure class. A deadline cannot stick the way a latch can.self._dictation_failsafe_task: asyncio.Task | None = None- self._rng = random.Random()+ self._rng = random.Random() # noqa: S311 — idle-animation timing, not cryptographyself._listening_transcript_text = ""# True while the pipeline is mid-completion-buffer (paused on an# incomplete fragment, waiting for the rest). Used so the next@@ -441,19 +462,26 @@ class OrbBusBridge:the Tk thread. Fire-and-forget; never blocks the Tk mainloop.Falls back to a one-shot ``asyncio.run`` ONLY when no backend loop was- ever captured (the Tk-only test harness). In the live app a state event- always fires before the orb is clickable, so the captured-loop path is- the one that runs — and the throwaway-loop cross-event-loop crash that- froze the mic (2026-06-28) cannot recur."""+ ever captured (the Tk-only test harness). In the live app ``attach()``+ runs on the backend loop, so the loop is known before any surface is+ clickable — including the desktop pet, which is on screen from boot.+ A loop that WAS captured but no longer runs (shutdown) drops the+ gesture instead: running the publish on a throwaway loop is the+ cross-event-loop crash that froze the mic (2026-06-28)."""loop = self._loop- if loop is not None and loop.is_running():- try:- asyncio.run_coroutine_threadsafe(coro, loop)- except RuntimeError as exc:- log.warning("%s publish dropped: %s", label, exc)+ if loop is not None:+ if loop.is_running():+ try:+ asyncio.run_coroutine_threadsafe(coro, loop)+ except RuntimeError as exc:+ coro.close()+ log.warning("%s publish dropped: %s", label, exc)+ return+ coro.close()+ log.info("%s publish dropped: the backend loop is no longer running", label)return- # No backend loop reachable — last resort so the gesture is not silently- # swallowed in a Tk-only harness. Never the live-app path.+ # No backend loop was ever captured — the Tk-only harness. Last resort+ # so the gesture is not silently swallowed there.try:asyncio.run(coro)except RuntimeError as exc:@@ -632,6 +660,7 @@ class OrbBusBridge:without ``set_muted`` (the mascot orb) is simply skipped — the call is ano-op, never an error. The write is a quick atomic flag set on thesurface; no Tk marshal needed (the bar reads it on its own frame loop)."""+ self._remember_loop()setter = getattr(self._orb, "set_muted", None)if not callable(setter):return@@ -811,15 +840,38 @@ class OrbBusBridge:self._status_flush_task = loop.create_task(_flush(), name="orb-pet-status-flush")def _pet_outcome(self, kind: str) -> None:- """Play the pet's one-shot ``success`` / ``error`` (no-op elsewhere)."""+ """Play the pet's one-shot ``success`` / ``error`` (no-op elsewhere).++ At most one outcome per ``PET_OUTCOME_MIN_INTERVAL_S``: a burst of+ results is one thing that happened, not a flicker of celebrations. The+ one exception is an error right after a success — the failure is the+ news the user must not miss.+ """+ now = self._clock()+ last = self._last_outcome+ if last is not None and now - last[1] < PET_OUTCOME_MIN_INTERVAL_S:+ if not (kind == "error" and last[0] == "success"):+ return+ self._last_outcome = (kind, now)self._call_surface("set_pet_outcome", kind)+ def _turn_in_progress(self) -> bool:+ """Is a voice or typed turn running right now?++ A tool result inside a turn is a step of that turn, not its outcome:+ the turn's own end (``SpeechSpoken`` kinds, a hang-up for an error)+ reports how it went.+ """+ return self._last_state not in ("IDLE", "ERROR", "PAUSED")+async def _on_speaker_mute_changed(self, event: VoiceSpeakerMuteChanged) -> None:"""Mirror the pipeline's speaker mute (TTS volume 0) on the surface."""+ self._remember_loop()self._call_surface("set_speaker_muted", bool(event.muted))async def _on_pet_visibility_toggle(self, event: PetVisibilityToggleRequested) -> None:"""The pet shortcut: hide the pet, or show it and bring it forward."""+ self._remember_loop()log.info("OrbBridge pet visibility toggle (source=%s)", event.source or "unknown")self._call_surface("toggle_visible")@@ -835,6 +887,11 @@ class OrbBusBridge:self._offer_status("thinking", line)async def _on_action_executed(self, event: ActionExecuted) -> None:+ """A tool result is an outcome only when no turn is running (work+ finished in the background or between turns). Inside a turn it is a+ step; a failed step the turn recovers from is not the user's failure."""+ if self._turn_in_progress():+ returnself._pet_outcome("success" if event.success else "error")async def _on_speech_spoken(self, event: SpeechSpoken) -> None:@@ -844,7 +901,11 @@ class OrbBusBridge:elif kind in PET_ERROR_SPOKEN_KINDS:self._pet_outcome("error")- async def _on_error_occurred(self, _event: ErrorOccurred) -> None:+ async def _on_error_occurred(self, event: ErrorOccurred) -> None:+ """Only an error nothing recovers from is shown: a provider retry or a+ fallback the user never notices must not make the pet look broken."""+ if event.recoverable:+ returnself._pet_outcome("error")async def _on_announcement(self, event: AnnouncementRequested) -> None:@@ -858,8 +919,16 @@ class OrbBusBridge:``text`` is the cumulative snapshot, so only its last sentence matters.The final snapshot (``done``) is forced through the rate limit, or thebubble could stop one sentence short of the answer.++ Spoken replies only (``voice`` / ``realtime``): a typed-chat or+ background reply is read in the app window, and an always-on-top+ bubble would put it on every shared screen."""- line = _last_sentence(event.text, complete_only=not event.done)+ if event.channel not in PET_STATUS_REPLY_CHANNELS:+ return+ if not getattr(self._orb, "wants_status_lines", False):+ return+ line = _tail_sentence(event.text, complete_only=not event.done)if line:self._offer_status("talking", line, force=bool(event.done))@@ -1095,6 +1164,9 @@ class OrbBusBridge:web-UI escape hatches, not permission to advertise a working microphone.``ready=False`` (warm-up start) leaves the gate closed."""+ # Runs on the backend loop: pin it here too, so a surface that is+ # clickable before the first state edge (the pet) marshals correctly.+ self._remember_loop()if not event.voice_usable:returnself._voice_usable = True@@ -1226,6 +1298,11 @@ class OrbBusBridge:self._last_response_text = ""self._show_listening_transcript("")self._completion_continuation = False+ # Every fresh turn of a conversation, not only the first one,+ # opens the pet's bubble with its "Listening …" header; the+ # reset keeps the feed from treating it as a repeat.+ self._status_feed.reset()+ self._offer_status("listening", "", force=True)self._cancel_idle_scheduler()elif state == "WAITING_FOR_COMPLETION":# User paused mid-sentence; the pipeline buffered an incomplete@@ -1361,7 +1438,8 @@ class OrbBusBridge:# diverge.self._listening_transcript_text = event.text.strip()self._show_listening_transcript(self._listening_transcript_text)- self._offer_status("listening", _last_sentence(self._listening_transcript_text))+ if getattr(self._orb, "wants_status_lines", False):+ self._offer_status("listening", _tail_sentence(self._listening_transcript_text))async def _on_response_generated(self, event: ResponseGenerated) -> None:"""Capture Jarvis's reply so the orb bubble can show it while speaking.@@ -1378,7 +1456,9 @@ class OrbBusBridge:# The pet's talking line, for reply paths that stream no# ``AssistantTextDelta``; after a streamed reply this is the same# sentence again and the feed treats it as such.- line = _last_sentence(self._last_response_text)+ if not getattr(self._orb, "wants_status_lines", False):+ return+ line = _tail_sentence(self._last_response_text)if line:self._offer_status("talking", line)diff --git a/ui/orb/controls.py b/ui/orb/controls.pyindex 00fd2a9603..2d091ecad6 100644--- a/ui/orb/controls.py+++ b/ui/orb/controls.py@@ -32,6 +32,7 @@ import loggingimport mathimport osimport sys+import threadingfrom collections.abc import Callable, Sequencefrom dataclasses import dataclass@@ -684,13 +685,17 @@ def toggle_speaker_mute(source: str = "orb") -> bool | None:setter = getattr(pipeline, "set_tts_volume", None)if not callable(setter):return None- current = _current_tts_volume(pipeline)- if current > 0.0:- _remember_volume(pipeline, current)- _apply_volume(setter, 0.0, source)- return True- _apply_volume(setter, _remembered_volume(pipeline), source)- return False+ # Read-modify-write under one lock: the Tk thread (this disc) and a REST+ # worker (the in-app button) can toggle at the same moment, and two+ # interleaved reads would both "mute" and lose the remembered volume.+ with _SPEAKER_TOGGLE_LOCK:+ current = _current_tts_volume(pipeline)+ if current > 0.0:+ _remember_volume(pipeline, current)+ _apply_volume(setter, 0.0, source)+ return True+ _apply_volume(setter, _remembered_volume(pipeline), source)+ return Falsedef _apply_volume(setter: Callable[..., object], volume: float, source: str) -> None:@@ -712,6 +717,9 @@ def _apply_volume(setter: Callable[..., object], volume: float, source: str) ->#: restarted pipeline cannot inherit a stale value._PRE_MUTE_VOLUME: dict[int, float] = {}+#: Serialises :func:`toggle_speaker_mute` across the Tk and REST threads.+_SPEAKER_TOGGLE_LOCK = threading.Lock()+def _current_tts_volume(pipeline: object) -> float:getter = getattr(pipeline, "get_tts_volume", None)@@ -737,7 +745,21 @@ def _remember_volume(pipeline: object, volume: float) -> None:def _remembered_volume(pipeline: object) -> float:- return _PRE_MUTE_VOLUME.get(id(pipeline), 1.0)+ """The volume to unmute to.++ The value parked by this toggle wins. Without one (the voice was silenced+ elsewhere, e.g. the in-app slider at 0) the configured ``[tts].volume``+ is restored, so unmuting never jumps to full volume for someone who keeps+ the voice quiet; only a configured 0 falls back to 1.0.+ """+ remembered = _PRE_MUTE_VOLUME.get(id(pipeline))+ if remembered is not None and remembered > 0.0:+ return remembered+ config = getattr(pipeline, "_config", None)+ configured = getattr(getattr(config, "tts", None), "volume", None)+ if isinstance(configured, int | float) and configured > 0.0:+ return max(0.0, min(1.0, float(configured)))+ return 1.0def speaker_is_muted() -> bool:diff --git a/ui/orb/overlay.py b/ui/orb/overlay.pyindex 032a0955ba..0aa5cdd572 100644--- a/ui/orb/overlay.py+++ b/ui/orb/overlay.py@@ -1294,6 +1294,9 @@ class OrbCommentBubble:self._status_showing = Falseself._status_expanded = Falseself._status_anchor: tuple[int, int, int, int] | None = None+ # (width, height) of the status bubble as last painted; a drag only+ # moves a bubble of this size instead of repainting it.+ self._status_size: tuple[int, int] | None = Noneself._status_auto_hide_ms: int | None = Noneself._ui_scale = 1.0self._build()@@ -1725,10 +1728,34 @@ class OrbCommentBubble:self._arm_status_hide()def move_status(self, anchor: tuple[int, int, int, int]) -> None:- """Follow the pet (drag, resize) without restarting the fade timer."""+ """Follow the pet (drag, resize) without restarting the fade timer.++ A drag calls this for every mouse motion, and neither the text nor the+ width changes then: only the window moves. The canvas is repainted+ only when nothing was painted yet.+ """self._status_anchor = anchor- if self._status_showing:+ if not self._status_showing:+ return+ size = self._status_size+ if size is None or self._top is None:self._render_status()+ return+ x, y = self._status_position(size[0], size[1], anchor)+ try:+ self._top.geometry(f"+{x}+{y}")+ except tk.TclError:+ logging.getLogger("jarvis.orb").debug("pet status bubble move failed", exc_info=True)++ def _status_position(+ self, bubble_w: int, height: int, anchor: tuple[int, int, int, int]+ ) -> tuple[int, int]:+ """Top-left corner for a bubble of this size: under the strip when it+ fits above ``limit_bottom``, else over the figure."""+ center_x, below_y, above_y, limit_bottom = anchor+ x = max(8, min(center_x - bubble_w // 2, self._screen_w - bubble_w - 8))+ y = below_y if below_y + height <= limit_bottom else max(8, above_y - height)+ return x, ydef arm_auto_hide(self, delay_ms: int | None) -> None:"""(Re)arm or cancel the status fade timer."""@@ -1790,9 +1817,7 @@ class OrbCommentBubble:if header_line:height += header_lh + (PET_BUBBLE_HEADER_GAP if lines else 0)- center_x, below_y, above_y, limit_bottom = self._status_anchor- x = max(8, min(center_x - bubble_w // 2, self._screen_w - bubble_w - 8))- y = below_y if below_y + height <= limit_bottom else max(8, above_y - height)+ x, y = self._status_position(bubble_w, height, self._status_anchor)try:self._top.geometry(f"{bubble_w}x{height}+{x}+{y}")self._canvas.configure(width=bubble_w, height=height)@@ -1827,8 +1852,10 @@ class OrbCommentBubble:self._top.lift()except tk.TclError:logging.getLogger("jarvis.orb").debug("pet status bubble paint failed", exc_info=True)+ self._status_size = Nonereturn Falseself._status_showing = True+ self._status_size = (bubble_w, height)return Truedef _cancel_timers(self) -> None:@@ -1848,6 +1875,7 @@ class OrbCommentBubble:def hide(self) -> None:self._status_showing = Falseself._status_expanded = False+ self._status_size = Noneif self._top is None:returnif self._dismiss_after_id is not None:@@ -2424,7 +2452,7 @@ class OrbOverlay:self._root: tk.Tk | None = Noneself._canvas: tk.Canvas | None = Noneself._comment_bubble: OrbCommentBubble | None = None- self._renderer: MascotRenderer | VoiceOrbRenderer | None = None+ self._renderer: MascotRenderer | VoiceOrbRenderer | PetRenderer | None = None# Cached mascot anchor + min-show-time guard.self._mascot_x: int = 0self._mascot_y: int = 0diff --git a/ui/orb/pet_renderer.py b/ui/orb/pet_renderer.pyindex c13510732e..667ee026fd 100644--- a/ui/orb/pet_renderer.py+++ b/ui/orb/pet_renderer.py@@ -181,7 +181,9 @@ class PetRenderer:try:pack = self._loader(requested)except Exception: # noqa: BLE001 — a broken pack must not kill the overlay- log.warning("pet %r failed to load; showing the strip only", requested)+ log.warning(+ "pet %r failed to load; showing the strip only", requested, exc_info=True+ )pack = Noneself._pack = pack# The id of what actually loaded: an unknown id falls back to the@@ -205,18 +207,42 @@ class PetRenderer:self._blank = Nonepack = self._packif pack is None:- strip_w, _strip_h = orb_controls.pet_strip_size(self._dpi_ratio)- self._factor = 1- self._size = (max(1, strip_w), 1)+ self._use_strip_only_size()returnedge = int(pack.manifest.frame_size)- self._factor = pixel_factor(edge, self._dpi_ratio, self._pet_scale)- frames: Mapping[str, Any] = pack.frames- for state, sequence in frames.items():- self._frames[str(state)] = tuple(- self._to_color_key(frame, self._factor, self._color_key) for frame in sequence+ factor = pixel_factor(edge, self._dpi_ratio, self._pet_scale)+ source: Mapping[str, Any] = pack.frames+ # States that borrow another row (STATE_FALLBACKS) share the SAME+ # source tuple in the pack; scale each tuple once, or a pet with only+ # an ``idle`` row would hold seven scaled copies of it.+ scaled_by_source: dict[int, tuple[Image.Image, ...]] = {}+ frames: dict[str, tuple[Image.Image, ...]] = {}+ try:+ for state, sequence in source.items():+ scaled = scaled_by_source.get(id(sequence))+ if scaled is None:+ scaled = tuple(+ self._to_color_key(frame, factor, self._color_key) for frame in sequence+ )+ scaled_by_source[id(sequence)] = scaled+ frames[str(state)] = scaled+ except Exception: # noqa: BLE001 — a frame that will not scale must not kill the overlay+ log.warning(+ "pet %r could not be scaled; showing the strip only", self._pet_id, exc_info=True)- self._size = (edge * self._factor, edge * self._factor)+ self._pack = None+ self._pet_id = NO_PET_ID+ self._use_strip_only_size()+ return+ self._frames = frames+ self._factor = factor+ self._size = (edge * factor, edge * factor)++ def _use_strip_only_size(self) -> None:+ """No figure: the window is a 1 px line as wide as the strip."""+ strip_w, _strip_h = orb_controls.pet_strip_size(self._dpi_ratio)+ self._factor = 1+ self._size = (max(1, strip_w), 1)@propertydef pet_id(self) -> str: