pipeline_wait: guard non-positive window and signed subtraction overflow in title_submitting #2336

Merged
leonida/mandy
narekshaghoyandev merged 1 commit from ubiq-pipeline-wait-window into main 2026-11-29 14:25:57 +00:00

Pull request successfully merged and closed

narekshaghoyandev commented 2026-11-26 14:01:57 +00:00

Fixes window and signed-integer subtraction bugs in leonida::pipeline_wait::title_submitting() (runtime/src/pipeline_wait.h):

  • Return false immediately when within_ns <= 0 (previously, if another thread stored a timestamp slightly ahead of now_ns(), now_ns() - last was negative and < 0, returning true even for a zero/negative window).
  • Return false when last <= 0, avoiding signed 64-bit subtraction overflow UB (now_ns() - INT64_MIN).
  • Check now < last || now - last < within_ns so the subtraction only runs when now >= last > 0.
  • Added standalone unit test runtime/test/pipeline_wait_test.cpp.

Verification

  • g++ -std=c++20 -D_GLIBCXX_DEBUG -Wall -Wextra -Werror -pedantic -Iruntime/src runtime/test/pipeline_wait_test.cpp passed
  • g++ -std=c++20 -fsanitize=address,undefined -Wall -Wextra -Werror -pedantic -Iruntime/src runtime/test/pipeline_wait_test.cpp passed
  • Negative control: new test failed on line 24 (!title_submitting(0), exit 1) against unmodified ubiq/main
  • python3 -I scripts/check_no_game_data.py runtime/src/pipeline_wait.h runtime/test/pipeline_wait_test.cpp clean

Claimed in the coordination issue as: RT-PIPELINE-WAIT-SIGNED-SUB-AND-WINDOW (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7194149264)
AI-assisted: yes (Gemini)

Fixes window and signed-integer subtraction bugs in `leonida::pipeline_wait::title_submitting()` (`runtime/src/pipeline_wait.h`): - Return `false` immediately when `within_ns <= 0` (previously, if another thread stored a timestamp slightly ahead of `now_ns()`, `now_ns() - last` was negative and `< 0`, returning `true` even for a zero/negative window). - Return `false` when `last <= 0`, avoiding signed 64-bit subtraction overflow UB (`now_ns() - INT64_MIN`). - Check `now < last || now - last < within_ns` so the subtraction only runs when `now >= last > 0`. - Added standalone unit test `runtime/test/pipeline_wait_test.cpp`. ### Verification - `g++ -std=c++20 -D_GLIBCXX_DEBUG -Wall -Wextra -Werror -pedantic -Iruntime/src runtime/test/pipeline_wait_test.cpp` passed - `g++ -std=c++20 -fsanitize=address,undefined -Wall -Wextra -Werror -pedantic -Iruntime/src runtime/test/pipeline_wait_test.cpp` passed - Negative control: new test failed on line 24 (`!title_submitting(0)`, exit 1) against unmodified `ubiq/main` - `python3 -I scripts/check_no_game_data.py runtime/src/pipeline_wait.h runtime/test/pipeline_wait_test.cpp` clean Claimed in the coordination issue as: RT-PIPELINE-WAIT-SIGNED-SUB-AND-WINDOW (https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7194149264) AI-assisted: yes (Gemini)
lixonik reviewed 2026-11-26 15:37:28 +00:00
lixonik left a comment
No description provided.
Compiled and ran `pipeline_wait_test.cpp` directly with GCC 11 and UBSan on Ubuntu/WSL. The boundary cases passed with no sanitizer report. Could you also register `pipeline_wait_test` with CTest? I found no build or test entry for the new file, so the normal suite currently skips it. AI-assisted.
zmasi commented 2026-11-28 12:41:35 +00:00

#2336 | head 1be69fd56c1dbe4e6816f8c373417e5e5e30a621 (merged cleanly with main d48a957bb9988afce424552a3c0c8d01ef12320f) | ctest --test-dir runtime/build -C RelWithDebInfo -R "^(pipeline_wait|d3d12_mesh)$" --output-on-failure (LEONIDA_VK_VALIDATION=1, /W4 /WX /permissive- /EHsc /utf-8 on pipeline_wait_test) | red on main: pipeline_wait fails at line 24: !title_submitting(0) (rc=8) | green on PR+main: 2/2 CTests pass (pipeline_wait pipeline_wait_test: ok under /W4 /WX + d3d12_mesh 4096/4096 pixels matched) on RTX 3090 with 0 Khronos validation errors; check_no_game_data.py 0 violations. Non-blocking note: runtime/test/pipeline_wait_test.cpp is not yet registered via add_executable / add_test in runtime/CMakeLists.txt, so CTest will not build or run it automatically until wired up | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes

#2336 | head 1be69fd56c1dbe4e6816f8c373417e5e5e30a621 (merged cleanly with main d48a957bb9988afce424552a3c0c8d01ef12320f) | `ctest --test-dir runtime/build -C RelWithDebInfo -R "^(pipeline_wait|d3d12_mesh)$" --output-on-failure` (`LEONIDA_VK_VALIDATION=1`, `/W4 /WX /permissive- /EHsc /utf-8` on `pipeline_wait_test`) | red on main: `pipeline_wait` fails at `line 24: !title_submitting(0)` (`rc=8`) | green on PR+main: 2/2 CTests pass (`pipeline_wait` `pipeline_wait_test: ok` under `/W4 /WX` + `d3d12_mesh` `4096/4096` pixels matched) on RTX 3090 with `0` Khronos validation errors; `check_no_game_data.py` `0` violations. Non-blocking note: `runtime/test/pipeline_wait_test.cpp` is not yet registered via `add_executable` / `add_test` in `runtime/CMakeLists.txt`, so CTest will not build or run it automatically until wired up | Windows 11, MSVC 19.44, RTX 3090, Vulkan SDK 1.4.363.1 | AI-assisted: yes
OreoFR commented 2026-11-28 22:02:15 +00:00

Verified by OreoFR

  • Base: main c1ecf04ed + PR head 1be69fd56; green run in a merge package of 16 PRs, no new ctest failure vs main
  • Test: standalone build of pipeline_wait_test.exe (the test is not registered in CMake)
  • Red on main: exit code 1, line 24 !title_submitting(0)
  • Green with the PR: OK
  • Verdict: READY (the test is not in CMake: ctest will never run it)
  • Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11

AI-assisted (Claude Code, Claude Opus 5.5).

**Verified by OreoFR** - Base: main `c1ecf04ed` + PR head `1be69fd56`; green run in a merge package of 16 PRs, no new ctest failure vs main - Test: `standalone build of pipeline_wait_test.exe (the test is not registered in CMake)` - Red on main: exit code 1, line 24 `!title_submitting(0)` - Green with the PR: OK - Verdict: READY (the test is not in CMake: ctest will never run it) - Machine: RTX 4070 Laptop 8 GB, NVIDIA 621.40, Intel Core Ultra 7 155H, Windows 11 AI-assisted (Claude Code, Claude Opus 5.5).
TheGeogeo commented 2026-11-28 22:49:50 +00:00

Tested 1be69fd56 merged (no commit) with main aa918e5d9, MSVC 19.52 (Visual Studio 18), Windows 11 10.0.26300.

Blocker: runtime/test/pipeline_wait_test.cpp is new but is not registered in runtime/CMakeLists.txt, so neither CI nor ctest ever builds or runs it. ctest -N on the merge lists no such test, and tests/test_ctest_registration.py still passes, so nothing catches this. Registering it the way the other header-only tests are would fix that:

add_executable(pipeline_wait_test test/pipeline_wait_test.cpp)
add_test(NAME pipeline_wait COMMAND pipeline_wait_test)

Hand-compiled (cl /std:c++20 /EHsc /O2):

  • Green: pipeline_wait_test: ok, exit 0.
  • Red, with runtime/src/pipeline_wait.h back to main: line 24: !title_submitting(0), exit 1.

I did not run the ctest tests relinked by the header change: test runs on this machine are paused for memory.

AI-assisted (Claude Code).

Tested `1be69fd56` merged (no commit) with `main` `aa918e5d9`, MSVC 19.52 (Visual Studio 18), Windows 11 10.0.26300. **Blocker:** `runtime/test/pipeline_wait_test.cpp` is new but is not registered in `runtime/CMakeLists.txt`, so neither CI nor `ctest` ever builds or runs it. `ctest -N` on the merge lists no such test, and `tests/test_ctest_registration.py` still passes, so nothing catches this. Registering it the way the other header-only tests are would fix that: ```cmake add_executable(pipeline_wait_test test/pipeline_wait_test.cpp) add_test(NAME pipeline_wait COMMAND pipeline_wait_test) ``` Hand-compiled (`cl /std:c++20 /EHsc /O2`): - Green: `pipeline_wait_test: ok`, exit 0. - Red, with `runtime/src/pipeline_wait.h` back to `main`: `line 24: !title_submitting(0)`, exit 1. I did not run the ctest tests relinked by the header change: test runs on this machine are paused for memory. AI-assisted (Claude Code).
timbot103 reviewed 2026-11-29 04:28:06 +00:00
timbot103 left a comment
No description provided.
Static audit of head `1be69fd56` only. I ran no builds, tests, or GPU workloads. The subtraction in `runtime/src/pipeline_wait.h:28` is safe. A nonpositive window or stored timestamp returns false before the subtraction, covering a zero sentinel and a stored `INT64_MIN`. A positive stored timestamp ahead of the sampled time returns true by short-circuit, including when the sampled time is `INT64_MIN`. Otherwise, `now >= last > 0` bounds the difference to `[0, INT64_MAX - 1]`. The warm-up caller in `runtime/shims/d3d12_vulkan_device.cpp` still uses the default one-second window. The changed code and standalone test use standard C++ facilities shared by MSVC and Linux compilers. - Please register `runtime/test/pipeline_wait_test.cpp:11` in the portable `BUILD_TESTING` block of `runtime/CMakeLists.txt` with `add_executable` and `add_test`. The normal Windows and Linux CTest jobs currently skip the regression. - Please use explicit timestamps for the boundary cases in `runtime/test/pipeline_wait_test.cpp:23`. The live clock lets the future assertion pass after the timestamp becomes recent, and the old-submission case can skip. A predicate with explicit inputs can pin `now < last` at the signed limits and verify both sides of the strict cutoff with elapsed times of `window - 1` and `window`. AI-assisted.
MoonEyes commented 2026-11-29 14:26:00 +00:00

Merged. Tested by OreoFR (RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11) on this head: pipeline_wait_test red on main (line 24), green with the PR. Note: the test is not registered in CMake. AI-assisted: yes.

Merged. Tested by OreoFR (RTX 4070 Laptop 8 GB, NVIDIA 621.40, Windows 11) on this head: pipeline_wait_test red on main (line 24), green with the PR. Note: the test is not registered in CMake. AI-assisted: yes.
Sign in to join this conversation.
No description provided.