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.

Ground the multi-turn smoke on the turn that survives a 270M model (#10025)

Daniel Hancbf3fdf8e49d
diff --git a/.github/scripts/studio_smoke/multi_turn_chat.py b/.github/scripts/studio_smoke/multi_turn_chat.py
index f5250c01fac..089b85a4a6d 100644
--- a/.github/scripts/studio_smoke/multi_turn_chat.py
+++ b/.github/scripts/studio_smoke/multi_turn_chat.py
@@ -27,6 +27,21 @@ import sys
SEED = 3407
MAX_TOKENS = 80
+# How many times the two-replay comparison may be re-run before a disagreement is
+# called a real fault. See main(): the retry lives there, NOT in check(), so
+# check()'s contract is unchanged and a divergence handed to it is still a hard
+# failure every time.
+ATTEMPTS = 3
+
+
+class Nondeterministic(AssertionError):
+ """Greedy decoding disagreed between two replays of the same conversation.
+
+ A subclass of AssertionError so `pytest.raises(AssertionError)` in
+ tests/studio/test_smoke_workflows_share_one_script.py keeps holding, and so
+ main() can tell this one failure apart from the others and retry only it.
+ """
+
# 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.
@@ -123,32 +138,61 @@ def check(label: str, first: list[str], second: list[str]) -> None:
# 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 carry turn 1's answer and turn 4 the city turn 3 produced.
- # Lower-cased substring checks, so formatting jitter is not a failure.
- joined = " ".join(first).lower()
+ if a.strip() != b.strip():
+ raise Nondeterministic(
+ f"{label} non-deterministic at turn {i} with temperature=0.0:\n"
+ f" run1: {a!r}\n run2: {b!r}"
+ )
numbers = re.findall(r"\d+", first[0])
assert numbers, f"{label}: turn-1 answer should contain a number, got {first[0]!r}"
- # From turn 1's reply, not a literal, so a turn 2 that contradicts turn 1 fails too.
- # Last number, since "58 + 27 = 95" restates the operands first. Per turn, since the
- # joined text already holds turn 1.
- answer = numbers[-1]
- assert answer in first[1], (
- f"{label}: turn 2 must carry turn 1's answer {answer!r}, so history reached the "
- f"model. Got {first[1]!r}"
+
+ # History grounding is asserted on the LAST turn, per turn. "Repeat the city name"
+ # names no city, so 'Paris' can only have come from turn 3, and a server that kept
+ # only the latest turn answers "Okay, I'm ready." -- measured against llama-server
+ # b10360 on the UD-Q4_K_XL file the workflow loads.
+ #
+ # #10009 asserted this on turn 2 instead, requiring the reply to restate turn 1's
+ # number, and that is a false failure on macOS: in the same run that turn 2 came
+ # back "You haven't provided the previous question.", turn 4 answered "The capital
+ # of France is Paris.", which is only possible with history attached. Whether a
+ # 270M model phrases a recalled number is a property of the model, not of the
+ # server's history wiring, so it cannot carry this assertion. #10009's actual
+ # finding -- that looking for 'paris' in the JOINED transcript proves nothing,
+ # because turn 3 supplies it on its own -- is what the per-turn check below keeps.
+ assert len(first) == len(PROMPTS), f"{label}: expected {len(PROMPTS)} replies, got {len(first)}"
+ assert "paris" in first[-1].lower(), (
+ f"{label}: the last turn must name the city from turn 3, so history reached the "
+ f"model. Its own prompt contains no city name. Got {first[-1]!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")
+ print(f"[{label}] OK -- 4 turns, run1 == run2, history grounded on the last turn")
def main() -> int:
for label, runner in (("openai", run_openai), ("anthropic", run_anthropic)):
- check(label, runner(), runner())
+ # Only a replay disagreement is retried, and only here. Two replays are not two
+ # identical requests: each turn is built from the reply before it, and the second
+ # replay meets the server holding cache and slot state the first one left behind,
+ # so a token the model is near-tied on can land differently without decoding
+ # being broken. A server that is actually non-deterministic disagrees on every
+ # attempt and still fails.
+ #
+ # Deliberately NOT done by softening check(): #5669 turned this assertion into a
+ # printed warning on the Linux leg and it went unnoticed for three months, so
+ # every divergence handed to check() is still a hard failure, and every other
+ # fault -- an empty reply, history not reaching the model -- fails on the first
+ # attempt without a retry.
+ for attempt in range(1, ATTEMPTS + 1):
+ try:
+ check(label, runner(), runner())
+ break
+ except Nondeterministic as divergence:
+ if attempt == ATTEMPTS:
+ print(f"[{label}] divergent on all {ATTEMPTS} attempts", file = sys.stderr)
+ raise
+ print(
+ f"[{label}] attempt {attempt}/{ATTEMPTS} disagreed between replays, "
+ f"retrying:\n{divergence}"
+ )
return 0
diff --git a/tests/studio/test_smoke_workflows_share_one_script.py b/tests/studio/test_smoke_workflows_share_one_script.py
index 93ee6c9110e..2b62c69d88a 100644
--- a/tests/studio/test_smoke_workflows_share_one_script.py
+++ b/tests/studio/test_smoke_workflows_share_one_script.py
@@ -109,27 +109,42 @@ def test_history_grounding_is_still_checked(script):
"""Two of the four turns are answerable only from the earlier ones. Those checks fail
when history is dropped, rather than when the model is wrong about France."""
good2 = "you asked about 2"
- with pytest.raises(AssertionError, match = "paris"):
+ with pytest.raises(AssertionError, match = "history reached the model"):
script.check("nohistory", ["1 is 2", good2, "c", "d"], ["1 is 2", good2, "c", "d"])
- # Without a turn-2 check a server dropping every turn but the last still passed:
- # "1" comes from turn 1 and "paris" from turn 3.
+ # The gap #10009 found: 'paris' in the JOINED transcript proves nothing, because
+ # turn 3 supplies it on its own. Checked per turn, a server that answers turn 3 and
+ # then loses the history still fails.
+ lost_after_3 = ["1 is 2", "b", "paris", "Okay, I'm ready."]
with pytest.raises(AssertionError, match = "history reached the model"):
- script.check(
- "noturn2", ["1 is 2", "b", "paris", "paris"], ["1 is 2", "b", "paris", "paris"]
- )
+ script.check("joined-is-not-enough", lost_after_3, list(lost_after_3))
-def test_turn_2_is_checked_against_turn_1_not_a_literal(script):
- """A hardcoded digit would accept a turn 2 that contradicts turn 1. The fixtures carry
- their own numbers, which is the point: the check reads turn 1 rather than a literal, so
- it holds whatever PROMPTS asks."""
- contradiction = ["1 is 3", "the answer was 2", "paris", "paris"]
+def test_grounding_is_asserted_on_a_turn_a_270m_model_can_carry(script):
+ """Which turn holds the grounding assertion is itself the regression risk.
+
+ #10009 put it on turn 2, requiring the reply to restate turn 1's number. On macOS
+ that failed against a server whose history demonstrably arrived: the same run
+ answered the last turn 'The capital of France is Paris.', which its own prompt
+ ("Repeat the city name") cannot produce without turn 3. So an unhelpfully worded
+ turn 2 must not fail, while a last turn that cannot name the city must.
+ """
+ # Exactly the macOS transcript, which is a healthy server.
+ macos = ["58 + 27 = 95", "You haven't provided the previous question.", "paris", "paris"]
+ script.check("macos", macos, list(macos))
+
+ # And the measured reply of a server sent the last prompt with no history at all.
+ no_history = ["58 + 27 = 95", "the answer was 95", "paris", "Okay, I'm ready."]
with pytest.raises(AssertionError, match = "history reached the model"):
- script.check("contradiction", contradiction, list(contradiction))
+ script.check("dropped", no_history, list(no_history))
- consistent = ["1 is 3", "the answer was 3", "paris", "paris"]
- script.check("consistent", consistent, list(consistent))
+
+def test_turn_1_must_still_answer_with_a_number(script):
+ """Turn 1 is what makes the conversation multi-turn; a server that cannot do
+ arithmetic at all is not exercising history."""
+ broken = ["I cannot do arithmetic.", "b", "paris", "paris"]
+ with pytest.raises(AssertionError, match = "should contain a number"):
+ script.check("nonumber", broken, list(broken))
def test_the_script_needs_no_environment_to_import(script):
@@ -146,3 +161,56 @@ def test_the_script_needs_no_environment_to_import(script):
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"
)
+
+
+def test_the_replay_retry_cannot_pass_a_truly_nondeterministic_server(script, monkeypatch):
+ """A retry is a way to hide a real fault, so it is pinned by running it.
+
+ The near-tie this exists for flips occasionally; a server that samples disagrees
+ every time. The first must pass and the second must still fail, and the retry must
+ be bounded rather than looping until it gets lucky.
+ """
+ clean = ["58 + 27 = 95", "the answer was 95", "paris", "paris"]
+
+ calls = {"n": 0}
+
+ def always_divergent():
+ calls["n"] += 1
+ # A different last turn every call, so no two replays ever agree.
+ return ["58 + 27 = 95", "the answer was 95", "paris", f"paris {calls['n']}"]
+
+ monkeypatch.setattr(script, "run_openai", always_divergent)
+ monkeypatch.setattr(script, "run_anthropic", always_divergent)
+ with pytest.raises(AssertionError, match = "non-deterministic"):
+ script.main()
+ # Bounded: two runners per attempt, and it must not have looped past ATTEMPTS.
+ assert calls["n"] == 2 * script.ATTEMPTS, calls["n"]
+
+ # And a single flip, followed by agreement, passes.
+ calls["n"] = 0
+
+ def flips_once():
+ calls["n"] += 1
+ if calls["n"] == 2: # the second replay of the first attempt
+ return ["58 + 27 = 95", "the answer was 95", "paris", "paris!"]
+ return list(clean)
+
+ monkeypatch.setattr(script, "run_openai", flips_once)
+ monkeypatch.setattr(script, "run_anthropic", flips_once)
+ assert script.main() == 0
+
+
+def test_a_non_divergence_failure_is_not_retried(script, monkeypatch):
+ """Retrying an empty reply or a dropped history would just cost three runs and
+ still fail, and would let a broken server look intermittent."""
+ calls = {"n": 0}
+
+ def no_history():
+ calls["n"] += 1
+ return ["58 + 27 = 95", "b", "paris", "Okay, I'm ready."]
+
+ monkeypatch.setattr(script, "run_openai", no_history)
+ monkeypatch.setattr(script, "run_anthropic", no_history)
+ with pytest.raises(AssertionError, match = "history reached the model"):
+ script.main()
+ assert calls["n"] == 2, f"retried a non-divergence failure {calls['n']} times"