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.

fix(feedback): cache the version probe and drop empty screenshot payloads

rubenluetke10-beep640d6a11274c
diff --git a/jarvis/ui/web/feedback_routes.py b/jarvis/ui/web/feedback_routes.py
index cbb2b22c24..cba18b4026 100644
--- a/jarvis/ui/web/feedback_routes.py
+++ b/jarvis/ui/web/feedback_routes.py
@@ -42,6 +42,7 @@ from __future__ import annotations
import base64
import datetime
+import functools
import json as _json
import logging
import platform
@@ -130,12 +131,17 @@ class FeedbackChannelStatus(BaseModel):
# ----------------------------------------------------------------------
[email protected]_cache(maxsize=1)
def _app_version() -> str:
"""Return the running app version string, with several fallback strategies.
1. ``jarvis.__version__`` if present (editable install with metadata).
2. The ``version = "..."`` field from ``pyproject.toml`` at repo root.
3. ``"unknown"`` if both fail.
+
+ Memoized: the version never changes within a running process, and the
+ pyproject fallback does synchronous file IO that must not repeat on every
+ request handled by the async routes.
"""
try:
import jarvis # type: ignore[import]
@@ -241,7 +247,9 @@ async def submit_feedback(body: FeedbackPayload) -> FeedbackResult:
f"({len(raw):,} bytes decoded)."
),
)
- screenshot_bytes = raw
+ # A data-URL without a payload decodes to b"" — treat that as "no
+ # screenshot" rather than attaching an empty file to Discord.
+ screenshot_bytes = raw or None
except HTTPException:
raise
except Exception as exc: # noqa: BLE001 — bad b64 → skip screenshot
diff --git a/tests/unit/ui/web/test_feedback_routes.py b/tests/unit/ui/web/test_feedback_routes.py
index a9c276a6a7..a9d8eb270d 100644
--- a/tests/unit/ui/web/test_feedback_routes.py
+++ b/tests/unit/ui/web/test_feedback_routes.py
@@ -118,6 +118,50 @@ def test_status_configured_never_leaks_the_webhook_url(client: TestClient, monke
assert webhook_url not in resp.text
+def test_empty_screenshot_payload_sends_no_attachment(client: TestClient, monkeypatch) -> None:
+ """A data-URL without a base64 payload decodes to b"" — the dispatch must
+ fall back to the plain JSON webhook call instead of attaching an empty
+ file to Discord."""
+ import jarvis.ui.web.feedback_routes as feedback_routes
+
+ captured: dict = {}
+
+ class _FakeResponse:
+ is_success = True
+ status_code = 204
+ text = ""
+
+ class _FakeAsyncClient:
+ def __init__(self, timeout: float | None = None) -> None:
+ pass
+
+ async def __aenter__(self) -> _FakeAsyncClient:
+ return self
+
+ async def __aexit__(self, *exc: object) -> bool:
+ return False
+
+ async def post(self, url: str, **kwargs: object) -> _FakeResponse:
+ captured.update({"url": url, **kwargs})
+ return _FakeResponse()
+
+ monkeypatch.setattr(
+ feedback_routes, "get_secret",
+ lambda *a, **k: "https://discord.com/api/webhooks/123/abc",
+ )
+ monkeypatch.setattr(feedback_routes.httpx, "AsyncClient", _FakeAsyncClient)
+
+ resp = client.post(
+ "/api/feedback", json=_payload(screenshot="data:image/png;base64,")
+ )
+
+ assert resp.status_code == 200
+ assert resp.json()["status"] == "sent"
+ # Plain JSON dispatch, no multipart upload of a zero-byte "image".
+ assert "json" in captured
+ assert "files" not in captured
+
+
def test_app_version_pyproject_fallback_reads_repo_root() -> None:
"""The pyproject.toml fallback must resolve to the real repo root — it
regressed once by pointing one directory ABOVE it (parents[4])."""