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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
studiobench: do not fail UI parity on repetitions that swap two renderings (#11772)
Daniel Han9815e7631342
diff --git a/tests/studio/studiobench/sweep/parity_shots.py b/tests/studio/studiobench/sweep/parity_shots.pyindex 1f3f33dee6f..d082f7b741f 100644--- a/tests/studio/studiobench/sweep/parity_shots.py+++ b/tests/studio/studiobench/sweep/parity_shots.py@@ -49,6 +49,7 @@ from tests.studio.studiobench.sweep.ui_parity import ( # noqa: E402in_arm_repeatability,is_unstable,shards_of,+ swapped_between_arms,unstable_set,)@@ -143,10 +144,13 @@ def differing_actions(out = []# `compare_all` returns (results, capture tally); only the results are wanted here.results, _tally = compare_all(result_paths)+ # Less the pairs whose repetitions swapped two renderings between the arms, which `report`+ # prints as uncorroborated and does not count.+ swapped = swapped_between_arms(results, min_reps)stable = [(action, shard, cell, r.get("moved", []))- for action, shard, cell, r in results- if r["verdict"] == P.DIFFER and not is_unstable(unstable, action, cell)+ for i, (action, shard, cell, r) in enumerate(results)+ if r["verdict"] == P.DIFFER and not is_unstable(unstable, action, cell) and i not in swapped]# Carrying the DIRECTION as the fifth element, exactly as `report` does, so the artifact# illustrates the same set the verdict counted. Without it a direction-reversing pair would bediff --git a/tests/studio/studiobench/sweep/selftest/test_studiobench_swapped_parity.py b/tests/studio/studiobench/sweep/selftest/test_studiobench_swapped_parity.pynew file mode 100644index 00000000000..ac80472dd69--- /dev/null+++ b/tests/studio/studiobench/sweep/selftest/test_studiobench_swapped_parity.py@@ -0,0 +1,377 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0+"""Two repetitions that swap the same two renderings between the arms are not a build difference.++THE FALSE ALARM THIS HOLDS. #11756 touched only the Images/Video/Audio model pickers and failed+the UI parity gate (run 35949769378) on four stable pairs:++ delete_message r100K rep0: thread scaffolding outside any message (11265->13287c)+ delete_message r100K rep1: thread scaffolding outside any message (13287->11265c)+ thread_reopen r100K rep0: thread scaffolding outside any message (11296->13308c)+ thread_reopen r100K rep1: thread scaffolding outside any message (13308->11296c)++In the recorded payload every field `rendering_of` reads is the same in rep0's base capture and+rep1's treatment capture, and the other way round. The extra 2012 and 2022 characters of scaffold+follow the attachment chip `image_upload` leaves in the composer (inside the thread root) when it+reaches its 800ms slot; on this run base missed it, head ran it, head missed it, base ran it. The+null control shows the same build rendering both states. `testdata/pr11756_*` are CI's payloads+trimmed to the fields the verdict reads (window rows dropped, action rows cut to the keys+`pr11727_*` keeps); the verdict text is identical on the trimmed and the full files.++Every "clears" test is paired with one that puts a genuine, consistent difference into the same+recorded payload and requires it to still fail.+"""++from __future__ import annotations++import copy+import gzip+import json+import sys+from pathlib import Path++import pytest++sys.path.insert(0, str(Path(__file__).resolve().parents[4]))++from tests.studio.studiobench.analysis import parity as P # noqa: E402+from tests.studio.studiobench.sweep import parity_shots as S # noqa: E402+from tests.studio.studiobench.sweep import ui_parity as U # noqa: E402++TESTDATA = Path(__file__).resolve().parent / "testdata"+SWAPPED = ("delete_message", "thread_reopen")+CELLS = ("r100K.base.rep0", "r100K.treatment.rep0", "r100K.base.rep1", "r100K.treatment.rep1")+++def _load(name: str) -> list[dict]:+ with gzip.open(TESTDATA / name, "rt", encoding = "utf-8") as fh:+ return [json.loads(line) for line in fh if line.strip()]+++def _recorded() -> tuple[list[dict], list[dict]]:+ return _load("pr11756_result.payload.jsonl.gz"), _load("pr11756_null.payload.jsonl.gz")+++def _write(rows: list[dict], path: Path) -> Path:+ path.mkdir(parents = True, exist_ok = True)+ with open(path / "payload.jsonl", "w", encoding = "utf-8") as fh:+ for row in rows:+ fh.write(json.dumps(row) + "\n")+ return path+++def _row(rows: list[dict], action: str, cell: str) -> dict:+ return next(+ r+ for r in rows+ if r.get("row_type") == "action" and r.get("action") == action and r.get("cell_id") == cell+ )+++def _run(+ tmp_path,+ capsys,+ result,+ null,+ min_reps = 2,+) -> tuple[int, str]:+ """The workflow's verdict step, flag for flag: (exit code, what it printed)."""+ rdir = _write(result, tmp_path / "parity-result")+ ndir = _write(null, tmp_path / "parity-null-control")+ rc = U.main(+ [+ "--min-reps",+ str(min_reps),+ "--min-compared",+ "16",+ "--null",+ str(ndir),+ str(rdir),+ ]+ )+ return rc, capsys.readouterr().out+++def _section(out: str, head: str) -> str:+ """The indented lines under `head`, or `""` when the heading is absent."""+ if head not in out:+ return ""+ lines = []+ for line in out.split(head, 1)[1].splitlines()[1:]:+ if line.startswith(" ") and not line.startswith(" "):+ continue # the heading's own wrapped second line+ if not line.startswith(" "):+ break+ lines.append(line)+ return "\n".join(lines)+++def _stable(out: str) -> str:+ return _section(out, "UI PARITY DIFFERENCES ON STABLE ACTIONS")+++def _swapped(out: str) -> str:+ return _section(out, "the repetitions SWAPPED the same two renderings")+++def _make_consistent(rows: list[dict], action: str) -> None:+ """rep1 renders exactly what rep0 did on each arm: base R1 and head R2 in both repetitions."""+ for arm in ("base", "treatment"):+ _row(rows, action, f"r100K.{arm}.rep1")["parity"] = copy.deepcopy(+ _row(rows, action, f"r100K.{arm}.rep0")["parity"]+ )+++# ── the evidence, as recorded ────────────────────────────────────────────────────────────────++[email protected]("action,extra", [("delete_message", 2022), ("thread_reopen", 2012)])+def test_the_recorded_repetitions_are_one_pair_of_renderings_swapped(action, extra):+ """The premise, checked on CI's bytes: rep0's (base, head) is rep1's (head, base), entire."""+ result, _null = _recorded()+ cap = {cell: _row(result, action, cell)["parity"] for cell in CELLS}+ b0, t0 = U.rendering_of(cap["r100K.base.rep0"]), U.rendering_of(cap["r100K.treatment.rep0"])+ b1, t1 = U.rendering_of(cap["r100K.base.rep1"]), U.rendering_of(cap["r100K.treatment.rep1"])+ assert None not in (b0, t0, b1, t1)+ assert b0 != t0+ assert (b0, t0) == (t1, b1)+ # About 2000 characters of scaffold and nothing else: every message row agrees across all four.+ sizes = sorted({c["chars_scaffold"] for c in cap.values()})+ assert sizes[1] - sizes[0] == extra+ assert len({json.dumps(c["messages"], sort_keys = True) for c in cap.values()}) == 1+++def test_the_extra_scaffold_follows_whether_image_upload_ran_in_that_cell():+ """The mechanism, on both payloads: the larger scaffold is exactly the cells where it ran."""+ for rows in _recorded():+ for cell in CELLS:+ ran = bool(_row(rows, "image_upload", cell).get("ran"))+ for action in SWAPPED:+ chars = _row(rows, action, cell)["parity"]["chars_scaffold"]+ assert (chars > 12000) == ran, (cell, action, chars, ran)+++def test_the_null_control_shows_one_build_rendering_both_states():+ _result, null = _recorded()+ for action in SWAPPED:+ sizes = {_row(null, action, cell)["parity"]["chars_scaffold"] for cell in CELLS}+ assert len(sizes) == 2, (action, sizes)+++# ── (a) the #11756 shape is not firm ─────────────────────────────────────────────────────────+++def test_swapped_repetitions_do_not_fail_the_verdict(tmp_path, capsys):+ result, null = _recorded()+ rc, out = _run(tmp_path, capsys, result, null)+ assert rc == 0, out+ assert _stable(out) == ""+ assert "stable actions differing: 0" in out+ # Reported, not dropped: all four readings are printed under UNCORROBORATED.+ section = _swapped(out)+ for action in SWAPPED:+ assert section.count(action) == 2, section+ assert "swapped between arms: 4" in out+++def test_the_null_audit_is_not_asked_to_excuse_a_swap(tmp_path, capsys):+ """Same predicate as the verdict: a pair it never counts needs no excuse from the null."""+ result, _null = _recorded()+ rdir = _write(result, tmp_path / "parity-result")+ assert U.actions_needing_an_excuse(U.shards_of(str(rdir)), 2) == set()+++def test_the_evidence_step_does_not_illustrate_a_swap(tmp_path):+ result, null = _recorded()+ rdir = _write(result, tmp_path / "parity-result")+ ndir = _write(null, tmp_path / "parity-null-control")+ assert S.differing_actions(U.shards_of(str(rdir)), U.shards_of(str(ndir)), min_reps = 2) == []+++# ── (b) a consistent difference in both repetitions stays firm ───────────────────────────────++[email protected]("action", SWAPPED)+def test_the_same_difference_in_both_repetitions_still_fails(tmp_path, capsys, action):+ """Base R1 and head R2 twice: the shape a head that always leaves the chip would record."""+ result, null = _recorded()+ _make_consistent(result, action)+ rc, out = _run(tmp_path, capsys, result, null)+ assert rc == 1, out+ assert _stable(out).count(action) == 2, _stable(out)+ assert action not in _swapped(out)+++def test_a_real_change_under_the_race_still_fails(tmp_path, capsys):+ """The recorded swap, plus 17 characters head adds to the scaffold in both repetitions.++ The renderings no longer line up across the repetitions, so the race cannot excuse them.+ """+ result, null = _recorded()+ for action in SWAPPED:+ for cell in ("r100K.treatment.rep0", "r100K.treatment.rep1"):+ cap = _row(result, action, cell)["parity"]+ cap["digest_scaffold"] += "x"+ cap["chars_scaffold"] += 17+ cap["digest"] += "x"+ cap["chars"] += 17+ rc, out = _run(tmp_path, capsys, result, null)+ assert rc == 1, out+ for action in SWAPPED:+ assert _stable(out).count(action) == 2, _stable(out)+ assert _swapped(out) == ""+++def test_a_swap_that_differs_anywhere_else_is_not_a_swap(tmp_path, capsys):+ """Only the style probe differs from an exact swap in one repetition: still counted."""+ result, null = _recorded()+ for action in SWAPPED:+ _row(result, action, "r100K.treatment.rep1")["parity"]["styles"]["digest"] = "0badc0de"+ rc, out = _run(tmp_path, capsys, result, null)+ assert rc == 1, out+ assert _swapped(out) == ""+++# ── (c) a swap in one action does not excuse a consistent difference in another ─────────────+++def test_a_swap_on_one_action_does_not_excuse_another(tmp_path, capsys):+ result, null = _recorded()+ _make_consistent(result, "thread_reopen")+ rc, out = _run(tmp_path, capsys, result, null)+ assert rc == 1, out+ stable, swapped = _stable(out), _swapped(out)+ assert stable.count("thread_reopen") == 2 and "delete_message" not in stable, stable+ assert swapped.count("delete_message") == 2 and "thread_reopen" not in swapped, swapped+ rdir = tmp_path / "parity-result"+ assert U.actions_needing_an_excuse(U.shards_of(str(rdir)), 2) == {("r100K", "thread_reopen")}+++def test_a_swap_at_one_rung_does_not_excuse_the_same_action_at_another():+ """Grouped by (action, rung), like `corroborated`: the partner has to be at the same rung."""+ r1, r2 = "R1", "R2"+ results = [+ ("delete_message", "s", "r1K rep0", {"verdict": P.DIFFER, "outcomes": (r1, r2)}),+ ("delete_message", "s", "r100K rep1", {"verdict": P.DIFFER, "outcomes": (r2, r1)}),+ ]+ assert U.swapped_between_arms(results, 2) == frozenset()+++def test_one_repetition_cannot_be_its_own_partner():+ """The same cell label in two shards is one repetition; a swap needs two."""+ results = [+ ("delete_message", "a", "r100K rep0", {"verdict": P.DIFFER, "outcomes": ("R1", "R2")}),+ ("delete_message", "b", "r100K rep0", {"verdict": P.DIFFER, "outcomes": ("R2", "R1")}),+ ]+ assert U.swapped_between_arms(results, 2) == frozenset()+++def test_one_reversal_excuses_only_one_repetition_of_the_other_direction():+ """Three repetitions of (R1, R2) and one of (R2, R1): one pair is a swap, and the two+ same-direction repetitions left over are still a difference seen twice."""+ results = [+ ("delete_message", "s", f"r100K rep{n}", {"verdict": P.DIFFER, "outcomes": outcomes})+ for n, outcomes in enumerate([("R1", "R2"), ("R1", "R2"), ("R1", "R2"), ("R2", "R1")])+ ]+ swapped = U.swapped_between_arms(results, 2)+ assert len(swapped) == 2 and 3 in swapped+ left = [results[i] for i in range(len(results)) if i not in swapped]+ firm, weak = U.corroborated([(a, s, c, r) for a, s, c, r in left], 2)+ assert len({e[2] for e in firm}) == 2 and not weak+++def test_a_reversal_recorded_in_two_shards_is_still_one_partner():+ """Three (R1, R2) repetitions and one (R2, R1) repetition carried by two shards: the duplicate+ is the same observation, so it excuses one forward repetition, not two."""+ results = [+ ("delete_message", "s", f"r100K rep{n}", {"verdict": P.DIFFER, "outcomes": ("R1", "R2")})+ for n in range(3)+ ] + [+ ("delete_message", shard, "r100K rep3", {"verdict": P.DIFFER, "outcomes": ("R2", "R1")})+ for shard in ("a", "b")+ ]+ swapped = U.swapped_between_arms(results, 2)+ assert {3, 4} <= swapped and len(swapped) == 3+ left = [results[i] for i in range(len(results)) if i not in swapped]+ firm, _weak = U.corroborated(left, 2)+ assert len({e[2] for e in firm}) == 2+++def test_a_forward_repetition_in_two_shards_is_excused_whole():+ results = [+ ("delete_message", shard, "r100K rep0", {"verdict": P.DIFFER, "outcomes": ("R1", "R2")})+ for shard in ("a", "b")+ ] + [("delete_message", "s", "r100K rep1", {"verdict": P.DIFFER, "outcomes": ("R2", "R1")})]+ assert U.swapped_between_arms(results, 2) == frozenset({0, 1, 2})+++def test_a_repetition_recorded_in_both_directions_is_never_excused():+ """rep0 carried by two shards that disagree (A->B and B->A), rep1 A->B, rep2 B->A: rep0 cannot+ say which side it saw, so only rep1 and rep2 pair, and rep0 stays as a difference."""+ results = [+ ("delete_message", "a", "r100K rep0", {"verdict": P.DIFFER, "outcomes": ("A", "B")}),+ ("delete_message", "b", "r100K rep0", {"verdict": P.DIFFER, "outcomes": ("B", "A")}),+ ("delete_message", "s", "r100K rep1", {"verdict": P.DIFFER, "outcomes": ("A", "B")}),+ ("delete_message", "s", "r100K rep2", {"verdict": P.DIFFER, "outcomes": ("B", "A")}),+ ]+ assert U.swapped_between_arms(results, 2) == frozenset({2, 3})+++def test_a_repetition_takes_part_in_one_swap_at_most():+ results = [+ ("delete_message", "s", "r100K rep0", {"verdict": P.DIFFER, "outcomes": ("A", "B")}),+ ("delete_message", "s", "r100K rep1", {"verdict": P.DIFFER, "outcomes": ("B", "A")}),+ ("delete_message", "s", "r100K rep2", {"verdict": P.DIFFER, "outcomes": ("A", "B")}),+ ]+ swapped = U.swapped_between_arms(results, 2)+ assert len({results[i][2] for i in swapped}) == 2+++def test_two_reversals_against_two_forwards_are_all_swaps():+ results = [+ ("delete_message", "s", f"r100K rep{n}", {"verdict": P.DIFFER, "outcomes": outcomes})+ for n, outcomes in enumerate([("R1", "R2"), ("R2", "R1"), ("R1", "R2"), ("R2", "R1")])+ ]+ assert U.swapped_between_arms(results, 2) == frozenset(range(4))+++# ── (d) payloads without what the swap needs are scored as before ────────────────────────────+++def test_results_without_renderings_are_never_excused():+ """A caller that builds results without `outcomes`, or a capture with no digest."""+ bare = [+ ("delete_message", "s", "r100K rep0", {"verdict": P.DIFFER}),+ ("delete_message", "s", "r100K rep1", {"verdict": P.DIFFER}),+ ]+ assert U.swapped_between_arms(bare, 2) == frozenset()+ half = [+ ("delete_message", "s", "r100K rep0", {"verdict": P.DIFFER, "outcomes": (None, "R2")}),+ ("delete_message", "s", "r100K rep1", {"verdict": P.DIFFER, "outcomes": ("R2", None)}),+ ]+ assert U.swapped_between_arms(half, 2) == frozenset()+ assert U.rendering_of(None) is None+ assert U.rendering_of({"parity_attempted": True, "error": "probe failed"}) is None+++def test_a_payload_whose_captures_carry_no_digest_fails_as_it_always_did(tmp_path, capsys):+ """The recorded run, with the aggregate `digest` stripped from every capture of the pair."""+ result, null = _recorded()+ for action in SWAPPED:+ for cell in CELLS:+ _row(result, action, cell)["parity"].pop("digest")+ rc, out = _run(tmp_path, capsys, result, null)+ assert rc == 1, out+ for action in SWAPPED:+ assert _stable(out).count(action) == 2, _stable(out)+ assert _swapped(out) == ""+++def test_min_reps_one_still_counts_every_difference(tmp_path, capsys):+ """`--min-reps 1` asks for every difference to count, so the swap is not consulted."""+ result, null = _recorded()+ rc, out = _run(tmp_path, capsys, result, null, min_reps = 1)+ assert rc == 1, out+ assert _swapped(out) == ""+ for action in SWAPPED:+ assert _stable(out).count(action) == 2, _stable(out)diff --git a/tests/studio/studiobench/sweep/selftest/testdata/pr11756_null.payload.jsonl.gz b/tests/studio/studiobench/sweep/selftest/testdata/pr11756_null.payload.jsonl.gznew file mode 100644index 00000000000..c34948f821cBinary files /dev/null and b/tests/studio/studiobench/sweep/selftest/testdata/pr11756_null.payload.jsonl.gz differdiff --git a/tests/studio/studiobench/sweep/selftest/testdata/pr11756_result.payload.jsonl.gz b/tests/studio/studiobench/sweep/selftest/testdata/pr11756_result.payload.jsonl.gznew file mode 100644index 00000000000..9d0b4302f15Binary files /dev/null and b/tests/studio/studiobench/sweep/selftest/testdata/pr11756_result.payload.jsonl.gz differdiff --git a/tests/studio/studiobench/sweep/ui_parity.py b/tests/studio/studiobench/sweep/ui_parity.pyindex 5b44b5ac0cc..574571c39fd 100644--- a/tests/studio/studiobench/sweep/ui_parity.py+++ b/tests/studio/studiobench/sweep/ui_parity.py@@ -1139,7 +1139,14 @@ def compare_all())continue- results.append((action, shard, cell, P.compare_rows(sides["base"], sides["treatment"])))+ out = P.compare_rows(sides["base"], sides["treatment"])+ # WHAT EACH ARM RENDERED, kept beside the verdict so `swapped_between_arms` can ask whether+ # another repetition saw the same two renderings on the opposite arms.+ out["outcomes"] = (+ rendering_of(sides["base"].get("parity")),+ rendering_of(sides["treatment"].get("parity")),+ )+ results.append((action, shard, cell, out))return results, got@@ -1221,7 +1228,12 @@ def actions_needing_an_excuse(paths: list[Path], min_reps: int) -> set[tuple[strthe verdict already declines to count is a question nobody is going to ask."""results, _ = compare_all(paths)- differing = [e for e in results if e[3]["verdict"] == P.DIFFER]+ # AND THE SWAP, for the same reason: `report` never counts a pair whose repetitions swapped two+ # renderings between the arms, so no excuse can move it either.+ swapped = swapped_between_arms(results, min_reps)+ differing = [+ e for i, e in enumerate(results) if e[3]["verdict"] == P.DIFFER and i not in swapped+ ]one_sided = [(e[0], e[1], e[2], e[3], e[3].get("one_sided") or None)for e in results@@ -1568,8 +1580,9 @@ def corroborated(entries: list[tuple], min_reps: int) -> tuple[list[tuple], listopposite arms. Keyed on the direction they separate, and each side is then a singlerepetition, so both print as UNCORROBORATED and the verdict does not rest on them.- A four-element entry has no direction and groups exactly as before, which is right for a- digest difference: `stable_bad` is a statement about a PAIR of arms and has no failing side.+ A four-element entry has no direction and groups exactly as before. A digest difference has+ no failing side, but it can still have a direction: two repetitions holding the same two+ renderings on opposite arms. `swapped_between_arms` takes those out before this runs."""by_action: dict[tuple, list[tuple]] = collections.defaultdict(list)for entry in entries:@@ -1587,6 +1600,115 @@ def corroborated(entries: list[tuple], min_reps: int) -> tuple[list[tuple], listreturn firm, weak+#: The capture fields that together are one arm's rendering of one action, for `rendering_of`.+#: Deliberately wider than what `compare` decides on: a field left out can only make two renderings+#: look equal, which is the direction that excuses, so everything the capture carries about the+#: thread root, the overlays and the style probe is in. `shot` and `shot_scroll_top` are not: the+#: first names the arm, so no rendering could ever equal the other arm's.+RENDERING_FIELDS: tuple[str, ...] = (+ "root_kind",+ "digest",+ "chars",+ "digest_scaffold",+ "chars_scaffold",+ "messages",+ "overlays",+ "styles",+ "mounted_messages",+ "thread_total",+ "in_flight",+ "streaming",+ "in_flight_unplaced",+ "queued_idle",+ "composer_control",+)+++def rendering_of(capture: Optional[dict]) -> Optional[str]:+ """One arm's capture reduced to an exact, comparable identity, or `None` when it has none.++ `None` for a capture with no `digest` -- a failed probe, or a payload recorded before the+ digest existed -- and `swapped_between_arms` then has nothing to match, so the pair is scored+ exactly as it was before that function existed.+ """+ if not isinstance(capture, dict) or not capture.get("digest"):+ return None+ fields = {k: capture.get(k) for k in RENDERING_FIELDS}+ return json.dumps(fields, sort_keys = True, default = str)+++def swapped_between_arms(results: list[tuple], min_reps: int) -> frozenset[int]:+ """Indices into `results` of differing pairs another repetition saw with the ARMS SWAPPED.++ A DIGEST DIFFERENCE CAN HAVE A DIRECTION TOO. `corroborated` separates two one-arm failures+ that blame opposite arms, and treats a digest difference as having no side. Measured on #11756+ (run 35949769378) that is not so: `thread_reopen` and `delete_message` differed in both+ repetitions at r100K, rep0 as (base R1, head R2) and rep1 as (base R2, head R1), byte for byte+ the same two renderings. The action just before them, `image_upload`, has an 800ms slot, and+ in the cells where it ran its attachment chip was still in the composer, which is inside the+ thread root, two actions later (+2012 and +2022 characters of scaffold). Which cells reached+ that slot was a race: base missed, head ran, head missed, base ran. Each build rendered BOTH+ states, so the difference is not a property of either, and two repetitions of it are one race+ seen from each side rather than one finding seen twice.++ EXACT, NOT A SIGN. A pair is excused only when another repetition of the same action at the+ same rung holds its two renderings, entire, on the opposite arms (`rendering_of`). A treatment+ that changes anything else in the thread moves at least one of the four renderings, so the+ swap no longer lines up and the pair is scored as before. A size-sign heuristic would excuse+ that too, and is not used.++ WHAT IT COSTS: a change that makes EACH build render the other's state in some repetition is+ indistinguishable from this race at this repetition count and is demoted to UNCORROBORATED,+ printed rather than dropped, exactly like a difference seen in one repetition.++ Off at `min_reps <= 1`, where every difference counts by request. A repetition is its cell+ label, as in `corroborated`, so a pair cannot excuse itself and one repetition recorded in two+ shards cannot supply its own partner. Pairs are matched ONE-TO-ONE: a reversal excuses exactly+ one observation in the other direction, and whatever is left is scored as before.+ """+ if min_reps <= 1:+ return frozenset()+ groups: dict[tuple[str, str], list[tuple[int, str, str, str]]] = collections.defaultdict(list)+ for i, (action, _shard, cell, r) in enumerate(results):+ if r.get("verdict") != P.DIFFER:+ continue+ base, treat = r.get("outcomes") or (None, None)+ if base is None or treat is None or base == treat:+ continue+ groups[(action, rung_of_cell(cell))].append((i, cell, base, treat))+ # ONE-TO-ONE, BY REPETITION. `corroborated` counts a repetition (cell) once, so a repetition is+ # the unit here too: all its rows are excused together or not at all, and it takes part in at+ # most one swap. A repetition recorded with BOTH directions of the same pair (two shards that+ # disagree) is ambiguous and is never excused, since it cannot say which side it saw. Each+ # reversed repetition then excuses exactly one repetition in the other direction, so three+ # repetitions of (R1, R2) against one (R2, R1) leave two (R1, R2) for `corroborated` to count.+ out: set[int] = set()+ for group in groups.values():+ by_cell: dict[str, dict[tuple[str, str], list[int]]] = collections.defaultdict(+ lambda: collections.defaultdict(list)+ )+ for i, cell, base, treat in group:+ by_cell[cell][(base, treat)].append(i)+ # One direction per repetition and pair; a repetition holding both is set aside whole.+ seen: dict[str, tuple[str, str]] = {}+ for cell, directions in by_cell.items():+ if len(directions) == 1:+ seen[cell] = next(iter(directions))+ used: set[str] = set()+ for cell in sorted(seen):+ if cell in used:+ continue+ base, treat = seen[cell]+ for other in sorted(seen):+ if other not in used and other != cell and seen[other] == (treat, base):+ used.update((cell, other))+ break+ for cell in used:+ for rows in by_cell[cell].values():+ out.update(rows)+ return frozenset(out)++def report(paths: list[Path],label: str,@@ -1621,7 +1743,9 @@ def report(expect_bad = []compared: set[tuple[str, str, str]] = set()matched = 0- for action, shard, cell, r in results:+ swapped = swapped_between_arms(results, min_reps)+ swapped_bad: list[tuple] = []+ for i, (action, shard, cell, r) in enumerate(results):# COLLECTED BEFORE THE VERDICT BRANCHES AND OUTSIDE THE EXEMPTION, because it is not a digest: an# action can produce two digests the instability exemption excuses and still have failed its own# assertion on one arm only, which is the one shape `ran` cannot see. `stop_generation` is the@@ -1670,7 +1794,13 @@ def report(continueentry = (action, shard, cell, r["moved"])compared.add((action, shard, cell))- (unstable_bad if is_unstable(unstable, action, cell) else stable_bad).append(entry)+ if is_unstable(unstable, action, cell):+ unstable_bad.append(entry)+ elif i in swapped:+ # Each build rendered both states; see `swapped_between_arms`. Never corroborates.+ swapped_bad.append(entry)+ else:+ stable_bad.append(entry)# SPLIT BEFORE THE COUNTS ARE PRINTED: "stable actions differing: 1" above a verdict of 0 is how# a reader concludes the tool is lying, so the headline number must be the one the exit code@@ -1718,6 +1848,11 @@ def report(f" uncorroborated: {len(uncorroborated)} (a stable action that differed "f"in fewer than {min_reps} repetitions; reported, not counted)")+ if swapped_bad:+ print(+ f" swapped between arms: {len(swapped_bad)} (a stable action whose repetitions "+ f"held the same two renderings on opposite arms; reported, not counted)"+ )print(f" ran on ONE arm only: {len(one_sided)}"+ (f" (in >= {min_reps} repetitions)" if min_reps > 1 else "")@@ -1743,7 +1878,7 @@ def report(# THE SAME SET, COUNTED TWICE, checked rather than assumed, so a later edit to either branch# cannot make the coverage floor answer about a different set than the summary does.- scored = matched + len(stable_bad) + len(uncorroborated) + len(unstable_bad)+ scored = matched + len(stable_bad) + len(uncorroborated) + len(swapped_bad) + len(unstable_bad)assert len(compared) == scored, (len(compared), scored)shortfall = coverage_shortfall(scored, len(results), min_compared)if shortfall:@@ -1794,7 +1929,7 @@ def report(# A DEMOTED DIFFERENCE IS STILL A COMPARISON: `corroborated` moves a sub-`min_reps` difference out# of `stable_bad`, and reading `matched` alone a payload whose every difference was uncorroborated# exited 2 "NOTHING WAS COMPARED" over a run that compared everything it had.- decided = matched + len(uncorroborated) + len(one_sided_weak)+ decided = matched + len(uncorroborated) + len(swapped_bad) + len(one_sided_weak)if stable_bad:print("\n UI PARITY DIFFERENCES ON STABLE ACTIONS -- these need explaining:")for action, shard, cell, moved in stable_bad:@@ -1831,6 +1966,15 @@ def report(for action, shard, cell, moved in uncorroborated[:8]:print(f" {action:<26} {shard} {cell}: {', '.join(moved[:3])}")+ if swapped_bad:+ # Printed for the same reason: a race is still a reading, and it names the surface.+ print(+ "\n UNCORROBORATED -- the repetitions SWAPPED the same two renderings between the"+ "\n arms, so each build produced both and the difference is not a property of either:"+ )+ for action, shard, cell, moved in swapped_bad[:8]:+ print(f" {action:<26} {shard} {cell}: {', '.join(moved[:3])}")+if blind:print("\n NOT COMPARABLE -- these surfaces carry no verdict in either direction:")for action, shard, cell, why in blind[:8]: