Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: quiet the image and video generation progress polls (#7869)

Daniel Han07b395f94958
diff --git a/studio/backend/loggers/handlers.py b/studio/backend/loggers/handlers.py
index 5d99ca85c6e..4492a4f03d4 100644
--- a/studio/backend/loggers/handlers.py
+++ b/studio/backend/loggers/handlers.py
@@ -41,6 +41,9 @@ _ACCESS_LOG_DEDUP_MS = _env_int("UNSLOTH_STUDIO_ACCESS_LOG_DEDUP_MS", 300)
# Liveness/UI polls whose line means only "still polling"; collapse to a longer
# heartbeat. First hit and errors still log. 0 = off.
_QUIET_POLL_DEDUP_MS = _env_int("UNSLOTH_STUDIO_ACCESS_LOG_POLL_DEDUP_MS", 10000)
+# Both windows off is what --verbose sets; the drop-the-2xx suppressor below has no
+# window of its own, so it must read the same signal to honour --verbose.
+_VERBOSE_ACCESS_LOG = _ACCESS_LOG_DEDUP_MS <= 0 and _QUIET_POLL_DEDUP_MS <= 0
_QUIET_POLL_PATHS = {
"/api/health",
"/api/auth/status",
@@ -55,6 +58,16 @@ _QUIET_POLL_PATHS = {
"/api/models/download-progress",
"/api/models/gguf-download-progress",
"/api/datasets/download-progress",
+ # Generation is fire-and-forget: its outcome only reaches the UI via these polls.
+ "/api/inference/images/generate-progress",
+ "/api/inference/video/generate-progress",
+ # Polled every 1.5s while the train UI is open.
+ "/api/train/diffusion/status",
+ # Unlike /api/inference/load-progress, these handlers log nothing and
+ # diffusion.loaded / video.loaded are terminal, so a minutes-long load would
+ # otherwise emit nothing at all.
+ "/api/inference/images/load-progress",
+ "/api/inference/video/load-progress",
}
_DEDUP_MAP_MAX = 4096
_NATIVE_PATH_LEASE_RE = re.compile(
@@ -110,8 +123,8 @@ def _is_quiet_success(method: str, path: str, status_code: int, pre_auth: bool)
"""GET-only. Suppress a 2xx poll line that carries no signal, plus a chat list
poll's transient pre-auth 401 (only in the bootstrap window before the first
successful token refresh). Mutations, real (post-refresh) auth failures, and
- all other errors always log."""
- if method != "GET":
+ all other errors always log. --verbose disables the whole suppressor."""
+ if _VERBOSE_ACCESS_LOG or method != "GET":
return False
if 200 <= status_code < 300:
return path in _QUIET_SUCCESS_PATHS or path in _CHAT_LIST_PATHS
diff --git a/studio/backend/tests/test_logging_middleware.py b/studio/backend/tests/test_logging_middleware.py
index d59e4dbee22..23d87dc4079 100644
--- a/studio/backend/tests/test_logging_middleware.py
+++ b/studio/backend/tests/test_logging_middleware.py
@@ -357,3 +357,87 @@ def test_legacy_download_progress_heartbeats_not_suppressed(logs, monkeypatch):
for _ in range(3):
_run(mw(_http_scope("/api/models/download-progress"), _noop_receive, _drop))
assert _paths_logged(logs) == ["/api/models/download-progress"]
+
+
+def test_generation_progress_polls_heartbeat(logs, monkeypatch):
+ # The 300ms poll timer always landed just outside the 300ms base dedup window.
+ monkeypatch.setattr(hmod, "_ACCESS_LOG_DEDUP_MS", 0)
+ monkeypatch.setattr(hmod, "_QUIET_POLL_DEDUP_MS", 1000)
+ for path in (
+ "/api/inference/images/generate-progress",
+ "/api/inference/video/generate-progress",
+ "/api/train/diffusion/status",
+ ):
+ mw = LoggingMiddleware(_status_app(200))
+ for _ in range(5):
+ _run(mw(_http_scope(path), _noop_receive, _drop))
+ assert _paths_logged(logs) == [path]
+ logs.events.clear()
+
+
+def test_generation_progress_errors_still_log(logs, monkeypatch):
+ # Heartbeat dedup is GET/2xx only, so a failing poll stays visible.
+ monkeypatch.setattr(hmod, "_ACCESS_LOG_DEDUP_MS", 0)
+ monkeypatch.setattr(hmod, "_QUIET_POLL_DEDUP_MS", 1000)
+ mw = LoggingMiddleware(_status_app(500))
+ for _ in range(3):
+ _run(mw(_http_scope("/api/inference/images/generate-progress"), _noop_receive, _drop))
+ assert _paths_logged(logs) == ["/api/inference/images/generate-progress"] * 3
+
+
+def test_image_video_load_progress_heartbeats(logs, monkeypatch):
+ # These handlers log nothing themselves, so keep a pulse for a multi-minute load.
+ monkeypatch.setattr(hmod, "_ACCESS_LOG_DEDUP_MS", 0)
+ monkeypatch.setattr(hmod, "_QUIET_POLL_DEDUP_MS", 1000)
+ for path in ("/api/inference/images/load-progress", "/api/inference/video/load-progress"):
+ mw = LoggingMiddleware(_status_app(200))
+ for _ in range(5):
+ _run(mw(_http_scope(path), _noop_receive, _drop))
+ assert _paths_logged(logs) == [path]
+ logs.events.clear()
+ mw = LoggingMiddleware(_status_app(503))
+ for _ in range(3):
+ _run(mw(_http_scope("/api/inference/images/load-progress"), _noop_receive, _drop))
+ assert _paths_logged(logs) == ["/api/inference/images/load-progress"] * 3
+
+
+def test_unrelated_image_routes_still_log(logs, monkeypatch):
+ # Only the timer-polled paths are quieted, not the event-driven reads.
+ monkeypatch.setattr(hmod, "_ACCESS_LOG_DEDUP_MS", 0)
+ for path in (
+ "/api/inference/images/status",
+ "/api/inference/images/info",
+ "/api/inference/video/status",
+ ):
+ _run(LoggingMiddleware(_status_app(200))(_http_scope(path), _noop_receive, _drop))
+ assert _paths_logged(logs) == [
+ "/api/inference/images/status",
+ "/api/inference/images/info",
+ "/api/inference/video/status",
+ ]
+
+
+def test_verbose_restores_the_dropped_success_polls(logs, monkeypatch):
+ # --verbose zeroes both windows, so the 2xx suppressor must stand down too.
+ monkeypatch.setattr(hmod, "_ACCESS_LOG_DEDUP_MS", 0)
+ monkeypatch.setattr(hmod, "_QUIET_POLL_DEDUP_MS", 0)
+ monkeypatch.setattr(hmod, "_VERBOSE_ACCESS_LOG", True)
+ for path in (
+ "/api/inference/load-progress",
+ "/api/hub/download-progress",
+ "/api/export/status",
+ "/api/chat/threads",
+ ):
+ mw = LoggingMiddleware(_status_app(200))
+ for _ in range(3):
+ _run(mw(_http_scope(path), _noop_receive, _drop))
+ assert _paths_logged(logs) == [path] * 3
+ logs.events.clear()
+
+
+def test_verbose_off_by_default_keeps_the_polls_quiet(logs):
+ # Default env leaves both windows set, so a normal launch is unchanged.
+ assert hmod._VERBOSE_ACCESS_LOG is False
+ for path in ("/api/inference/load-progress", "/api/hub/download-progress"):
+ _run(LoggingMiddleware(_status_app(200))(_http_scope(path), _noop_receive, _drop))
+ assert logs.events == []