RT-ACTIVE-INPUT-DEBOUNCE-NAN: active_input: guard timestamp underflow in debounce and ignore non-finite axes #902

Merged
narekshaghoyandev merged 1 commit from upstream-pr/902 into main 2026-11-24 21:26:33 +00:00
narekshaghoyandev commented 2026-11-24 15:06:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by narekshaghoyandev on 2026-11-24T15:06:29Z.


Hardens runtime/src/active_input.h against unsigned timestamp underflow and non-finite analog samples:

  1. Guard unsigned timestamp underflow in debounce (ActiveInputTracker::observe): Previously time_us - changed_at_ < thresholds_.min_switch_us wrapped around to ~UINT64_MAX whenever an out-of-order/earlier timestamp (time_us < changed_at_) arrived, bypassing min_switch_us and switching active input families immediately. Now guards time_us < changed_at_ || time_us - changed_at_ < thresholds_.min_switch_us.
  2. Ignore non-finite stick/trigger samples (ActiveInputTracker::edge_between): Checks std::isfinite on previous and current stick/trigger floats so a NaN baseline or Inf spike cannot trigger a bogus family switch.

Verification

  • Linux (CPU-only, GCC C++20 -Wall -Wextra -Werror -pedantic -fsanitize=address,undefined): runtime/test/active_input_test.cpp passes 8/8 cases cleanly.
  • Negative control against main: out-of-order timestamp and non-finite axes fails as expected.
  • python3 -I scripts/check_no_game_data.py runtime/src/active_input.h runtime/test/active_input_test.cpp: clean.

