From a156f8bbb737f79f9f63e594c9b39cb215c4a670 Mon Sep 17 00:00:00 2001 From: Sebastian Kondratowicz Date: Wed, 25 Nov 2026 11:45:49 +0100 Subject: [PATCH 1/2] Scripts: pr_check takes the newest clean main smoke block as the baseline (#2226) The PR's own smoke block already had to be free of "(uncommitted changes)", but a main block with local changes counted as main. When several main blocks had the PR's title and time, the first pasted one was the baseline, so an older, more favourable run could be put first. - A main block whose commit line says "(uncommitted changes)" is not a baseline; when it is the only one, the check says to rerun on a clean main. - With the commit distance known (`main_behind`: git rev-list locally, compare/...main ahead_by on GitHub), the baseline is the matching block of the newest main commit; without it, the first block as before. - How many commits behind main each main block is gets printed, not judged: the cut-off for an old baseline is the maintainer's call. Co-Authored-By: Claude Opus 5.5 --- scripts/pr_check.py | 55 ++++++++++++++++++++++++++++++++++------ scripts/test_pr_check.py | 30 ++++++++++++++++++++++ 2 files changed, 77 insertions(+), 8 deletions(-) diff --git a/scripts/pr_check.py b/scripts/pr_check.py index cb0ef3ef9e..5ac9ea1c33 100644 --- a/scripts/pr_check.py +++ b/scripts/pr_check.py @@ -100,10 +100,25 @@ def section_has_content(body, section): return False -def check(body, head, files, is_main_ancestor, *, test_only=False): +def main_baseline(candidates, main_behind): + """The main block the PR's run is compared with, of those with its title and time: the one of + the newest main commit when `main_behind(sha)` (commits main is ahead of `sha`) is given, so + pasting an older block first does not choose it (#2226); else, or when the distance of any of + them is unknown (a failed API call must not make an older block win), the first.""" + if not candidates: + return None + if main_behind is None: + return candidates[0] + behind = [main_behind(b["commit"].split()[0]) for b in candidates] + if None in behind: + return candidates[0] + return candidates[behind.index(min(behind))] + + +def check(body, head, files, is_main_ancestor, *, test_only=False, main_behind=None): """The problems (empty: mergeable as far as this check goes). `files`: (path, status, binary, size) with `size` a function giving the file's bytes; `is_main_ancestor(sha)`: whether the - commit is on main.""" + commit is on main; `main_behind(sha)`: how many commits main is ahead of it (None: unknown).""" body = body.replace("\r\n", "\n") problems = [] for section in SECTIONS: @@ -135,8 +150,14 @@ def check(body, head, files, is_main_ancestor, *, test_only=False): if not clean: problems.append(f"the PR changes the runtime: **Regression run** needs an `xcl-smoke` block made on this PR's " f"head commit {head[:12]} with no uncommitted changes (rerun scripts/smoke.ps1 after every push)") - main = [b for b in base if is_main_ancestor(b["commit"].split()[0])] - if not main: + on_main = [b for b in base if is_main_ancestor(b["commit"].split()[0])] + # a run with local changes is not main, for the baseline as for the PR's run (#2226) + main = [b for b in on_main if "uncommitted" not in b.get("commit", "")] + if not main and on_main: + problems.append("the main regression run (`xcl-smoke` block of commit " + f"{on_main[0]['commit'].split()[0]}) has uncommitted changes: rerun scripts/smoke.ps1 " + "on a clean checkout of main") + elif not main: problems.append("**Regression run** needs an `xcl-smoke` block made on a commit of main (not the PR's), " "with the same title and time as the PR's") if clean: @@ -148,18 +169,22 @@ def check(body, head, files, is_main_ancestor, *, test_only=False): if pr.get("exit", "").startswith("killed"): problems.append("the PR's regression run did not end by itself (killed)") if main: - m = next((b for b in main if b.get("title") == pr.get("title") and b.get("seconds") == pr.get("seconds")), None) + m = main_baseline([b for b in main if b.get("title") == pr.get("title") and b.get("seconds") == pr.get("seconds")], main_behind) for b in [m] if m else main: problems += field_problems(b, "the main") if m is None: problems.append("the main and PR regression runs are not of the same title for the same time") else: + # an old baseline is named where the comparison fails, not only in the log + n = main_behind(m["commit"].split()[0]) if main_behind else None + old = (f"; the main block is {n} commit(s) behind main: rerun it before comparing" + if n else "") pf, mf = number(pr.get("frames shown")), number(m.get("frames shown")) if mf and (pf is None or pf < FRAMES_KEPT * mf): - problems.append(f"the PR's run shows fewer frames than main's ({pf} against {mf})") + problems.append(f"the PR's run shows fewer frames than main's ({pf} against {mf}){old}") pc, mc = number(pr.get("peak commit")), number(m.get("peak commit")) if pc and mc and pc > COMMIT_GROWTH * mc: - problems.append(f"the PR's run commits much more memory than main's ({pc} MB against {mc} MB)") + problems.append(f"the PR's run commits much more memory than main's ({pc} MB against {mc} MB){old}") return problems @@ -193,7 +218,21 @@ def is_main_ancestor(sha): r = subprocess.run(["gh", "api", f"repos/{o.repo}/compare/{sha}...main", "--jq", ".status"], capture_output=True, text=True) return r.returncode == 0 and r.stdout.strip() in ("ahead", "identical") - problems = check(body, o.head, files, is_main_ancestor, test_only=o.test_only) + def main_behind(sha): + if o.local: + r = subprocess.run(["git", "rev-list", "--count", f"{sha}..origin/main"], capture_output=True, text=True) + else: + r = subprocess.run(["gh", "api", f"repos/{o.repo}/compare/{sha}...main", "--jq", ".ahead_by"], capture_output=True, text=True) + return int(r.stdout.strip()) if r.returncode == 0 and r.stdout.strip().isdigit() else None + + problems = check(body, o.head, files, is_main_ancestor, test_only=o.test_only, main_behind=main_behind) + # how old the baseline is: shown, not judged (the limit is the maintainer's call, #2226) + for b in smoke_blocks(body.replace("\r\n", "\n")): + sha = (b.get("commit") or "").split()[0] if b.get("commit") else "" + if len(sha) >= 7 and not o.head.startswith(sha) and is_main_ancestor(sha): + n = main_behind(sha) + if n is not None: + print(f"main regression run {sha[:12]}: {n} commit(s) behind main") if problems: print("This PR cannot be merged yet (see CONTRIBUTING.md, 'What a PR needs to be merged'):") for p in problems: diff --git a/scripts/test_pr_check.py b/scripts/test_pr_check.py index 8cc45d5d06..e809f45c6c 100644 --- a/scripts/test_pr_check.py +++ b/scripts/test_pr_check.py @@ -96,6 +96,36 @@ def test_blocks_with_only_commit_lines_fail(self): for run in ("the PR's", "the main"): self.assertTrue(any(p.startswith(run) and f"no `{field}` line" in p for p in problems), problems) + RUN = "title: G\nseconds: 60\ndevice removals: 0\ncrashes: 0\npeak commit: {} MB\nframes shown: {}\n" + + def test_a_main_run_with_uncommitted_changes_is_not_a_baseline(self): + body = ("```\nxcl-smoke v1\ncommit: 1111111aaaa (uncommitted changes)\n" + self.RUN.format(100, 100) + "```\n" + "```\nxcl-smoke v1\ncommit: 1234567890\n" + self.RUN.format(100, 100) + "```\n") + problems = check(BODY + body, HEAD, [changed("crates/xcl/src/hle/d3d12x/vram.rs")], lambda sha: sha == "1111111aaaa") + self.assertEqual(["the main regression run (`xcl-smoke` block of commit 1111111aaaa) has uncommitted " + "changes: rerun scripts/smoke.ps1 on a clean checkout of main"], problems) + + def test_the_newest_main_block_is_the_baseline_whatever_its_place(self): + # an old main run with a low peak pasted first, the current main run after it + old = "```\nxcl-smoke v1\ncommit: 1111111aaaa\n" + self.RUN.format(1000, 100) + "```\n" + new = "```\nxcl-smoke v1\ncommit: 2222222bbbb\n" + self.RUN.format(4000, 100) + "```\n" + pr = "```\nxcl-smoke v1\ncommit: 1234567890\n" + self.RUN.format(4000, 100) + "```\n" + files = [changed("crates/xcl/src/hle/d3d12x/vram.rs")] + on_main = lambda sha: sha in ("1111111aaaa", "2222222bbbb") + behind = {"1111111aaaa": 40, "2222222bbbb": 2}.get + for order in (old + new, new + old): + self.assertEqual([], check(BODY + order + pr, HEAD, files, on_main, main_behind=behind)) + # without the distance the first block is taken, as before + self.assertIn("the PR's run commits much more memory than main's (4000 MB against 1000 MB)", + check(BODY + old + new + pr, HEAD, files, on_main)) + # an unknown distance (a failed API call) does not reorder: the first block, not the older one + flaky = {"1111111aaaa": 40, "2222222bbbb": None}.get + self.assertEqual([], check(BODY + new + old + pr, HEAD, files, on_main, main_behind=flaky)) + # a failing comparison with an old baseline says how old it is + self.assertIn("the PR's run commits much more memory than main's (4000 MB against 1000 MB); " + "the main block is 40 commit(s) behind main: rerun it before comparing", + check(BODY + old + pr, HEAD, files, on_main, main_behind=behind)) + def test_non_numeric_frames_shown_fails(self): run = "title: G\nseconds: 60\ndevice removals: 0\ncrashes: 0\n" problems = self.smoke_problems(run + "frames shown: 100\n", run + "frames shown: many\n") From 5d1b0a0fa7a9b86cbeba9ccafe8ec2aa08023296 Mon Sep 17 00:00:00 2001 From: Sebastian Kondratowicz Date: Wed, 25 Nov 2026 11:55:10 +0100 Subject: [PATCH 2/2] Scripts: pr_check compares smoke runs only on the same GPU (#2232) The PR's smoke block was matched with a main block on title and time only; the gpu line was neither required nor compared, so a PR run on one GPU could be held against main on another and the 80 % frames and 125 % commit limits said nothing. smoke.ps1 already writes the gpu line, so blocks it made pass as before. - `gpu` joins the lines a block must have. - The baseline is a main block with the PR's title, time and GPU (case and runs of whitespace do not count); when main blocks of that title and time exist only on other GPUs the check says so. Co-Authored-By: Claude Opus 5.5 --- scripts/pr_check.py | 19 +++++++++++++++---- scripts/test_pr_check.py | 40 +++++++++++++++++++++++++++++++--------- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/scripts/pr_check.py b/scripts/pr_check.py index 5ac9ea1c33..3115c1762e 100644 --- a/scripts/pr_check.py +++ b/scripts/pr_check.py @@ -34,8 +34,9 @@ FRAMES_KEPT = 0.8 # the PR's frames at least this share of main's COMMIT_GROWTH = 1.25 # the PR's peak commit at most this times main's # the lines a smoke block needs to be compared with the other (the crash and device-removal -# counts are checked where they are used), and those of them that are numbers -SMOKE_FIELDS = ("title", "seconds", "frames shown") +# counts are checked where they are used), and those of them that are numbers; `gpu` because +# frames and memory of runs on two GPUs say nothing about each other (#2232) +SMOKE_FIELDS = ("title", "seconds", "frames shown", "gpu") SMOKE_NUMBERS = ("seconds", "frames shown") @@ -100,6 +101,11 @@ def section_has_content(body, section): return False +def gpu_name(block): + """The block's `gpu:` line, with case and runs of whitespace not counting (#2232).""" + return " ".join((block.get("gpu") or "").split()).casefold() + + def main_baseline(candidates, main_behind): """The main block the PR's run is compared with, of those with its title and time: the one of the newest main commit when `main_behind(sha)` (commits main is ahead of `sha`) is given, so @@ -169,10 +175,15 @@ def check(body, head, files, is_main_ancestor, *, test_only=False, main_behind=N if pr.get("exit", "").startswith("killed"): problems.append("the PR's regression run did not end by itself (killed)") if main: - m = main_baseline([b for b in main if b.get("title") == pr.get("title") and b.get("seconds") == pr.get("seconds")], main_behind) + same_run = [b for b in main if b.get("title") == pr.get("title") and b.get("seconds") == pr.get("seconds")] + m = main_baseline([b for b in same_run if gpu_name(b) == gpu_name(pr)], main_behind) for b in [m] if m else main: problems += field_problems(b, "the main") - if m is None: + if m is None and same_run and pr.get("gpu"): + gpus = sorted({b.get("gpu") or "none" for b in same_run}) + problems.append(f"the main and PR regression runs are not on the same GPU ({pr.get('gpu')} against " + f"{', '.join(gpus)}): run both on one machine") + elif m is None: problems.append("the main and PR regression runs are not of the same title for the same time") else: # an old baseline is named where the comparison fails, not only in the log diff --git a/scripts/test_pr_check.py b/scripts/test_pr_check.py index e809f45c6c..574d82545f 100644 --- a/scripts/test_pr_check.py +++ b/scripts/test_pr_check.py @@ -71,7 +71,7 @@ def test_frontier_models_and_ordinary_words_pass(self): class SmokeBlockTests(unittest.TestCase): def test_two_blocks_in_one_fence_are_two_blocks(self): - run = "title: G\nseconds: 60\nframes shown: 100\ndevice removals: 0\ncrashes: 0\n" + run = "title: G\ngpu: GPU A\nseconds: 60\nframes shown: 100\ndevice removals: 0\ncrashes: 0\n" body = ("```\nxcl-smoke v1\ncommit: 1111111aaaa\n" + run + "\n" "xcl-smoke v1\ncommit: 1234567890\n" + run + "```\n") blocks = smoke_blocks(body) @@ -92,24 +92,46 @@ def smoke_problems(self, main_run, pr_run): def test_blocks_with_only_commit_lines_fail(self): problems = self.smoke_problems("", "") - for field in ("title", "seconds", "frames shown"): + for field in ("title", "seconds", "frames shown", "gpu"): for run in ("the PR's", "the main"): self.assertTrue(any(p.startswith(run) and f"no `{field}` line" in p for p in problems), problems) - RUN = "title: G\nseconds: 60\ndevice removals: 0\ncrashes: 0\npeak commit: {} MB\nframes shown: {}\n" + RUN = "title: G\ngpu: {gpu}\nseconds: 60\ndevice removals: 0\ncrashes: 0\npeak commit: {} MB\nframes shown: {}\n" + + def block(self, commit, peak, frames, gpu="GPU A"): + return f"```\nxcl-smoke v1\ncommit: {commit}\n" + self.RUN.format(peak, frames, gpu=gpu) + "```\n" + + def test_runs_on_different_gpus_are_not_compared(self): + files = [changed("crates/xcl/src/hle/d3d12x/vram.rs")] + on_main = lambda sha: sha in ("1111111aaaa", "2222222bbbb") + # main only on a slower GPU: refused, though the PR's numbers would pass against it + body = self.block("1111111aaaa", 4000, 50, "GPU B") + self.block("1234567890", 4000, 100) + self.assertEqual(["the main and PR regression runs are not on the same GPU (GPU A against GPU B): " + "run both on one machine"], check(BODY + body, HEAD, files, on_main)) + # a main run on the PR's GPU next to one on another: compared with the one on the same GPU + body = (self.block("1111111aaaa", 1000, 300, "GPU B") + self.block("2222222bbbb", 4000, 100) + + self.block("1234567890", 4000, 100)) + self.assertEqual([], check(BODY + body, HEAD, files, on_main)) + # the same GPU written with other case or spacing is the same GPU + body = self.block("1111111aaaa", 4000, 100, "gpu a") + self.block("1234567890", 4000, 100) + self.assertEqual([], check(BODY + body, HEAD, files, on_main)) + # a block without a gpu line is incomplete + body = self.block("1111111aaaa", 4000, 100).replace("gpu: GPU A\n", "") + self.block("1234567890", 4000, 100) + self.assertIn("the main regression run (`xcl-smoke` block of commit 1111111aaaa) has no `gpu` line", + check(BODY + body, HEAD, files, on_main)) def test_a_main_run_with_uncommitted_changes_is_not_a_baseline(self): - body = ("```\nxcl-smoke v1\ncommit: 1111111aaaa (uncommitted changes)\n" + self.RUN.format(100, 100) + "```\n" - "```\nxcl-smoke v1\ncommit: 1234567890\n" + self.RUN.format(100, 100) + "```\n") + body = ("```\nxcl-smoke v1\ncommit: 1111111aaaa (uncommitted changes)\n" + self.RUN.format(100, 100, gpu="GPU A") + "```\n" + "```\nxcl-smoke v1\ncommit: 1234567890\n" + self.RUN.format(100, 100, gpu="GPU A") + "```\n") problems = check(BODY + body, HEAD, [changed("crates/xcl/src/hle/d3d12x/vram.rs")], lambda sha: sha == "1111111aaaa") self.assertEqual(["the main regression run (`xcl-smoke` block of commit 1111111aaaa) has uncommitted " "changes: rerun scripts/smoke.ps1 on a clean checkout of main"], problems) def test_the_newest_main_block_is_the_baseline_whatever_its_place(self): # an old main run with a low peak pasted first, the current main run after it - old = "```\nxcl-smoke v1\ncommit: 1111111aaaa\n" + self.RUN.format(1000, 100) + "```\n" - new = "```\nxcl-smoke v1\ncommit: 2222222bbbb\n" + self.RUN.format(4000, 100) + "```\n" - pr = "```\nxcl-smoke v1\ncommit: 1234567890\n" + self.RUN.format(4000, 100) + "```\n" + old = "```\nxcl-smoke v1\ncommit: 1111111aaaa\n" + self.RUN.format(1000, 100, gpu="GPU A") + "```\n" + new = "```\nxcl-smoke v1\ncommit: 2222222bbbb\n" + self.RUN.format(4000, 100, gpu="GPU A") + "```\n" + pr = "```\nxcl-smoke v1\ncommit: 1234567890\n" + self.RUN.format(4000, 100, gpu="GPU A") + "```\n" files = [changed("crates/xcl/src/hle/d3d12x/vram.rs")] on_main = lambda sha: sha in ("1111111aaaa", "2222222bbbb") behind = {"1111111aaaa": 40, "2222222bbbb": 2}.get @@ -127,7 +149,7 @@ def test_the_newest_main_block_is_the_baseline_whatever_its_place(self): check(BODY + old + pr, HEAD, files, on_main, main_behind=behind)) def test_non_numeric_frames_shown_fails(self): - run = "title: G\nseconds: 60\ndevice removals: 0\ncrashes: 0\n" + run = "title: G\ngpu: GPU A\nseconds: 60\ndevice removals: 0\ncrashes: 0\n" problems = self.smoke_problems(run + "frames shown: 100\n", run + "frames shown: many\n") self.assertIn("the PR's regression run (`xcl-smoke` block of commit 1234567890) " "has a non-numeric `frames shown`: many", problems)