D3D12-GPU-AB-PARSE-FINITE-SECONDS: reject non-finite LEONIDA_AB phase duration #2997

Merged
bobcatchris merged 1 commit from upstream-pr/2997 into main 2026-12-02 13:36:25 +00:00
bobcatchris commented 2026-12-01 22:53:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-12-01T22:53:50Z.


Addresses claim in https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7328405572.

Cause

ab::parse (d3d12/crates/leonida-gpu/src/ab.rs:19) checked *s > 1.0 without s.is_finite(), so LEONIDA_AB=inf,<switch> passed parsing (f64::INFINITY > 1.0). In ab::presented (((now - p.started).as_secs_f64() / asked.seconds) as u64), dividing by +inf yields 0.0, pinning LEONIDA_AB at phase 0 forever.

Fix

  • Require s.is_finite() && *s > 1.0 in ab::parse.
  • Add inf, -inf, and nan test cases to ab::tests::switches_and_seconds_are_read_and_frames_summed_up.

Verification

  • Red -> Green: With .is_finite() omitted, ab::tests::switches_and_seconds_are_read_and_frames_summed_up fails (RED_AB_EXIT=101); with the guard, ab::tests passes (4 passed, 0 failed).
  • Default feature build (cargo test --locked -p leonida-gpu --lib -- ab::tests) compiles cleanly.
  • python -I tools/d3d12_switches.py --check d3d12/docs/switches.md: exit 0.
  • python -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/ab.rs: exit 0.
  • Independent read-only code review: approved.