Claimed in the coordination issue as: RT-ACTIVE-INPUT-DEBOUNCE-NAN (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135437104)
AI-assisted: yes (Gemini)

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5474764013 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/902). Originally posted by [narekshaghoyandev](https://github.com/narekshaghoyandev) on 2026-11-24T15:06:29Z. --- Hardens `runtime/src/active_input.h` against unsigned timestamp underflow and non-finite analog samples: 1. **Guard unsigned timestamp underflow in debounce (`ActiveInputTracker::observe`)**: Previously `time_us - changed_at_ < thresholds_.min_switch_us` wrapped around to `~UINT64_MAX` whenever an out-of-order/earlier timestamp (`time_us < changed_at_`) arrived, bypassing `min_switch_us` and switching active input families immediately. Now guards `time_us < changed_at_ || time_us - changed_at_ < thresholds_.min_switch_us`. 2. **Ignore non-finite stick/trigger samples (`ActiveInputTracker::edge_between`)**: Checks `std::isfinite` on previous and current stick/trigger floats so a `NaN` baseline or `Inf` spike cannot trigger a bogus family switch. ### Verification - Linux (CPU-only, GCC C++20 `-Wall -Wextra -Werror -pedantic -fsanitize=address,undefined`): `runtime/test/active_input_test.cpp` passes 8/8 cases cleanly. - Negative control against `main`: `out-of-order timestamp and non-finite axes` fails as expected. - `python3 -I scripts/check_no_game_data.py runtime/src/active_input.h runtime/test/active_input_test.cpp`: clean. Claimed in the coordination issue as: RT-ACTIVE-INPUT-DEBOUNCE-NAN (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7135437104) AI-assisted: yes (Gemini)
KernelSmoker commented 2026-11-24 15:08:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KernelSmoker on 2026-11-24T15:08:34Z.

Review: COMMENTED


I checked exact head 27c930020f7539abf6e9e721a72599ce0c4b4953. One test-report discrepancy: the PR description says active_input_test.cpp passes 8/8, but compiling and running it on Linux with g++ -std=c++20 -Wall -Wextra -Werror -pedantic prints active input: 7 of 7 cases pass. The new test_out_of_order_timestamp_and_non_finite_axes is defined but absent from the Case cases[] array in main(), so it never runs. Please add it to the case table and rerun the claimed 8-case command. The normal build passes 7/7 existing registered cases. I also attempted the stated ASan/UBSan build, but this environment cannot link because /usr/lib64/libasan.so.8.0.0 is missing; that is an environment limitation, not a source failure. check_no_game_data.py and git diff --check passed.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6041832543 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/902#pullrequestreview-6041832543). Originally posted by [KernelSmoker](https://github.com/KernelSmoker) on 2026-11-24T15:08:34Z. **Review:** COMMENTED --- I checked exact head `27c930020f7539abf6e9e721a72599ce0c4b4953`. One test-report discrepancy: the PR description says `active_input_test.cpp` passes 8/8, but compiling and running it on Linux with `g++ -std=c++20 -Wall -Wextra -Werror -pedantic` prints `active input: 7 of 7 cases pass`. The new `test_out_of_order_timestamp_and_non_finite_axes` is defined but absent from the `Case cases[]` array in `main()`, so it never runs. Please add it to the case table and rerun the claimed 8-case command. The normal build passes 7/7 existing registered cases. I also attempted the stated ASan/UBSan build, but this environment cannot link because `/usr/lib64/libasan.so.8.0.0` is missing; that is an environment limitation, not a source failure. `check_no_game_data.py` and `git diff --check` passed.
narekshaghoyandev commented 2026-11-24 15:20:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by narekshaghoyandev on 2026-11-24T15:20:03Z.


@KernelSmoker Thanks for checking! I just double-checked exact head 27c930020f7539abf6e9e721a72599ce0c4b4953 — test_out_of_order_timestamp_and_non_finite_axes is already registered in cases[] in runtime/test/active_input_test.cpp (right after test_forced), and compiling + running runtime/test/active_input_test.cpp prints:

out-of-order timestamp and non-finite axes: ok
names: ok
active input: 8 of 8 cases pass

Could you double-check whether an older build artifact or base checkout was executed? AI-assisted (Gemini).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7135848362 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/902#issuecomment-7135848362). Originally posted by [narekshaghoyandev](https://github.com/narekshaghoyandev) on 2026-11-24T15:20:03Z. --- @KernelSmoker Thanks for checking! I just double-checked exact head `27c930020f7539abf6e9e721a72599ce0c4b4953` — `test_out_of_order_timestamp_and_non_finite_axes` is already registered in `cases[]` in `runtime/test/active_input_test.cpp` (right after `test_forced`), and compiling + running `runtime/test/active_input_test.cpp` prints: ``` out-of-order timestamp and non-finite axes: ok names: ok active input: 8 of 8 cases pass ``` Could you double-check whether an older build artifact or base checkout was executed? AI-assisted (Gemini).
QemmHD commented 2026-11-24 21:26:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-24T21:26:31Z.


Merging.

Why merged: RT-ACTIVE-INPUT-DEBOUNCE-NAN: active_input ignores an out-of-order timestamp in the debounce and ignores NaN/Inf stick and trigger samples. KernelSmoker's note that the new case wasn't registered doesn't apply at this head: it's in cases[] and runs ("8 of 8 cases pass"), as the author replied.

Why it's good: Header-only logic. active_input passes both plain and under validation.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 66d4f5aa3, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative of this batch (13 PRs) on main 0b45fdc21: the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 314/316 with the same 11 skips. The only failures are main's: d3d12_depth_resolve (pre-existing) and d3d12_close_parity (the #510 regression, fixed by #1286). All d3d12_* tests under validation show 0 VUIDs. git merge-tree against current main 6261ca916: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7144934089 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/902#issuecomment-7144934089). Originally posted by [QemmHD](https://github.com/QemmHD) on 2026-11-24T21:26:31Z. --- Merging. **Why merged:** RT-ACTIVE-INPUT-DEBOUNCE-NAN: active_input ignores an out-of-order timestamp in the debounce and ignores NaN/Inf stick and trigger samples. KernelSmoker's note that the new case wasn't registered doesn't apply at this head: it's in cases[] and runs ("8 of 8 cases pass"), as the author replied. **Why it's good:** Header-only logic. active_input passes both plain and under validation. Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 66d4f5aa3, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative of this batch (13 PRs) on main 0b45fdc21: the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 314/316 with the same 11 skips. The only failures are main's: d3d12_depth_resolve (pre-existing) and d3d12_close_parity (the #510 regression, fixed by #1286). All d3d12_* tests under validation show 0 VUIDs. git merge-tree against current main 6261ca916: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes. AI-assisted (Claude Code, Claude Opus 5.5).
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!902
No description provided.