Prevent false GPU passes from shared test work directories #1966

Open
github-bot wants to merge 2 commits from github-bot/gh-1966 into main AGit
Owner

@⁠lgr123 on GitHub · 2026-11-25 16:56 UTC · original
lgr123:lgr123/gpu-test-work-ownership → main · +64 −2 · 3 files · 2 commits · open

Claimed as GPU-TEST-WORK-OWNERSHIP.

Two GPU test runs sharing explicit --work can produce a false PASS. In the reproduction, a failing synthetic cs_lds test reported 0/1 passed when run alone and 1/1 passed when a second process replaced its module before it was checked. This reproduced on native Windows and Linux.

The patched CLI reserves an explicit work directory until validation finishes. A second patched run targeting that directory exits before changing any artifacts. Give simultaneous runs separate work directories when mixing versions. An older runner can still overwrite artifacts because it does not acquire the lock. Sequential replay keeps the same artifact paths. The empty lock file stays in the directory so contenders lock the same file, and the OS releases the lock when its handle closes. The testing guide now documents separate directories for simultaneous runs.

Independent Radeon 780M verification reproduced the false PASS with real shaders, checked that two patched runners cannot race, and verified sequential reuse.

Reviewer check

python -I tests/test_run_gpu_tests_paths.py WorkDirectory.test_simultaneous_cli_runs_cannot_share_an_explicit_work_directory

The regression exercises the CLI with a second process, a separate work directory, and a retry after the owner exits with a failed result. It requires no GPU, Wine, or game files.

Tested

  • Linux x86-64, Python 3.11.17. 120 GPU-runner unit tests passed.
  • Windows x64, Python 3.12.16. 119 passed, with one platform skip.
  • Two-process baseline and patched comparisons on both systems used synthetic translator/GPU stand-ins. With the fix, the first run reports the intended failure and the second passes on retry.
  • git diff --check and the source-only policy check passed.

GPUs tested: n/a.

AI-assisted: yes.

Checklist

  • Based on current main.
  • One topic.
  • No game data, keys or decryption.
