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.

Settle the permission step's reloads on the pill instead of networkidle (#12153)

Daniel Hand96e922f3908
diff --git a/tests/studio/playwright_chat_ui.py b/tests/studio/playwright_chat_ui.py
index 6b2a39583d6..987af7c1014 100644
--- a/tests/studio/playwright_chat_ui.py
+++ b/tests/studio/playwright_chat_ui.py
@@ -314,12 +314,14 @@ def exercise_permission_mode_controls(page, shoot):
# same reason and with the same note about macOS. This does the same after
# each reload. It asserts exactly what it asserted before; it just stops
# asking before the answer can exist.
+ #
+ # The pill wait is the settle, not "networkidle". With this block's page.route on /api/chat/settings
+ # in place, Playwright's networkidle wait after a reload stopped returning at all once /api reads
+ # went out as Cache-Control: no-store (#12148): its own 30s timeout never fired, and the step sat
+ # there until the 180s watchdog killed the job (Chat UI Tests (chat) on main at 1dddc1437). The
+ # pill is the one thing the next assertion needs, and waiting for it is bounded.
def reload_and_wait_for_pill():
- page.reload(wait_until = "domcontentloaded")
- try:
- page.wait_for_load_state("networkidle", timeout = 30_000)
- except Exception:
- pass # best-effort -- proceed even if network never idles
+ page.reload(wait_until = "load")
expect(pill).to_be_visible(timeout = 30_000)
# choose() only drives THIS tab.
diff --git a/tests/studio/test_chat_ui_permission_reload_wait.py b/tests/studio/test_chat_ui_permission_reload_wait.py
new file mode 100644
index 00000000000..4eee9c0f325
--- /dev/null
+++ b/tests/studio/test_chat_ui_permission_reload_wait.py
@@ -0,0 +1,74 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""The permission step's reload must settle on the pill, never on "networkidle".
+
+The step reloads with a page.route on /api/chat/settings in place. Once /api reads went out as
+Cache-Control: no-store (#12148), Playwright's `wait_for_load_state("networkidle", timeout = 30_000)`
+after that reload stopped returning at all: the 30 s timeout never fired and the step hung until
+the 180 s watchdog ended the job, 3 runs out of 3 locally and on main at 1dddc1437. The same step
+passes 3 out of 3 with the header in place once the reload settles on the pill instead, so this
+pins the helper to the bounded wait.
+"""
+
+from __future__ import annotations
+
+import ast
+from pathlib import Path
+
+
+DRIVER = (Path(__file__).resolve().parent / "playwright_chat_ui.py").read_text(encoding = "utf-8")
+STEP = "exercise_permission_mode_controls"
+HELPER = "reload_and_wait_for_pill"
+
+
+def _helper() -> ast.FunctionDef:
+ for node in ast.walk(ast.parse(DRIVER)):
+ if isinstance(node, ast.FunctionDef) and node.name == STEP:
+ for inner in ast.walk(node):
+ if isinstance(inner, ast.FunctionDef) and inner.name == HELPER:
+ return inner
+ raise AssertionError(f"{HELPER} is no longer defined inside {STEP}")
+
+
+def _calls(fn: ast.FunctionDef, name: str) -> list[ast.Call]:
+ return [
+ node
+ for node in ast.walk(fn)
+ if isinstance(node, ast.Call)
+ and isinstance(node.func, ast.Attribute)
+ and node.func.attr == name
+ ]
+
+
+def test_the_permission_reload_never_waits_for_networkidle():
+ helper = _helper()
+ # Positional or `state = "networkidle"`: both are the same wait.
+ idle = [
+ call
+ for call in _calls(helper, "wait_for_load_state")
+ if any(
+ isinstance(value, ast.Constant) and value.value == "networkidle"
+ for value in [*call.args[:1], *(kw.value for kw in call.keywords if kw.arg == "state")]
+ )
+ ]
+ assert not idle, (
+ f"{HELPER} waits for networkidle again; with the step's page.route and no-store /api reads "
+ "that wait never returns and the watchdog kills the job"
+ )
+ for call in _calls(helper, "reload"):
+ for keyword in call.keywords:
+ if keyword.arg == "wait_until":
+ assert getattr(keyword.value, "value", None) != "networkidle", ast.unparse(call)
+
+
+def test_the_permission_reload_settles_on_a_bounded_pill_wait():
+ helper = _helper()
+ reloads = _calls(helper, "reload")
+ visible = _calls(helper, "to_be_visible")
+ assert reloads and visible, ast.unparse(helper)
+ assert reloads[0].lineno < visible[0].lineno, "the pill wait must follow the reload"
+ timeout = next((kw.value for kw in visible[0].keywords if kw.arg == "timeout"), None)
+ assert isinstance(timeout, ast.Constant) and 0 < timeout.value <= 60_000, ast.unparse(
+ visible[0]
+ )