AI-assisted

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5596111904 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2997). Originally posted by [bobcatchris](https://github.com/bobcatchris) on 2026-12-01T22:53:50Z. --- Addresses claim in https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7328405572. ### Cause `ab::parse` (`d3d12/crates/leonida-gpu/src/ab.rs:19`) checked `*s > 1.0` without `s.is_finite()`, so `LEONIDA_AB=inf,<switch>` passed parsing (`f64::INFINITY > 1.0`). In `ab::presented` (`((now - p.started).as_secs_f64() / asked.seconds) as u64`), dividing by `+inf` yields `0.0`, pinning `LEONIDA_AB` at phase `0` forever. ### Fix - Require `s.is_finite() && *s > 1.0` in `ab::parse`. - Add `inf`, `-inf`, and `nan` test cases to `ab::tests::switches_and_seconds_are_read_and_frames_summed_up`. ### Verification - **Red -> Green**: With `.is_finite()` omitted, `ab::tests::switches_and_seconds_are_read_and_frames_summed_up` fails (`RED_AB_EXIT=101`); with the guard, `ab::tests` passes (`4 passed, 0 failed`). - Default feature build (`cargo test --locked -p leonida-gpu --lib -- ab::tests`) compiles cleanly. - `python -I tools/d3d12_switches.py --check d3d12/docs/switches.md`: exit 0. - `python -I scripts/check_no_game_data.py d3d12/crates/leonida-gpu/src/ab.rs`: exit 0. - Independent read-only code review: approved. AI-assisted
andrew-ai commented 2026-12-01 22:58:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by andrew-ai on 2026-12-01T22:58:29Z.


Verified ef429f923 through presented() and pick() in the diagnostics build on Windows. I used a temporary crate test and launched a fresh process per LEONIDA_AB value so the cached environment configuration was independent each time.

For inf, -inf, NaN, and 1e309 (decimal overflow), presenting created no phase, emitted no change callback, and left pick(switch) at None. With 2.5 seconds the override started off. Advancing the stored phase start to simulate 3 and 6 seconds elapsed produced exactly two callbacks for the named switch, off to on and back to off. All five runs passed. This checks the timer and override behavior without a game or GPU workload. Codex-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7328575741 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2997#issuecomment-7328575741). Originally posted by [andrew-ai](https://github.com/andrew-ai) on 2026-12-01T22:58:29Z. --- Verified ef429f923 through presented() and pick() in the diagnostics build on Windows. I used a temporary crate test and launched a fresh process per LEONIDA_AB value so the cached environment configuration was independent each time. For inf, -inf, NaN, and 1e309 (decimal overflow), presenting created no phase, emitted no change callback, and left pick(switch) at None. With 2.5 seconds the override started off. Advancing the stored phase start to simulate 3 and 6 seconds elapsed produced exactly two callbacks for the named switch, off to on and back to off. All five runs passed. This checks the timer and override behavior without a game or GPU workload. Codex-assisted.
imShangLi commented 2026-12-02 07:09:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by imShangLi on 2026-12-02T07:09:28Z.


VERIFY-2997 — Linux, Fedora 45, Rust 1.98.1, cross-compiled for x86_64-pc-windows-gnu, Wine 11.21, no GPU device, no game files

Verdict: PASS. The red side fails on exactly the line the pull request adds — parse("inf,LEONIDA_A") returns Some on the base, because inf > 1.0 — and the green side passes it. That is a genuine red-then-green, and it fails for the reason the title says. One thing to flag: two of the three new assertions would pass on the base too, so the whole case rests on the inf one.

Head ef429f92, base the current main (0ae5a266), merge base 1abef08d, 1 file, +4/−1: d3d12/crates/leonida-gpu/src/ab.rs.

1. What it changes

LEONIDA_AB=<seconds>,<switch>[,<switch>..] makes the diagnostics build measure switch combinations in turns: every so many seconds the next phase begins and switch n is on in the phases whose number has bit n. The pull request hardens the one thing that parses the interval a human types:

-    let seconds = parts.next()?.parse::<f64>().ok().filter(|s| *s > 1.0)?;
+    let seconds = parts.next()?.parse::<f64>().ok().filter(|s| s.is_finite() && *s > 1.0)?;

and adds three assertions to the existing test ab::tests::switches_and_seconds_are_read_and_frames_summed_up:

         assert!(parse("0,LEONIDA_A").is_none());
+        assert!(parse("inf,LEONIDA_A").is_none());
+        assert!(parse("-inf,LEONIDA_A").is_none());
+        assert!(parse("nan,LEONIDA_A").is_none());

parse is read from the environment once, through asked(), so a non-finite value can only come from whoever sets LEONIDA_AB, never from the title.

2. The new test checks the property that matters

Two things worth saying before the numbers.

The module is feature-gated. lib.rs:124 declares it #[cfg(all(windows, feature = "diagnostics"))] mod ab;, so a plain cargo test -p leonida-gpu never compiles it. My first harness run without the feature reported 703 tests, red_to_green: [], and — the giveaway — zero ab:: names on either side: the test could not fail because it did not exist. Re-running the same tool with --features diagnostics gives 786 tests, and now the discrimination shows. Anyone reviewing this should treat the plain run as having verified nothing about this pull request.

Only one of the three new lines discriminates.

input base's parse why
inf,LEONIDA_A Some(inf) — the bug inf > 1.0 is true, so it clears the filter
-inf,LEONIDA_A None -inf > 1.0 is false; rejected by the base already
nan,LEONIDA_A None nan > 1.0 is false in IEEE; rejected by the base already

So the pull request's fix is entirely carried by the inf case, and the other two assertions are regression guards documenting intent rather than discriminators. Worth knowing, not a defect.

The base failure, captured on the red side (merge base plus only this pull request's test hunks, with diagnostics on):

PR 2997: base 1abef08d09f6 red_commit a771b1bae70a files ['d3d12/crates/leonida-gpu/src/ab.rs']

running 4 tests
test ab::tests::switches_and_seconds_are_read_and_frames_summed_up ... FAILED

---- ab::tests::switches_and_seconds_are_read_and_frames_summed_up stdout ----

thread 'ab::tests::switches_and_seconds_are_read_and_frames_summed_up' (296) panicked at crates/leonida-gpu/src/ab.rs:253:9:
assertion failed: parse("inf,LEONIDA_A").is_none()

Line 253 is the inf assertion, as the table predicts. On the head the same four ab::tests pass, three runs in a row.

The bug is not cosmetic. asked.seconds is a divisor, ab.rs:193:

    let number = ((now - p.started).as_secs_f64() / asked.seconds) as u64;
    if number == p.number {
        return;
    }

x / inf is 0.0 for every x, so the phase number is 0 forever, the guard returns at once, and the A/B never advances once — a run that looks like "the switches never changed" rather than a rejected setting. nan casts to 0 the same way. The fix returns None, asked() is None, and the switch takes its own variable as the docs say. That is fixing the cause at the parse, not papering over the symptom.

3. What the tests do here

red (merge base + test hunks) green (head)
tests 786 786
pass 722 726
fail 5 4
ignored 59 59
  • red → green: 1 — ab::tests::switches_and_seconds_are_read_and_frames_summed_up. This is the pull request.
  • regressions (pass on red, fail on green): 0.
  • fail on both: 4 — watch::many_askers_tests::holes_are_known_until_the_runtime_tells, watch::many_askers_tests::no_mapping_is_lost_between_askers, watch::tests::what_is_left_alone_is_no_known_hole, timeline::report::tests::real_waits_are_recorded_with_who_ended_them.
  • pass on both: 721. only on red / only on green: 0 / 0.

The same tool without --features diagnostics reports 703 on each side, 641 passing on both, and none of this pull request: the ab module is not in the build.

4. Any failure I saw, and why it is not this pull request

Four tests fail on both sides, so they predate this change.

Three of them are watch tests, and they fail identically on the merge base — I ran the base through the same tool and got the same three. They are the address-space bookkeeping module, and they exercise mapping and decommit behaviour that Wine's VirtualAlloc emulation does not reproduce. The pull request touches none of it.

The fourth, timeline::report::tests::real_waits_are_recorded_with_who_ended_them, is timing-dependent by construction: it spawns a worker that sleeps 5 ms and then spins for 30 ms, then asserts ms(work) >= 20.0 on the recorded span. It relies on the wall clock behaving under Wine while 785 other tests run beside it. It is not in this pull request's file.

None of them is ab::. The one ab test that changed is the one that went from failing to passing, and it is deterministic (a pure string parse, no device, no clock), so I did not need to repeat it many times — I did anyway, three times, and it was stable.

5. What I did not check

  • A GPU, a D3D12 adapter, or the running title. ab is diagnostics; its tests here are pure functions, so nothing GPU-shaped is exercised. That is also why this one is cheap to verify.
  • A real LEONIDA_AB run. I checked the arithmetic by reading the divisor, not by timing a run. I have not confirmed on hardware that a phase really does advance at the interval a human types, nor that the rejection is surfaced somewhere the operator can see (the change makes asked() None silently; whether a warning should be logged is a design call, not a defect I can settle here).
  • LEONIDA_AB acceptance of 1e400. f64::from_str("1e400") is Ok(inf), which is now rejected as !is_finite() — I reasoned that through rather than running it, and it is the same overflow path as inf. Cheap, but unverified by execution.
  • The four failures on a native Windows box. They look like Wine and wall-clock effects here, but I have not run this suite outside Wine, so I cannot say they are clean upstream.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7337844223 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2997#issuecomment-7337844223). Originally posted by [imShangLi](https://github.com/imShangLi) on 2026-12-02T07:09:28Z. --- ## VERIFY-2997 — Linux, Fedora 45, Rust 1.98.1, cross-compiled for x86_64-pc-windows-gnu, Wine 11.21, no GPU device, no game files **Verdict: PASS.** The red side fails on exactly the line the pull request adds — `parse("inf,LEONIDA_A")` returns `Some` on the base, because `inf > 1.0` — and the green side passes it. That is a genuine red-then-green, and it fails for the reason the title says. One thing to flag: two of the three new assertions would pass on the base too, so the whole case rests on the `inf` one. Head `ef429f92`, base the current `main` (`0ae5a266`), merge base `1abef08d`, 1 file, +4/−1: `d3d12/crates/leonida-gpu/src/ab.rs`. ### 1. What it changes `LEONIDA_AB=<seconds>,<switch>[,<switch>..]` makes the diagnostics build measure switch combinations in turns: every so many seconds the next phase begins and switch *n* is on in the phases whose number has bit *n*. The pull request hardens the one thing that parses the interval a human types: ```rust - let seconds = parts.next()?.parse::<f64>().ok().filter(|s| *s > 1.0)?; + let seconds = parts.next()?.parse::<f64>().ok().filter(|s| s.is_finite() && *s > 1.0)?; ``` and adds three assertions to the existing test `ab::tests::switches_and_seconds_are_read_and_frames_summed_up`: ```rust assert!(parse("0,LEONIDA_A").is_none()); + assert!(parse("inf,LEONIDA_A").is_none()); + assert!(parse("-inf,LEONIDA_A").is_none()); + assert!(parse("nan,LEONIDA_A").is_none()); ``` `parse` is read from the environment once, through `asked()`, so a non-finite value can only come from whoever sets `LEONIDA_AB`, never from the title. ### 2. The new test checks the property that matters Two things worth saying before the numbers. **The module is feature-gated.** `lib.rs:124` declares it `#[cfg(all(windows, feature = "diagnostics"))] mod ab;`, so a plain `cargo test -p leonida-gpu` never compiles it. My first harness run without the feature reported 703 tests, `red_to_green: []`, and — the giveaway — **zero** `ab::` names on either side: the test could not fail because it did not exist. Re-running the same tool with `--features diagnostics` gives 786 tests, and now the discrimination shows. Anyone reviewing this should treat the plain run as having verified nothing about this pull request. **Only one of the three new lines discriminates.** | input | base's `parse` | why | |---|---|---| | `inf,LEONIDA_A` | `Some(inf)` — **the bug** | `inf > 1.0` is true, so it clears the filter | | `-inf,LEONIDA_A` | `None` | `-inf > 1.0` is false; rejected by the base already | | `nan,LEONIDA_A` | `None` | `nan > 1.0` is false in IEEE; rejected by the base already | So the pull request's fix is entirely carried by the `inf` case, and the other two assertions are regression guards documenting intent rather than discriminators. Worth knowing, not a defect. The base failure, captured on the red side (merge base plus only this pull request's test hunks, with `diagnostics` on): ``` PR 2997: base 1abef08d09f6 red_commit a771b1bae70a files ['d3d12/crates/leonida-gpu/src/ab.rs'] running 4 tests test ab::tests::switches_and_seconds_are_read_and_frames_summed_up ... FAILED ---- ab::tests::switches_and_seconds_are_read_and_frames_summed_up stdout ---- thread 'ab::tests::switches_and_seconds_are_read_and_frames_summed_up' (296) panicked at crates/leonida-gpu/src/ab.rs:253:9: assertion failed: parse("inf,LEONIDA_A").is_none() ``` Line 253 is the `inf` assertion, as the table predicts. On the head the same four `ab::tests` pass, three runs in a row. **The bug is not cosmetic.** `asked.seconds` is a divisor, `ab.rs:193`: ```rust let number = ((now - p.started).as_secs_f64() / asked.seconds) as u64; if number == p.number { return; } ``` `x / inf` is `0.0` for every `x`, so the phase number is 0 forever, the guard returns at once, and the A/B never advances once — a run that looks like "the switches never changed" rather than a rejected setting. `nan` casts to `0` the same way. The fix returns `None`, `asked()` is `None`, and the switch takes its own variable as the docs say. That is fixing the cause at the parse, not papering over the symptom. ### 3. What the tests do here | | red (merge base + test hunks) | green (head) | |---|---|---| | tests | 786 | 786 | | pass | 722 | 726 | | fail | 5 | 4 | | ignored | 59 | 59 | - **red → green: 1** — `ab::tests::switches_and_seconds_are_read_and_frames_summed_up`. This is the pull request. - **regressions (pass on red, fail on green): 0.** - **fail on both: 4** — `watch::many_askers_tests::holes_are_known_until_the_runtime_tells`, `watch::many_askers_tests::no_mapping_is_lost_between_askers`, `watch::tests::what_is_left_alone_is_no_known_hole`, `timeline::report::tests::real_waits_are_recorded_with_who_ended_them`. - **pass on both: 721.** **only on red / only on green: 0 / 0.** The same tool without `--features diagnostics` reports 703 on each side, 641 passing on both, and **none** of this pull request: the `ab` module is not in the build. ### 4. Any failure I saw, and why it is not this pull request Four tests fail on both sides, so they predate this change. Three of them are `watch` tests, and they fail identically on the merge base — I ran the base through the same tool and got the same three. They are the address-space bookkeeping module, and they exercise mapping and decommit behaviour that Wine's `VirtualAlloc` emulation does not reproduce. The pull request touches none of it. The fourth, `timeline::report::tests::real_waits_are_recorded_with_who_ended_them`, is timing-dependent by construction: it spawns a worker that sleeps 5 ms and then spins for 30 ms, then asserts `ms(work) >= 20.0` on the recorded span. It relies on the wall clock behaving under Wine while 785 other tests run beside it. It is not in this pull request's file. None of them is `ab::`. The one `ab` test that changed is the one that went from failing to passing, and it is deterministic (a pure string parse, no device, no clock), so I did not need to repeat it many times — I did anyway, three times, and it was stable. ### 5. What I did not check - **A GPU, a D3D12 adapter, or the running title.** `ab` is diagnostics; its tests here are pure functions, so nothing GPU-shaped is exercised. That is also why this one is cheap to verify. - **A real `LEONIDA_AB` run.** I checked the arithmetic by reading the divisor, not by timing a run. I have not confirmed on hardware that a phase really does advance at the interval a human types, nor that the rejection is surfaced somewhere the operator can see (the change makes `asked()` `None` silently; whether a warning should be logged is a design call, not a defect I can settle here). - **`LEONIDA_AB` acceptance of `1e400`.** `f64::from_str("1e400")` is `Ok(inf)`, which is now rejected as `!is_finite()` — I reasoned that through rather than running it, and it is the same overflow path as `inf`. Cheap, but unverified by execution. - **The four failures on a native Windows box.** They look like Wine and wall-clock effects here, but I have not run this suite outside Wine, so I cannot say they are clean upstream.
MoonEyes commented 2026-12-02 13:16:03 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T13:16:03Z.


RUN (in game, grouped): this head ef429f923 was merged with git merge --no-ff, together with nine other rendering pull requests, onto main f6dd2242e (no conflicts), and the d3d12 layer was rebuilt from that tree (diag profile, with DLSS). RTX 4060 8 GB, driver 610.88, Windows 11; scripts/play-d3d12.ps1 -SeriesS -Resolution 1080 -FrameGen 2, low-memory profile, keyboard-driven entry into the world and a walking route.

  • At least 381 s in the world (time limit 330 s, then the run script stopped the game): no device loss, no unhandled exception, no hang or GPU stall in the log.
  • Rendering 14.7 frames/s median over the last 240 s (a single earlier run with the same launcher options on a different tree: 15.2).
  • Limits: one run, grouped, so a failure would not have named one pull request; the picture was not checked; free RAM was about 1.2 GB during the run.

Heads in this run: #2854 81a6e94a9, #2936 68215ad0b, #2939 561bbc19c, #2997 ef429f923, #3043 915d4d5aa, #3045 cb30a595a, #3046 0f19a0819, #3047 c33e5b48e, #3048 2ab0b4b9d, #3051 856615ce7.

AI-assisted (Claude Code, Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7346606671 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2997#issuecomment-7346606671). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T13:16:03Z. --- RUN (in game, grouped): this head `ef429f923` was merged with `git merge --no-ff`, together with nine other rendering pull requests, onto `main` `f6dd2242e` (no conflicts), and the d3d12 layer was rebuilt from that tree (diag profile, with DLSS). RTX 4060 8 GB, driver 610.88, Windows 11; `scripts/play-d3d12.ps1 -SeriesS -Resolution 1080 -FrameGen 2`, low-memory profile, keyboard-driven entry into the world and a walking route. - At least 381 s in the world (time limit 330 s, then the run script stopped the game): no device loss, no unhandled exception, no hang or GPU stall in the log. - Rendering 14.7 frames/s median over the last 240 s (a single earlier run with the same launcher options on a different tree: 15.2). - Limits: one run, grouped, so a failure would not have named one pull request; the picture was not checked; free RAM was about 1.2 GB during the run. Heads in this run: #2854 81a6e94a9, #2936 68215ad0b, #2939 561bbc19c, #2997 ef429f923, #3043 915d4d5aa, #3045 cb30a595a, #3046 0f19a0819, #3047 c33e5b48e, #3048 2ab0b4b9d, #3051 856615ce7. AI-assisted (Claude Code, Claude Opus 5.5)
MoonEyes commented 2026-12-02 13:20:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T13:20:30Z.


Merging. Head ef429f923 merges cleanly with main bf7886746 and does not force a rebase of #2566. Checked on head ef429f923: all 6 CI checks green; third-party red/green by imShangLi on this head; an in-game run of at least 381 s with this head merged onto main f6dd2242e (grouped with nine other rendering pull requests, comment above) showed no device loss, no unhandled exception and no hang; item claimed in the coordination issue; author has earlier merged pull requests; conflict-free merge against main. Merged by MoonEyes.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7346722246 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2997#issuecomment-7346722246). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T13:20:30Z. --- Merging. Head `ef429f923` merges cleanly with `main` `bf7886746` and does not force a rebase of #2566. Checked on head ef429f923: all 6 CI checks green; third-party red/green by imShangLi on this head; an in-game run of at least 381 s with this head merged onto main f6dd2242e (grouped with nine other rendering pull requests, comment above) showed no device loss, no unhandled exception and no hang; item claimed in the coordination issue; author has earlier merged pull requests; conflict-free merge against main. Merged by MoonEyes. AI-assisted (Claude Code).
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!2997
No description provided.