Skip to content

scripts: game-abba.ps1 runs an in-game ABBA comparison over gate runs (D3D12-GAME-ABBA) - #2804

Open
TheGeogeo wants to merge 7 commits into
ProjectLeonida:mainfrom
TheGeogeo:d3d12-game-abba
Open

TheGeogeo wants to merge 7 commits into
ProjectLeonida:mainfrom
TheGeogeo:d3d12-game-abba

Conversation

@TheGeogeo

@TheGeogeo TheGeogeo commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: D3D12-GAME-ABBA (#2570 (comment))

What and why

An A/B between separate runs needs a balanced order, warm caches, the same exe throughout, and every run checked before it counts. Testers still do this by hand, one gate run at a time. This adds the runner that #2783's plan and abba were written for:

  • scripts/game-abba.ps1 takes the order from d3d12_ab_compare.py plan: warm-up runs of each arm, then discarded runs, then -Pairs pairs in ABBA order. It runs each slot through scripts/game-gate.ps1 (d3d12: an in-game gate: one command, one run folder, one summary.json (D3D12-GAME-GATE) #2782).
    • One exe with two settings: -Data, -MoreA, -MoreB.
    • Two builds: -CheckoutA, -DataA, -CheckoutB, -DataB. Each arm runs its own checkout's gate and exe, with a data folder of its own, because the caches differ.
  • The new d3d12_ab_compare.py check checks each measured run. A run counts only if all of these hold:
    • its gate passed;
    • the pipeline cache was warm before the measured window (60 s into the world);
    • its exe is the one its arm started with;
    • its arm's own -MoreA/-MoreB settings show in the runtime's settings line (d3d12: a run logs the LEONIDA_ settings it starts with (D3D12-RUN-SETTINGS-LINE) #2775), when the run has one. A value the line hides counts as shown;
    • it has a frame rate (the same definition abba uses: check is built on it).
  • -MoreA/-MoreB are read once, the gate's way (d3d12_ab_compare.py settings, check --more): names and values trimmed, the last value of a name kept. Items the settings line could never show (no =, a name that is not LEONIDA_..., an empty value, a space or more than 120 characters in a value the line shows as it is) are refused before the first run. The rule for "shows as it is" mirrors leonida.rs, pinned by a contract test. Messages name an item by its position, never by its text.
  • A run that fails a check (an unreadable summary.json included) gets an ab-excluded.txt, which abba now leaves out, and its slot runs again (-Retry, 1). A failed warm-up or discarded run stops the series at once.
  • It ends with abba into <Out>/comparison.txt and comparison.json. Every comparator call's exit code is checked before its output is used. Exit 0 with a comparison, 1 without one.
  • abba.json records the arms' inputs (-MoreA, -MoreB, -More, -PlayArgs, the folders), what ran, which exe and commit, and what was left out and why. It is written at the start and after each run, beside itself then moved over, so an error leaves a record. The files the runner writes are LF.
  • A re-run into the same -Out starts clean, but only when its abba.json is this runner's. Anything else there is refused and kept. Every folder and each checkout's scripts\game-gate.ps1 is checked before anything is deleted.
  • -DryRun prints the plan and every gate command without starting anything.
  • It refuses:
    • two builds sharing one data folder (paths compared in full, without an ending separator, case ignored);
    • one exe with no setting that differs;
    • fewer than 3 pairs (2 pairs are 2 runs a side, which abba can never compare);
    • an -Out inside a checkout or holding one, or overlapping -Game, -DataTemplate or a data folder;
    • -Retry below 0.
  • Empty -More/-PlayArgs are not passed to the gate.
  • It needs PowerShell 7 (#Requires -Version 7.0).
  • docs/measuring_fps.md (section 3) and docs/game_gate.md describe it.

Tested

On Windows 11 Pro 10.0.26300, rebased on main 8422def:

  • tests/test_game_abba.py, 23 tests. Besides the dry runs and refusals, a stand-in gate that writes run.json and summary.json drives the whole path (gate, check, retry, outputs): a failed run left out and run again in the A B B A order, a cut summary, a failed comparator, a failed warm-up, too few runs left, runs measuring another exe or other settings, a re-run into the same -Out, an -Out the runner did not write, the record's fields and bytes.
  • tests/test_d3d12_ab_compare.py, 26 tests: check (each reason to leave a run out, an unreadable summary, a run without a frame rate), the settings reader (hidden values, last value of a name, items named by position), the contract on leonida.rs, and an excluded run left out by abba.
  • Each fix asked for in the reviews has a test that fails without it.
  • test_game_gate.py, test_tool_stdout_encoding.py, test_ci_registration.py, the docs tests, scripts/check_no_game_data.py on the changed files, and git diff --check are clean.
  • In game, RTX 3080 10 GB, driver 32.0.16.2140, Series S profile, the diagnostics build of main 8f41d7d code: a null A/B, LEONIDA_FPS_LINE=1 against =0 (the top-left frame-rate line). One exe with two settings, 4 pairs, 120 s in the world per run, with the driver mod from mods: gate_driver takes a run from the menus into the world (D3D12-GATE-DRIVER-MOD) #2784 enabled through -More.
    • 11 runs. All 8 measured runs passed their gate, none was left out, and none was retried.
    • Verdict "no clear difference": effect -0.08 ms (-0.2 %), standard error 0.53, 95 % [-1.78, +1.63] ms, 3 of 4 pairs agree.
    • The world median frame time of the measured runs was 41.05 / 40.50 / 39.45 / 37.92 / 38.49 / 37.79 / 37.89 / 38.48 ms in ABBA order. The first pair was still a little slower, which the balanced pairs absorb.
    • An earlier attempt of the same A/B had all its runs stopped early by an outside guard. It showed the other path: every run was marked and left out, each slot ran again once, and the verdict was "not enough runs".

GPUs tested: NVIDIA GeForce RTX 3080 10 GB, driver 32.0.16.2140, Windows 11 Pro 10.0.26300

AI-assisted: yes. Claude Code (Claude Fable 5.2 and Claude Opus 5.5); a separate Claude Opus 5.5 agent reviewed the diff before this push.

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator change)

@OreoFR

OreoFR commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Verified by OreoFR on macOS 27.2.1, Apple M5, Python 3.12, head 413212ff9, main b7a1be296. CPU only, no pwsh and no game on this machine.

MEASURED

  • Red (main + only this PR's tests): 6 failed, 14 passed, 4 skipped.
    • In test_d3d12_ab_compare.py, the four new Runs tests fail: check doesn't exist on main.
    • In test_game_abba.py, test_it_needs_powershell_7 and test_no_variable_takes_a_parameters_name_in_another_case fail: the script doesn't exist on main.
  • Green (main + this PR, merge-tree): 20 passed, 4 skipped (test_d3d12_ab_compare.py 18 passed; test_game_abba.py 2 passed, 4 skipped).
  • The 4 skips are test_game_abba.py:50, :65, :81, :97, all "needs Windows and pwsh". So the parts of game-abba.ps1 that run are not exercised here. Only the static checks ran (the #Requires -Version 7.0 line and the variable/parameter case clash).

READ IN CODE

ASSUMED

  • The ABBA run itself (order, retries, exclusions, abba.json) needs a Windows run, or at least -DryRun under pwsh 7. Not reproduced here.

AI-assisted: Claude Code

@fiestorra

Copy link
Copy Markdown
Contributor

Verified on Windows, with the control that matters: the tests fail when the change is reverted.

Cherry-picked onto main d920d850d in a clean worktree, Python 3.13.14:

python -m pytest tests/test_game_abba.py + tests/test_d3d12_ab_compare.py -q with this pull request: 6 + 18 passed with scripts/game-abba.ps1 y tools/d3d12_ab_compare.py from main: 6 failed (script borrado) y 4 failed (tool de main)

So the new tests are tied to the change and not to each other's fixtures. No part of this needed a GPU, a display or game data, which is what the gate tests are built for.

What I could not test: the script against a real run folder - game-abba.ps1 drives one, and this machine has the game but not the gate harness the other contributors used, so the shape is proven and the run is not.

AI-assisted: yes - DeepSeek v4.1 (flash), applied and ran both arms on the machine above.

Written with an AI assistant.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified with pwsh here: 6/6 test_game_abba.py, 18/18 test_d3d12_ab_compare.py, 21/21 test_game_gate.py. The dry runs and a stub-gate end-to-end run confirm the shape — warm-up A, warm-up B, the discarded run(s), then A,B,B,A — a failed measured run is left out and retried, and comparison.txt/json + abba.json are written. plan (tools/d3d12_ab_compare.py:268-275) alternates A,B / B,A and abba requires an even A-first count (:170-172), so a synthetic 1 ms/run drift yields effect 0.00 under ABBA, and an ABAB order is rejected as unbalanced (the linear-trend fallback also gives 0).

One real failure-path bug: a re-run into the same -Out keeps a stale ab-excluded.txt. Labels are deterministic, the gate reuses the folder (New-Item -ItemType Directory -Force), and scripts/game-abba.ps1:112 only writes the exclusion. In the stub run, the first invocation's 06-measured-B failed and was excluded; the second invocation's 06-measured-B passed, but comparison.txt still said left out (excluded: gate FAIL) while abba.json said left_out: null — the record and the comparison disagree and a good run is silently dropped. Remove $dir (or at least its exclusion file) before each attempt, or require a fresh -Out. The previous run's data copy is left behind the same way.

Two smaller ones:

  • In two-build mode -Out inside the runner's checkout is accepted: the guard (:65-67) loops only -CheckoutA/-CheckoutB; add $repo. I passed -Out inside the runner's tree and the dry run was happy.
  • A failed warm-up or discarded run is neither checked nor retried, so a broken environment runs every measured slot (about an hour) before failing with "not enough runs". Fail fast on a warm-up gate failure.

Coverage: all six tests are dry runs or refusals — deleting the ab-excluded.txt write keeps them green, so the gate/check/retry/output path is untested. A stub game-gate.ps1 writing run.json/summary.json (the shape tests/test_game_gate.py's Fake already uses) would cover it and the stale-file case. Also abba.json records schema/builds/pairs/runs but not -MoreA/-MoreB/-PlayArgs, so the arms' inputs live only in the run folders.

@merzleckeier

Copy link
Copy Markdown
Contributor

I checked 413212ff9 on bf30e2585. All 18 comparison tests passed. I also forced the ABBA dry-run tests to execute on Linux with PowerShell 7.4.21. Five of six passed. The checkout-containment case failed because the check appends a Windows path separator on Linux. Using [IO.Path]::DirectorySeparatorChar for both paths passes all six with the same fixtures, without launching a game.

This is a portability note for Linux dry runs. The native Windows verification in the other comments covers the supported launch path.

AI-assisted with OpenAI Codex.

@andrew-ai

Copy link
Copy Markdown

The two-build cache guard accepts the same Windows directory if one argument ends in a separator. At 413212f I ran game-abba.ps1 with two distinct checkout directories, -Pairs 2 and -DryRun. Passing the same existing folder to -DataA and -DataB exited 1 before planning. Appending a backslash to just -DataB exited 0 and printed all eight gate commands. Python os.path.samefile confirmed both arguments named the same directory. A control using separate data directories also planned eight commands. This would let both builds write their caches to the same place in a measured run. For the reproduced spelling, normalize optional trailing separators on both absolute paths with Path.TrimEndingDirectorySeparator before comparing, and cover it alongside the exact-spelling refusal. No game was launched. Codex-assisted.

@andrew-ai

Copy link
Copy Markdown

A truncated summary can make game-abba.ps1 exit 0 with an empty comparison.json. On Windows at 413212f I ran the unmodified runner and comparator with a synthetic gate, -Pairs 2 and -Retry 1. The first measured A wrote a valid run.json then exited 1. With summary.json absent the runner recorded no summary, retried that slot, and produced both pairs. With the same failed gate writing a truncated JSON object instead, check raised JSONDecodeError; the runner recorded left_out=null, skipped the retry, and the final text and JSON comparison commands both raised the same error. The runner still exited 0. Treating an unreadable summary as an exclusion would allow the existing retry. Checking the comparator exit codes before consuming their output would also keep failed comparisons from being published as successful. All other synthetic slots had valid passing summaries. Codex-assisted.

… (D3D12-GAME-ABBA)

The runner takes the order from d3d12_ab_compare.py plan (warm-up runs, discarded runs, then ABBA pairs) and
runs each slot through scripts/game-gate.ps1, for one exe with two settings or for two builds (a checkout and
a data folder per arm). Each measured run is checked by the new `d3d12_ab_compare.py check`: its gate passed,
the pipeline cache was warm before the measured window, its exe is its arm's first one, and its arm's own
settings show in the runtime's settings line when there is one. A run that fails gets an ab-excluded.txt,
which `abba` now leaves out, and its slot runs again (-Retry, 1). The runner ends with the comparison in
<Out>/comparison.txt and comparison.json, and abba.json says what ran and what was left out. -DryRun prints
the plan and the gate commands. It needs PowerShell 7 (#Requires).
…on out (review)

A summary.json cut short (a gate stopped while writing it), not JSON, or not an object made `check` and
`abba` raise. Both now read it through read_summary() and give "unreadable summary" as the reason the run
is left out, so the runner retries the slot instead of recording nothing and comparing without it.
…up, checks the comparator and records the arms (review)

- A run into an -Out used before first deletes what the earlier one wrote there (runs, abba.json,
  comparison.*): a run folder of the same name kept its ab-excluded.txt, which left a good run out while
  abba.json said left_out null, and its data copy.
- A warm-up or discarded run whose gate fails stops the runner at once, before the measured runs.
- Every call of d3d12_ab_compare.py (plan, check, abba) has its exit code checked before its output is
  used: a failed comparator writes no comparison. The runner exits 1 when the runs left give no
  comparison (too few runs, unbalanced pairs), 0 with one.
- abba.json records the arms' inputs (more, more_a, more_b, play_args, max_minutes, retry) and each run's
  commit.
- The guard on -Out covers the runner's own checkout in two-build mode, appends
  [IO.Path]::DirectorySeparatorChar, and -DataA/-DataB (and the checkouts) compare as full paths without an
  ending separator, so "dir" and "dir\" are one folder.
- tests/test_game_abba.py runs the script over a stand-in gate that writes run.json and summary.json:
  a failed and a cut-short run left out and retried, the outputs, a re-run into the same -Out, a failed
  warm-up or discarded run, a failing comparator, too few runs left, and the record's fields.
- docs/measuring_fps.md: the re-run, the stop on a failed warm-up, the exit codes and abba.json's fields.
2 pairs are 2 runs a side, and `abba` needs 3 runs a side (side and linear trend) or 4 pairs (a verdict from
the pairs themselves): such a run could never give a comparison and would only say so, exit 1, after about an
hour of gate runs. The runner now refuses -Pairs below 3 before any run, and says why. The header comment and
docs/measuring_fps.md say the minimum; the dry-run tests that plan use 3 pairs, and the refusals cover 1 and 2.
…ver be checked, writes LF records as it goes (review)

- A re-run deletes runs, abba.json and comparison.* only when -Out's abba.json is this runner's (its schema); an
  -Out holding any of those without it is refused and kept. Each arm's scripts\game-gate.ps1, -Game,
  -DataTemplate and the data folders are checked before anything is deleted (two-build mode needs the gate in
  each checkout).
- -Out may not be -Game, -DataTemplate or a data folder, nor be inside one or hold one (full paths without an
  ending separator, case ignored on Windows). -Retry is 0 or more.
- One reading of an arm's settings, d3d12_ab_compare.py's arm_settings(): the way game-gate.ps1 reads -More
  (split at ";", name and value trimmed). The runner refuses before the first run what the runtime's settings
  line could never show (not LEONIDA_NAME=value, a value with a space or over 120 characters), through the new
  `settings` command, and passes the arm's text to `check --more`, which compares with the same reading.
- `check` builds on run_value, so a run that counts has one definition (a PASS without a frame rate is left out
  and run again), and takes AFTER_WORLD_S from tools/game_gate.py. Its docstring no longer says it prints no
  argument text.
- abba.json holds the folders and checkouts as well, and is written at the start and after each run, so an error
  leaves it. abba.json, comparison.txt, comparison.json and ab-excluded.txt are LF with one final newline.
- An empty -More or -PlayArgs is not passed to the gate (PowerShell 7.0 to 7.2 drop an empty argument).
- Tests: the stand-in gate notes the parameters it gets and can end a run with another exe, another setting or
  no frame rate; new cases for each point above, a slot left out on every try keeping its place, and the bytes
  of the files written. test_d3d12_ab_compare.py removes its temporary folders.
- docs/measuring_fps.md: the refusals, the gate each checkout needs, the record and the re-run.
…m, keeps a name's last value, refuses a checkout in -Out (review)

- arm_settings applies the space and length rules only to a value the runtime's settings line shows as it is:
  one of ASCII letters, digits and " ._,:+=*-", the `plain` test of d3d12/apps/leonida/src/leonida.rs line 65,
  mirrored and quoted in d3d12_ab_compare.py's new SOURCES, which a contract test checks against leonida.rs.
  Any other value (a folder with a space, a long path) shows as "<hidden, N chars>", which `check` takes as
  shown, so it can be an arm.
- A name given twice in one arm counts with its last value, as the gate keeps it.
- `settings` names an item by its position (and its LEONIDA_ name), never by its text, so no path is said back.
- The runner refuses a checkout inside -Out, where a re-run's clean-up could reach it.
- The files the runner writes are written beside themselves and moved over, so abba.json, rewritten after every
  run, is never found cut short; an -Out whose abba.json exists but is not readable as this runner's is refused
  as such ("no readable abba.json of this runner").
- docs/measuring_fps.md and the script's header say the same.
@TheGeogeo

Copy link
Copy Markdown
Contributor Author

Rebased on main 8422def and changed after the reviews of @KelboLive, @andrew-ai and @merzleckeier (head ac3e217):

  • Re-run into the same -Out: it starts clean, but only when its abba.json is this runner's (the schema marks it). Anything else in -Out is refused and kept. Every folder and each checkout's scripts\game-gate.ps1 is checked before anything is deleted. A stale ab-excluded.txt can no longer drop a good run.
  • Fail fast: a failed warm-up or discarded run stops the series at once.
  • Cut summary.json: an unreadable summary is a left-out run, so its slot runs again. Every comparator call's exit code is checked before its output is used. The exit code is 0 with a comparison and 1 without one, and -Pairs must be 3 or more, because 2 pairs can never be compared.
  • Paths: both data folders are compared in full, without an ending separator, case ignored. -Out may not overlap a checkout (the runner's own included), -Game, -DataTemplate or a data folder, in either direction. The separator comes from [IO.Path]::DirectorySeparatorChar.
  • Settings: -MoreA/-MoreB are read once, the gate's way, and the last value of a name counts. Items the settings line could never show are refused before the first run. Values it hides (a folder with a space, a long path) count as shown, mirroring leonida.rs under a contract test. check uses abba's own definition of a run that counts.
  • Record: abba.json records -MoreA, -MoreB, -More, -PlayArgs and the folders. It is written as the run goes, beside itself and then moved over. The files are LF. Empty -More/-PlayArgs are not passed to the gate, which matters under PowerShell 7.0-7.2.
  • Coverage: a stand-in gate now drives the whole path (gate, check, retry, outputs) in tests/test_game_abba.py, 23 tests. tests/test_d3d12_ab_compare.py has 26 tests. Each fix has a test that fails without it.

AI-assisted (Claude Code, Claude Fable 5.2 and Claude Opus 5.5; a separate Claude Opus 5.5 agent reviewed the diff before this push).

…er (review)

The Windows runner of the `check` job failed three of these tests; the script was right.

- Its TEMP is an 8.3 short path (C:\Users\RUNNER~1\...), and [IO.Path]::GetFullPath, which the script uses for
  every folder it compares and records, expands short names: the printed gate path and abba.json's folders were
  the long spelling of what the tests gave. The tests now take the real path of their temporary folders and
  compare paths after realpath and normcase.
- Its console colours PowerShell's error text and wraps it with the escape sequences inside the wrap, which
  unwrapped() did not join. The tests now run pwsh with NO_COLOR=1, and unwrapped() removes colour sequences
  before it joins the wrapped lines.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants