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

Merged
narekshaghoyandev merged 1 commit from upstream-pr/2336 into main 2026-11-29 14:25:57 +00:00
narekshaghoyandev commented 2026-11-26 14:01:57 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by narekshaghoyandev on 2026-11-26T14:01:57Z.


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)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5511416421 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2336). Originally posted by [narekshaghoyandev](https://github.com/narekshaghoyandev) on 2026-11-26T14:01:57Z. --- 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 commented 2026-11-26 15:37:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T15:37:28Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6076880367 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2336#pullrequestreview-6076880367). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T15:37:28Z. **Review:** COMMENTED --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-28T12:41:35Z.


#2336 | head 1be69fd56c (merged cleanly with main d48a957bb9) | 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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7239401891 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2336#issuecomment-7239401891). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-28T12:41:35Z. --- #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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-28T22:02:15Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246450979 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2336#issuecomment-7246450979). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-28T22:02:15Z. --- **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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-28T22:49:50Z.


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).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7247012437 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2336#issuecomment-7247012437). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-28T22:49:50Z. --- 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 commented 2026-11-29 04:28:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by timbot103 on 2026-11-29T04:28:06Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6101398632 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2336#pullrequestreview-6101398632). Originally posted by [timbot103](https://github.com/timbot103) on 2026-11-29T04:28:06Z. **Review:** COMMENTED --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-29T14:26:00Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7257298986 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2336#issuecomment-7257298986). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-29T14:26:00Z. --- 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 reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!2336
No description provided.