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.

One multi-turn smoke script for all three operating systems (#9086)

Daniel Hanfa6be357dd93
diff --git a/.github/scripts/studio_smoke/multi_turn_chat.py b/.github/scripts/studio_smoke/multi_turn_chat.py
new file mode 100644
index 00000000000..e1687cf900c
--- /dev/null
+++ b/.github/scripts/studio_smoke/multi_turn_chat.py
@@ -0,0 +1,138 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""Four turns through both SDKs, twice, against a running Unsloth server.
+
+Two properties at once. The conversation is built so that turns 2 and 4 are only
+answerable from the earlier turns, which exercises the history wiring; and the whole
+conversation is run twice at temperature 0.0 with a fixed seed, which is the only check
+anywhere that greedy decoding is reproducible.
+
+This lived inline in three workflows, and being three copies is what let one of them
+stop checking. On 2026-05-22 an unrelated event-loop fix (#5669) relaxed the Linux copy
+to print a warning instead of failing; the macOS and Windows copies, which are otherwise
+byte-identical in logic, kept the assertion. Linux is the leg that runs on every pull
+request, so the check was effectively off where it mattered most, for three months, with
+nothing to notice it. One file cannot drift from itself.
+
+Reads BASE_URL and TOKEN from the environment, which is the only thing that differs
+between the three callers: each boots its server on its own port.
+"""
+
+from __future__ import annotations
+
+import os
+import sys
+
+SEED = 3407
+MAX_TOKENS = 80
+
+# Turn 2 cannot be answered without turn 1, and turn 4 without turn 3, so a server that
+# drops history fails here rather than returning something plausible.
+PROMPTS = [
+ "What is 1+1?",
+ "What did I ask before?",
+ "What is the capital of France?",
+ "Repeat the city name",
+]
+
+
+def _server() -> tuple[str, str]:
+ """Where to talk and what to send. The only thing that differs per caller: each
+ workflow boots its server on its own port. Read here rather than at import, so the
+ checking half of this file can be exercised without a server or the SDKs."""
+ return os.environ["BASE_URL"], os.environ["TOKEN"] # a JWT is accepted as Bearer
+
+
+def run_openai() -> list[str]:
+ from openai import OpenAI
+
+ BASE, KEY = _server()
+ client = OpenAI(base_url = f"{BASE}/v1", api_key = KEY)
+ history: list[dict] = []
+ replies = []
+ for prompt in PROMPTS:
+ history.append({"role": "user", "content": prompt})
+ resp = client.chat.completions.create(
+ model = "default",
+ messages = history,
+ temperature = 0.0,
+ max_tokens = MAX_TOKENS,
+ seed = SEED,
+ extra_body = {"enable_thinking": False},
+ )
+ text = resp.choices[0].message.content or ""
+ replies.append(text)
+ history.append({"role": "assistant", "content": text})
+ return replies
+
+
+def run_anthropic() -> list[str]:
+ from anthropic import Anthropic
+
+ BASE, KEY = _server()
+ # Two SDK quirks against Unsloth:
+ # 1. base_url must NOT include /v1 -- the SDK appends /v1/messages itself, and a
+ # base_url that already has it hits /v1/v1/messages and 405s.
+ # 2. The SDK sends x-api-key by default, but Unsloth's auth layer is HTTPBearer
+ # only, so Authorization has to be set through default_headers instead.
+ client = Anthropic(
+ base_url = BASE,
+ api_key = "unused",
+ default_headers = {"Authorization": f"Bearer {KEY}"},
+ )
+ history: list[dict] = []
+ replies = []
+ for prompt in PROMPTS:
+ history.append({"role": "user", "content": prompt})
+ msg = client.messages.create(
+ model = "default",
+ max_tokens = MAX_TOKENS,
+ messages = history,
+ temperature = 0.0,
+ extra_body = {"seed": SEED, "enable_thinking": False},
+ )
+ text = "".join(b.text for b in msg.content if getattr(b, "type", None) == "text")
+ replies.append(text)
+ history.append({"role": "assistant", "content": text})
+ return replies
+
+
+def check(label: str, first: list[str], second: list[str]) -> None:
+ for i, (a, b) in enumerate(zip(first, second), start = 1):
+ print(f"[{label} turn {i}] {a!r}")
+ # BOTH runs, not just the first. Stripping makes the comparison below blind to
+ # the difference between "\n" and "": a second run that returned nothing at all
+ # would compare equal to a first that returned only tolerated whitespace, and the
+ # smoke test would print OK for a server that had stopped answering. The Linux
+ # copy asserted both before this was consolidated; the macOS one it was taken
+ # from asserted only the first.
+ assert a, f"{label}: empty turn {i} response in the first run"
+ assert b, f"{label}: empty turn {i} response in the second run"
+ # Compared stripped: llama-server varies trailing whitespace (a final newline)
+ # between otherwise identical greedy runs, depending on the batch-flush boundary
+ # at which the stream is closed. The generated tokens are the same; only that
+ # whitespace differs. The raw repr stays in the message so a real divergence is
+ # still legible.
+ assert a.strip() == b.strip(), (
+ f"{label} non-deterministic at turn {i} with temperature=0.0:\n"
+ f" run1: {a!r}\n run2: {b!r}"
+ )
+ # Turn 2 should mention the earlier question and turn 4 the city turn 3 produced.
+ # Lower-cased substring checks, so formatting jitter is not a failure.
+ joined = " ".join(first).lower()
+ assert "1" in first[0], f"{label}: turn-1 answer should contain '1', got {first[0]!r}"
+ assert (
+ "paris" in joined
+ ), f"{label}: expected 'paris' somewhere in the four-turn transcript: {first}"
+ print(f"[{label}] OK -- 4 turns, run1 == run2, history grounded")
+
+
+def main() -> int:
+ for label, runner in (("openai", run_openai), ("anthropic", run_anthropic)):
+ check(label, runner(), runner())
+ return 0
+
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/.github/workflows/studio-inference-smoke.yml b/.github/workflows/studio-inference-smoke.yml
index 6264f85e61f..ffb6074216c 100644
--- a/.github/workflows/studio-inference-smoke.yml
+++ b/.github/workflows/studio-inference-smoke.yml
@@ -202,105 +202,7 @@ jobs:
env:
BASE_URL: http://127.0.0.1:18888
run: |
- python - <<'PY'
- import json
- import os
- from openai import OpenAI
- from anthropic import Anthropic
-
- BASE = os.environ["BASE_URL"]
- KEY = os.environ["TOKEN"] # JWT also accepted as Bearer on /v1/*
- SEED = 3407
-
- # Four-turn conversation: the second and fourth turns can only be
- # answered correctly if the model sees the prior turns, so this
- # also exercises the conversation-history wiring.
- PROMPTS = [
- "What is 1+1?",
- "What did I ask before?",
- "What is the capital of France?",
- "Repeat the city name",
- ]
-
- def run_openai():
- client = OpenAI(base_url = f"{BASE}/v1", api_key = KEY)
- history, replies = [], []
- for prompt in PROMPTS:
- history.append({"role": "user", "content": prompt})
- resp = client.chat.completions.create(
- model = "default",
- messages = history,
- temperature = 0.0,
- max_tokens = 80,
- seed = SEED,
- extra_body = {"enable_thinking": False},
- )
- text = resp.choices[0].message.content or ""
- replies.append(text)
- history.append({"role": "assistant", "content": text})
- return replies
-
- def run_anthropic():
- # Two SDK quirks vs. Unsloth:
- # 1. base_url must NOT include /v1 -- the SDK appends
- # /v1/messages itself; otherwise the request hits
- # /v1/v1/messages and 405s.
- # 2. The SDK sends `x-api-key` by default, but Unsloth's
- # auth layer is HTTPBearer-only. Override via
- # default_headers so Authorization: Bearer ... is
- # sent instead.
- client = Anthropic(
- base_url = BASE,
- api_key = "unused",
- default_headers = {"Authorization": f"Bearer {KEY}"},
- )
- history, replies = [], []
- for prompt in PROMPTS:
- history.append({"role": "user", "content": prompt})
- msg = client.messages.create(
- model = "default",
- max_tokens = 80,
- messages = history,
- temperature = 0.0,
- extra_body = {"seed": SEED, "enable_thinking": False},
- )
- text = "".join(b.text for b in msg.content if getattr(b, "type", None) == "text")
- replies.append(text)
- history.append({"role": "assistant", "content": text})
- return replies
-
- for label, runner in (("openai", run_openai), ("anthropic", run_anthropic)):
- first = runner()
- second = runner()
- determinism_failures = []
- for i, (a, b) in enumerate(zip(first, second), start = 1):
- print(f"[{label} turn {i}] {a!r}")
- # Both runs must be non-empty; small-quant drift
- # across runs is WARN-only (grounding asserts below
- # are the stronger signal).
- assert a, f"{label}: empty turn {i} response in first run"
- assert b, f"{label}: empty turn {i} response in second run"
- if a.strip() != b.strip():
- determinism_failures.append(
- f"turn {i}: run1={a!r} run2={b!r}"
- )
- if determinism_failures:
- print(
- f"[{label}] WARN non-determinism at temperature=0.0 across "
- f"{len(determinism_failures)} of {len(first)} turn(s); "
- f"small-quant model drift, not an Unsloth regression. "
- f"Details: " + " | ".join(determinism_failures)
- )
- # Sanity: turn-2 reply should mention the earlier question, and
- # turn-4 reply should mention Paris (model echoes the city it
- # produced for turn 3). Lower-cased substring checks keep the
- # assertion robust to formatting jitter.
- joined = " ".join(first).lower()
- assert "1" in first[0], f"{label}: turn-1 answer should contain '1', got {first[0]!r}"
- assert "paris" in joined, f"{label}: expected 'paris' somewhere in the four-turn transcript: {first}"
- status_word = "PASS" if not determinism_failures else "PASS (with drift)"
- print(f"[{label}] {status_word} -- 4 turns, history grounded ('paris' present)")
- PY
+ python3 .github/scripts/studio_smoke/multi_turn_chat.py
- name: Stop Unsloth
if: always()
diff --git a/.github/workflows/studio-mac-inference-smoke.yml b/.github/workflows/studio-mac-inference-smoke.yml
index 09b42767edb..c0b56ef3c15 100644
--- a/.github/workflows/studio-mac-inference-smoke.yml
+++ b/.github/workflows/studio-mac-inference-smoke.yml
@@ -270,99 +270,7 @@ jobs:
env:
BASE_URL: http://127.0.0.1:18888
run: |
- python - <<'PY'
- import json
- import os
- from openai import OpenAI
- from anthropic import Anthropic
-
- BASE = os.environ["BASE_URL"]
- KEY = os.environ["TOKEN"] # JWT also accepted as Bearer on /v1/*
- SEED = 3407
-
- # Four-turn conversation: the second and fourth turns can only be
- # answered correctly if the model sees the prior turns, so this
- # also exercises the conversation-history wiring.
- PROMPTS = [
- "What is 1+1?",
- "What did I ask before?",
- "What is the capital of France?",
- "Repeat the city name",
- ]
-
- def run_openai():
- client = OpenAI(base_url = f"{BASE}/v1", api_key = KEY)
- history, replies = [], []
- for prompt in PROMPTS:
- history.append({"role": "user", "content": prompt})
- resp = client.chat.completions.create(
- model = "default",
- messages = history,
- temperature = 0.0,
- max_tokens = 80,
- seed = SEED,
- extra_body = {"enable_thinking": False},
- )
- text = resp.choices[0].message.content or ""
- replies.append(text)
- history.append({"role": "assistant", "content": text})
- return replies
-
- def run_anthropic():
- # Two SDK quirks vs. Unsloth:
- # 1. base_url must NOT include /v1 -- the SDK appends
- # /v1/messages itself; otherwise the request hits
- # /v1/v1/messages and 405s.
- # 2. The SDK sends `x-api-key` by default, but Unsloth's
- # auth layer is HTTPBearer-only. Override via
- # default_headers so Authorization: Bearer ... is
- # sent instead.
- client = Anthropic(
- base_url = BASE,
- api_key = "unused",
- default_headers = {"Authorization": f"Bearer {KEY}"},
- )
- history, replies = [], []
- for prompt in PROMPTS:
- history.append({"role": "user", "content": prompt})
- msg = client.messages.create(
- model = "default",
- max_tokens = 80,
- messages = history,
- temperature = 0.0,
- extra_body = {"seed": SEED, "enable_thinking": False},
- )
- text = "".join(b.text for b in msg.content if getattr(b, "type", None) == "text")
- replies.append(text)
- history.append({"role": "assistant", "content": text})
- return replies
-
- for label, runner in (("openai", run_openai), ("anthropic", run_anthropic)):
- first = runner()
- second = runner()
- for i, (a, b) in enumerate(zip(first, second), start = 1):
- print(f"[{label} turn {i}] {a!r}")
- assert a, f"{label}: empty turn {i} response"
- # Compare on stripped content: llama-server can vary
- # trailing whitespace (specifically a final '\n') between
- # otherwise-identical greedy runs depending on the
- # batch-flush boundary at which the stream is closed. The
- # generated tokens are identical; only the trailing
- # whitespace differs. Keep the raw repr in the failure
- # message so a real divergence is still legible.
- assert a.strip() == b.strip(), (
- f"{label} non-deterministic at turn {i} with temperature=0.0:\n"
- f" run1: {a!r}\n run2: {b!r}"
- )
- # Sanity: turn-2 reply should mention the earlier question, and
- # turn-4 reply should mention Paris (model echoes the city it
- # produced for turn 3). Lower-cased substring checks keep the
- # assertion robust to formatting jitter.
- joined = " ".join(first).lower()
- assert "1" in first[0], f"{label}: turn-1 answer should contain '1', got {first[0]!r}"
- assert "paris" in joined, f"{label}: expected 'paris' somewhere in the four-turn transcript: {first}"
- print(f"[{label}] OK -- 4 turns, run1 == run2, history grounded")
- PY
+ python3 .github/scripts/studio_smoke/multi_turn_chat.py
- name: Stop Unsloth
if: always()
diff --git a/.github/workflows/studio-windows-inference-smoke.yml b/.github/workflows/studio-windows-inference-smoke.yml
index 635f7cccee6..b9487a83b76 100644
--- a/.github/workflows/studio-windows-inference-smoke.yml
+++ b/.github/workflows/studio-windows-inference-smoke.yml
@@ -404,84 +404,7 @@ jobs:
env:
BASE_URL: http://127.0.0.1:18888
run: |
- python - <<'PY'
- import json
- import os
- from openai import OpenAI
- from anthropic import Anthropic
-
- BASE = os.environ["BASE_URL"]
- KEY = os.environ["TOKEN"]
- SEED = 3407
-
- PROMPTS = [
- "What is 1+1?",
- "What did I ask before?",
- "What is the capital of France?",
- "Repeat the city name",
- ]
-
- def run_openai():
- client = OpenAI(base_url = f"{BASE}/v1", api_key = KEY)
- history, replies = [], []
- for prompt in PROMPTS:
- history.append({"role": "user", "content": prompt})
- resp = client.chat.completions.create(
- model = "default",
- messages = history,
- temperature = 0.0,
- max_tokens = 80,
- seed = SEED,
- extra_body = {"enable_thinking": False},
- )
- text = resp.choices[0].message.content or ""
- replies.append(text)
- history.append({"role": "assistant", "content": text})
- return replies
-
- def run_anthropic():
- client = Anthropic(
- base_url = BASE,
- api_key = "unused",
- default_headers = {"Authorization": f"Bearer {KEY}"},
- )
- history, replies = [], []
- for prompt in PROMPTS:
- history.append({"role": "user", "content": prompt})
- msg = client.messages.create(
- model = "default",
- max_tokens = 80,
- messages = history,
- temperature = 0.0,
- extra_body = {"seed": SEED, "enable_thinking": False},
- )
- text = "".join(b.text for b in msg.content if getattr(b, "type", None) == "text")
- replies.append(text)
- history.append({"role": "assistant", "content": text})
- return replies
-
- for label, runner in (("openai", run_openai), ("anthropic", run_anthropic)):
- first = runner()
- second = runner()
- for i, (a, b) in enumerate(zip(first, second), start = 1):
- print(f"[{label} turn {i}] {a!r}")
- assert a, f"{label}: empty turn {i} response"
- # Compare on stripped content: llama-server can vary
- # trailing whitespace (specifically a final '\n') between
- # otherwise-identical greedy runs depending on the
- # batch-flush boundary at which the stream is closed. The
- # generated tokens are identical; only the trailing
- # whitespace differs. Keep the raw repr in the failure
- # message so a real divergence is still legible.
- assert a.strip() == b.strip(), (
- f"{label} non-deterministic at turn {i} with temperature=0.0:\n"
- f" run1: {a!r}\n run2: {b!r}"
- )
- joined = " ".join(first).lower()
- assert "1" in first[0], f"{label}: turn-1 answer should contain '1', got {first[0]!r}"
- assert "paris" in joined, f"{label}: expected 'paris' somewhere in the four-turn transcript: {first}"
- print(f"[{label}] OK -- 4 turns, run1 == run2, history grounded")
- PY
+ python .github/scripts/studio_smoke/multi_turn_chat.py
- name: Stop Unsloth
if: always()
diff --git a/.github/workflows/workflow-trigger-lint.yml b/.github/workflows/workflow-trigger-lint.yml
index c1496b8577a..9c622ccca3e 100644
--- a/.github/workflows/workflow-trigger-lint.yml
+++ b/.github/workflows/workflow-trigger-lint.yml
@@ -86,3 +86,9 @@ jobs:
# test and merged green. Only this job sees such a PR.
- name: Main runs still survive a merge burst
run: python3 -m pytest tests/studio/test_main_runs_survive_merge_bursts.py -q
+
+ # And here for the same reason: this one reads the three OS smoke workflows, so
+ # the change that breaks it edits a workflow and nothing else, which no paths
+ # filter in the repo matches. Filesystem reads, seconds.
+ - name: The OS smoke legs still share one script
+ run: python3 -m pytest tests/studio/test_smoke_workflows_share_one_script.py -q
diff --git a/tests/studio/test_smoke_workflows_share_one_script.py b/tests/studio/test_smoke_workflows_share_one_script.py
new file mode 100644
index 00000000000..e4c7d8ecd97
--- /dev/null
+++ b/tests/studio/test_smoke_workflows_share_one_script.py
@@ -0,0 +1,129 @@
+# 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 same smoke test on three operating systems has to be the same test.
+
+The multi-turn chat check ran inline in studio-inference-smoke.yml,
+studio-mac-inference-smoke.yml and studio-windows-inference-smoke.yml as three copies of
+one script. On 2026-05-22 an unrelated event-loop fix (#5669) turned the Linux copy's
+determinism assertion into a printed warning. macOS and Windows kept it and are otherwise
+identical in logic. Nothing compared them, so for three months the leg that runs on every
+pull request was the one not checking, and the two that still checked run rarely.
+
+So the copies are gone, and these tests are about keeping them gone.
+"""
+
+import importlib.util
+import sys
+from pathlib import Path
+
+import pytest
+
+REPO = Path(__file__).resolve().parents[2]
+SCRIPT = REPO / ".github" / "scripts" / "studio_smoke" / "multi_turn_chat.py"
+LEGS = (
+ "studio-inference-smoke.yml",
+ "studio-mac-inference-smoke.yml",
+ "studio-windows-inference-smoke.yml",
+)
+
+
+def _workflow(name: str) -> str:
+ return (REPO / ".github" / "workflows" / name).read_text(encoding = "utf-8")
+
+
[email protected](scope = "module")
+def script():
+ """The shared script, imported. It reads no environment and imports no SDK at module
+ level precisely so this is possible."""
+ assert SCRIPT.is_file(), f"{SCRIPT} is gone; the three legs have nothing to share"
+ spec = importlib.util.spec_from_file_location("multi_turn_chat", SCRIPT)
+ module = importlib.util.module_from_spec(spec)
+ sys.modules["multi_turn_chat"] = module
+ spec.loader.exec_module(module)
+ return module
+
+
+def test_every_leg_runs_the_shared_script():
+ missing = [name for name in LEGS if "studio_smoke/multi_turn_chat.py" not in _workflow(name)]
+ assert not missing, (
+ f"{missing} no longer run the shared multi-turn check. Three copies of it is how "
+ f"one of them stopped asserting determinism without anyone noticing."
+ )
+
+
+def test_no_leg_has_grown_its_own_copy_back():
+ """Reverting one leg to an inline block is the regression, and it looks additive."""
+ offenders = [name for name in LEGS if "def run_anthropic" in _workflow(name)]
+ assert not offenders, (
+ f"{offenders} carry an inline copy of the multi-turn check again. Change "
+ f"{SCRIPT.relative_to(REPO)} instead, so the other legs get the change too."
+ )
+
+
+def test_a_divergent_second_run_is_a_failure_not_a_warning(script):
+ """The assertion #5669 removed on Linux, pinned by running it.
+
+ Asserted through behaviour rather than the text of the check, so rewriting it is
+ fine and weakening it is not.
+ """
+ clean = ["1 is 2", "you asked about 1+1", "paris", "paris"]
+ script.check("ok", clean, list(clean)) # the baseline passes, or nothing below means anything
+
+ with pytest.raises(AssertionError, match = "non-deterministic"):
+ script.check("drift", clean, ["1 is 2", "you asked about 1+1", "paris", "london"])
+
+
+def test_trailing_whitespace_alone_is_still_tolerated(script):
+ """The reason the comparison is on stripped text, kept honest.
+
+ llama-server varies a final newline between identical greedy runs depending on where
+ the stream is closed. Tightening this to an exact match would fail on that.
+ """
+ clean = ["1 is 2", "you asked about 1+1", "paris", "paris"]
+ script.check("whitespace", clean, [t + "\n" for t in clean])
+
+
+def test_an_empty_reply_is_a_failure_in_either_run(script):
+ """A server answering nothing at all is deterministic, and the worst outcome.
+
+ Both runs, because the stripped comparison cannot tell them apart: a second run
+ returning "" against a first returning "\n" compares EQUAL, so checking only the
+ first would print OK for a server that had stopped answering halfway through. The
+ Linux copy asserted both before this was consolidated onto the macOS one, which
+ asserted only the first.
+ """
+ clean = ["1 is 2", "you asked about 1+1", "paris", "paris"]
+ with pytest.raises(AssertionError, match = "empty turn"):
+ script.check("first", ["", "b", "paris", "paris"], ["", "b", "paris", "paris"])
+ with pytest.raises(AssertionError, match = "empty turn"):
+ script.check("second", clean, ["", "b", "paris", "paris"])
+ # The exact pair the stripped comparison is blind to.
+ with pytest.raises(AssertionError, match = "empty turn"):
+ script.check(
+ "whitespace vs nothing", ["\n", "b", "paris", "paris"], ["", "b", "paris", "paris"]
+ )
+
+
+def test_history_grounding_is_still_checked(script):
+ """Two of the four turns are answerable only from the earlier ones. That is what the
+ 'paris' check is for: it fails when history is dropped, rather than when the model is
+ wrong about France."""
+ with pytest.raises(AssertionError, match = "paris"):
+ script.check("nohistory", ["1 is 2", "b", "c", "d"], ["1 is 2", "b", "c", "d"])
+
+
+def test_the_script_needs_no_environment_to_import(script):
+ """What lets every test above exist.
+
+ Reading BASE_URL at module level, or importing the SDKs there, would make the
+ checking half unreachable from a test and put it back where it was: only ever
+ exercised by a full smoke run on three operating systems.
+ """
+ source = SCRIPT.read_text(encoding = "utf-8")
+ head = source.split("def _server", 1)[0]
+ for forbidden in ("os.environ[", "from openai", "from anthropic"):
+ assert forbidden not in head, (
+ f"{forbidden} moved to module level in {SCRIPT.name}, so importing it now "
+ f"needs a running server or the SDKs installed, and these tests cannot run"
+ )