**@⁠lgr123** on GitHub · 2026-11-25 16:56 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1966) `lgr123:lgr123/gpu-test-work-ownership` → `main` · +64 −2 · 3 files · 2 commits · open Claimed as [GPU-TEST-WORK-OWNERSHIP](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608). Two GPU test runs sharing explicit `--work` can produce a false PASS. In the reproduction, a failing synthetic `cs_lds` test reported `0/1 passed` when run alone and `1/1 passed` when a second process replaced its module before it was checked. This reproduced on native Windows and Linux. The patched CLI reserves an explicit work directory until validation finishes. A second patched run targeting that directory exits before changing any artifacts. Give simultaneous runs separate work directories when mixing versions. An older runner can still overwrite artifacts because it does not acquire the lock. Sequential replay keeps the same artifact paths. The empty lock file stays in the directory so contenders lock the same file, and the OS releases the lock when its handle closes. The testing guide now documents separate directories for simultaneous runs. [Independent Radeon 780M verification](https://git.gtahub.st/github/ubiquitarianism--leonida/pulls/1966) reproduced the false PASS with real shaders, checked that two patched runners cannot race, and verified sequential reuse. ### Reviewer check `python -I tests/test_run_gpu_tests_paths.py WorkDirectory.test_simultaneous_cli_runs_cannot_share_an_explicit_work_directory` The regression exercises the CLI with a second process, a separate work directory, and a retry after the owner exits with a failed result. It requires no GPU, Wine, or game files. ### Tested - Linux x86-64, Python 3.11.17. 120 GPU-runner unit tests passed. - Windows x64, Python 3.12.16. 119 passed, with one platform skip. - Two-process baseline and patched comparisons on both systems used synthetic translator/GPU stand-ins. With the fix, the first run reports the intended failure and the second passes on retry. - git diff --check and the source-only policy check passed. GPUs tested: n/a. AI-assisted: yes. ### Checklist - [x] Based on current main. - [x] One topic. - [x] No game data, keys or decryption.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:13:02 +00:00
Author
Owner

@⁠Mby159 on GitHub · 2026-11-25 17:40 UTC · original

Independent verification on a real GPU (AMD Radeon 780M, Windows 11), including a reproduction of the false PASS.

Machine. AMD Radeon 780M Graphics (RDNA3 iGPU, gfx1103), AMD proprietary 26.10.2 (LLPC), Vulkan 1.4.359, Windows 11 10.0.29712. Python 3.13.17, llvm-mc 23.1.6, CMake 4.5.1 + Ninja, llvm-mingw clang++ 23.1.6. Built main at fe1553456 (targets vk_compute_test, vk_store_test, vk_harness).

Your reviewer check passes here.

python -I tests/test_run_gpu_tests_paths.py WorkDirectory.test_simultaneous_cli_runs_cannot_share_an_explicit_work_directory
Ran 1 test in 9.270s
OK

The whole file (tests/test_run_gpu_tests_paths.py) runs 22 tests in 18.637s, all OK.

The false PASS reproduces on main with a real GPU, and your fix stops it (run 4; see the scope note below for the mixed-runner case). I used the repo's own cs_imgatomic_ext case: on this GPU it fails on main and passes with #1518's two changed lines (s12 and s15 in runtime/test/shaders/cs_imgatomic_ext.asm) applied, so two checkouts of the same repository produce two different modules for the same test name.

  1. main alone, --filter cs_imgatomic:
    FAIL cs_imgatomic_ext 6 of 64 sint words differ; first word 32: got 0x0badf00d, expected 0x00000101, 2/3 passed, exit 1.

  2. #1518 alone, same filter: PASS cs_imgatomic_ext, 3/3 passed, exit 0.

  3. Both at once on the same --work, both runs using the unpatched main runner - the first run from the main checkout, the second from the #1518 checkout, started 1.0 s after the first: the first run reported PASS cs_imgatomic_ext and 3/3 passed with exit 0 - the verdict of the module it did not produce. The shared spirv/cs_imgatomic_ext.spv changed content 0.96 s after the first run wrote it (hash 3554efc44f74 -> fd38b80f527e), so it was replaced before it was checked.

  4. The same race with your runner on both sides: the second run exited 2 with

    error: cannot lock GPU test directory <work dir>; use a different --work directory for simultaneous runs (Permission denied)
    

    and printed no shaders: line, so it exited before the translation step. The first run kept the true FAIL (2/3 passed, exit 1) and its module was written only once.

  5. Two sequential runs on one --work with your runner both ran normally (2/3 passed, exit 1), so sequential reuse of a work directory still works.

One scope note. The lock is cooperative. In a race between your runner and a second run of an unpatched CLI on the same --work, the second run was not refused - it printed 3 shaders: 3 translated, 3 pass spirv-val - and the first run again reported the false 3/3 passed, with the shared .spv hash changing twice 0.947 s apart. The race this lock covers is CLI-versus-CLI, and run 4 shows it closes that case; a process that does not take the lock can still replace the module, so the lock is not a sandbox for the directory. Not a blocker for me; it is where the guarantee ends.

Two smaller notes.

  • docs/testing.md describes the flag as "--filter <text> runs only matching tests, and --work <dir> keeps the intermediate files" and does not say that a --work directory serves one run at a time. Your new --help text does ("artifact directory to keep for replay; one run can use it at a time"), but that is only visible to someone who reads the help output. One sentence in docs/testing.md would put the caveat where people read it (that file has no translation copies, so it stays one sentence in one place).
  • .github/workflows/runtime.yml uses four different work directories ($RUNNER_TEMP/gpu-native, gpu-w64, gpu-bary, gpu), so no two CI steps share one and the workflow needs no change. If a future step does share one, the lock will make it exit with the lock error instead of racing silently.

For the record on our own numbers. Every GPU run behind our published 780M record used --build (and sometimes --filter) and never --work, so each of those runs had its own tempfile.mkdtemp(prefix="leonida_gpu_tests_") directory. Those results are not affected by this.

Untested question, in case someone has a --work directory on a network share: if the lock call cannot succeed there, a single run would presumably be refused with the same "cannot lock" message. I did not test a share.

**@⁠Mby159** on GitHub · 2026-11-25 17:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1966#issuecomment-7169847627) Independent verification on a real GPU (AMD Radeon 780M, Windows 11), including a reproduction of the false PASS. **Machine.** AMD Radeon 780M Graphics (RDNA3 iGPU, gfx1103), AMD proprietary 26.10.2 (LLPC), Vulkan 1.4.359, Windows 11 10.0.29712. Python 3.13.17, llvm-mc 23.1.6, CMake 4.5.1 + Ninja, llvm-mingw clang++ 23.1.6. Built `main` at `fe1553456` (targets `vk_compute_test`, `vk_store_test`, `vk_harness`). **Your reviewer check passes here.** ``` python -I tests/test_run_gpu_tests_paths.py WorkDirectory.test_simultaneous_cli_runs_cannot_share_an_explicit_work_directory Ran 1 test in 9.270s OK ``` The whole file (`tests/test_run_gpu_tests_paths.py`) runs 22 tests in 18.637s, all OK. **The false PASS reproduces on `main` with a real GPU, and your fix stops it** (run 4; see the scope note below for the mixed-runner case). I used the repo's own `cs_imgatomic_ext` case: on this GPU it fails on `main` and passes with #1518's two changed lines (`s12` and `s15` in `runtime/test/shaders/cs_imgatomic_ext.asm`) applied, so two checkouts of the same repository produce two different modules for the same test name. 1. `main` alone, `--filter cs_imgatomic`: `FAIL cs_imgatomic_ext 6 of 64 sint words differ; first word 32: got 0x0badf00d, expected 0x00000101`, `2/3 passed`, exit 1. 2. #1518 alone, same filter: `PASS cs_imgatomic_ext`, `3/3 passed`, exit 0. 3. Both at once on the same `--work`, both runs using the unpatched `main` runner - the first run from the `main` checkout, the second from the #1518 checkout, started 1.0 s after the first: **the first run reported `PASS cs_imgatomic_ext` and `3/3 passed` with exit 0** - the verdict of the module it did not produce. The shared `spirv/cs_imgatomic_ext.spv` changed content 0.96 s after the first run wrote it (hash `3554efc44f74` -> `fd38b80f527e`), so it was replaced before it was checked. 4. The same race with your runner on both sides: the second run exited 2 with ``` error: cannot lock GPU test directory <work dir>; use a different --work directory for simultaneous runs (Permission denied) ``` and printed no `shaders:` line, so it exited before the translation step. The first run kept the true `FAIL` (`2/3 passed`, exit 1) and its module was written only once. 5. Two sequential runs on one `--work` with your runner both ran normally (`2/3 passed`, exit 1), so sequential reuse of a work directory still works. **One scope note.** The lock is cooperative. In a race between your runner and a second run of an *unpatched* CLI on the same `--work`, the second run was not refused - it printed `3 shaders: 3 translated, 3 pass spirv-val` - and the first run again reported the false `3/3 passed`, with the shared `.spv` hash changing twice 0.947 s apart. The race this lock covers is CLI-versus-CLI, and run 4 shows it closes that case; a process that does not take the lock can still replace the module, so the lock is not a sandbox for the directory. Not a blocker for me; it is where the guarantee ends. **Two smaller notes.** - `docs/testing.md` describes the flag as "`--filter <text>` runs only matching tests, and `--work <dir>` keeps the intermediate files" and does not say that a `--work` directory serves one run at a time. Your new `--help` text does ("artifact directory to keep for replay; one run can use it at a time"), but that is only visible to someone who reads the help output. One sentence in `docs/testing.md` would put the caveat where people read it (that file has no translation copies, so it stays one sentence in one place). - `.github/workflows/runtime.yml` uses four different work directories (`$RUNNER_TEMP/gpu-native`, `gpu-w64`, `gpu-bary`, `gpu`), so no two CI steps share one and the workflow needs no change. If a future step does share one, the lock will make it exit with the lock error instead of racing silently. **For the record on our own numbers.** Every GPU run behind our published 780M record used `--build` (and sometimes `--filter`) and never `--work`, so each of those runs had its own `tempfile.mkdtemp(prefix="leonida_gpu_tests_")` directory. Those results are not affected by this. Untested question, in case someone has a `--work` directory on a network share: if the lock call cannot succeed there, a single run would presumably be refused with the same "cannot lock" message. I did not test a share.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1966/head:github-bot/gh-1966'
git switch 'github-bot/gh-1966'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1966'
git switch 'github-bot/gh-1966'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1966'
git switch 'github-bot/gh-1966'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1966'
git switch 'main'
git merge --squash 'github-bot/gh-1966'
git switch 'main'
git merge --ff-only 'github-bot/gh-1966'
git switch 'main'
git merge 'github-bot/gh-1966'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.