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.

Wheel the voice model picker once its rows are on screen (#8743)

Daniel Hanad96b66659b3
diff --git a/tests/studio/playwright_extra_ui.py b/tests/studio/playwright_extra_ui.py
index fa709310134..27a1ba7b80a 100644
--- a/tests/studio/playwright_extra_ui.py
+++ b/tests/studio/playwright_extra_ui.py
@@ -9,6 +9,7 @@ import re
import sys
import time
import urllib.error
+import urllib.parse
import urllib.request
from pathlib import Path
from playwright.sync_api import sync_playwright
@@ -44,6 +45,30 @@ TURN_TIMEOUT_MS = int(os.environ.get("STUDIO_UI_TURN_TIMEOUT_MS", "180000"))
WALL_TIMEOUT_S = float(os.environ.get("STUDIO_UI_WALL_TIMEOUT_S", "720"))
FETCH_TIMEOUT_MS = int(os.environ.get("STUDIO_UI_FETCH_TIMEOUT_MS", "30000"))
LOAD_FETCH_TIMEOUT_MS = int(os.environ.get("STUDIO_UI_LOAD_TIMEOUT_MS", "180000"))
+# Declares a runner with no route to the Hub, for the voice-picker wheel step. Egress that is
+# blackholed rather than refused can leave the search hanging with no transport failure to observe,
+# so the fallback needs a way to be asserted as well as detected.
+HF_OFFLINE = os.environ.get("STUDIO_UI_HF_OFFLINE", "0") == "1"
+# Voice-picker wheel budget, both halves set by the frontend rather than picked round. The
+# searched rows are up to 15.3s away on a healthy runner: the query is debounced 300ms and the
+# Hugging Face search is then given 15s (HF_SEARCH_TIMEOUT_MS,
+# studio/frontend/src/features/hub/hooks/use-hub-model-search.ts). Waiting 15.5s for them clears
+# that, so a slow-but-working Hub is not red, and it also outlives the abort at 15.3s that a
+# blackholed runner's search ends in, so the transport failure that permits the fallback is
+# observed before the wait gives up. Those 200ms of headroom only hold while the debounce fires
+# on time, so when the wait runs out with the search still open the budget is re-based onto the
+# request itself (search_abort_extension) rather than spent. The 30s ceiling is that wait
+# plus the re-basing a starved runner needs, plus what is left to do after
+# it: a list swap landing mid-wheel costs one 2s wheel round, and an unreachable-Hub run has
+# already spent its first 15.5s searching when it clears the query and wheels the built-in list.
+# Only a failing run pays either; a passing run leaves on the first wheel, 1.5s end to end in CI.
+WHEEL_ROWS_TIMEOUT_MS = 15_500
+WHEEL_DEADLINE_S = 30.0
+# The ceiling the deadline may be pushed to when the wait is re-based onto a request that is
+# still open. WHEEL_DEADLINE_S covers one search, and the picker runs two in sequence, so
+# re-basing onto the second has to be allowed to outlast it. Measured from the step's start so
+# a page that keeps opening requests cannot hold the step open indefinitely.
+WHEEL_DEADLINE_MAX_S = 75.0
_n = [0]
_failed: list[str] = []
@@ -104,6 +129,93 @@ with sync_playwright() as p:
reduced_motion = "reduce",
)
install_view_transition_killer(ctx)
+
+ # Evidence that this runner cannot reach the Hub, collected for the whole session because the
+ # frontend backs off for 30s after a failed Hub request (REMOTE_OFFLINE_TTL_MS in
+ # studio/frontend/src/features/hub/lib/network.ts) and may not retry inside a later step. Bound
+ # to the context, not the page, so a replacement page is covered too.
+ hf_unreachable: list[str] = []
+ # Set while the wheel step owns the picker, so an aborted Hub request can be attributed.
+ wheel_step_active = [False]
+ # Hub requests still in flight, by start time, so a wait that runs out while the frontend's
+ # own search timeout is still running can wait for its abort instead of guessing.
+ hf_inflight: dict[object, float] = {}
+
+ def _is_hub_url(url: str) -> bool:
+ """Only the origin the picker itself queries counts as Hub connectivity.
+
+ A substring test also matches datasets-server.huggingface.co, which the training
+ split lookup calls. The frontend keys its backoff by exact origin
+ (HUGGING_FACE_ORIGIN in studio/frontend/src/features/hub/lib/network.ts), so a
+ failure at a sibling host says nothing about the picker's search, and counting it
+ would let an unrelated lookup hand a real search regression the built-in list.
+ """
+ try:
+ return urllib.parse.urlsplit(url).netloc.lower() == "huggingface.co"
+ except Exception:
+ return False
+
+ def _note_hf_unreachable(why: str) -> None:
+ if not hf_unreachable:
+ info(f"WARN Hugging Face unreachable from this runner: {why}")
+ hf_unreachable.append(why)
+
+ def _on_request(req) -> None:
+ try:
+ if _is_hub_url(req.url):
+ hf_inflight[req] = time.monotonic()
+ except Exception:
+ pass
+
+ def _on_requestfailed(req) -> None:
+ try:
+ hf_inflight.pop(req, None)
+ if not _is_hub_url(req.url):
+ return
+ failure = req.failure or ""
+ # net::ERR_ABORTED is how a blackholed request ends, at the frontend's own 15s
+ # search timeout, and equally how a superseded query or an unmounting picker ends.
+ # It only says "unreachable" while the wheel step holds the picker open on a single
+ # query, where nothing else can be cancelling anything. Every other failure is a
+ # transport error and counts wherever it happens.
+ if "ERR_ABORTED" in failure and not wheel_step_active[0]:
+ return
+ _note_hf_unreachable(f"request failed: {failure}")
+ except Exception:
+ pass
+
+ def _on_requestfinished(req) -> None:
+ try:
+ hf_inflight.pop(req, None)
+ except Exception:
+ pass
+
+ def _on_response(resp) -> None:
+ # 429 and 5xx are the Hub refusing to serve this runner. Every other 4xx is a request the
+ # app itself built wrong, which is a real defect and must not excuse anything.
+ try:
+ if not _is_hub_url(resp.url):
+ return
+ if resp.status == 429 or resp.status >= 500:
+ _note_hf_unreachable(f"HTTP {resp.status}")
+ elif hf_unreachable:
+ # A served response proves this runner has a route to the Hub, so the earlier
+ # failures are stale and must stop excusing anything: the frontend drops its own
+ # offline state on exactly this signal (markRemoteNetworkOnline,
+ # studio/frontend/src/features/hub/lib/network.ts). Keeping them would let one
+ # transient failure hand a later search-rendering regression the built-in list.
+ info(
+ f"Hugging Face reachable again (HTTP {resp.status}); dropping "
+ f"{len(hf_unreachable)} earlier failure(s)"
+ )
+ hf_unreachable.clear()
+ except Exception:
+ pass
+
+ ctx.on("request", _on_request)
+ ctx.on("requestfailed", _on_requestfailed)
+ ctx.on("requestfinished", _on_requestfinished)
+ ctx.on("response", _on_response)
page = ctx.new_page()
# 60s default for the slow macos-14 runner (second Unsloth boot of the job).
page.set_default_timeout(60_000)
@@ -548,25 +660,187 @@ with sync_playwright() as p:
page.get_by_test_id("dictation-engine-trigger").click()
page.get_by_test_id("dictation-engine-model").click()
page.get_by_test_id("stt-model-trigger").click()
- page.get_by_test_id("stt-model-search").fill("whisper")
+ wheel_step_active[0] = True
results = page.get_by_test_id("stt-model-results")
- page.wait_for_function(
- """() => {
- const node = document.querySelector('[data-testid="stt-model-results"]');
- return !!node && node.scrollHeight > node.clientHeight;
- }""",
- timeout = 30_000,
- )
- results.hover()
- page.mouse.wheel(0, 700)
- page.wait_for_function(
- """() => {
- const node = document.querySelector('[data-testid="stt-model-results"]');
- return !!node && node.scrollTop > 0;
- }""",
- timeout = 5_000,
- )
- info("OK Voice model picker mouse wheel changed scrollTop")
+ # Wheel at the searched rows, not at whatever overflows first. The query is
+ # debounced 300ms and the list is then replaced by a one-line spinner for as
+ # long as the Hugging Face search takes, so the first paint that overflows is
+ # the pre-search built-in list: on macos-15 the hover + wheel lands after the
+ # swap, on a container that is one spinner row tall and has nothing to scroll.
+ # Requiring rendered model rows (the loading and empty states are plain divs,
+ # every row is a button) pins the assertion to the state a user scrolls, and
+ # re-wheeling until the deadline absorbs a swap that lands mid-wheel.
+ #
+ # Rows alone are not enough, though: the built-in list is rows, and it overflows
+ # from the moment the popover opens, so a fast runner can satisfy that inside the
+ # 300ms debounce and never wheel a searched row at all. Snapshot the built-in
+ # rows first and require the list to have become something else, so the search is
+ # what is being scrolled. The built-in list is accepted only on proof that the
+ # Hub is unreachable (see below), which is also the only branch that clears the
+ # query and so the only one that waits on `rows_overflow`.
+ builtin_rows_js = """() => {
+ const node = document.querySelector('[data-testid="stt-model-results"]');
+ if (!node) return "";
+ return Array.from(node.querySelectorAll('button'))
+ .map((row) => row.innerText).join("\\u0000");
+ }"""
+ try:
+ results.locator("button").first.wait_for(state = "attached", timeout = 10_000)
+ except Exception as builtin_err:
+ info(f"WARN built-in model rows never rendered: {builtin_err!r}")
+ builtin_rows = robust_evaluate(page, builtin_rows_js)
+ page.get_by_test_id("stt-model-search").fill("whisper")
+ query_typed_at = time.monotonic()
+ searched_rows_overflow = """(builtin) => {
+ const node = document.querySelector('[data-testid="stt-model-results"]');
+ if (!node || node.scrollHeight <= node.clientHeight) return false;
+ const rows = Array.from(node.querySelectorAll('button'));
+ if (rows.length === 0) return false;
+ return rows.map((row) => row.innerText).join("\\u0000") !== builtin;
+ }"""
+ rows_overflow = """() => {
+ const node = document.querySelector('[data-testid="stt-model-results"]');
+ return !!node
+ && node.querySelectorAll('button').length > 0
+ && node.scrollHeight > node.clientHeight;
+ }"""
+ scrolled_js = """() => {
+ const node = document.querySelector('[data-testid="stt-model-results"]');
+ return !!node && node.scrollTop > 0;
+ }"""
+ wheel_started_at = time.monotonic()
+ wheel_deadline = wheel_started_at + WHEEL_DEADLINE_S
+ wheel_scrolled = False
+ cleared_search = False
+ extended_for: set = set()
+ next_rows_ms = float(WHEEL_ROWS_TIMEOUT_MS)
+
+ def search_abort_extension() -> tuple:
+ """How much of the frontend's own search timeout is still to run.
+
+ WHEEL_ROWS_TIMEOUT_MS is counted from `fill`, but the frontend starts its 15s
+ from the debounced request, which a CPU-starved runner can schedule well past
+ the nominal 300ms. While that request is in flight the abort that proves the
+ Hub unreachable has not happened yet, so the budget is re-based onto the
+ request rather than the step deciding the Hub is healthy without it.
+
+ Only requests issued after the query was typed count: an unrelated Hub
+ request left hanging from an earlier step started long ago and would anchor
+ the budget to a deadline that has already passed.
+
+ Returns the request as well, because the picker searches twice in sequence
+ (unsloth-owned, then general: mergedModelIterator in
+ studio/frontend/src/features/hub/hooks/use-hub-model-search.ts). A slow but
+ healthy first search can spend the extension, and the second then starts with
+ its own full budget, so the caller has to be able to re-base onto that one
+ rather than treat the step as already extended.
+ """
+ live = [(at, req) for req, at in hf_inflight.items() if at >= query_typed_at]
+ if not live:
+ return None, 0.0
+ started, req = min(live, key = lambda pair: pair[0])
+ return req, max(
+ 0.0, (started - time.monotonic()) * 1000 + WHEEL_ROWS_TIMEOUT_MS
+ )
+
+ while not wheel_scrolled:
+ remaining_ms = (wheel_deadline - time.monotonic()) * 1000
+ if remaining_ms <= 0:
+ break
+ rows_ms = min(remaining_ms, next_rows_ms)
+ next_rows_ms = float(WHEEL_ROWS_TIMEOUT_MS)
+ try:
+ if cleared_search:
+ page.wait_for_function(rows_overflow, timeout = rows_ms)
+ else:
+ page.wait_for_function(
+ searched_rows_overflow,
+ arg = builtin_rows,
+ timeout = rows_ms,
+ )
+ except Exception as row_err:
+ # A dead renderer must reach the crash handler below, exactly as in the
+ # wheel wait; swallowed here it becomes a hard "did not wheel-scroll".
+ if page_crashed(page, row_err):
+ raise
+ if not (cleared_search or hf_unreachable or HF_OFFLINE):
+ open_req, extra_ms = search_abort_extension()
+ if (
+ open_req is not None
+ and open_req not in extended_for
+ and extra_ms > 0
+ ):
+ extended_for.add(open_req)
+ next_rows_ms = extra_ms
+ # The extension is worth nothing if the step deadline still
+ # ends inside it: rows_ms is min()ed against what is left, so
+ # the second search would be cut off mid-flight and reported
+ # as a scroll failure. Push the deadline past the request just
+ # re-based onto, up to the ceiling.
+ wheel_deadline = min(
+ wheel_started_at + WHEEL_DEADLINE_MAX_S,
+ max(wheel_deadline, time.monotonic() + extra_ms / 1000),
+ )
+ info(
+ "WARN search rows are not in and a Hugging Face request is "
+ f"still open; waiting {extra_ms / 1000:.1f}s more for it to "
+ "answer or abort"
+ )
+ continue
+ # Falling back to the built-in list means asserting the wheel against the
+ # pre-search list this step was rewritten to stop accepting, so it takes
+ # proof that the Hub is what is missing: a failed huggingface.co request
+ # (or 429/5xx), or a runner that declares itself offline. Search rendering
+ # that breaks with the Hub answering normally has no such proof and fails
+ # here with the geometry, instead of passing on the built-in list.
+ offline = bool(hf_unreachable) or HF_OFFLINE
+ if cleared_search or not offline:
+ break # never overflowed with rows; geometry is reported below
+ why = hf_unreachable[0] if hf_unreachable else "STUDIO_UI_HF_OFFLINE=1"
+ info(
+ f"WARN no 'whisper' search rows and the Hub is unreachable ({why}); "
+ "wheeling the built-in list instead"
+ )
+ cleared_search = True
+ page.get_by_test_id("stt-model-search").fill("")
+ continue
+ results.hover()
+ page.mouse.wheel(0, 700)
+ try:
+ page.wait_for_function(scrolled_js, timeout = 2_000)
+ except Exception as wheel_err:
+ # A dead renderer must still reach the crash handler below, not be
+ # retried until the deadline and reported as a scroll failure.
+ if page_crashed(page, wheel_err):
+ raise
+ continue
+ wheel_scrolled = True
+ if wheel_scrolled:
+ info("OK Voice model picker mouse wheel changed scrollTop")
+ else:
+ # Geometry in the message: the next failure says whether the list was
+ # short, empty or scrollable-but-unscrolled without a second CI run.
+ try:
+ geom = robust_evaluate(
+ page,
+ """() => {
+ const node = document.querySelector('[data-testid="stt-model-results"]');
+ if (!node) return null;
+ return {
+ scrollTop: node.scrollTop,
+ scrollHeight: node.scrollHeight,
+ clientHeight: node.clientHeight,
+ rows: node.querySelectorAll('button').length,
+ };
+ }""",
+ )
+ except Exception as geom_err:
+ geom = f"<unreadable: {geom_err!r}>"
+ fail(
+ f"Voice model picker did not wheel-scroll: {geom} "
+ f"hub_unreachable={hf_unreachable[:1] or False} "
+ f"cleared_search={cleared_search}"
+ )
except Exception as exc:
if page_crashed(page, exc) and MACOS_RUNNER:
runtime_warn(f"Voice model picker aborted (browser/page unstable): {exc!r}")
@@ -578,6 +852,8 @@ with sync_playwright() as p:
)
else:
fail(f"Voice model picker did not wheel-scroll: {exc!r}")
+ finally:
+ wheel_step_active[0] = False
# When the crash closed the context/browser, recover_or_replace_page hands back the closed page;
# skip the cosmetic teardown rather than re-raise TargetClosedError on it.
if not page.is_closed():