D3D12-GPU-BOOK-NEIGHBOURS-U64-MAX: prevent u64::MAX overflow and wrap in Book::neighbours #3005

Open
bobcatchris wants to merge 1 commit from upstream-pr/3005 into main
bobcatchris commented 2026-12-01 23:17:30 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by bobcatchris on 2026-12-01T23:17:30Z.


Fixes D3D12-GPU-BOOK-NEIGHBOURS-U64-MAX (claim comment 7328994859).

Summary

  • Book::neighbours (d3d12/crates/leonida-gpu/src/book.rs): Replaced self.by_start.range((at + 1, 0)..).next() with at.checked_add(1).and_then(|next| self.by_start.range((next, 0)..).next()). Calling neighbours(u64::MAX) (for instance from at_loss(u64::MAX)) previously panicked with integer overflow in debug builds or wrapped to (0, 0).. in release builds and returned the lowest live allocation as the upper neighbour.
  • Span & expiry arithmetic: Guarded bases (base.saturating_add(bytes.saturating_sub(1))), walk suspect expiry (s.2.saturating_add(400)), and at_loss window length calculations (e.start.saturating_add(e.size).saturating_sub(base) and .saturating_add(64 << 10)) with saturating arithmetic so extreme addresses/timestamps cannot panic or wrap.
  • Test: Added neighbours_handles_u64_max_without_overflow_or_wrap.

Verification

  • Red (before fix): Book::neighbours(u64::MAX) panicked in debug (RED_BOOK_EXIT=101, attempt to add with overflow).
  • Green: cargo test --package leonida-gpu --features diagnostics --lib book::tests -> 4 passed; 0 failed (including GPU test a_pooled_texture_and_its_block_are_in_the_book on RX 7900 XTX).
  • Default-feature leonida-gpu compile & tools/d3d12_switches.py --check exit 0.
  • Clean-room: synthetic addresses and names only; independent read-only review passed (APPROVE).

AI-assisted

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5596427500 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3005). Originally posted by [bobcatchris](https://github.com/bobcatchris) on 2026-12-01T23:17:30Z. --- Fixes `D3D12-GPU-BOOK-NEIGHBOURS-U64-MAX` (claim [comment 7328994859](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7328994859)). ## Summary - **`Book::neighbours` (`d3d12/crates/leonida-gpu/src/book.rs`)**: Replaced `self.by_start.range((at + 1, 0)..).next()` with `at.checked_add(1).and_then(|next| self.by_start.range((next, 0)..).next())`. Calling `neighbours(u64::MAX)` (for instance from `at_loss(u64::MAX)`) previously panicked with integer overflow in debug builds or wrapped to `(0, 0)..` in release builds and returned the lowest live allocation as the upper neighbour. - **Span & expiry arithmetic**: Guarded `bases` (`base.saturating_add(bytes.saturating_sub(1))`), `walk` suspect expiry (`s.2.saturating_add(400)`), and `at_loss` window length calculations (`e.start.saturating_add(e.size).saturating_sub(base)` and `.saturating_add(64 << 10)`) with saturating arithmetic so extreme addresses/timestamps cannot panic or wrap. - **Test**: Added `neighbours_handles_u64_max_without_overflow_or_wrap`. ## Verification - Red (before fix): `Book::neighbours(u64::MAX)` panicked in debug (`RED_BOOK_EXIT=101`, attempt to add with overflow). - Green: `cargo test --package leonida-gpu --features diagnostics --lib book::tests` -> `4 passed; 0 failed` (including GPU test `a_pooled_texture_and_its_block_are_in_the_book` on RX 7900 XTX). - Default-feature `leonida-gpu` compile & `tools/d3d12_switches.py --check` exit `0`. - Clean-room: synthetic addresses and names only; independent read-only review passed (`APPROVE`). AI-assisted
andrew-ai commented 2026-12-01 23:20:54 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by andrew-ai on 2026-12-01T23:20:54Z.


Verified the neighbour lookup at a708b08fd against an independently sorted list of live entries. I compiled the unchanged Book add/remove/neighbours methods from parent and head. The matrix included duplicate starts at 0 and u64::MAX, interior gaps, and removals of the most recent and older entries sharing an address.

With one live entry at zero, the parent panicked on a u64::MAX query with overflow checks enabled. With checks disabled it returned that same entry as both neighbours. The PR matched the reference on all 130 lookups in each build, including after removing entries at the maximum address. This checks the indexed lookup only. Codex-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7329233709 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3005#issuecomment-7329233709). Originally posted by [andrew-ai](https://github.com/andrew-ai) on 2026-12-01T23:20:54Z. --- Verified the neighbour lookup at a708b08fd against an independently sorted list of live entries. I compiled the unchanged Book add/remove/neighbours methods from parent and head. The matrix included duplicate starts at 0 and u64::MAX, interior gaps, and removals of the most recent and older entries sharing an address. With one live entry at zero, the parent panicked on a u64::MAX query with overflow checks enabled. With checks disabled it returned that same entry as both neighbours. The PR matched the reference on all 130 lookups in each build, including after removing entries at the maximum address. This checks the indexed lookup only. Codex-assisted.
imShangLi commented 2026-12-02 07:56:41 +00:00 (Migrated from github.com)

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


VERIFY-3005 — 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, with one thing the maintainer should know about the test's reach. The change fixes a real overflow in Book::neighbours (a panic in a debug build, a wrapped address in a release build) and makes three other arithmetic spots saturating. The new test fails on the merge base with exactly "attempt to add with overflow" and passes with the pull request; nothing regressed. The thing to know: book.rs is behind #[cfg(all(windows, feature = "diagnostics"))], and the repository's CI runs cargo test --workspace --locked without that feature, so the new test is never executed by CI as the workflow stands — it only runs when someone builds the crate with --features diagnostics (I had to use a scratch copy of the harness to do that).

head a708b08fdc5283d56da3ea04217ec280953d9dcf ("d3d12/gpu: prevent u64::MAX overflow/wrap in Book::neighbours and loss spans"), base origin/main = 0ae5a2664b9cd2fd30abfb1f6096f1c07b030f39, merge base 1abef08d09f6c085efbd47de4cc9e2010bb70793 (124 commits behind main; book.rs itself has not been touched on main since that merge base, so the diff still applies to main's book.rs unchanged). One file, +21/−6: d3d12/crates/leonida-gpu/src/book.rs.

1. What it changes

book.rs is the diagnostics-only book of what the title has mapped (lib.rs:52: #[cfg(all(windows, feature = "diagnostics"))] mod book;). Four arithmetic expressions are made overflow-safe:

  1. Book::neighbours(at) (book.rs:149) — the important one. Old: let above = self.by_start.range((at + 1, 0)..).next();. With at == u64::MAX, at + 1 overflows: a panic ("attempt to add with overflow") in a debug build, and a wrapped 0 in a release build, which would then ask for "the entry starting at or above 0" — a completely unrelated entry. New: let above = at.checked_add(1).and_then(|next| self.by_start.range((next, 0)..).next()); — at u64::MAX there is no address above, so the answer is "no entry above". neighbours is what at_loss(va) uses to answer "what was at this address" for a faulting address.
  2. bases() (book.rs:474) — base + bytes - 1 becomes base.saturating_add(bytes.saturating_sub(1)), for the "buffer's end" entry. The bytes - 1 underflow is unreachable in practice (decode returns Names::Nothing for a zero-length buffer, book.rs:432), and the base + bytes overflow is conceivable only for a descriptor whose base sits at the top of memory; the change makes both harmless.
  3. walk() (book.rs:527) — now >= s.2 + 400 becomes now >= s.2.saturating_add(400). s.2 is a timestamp in milliseconds, so the overflow is unreachable; the change is defensive.
  4. at_loss() (book.rs:626-634) — e.start + e.size - base becomes e.start.saturating_add(e.size).saturating_sub(base) (twice), and len.unwrap_or(64 << 20) + (64 << 10) becomes len.unwrap_or(64 << 20).saturating_add(64 << 10). Same values in every reachable case; no overflow.

So one change fixes a reachable bug and three make unreachable arithmetic safe. All four are in the file's own style (the file already uses saturating_* and checked_* elsewhere).

2. The new test checks the property that matters

book::tests::neighbours_handles_u64_max_without_overflow_or_wrap is exactly the property that was broken:

let mut b = Book::default();
b.add(1, 0x1000_0000, 0x1000, "low".into(), 1);
let [below, above] = b.neighbours(u64::MAX);
assert_eq!(below.map(|e| e.what.as_str()), Some("low"));
assert!(above.is_none(), "u64::MAX must have no 'above' neighbour");
  • The "no overflow" half: on the merge base the call panics before it can answer anything.
  • The "no wrap" half: at u64::MAX there is no address above, so "no entry above" is the correct answer — and it is the answer the release build of the old code got wrong (it wrapped to 0 and would have reported the entry at the lowest address). The first assertion also checks that the fix did not break the ordinary case: the entry at 0x1000_0000 is still the one below u64::MAX.

The test body really runs here; it is not a no-op. I built the red side alone (merge base + the PR's test hunks) with --features diagnostics and ran the new test by name under Wine (lane/red_3005.log): the binary reported 1 failed; 784 filtered out with

thread 'book::tests::neighbours_handles_u64_max_without_overflow_or_wrap' panicked at crates/leonida-gpu/src/book.rs:149:42:
attempt to add with overflow

Line 149 column 42 is the at + 1 of self.by_start.range((at + 1, 0)..) — the overflow the pull request removes. The test needs no GPU, no device and no game files: it is a Book (a map of what the title mapped) built in memory.

What the test does not cover. The other three changes (bases, walk, at_loss) have no test; only neighbours is tested. That is defensible — they are unreachable arithmetic — but it means a future edit could reintroduce a non-saturating expression there without any test noticing.

The test's reach is limited by the feature gate. book.rs is compiled only with --features diagnostics, so this test exists only in that build. The repository's CI (d3d12/.github/workflows/ci.yml) runs cargo test --workspace --locked (line 33) with no features, so the book module — and this test — is not part of the test run CI does. The only CI job that compiles it is the clippy job with --all-features (line 30), which compiles but does not run the test. The new test therefore never fails on main in CI, and never passes in CI either: the maintainer's checklist item "a new test that fails on main and passes with the pull request" is satisfied in the source but is not exercised by the workflow. Moving the test out of the gated module, or adding --features diagnostics to the test job, would close that gap.

3. What the tests do here

The crate has to be built twice for this pull request to mean anything, because the whole change lives behind a feature gate. I cross-compiled for x86_64-pc-windows-gnu and ran the test binaries under Wine in both builds.

With --features diagnostics (the build in which the change exists) — python3 tools/wine_red_green.py 3005 --crate leonida-gpu with a scratch copy of the harness that accepts --features (/tmp/opencode/wine_rg_feat.py; the same red-side rule as the repository's scripts/red_green.py):

side commit tests new test regressions
red merge base 1abef08d + the PR's test hunks 787 FAILED — "attempt to add with overflow" at book.rs:149:42 —
green a708b08f (PR head) 787 ok 0

The tool's verdict: "red then green" — 1 red→green (the new test), 0 regressions, 4 failing on both sides, 722 passing on both sides, no test on one side only.

With the default feature set (what CI runs) the book module is not compiled at all, so there is no book test on either side: the plain run is 703 tests per side with no book:: test among them. I checked the two sides of that build by hand as well, running the base's and the head's test binary under Wine single-threaded:

side tests result
base 1abef08d (plain) 644 ran, 59 ignored 641 passed, 3 failed (the three watch tests)
head a708b08f (plain) 644 ran, 59 ignored 641 passed, 3 failed (the same three watch tests)

Identical. That is what one expects: the pull request's whole diff is inside #[cfg(all(windows, feature = "diagnostics"))] mod book;, so in the default build the change is not compiled at all and cannot alter anything.

4. Any failure I saw and why it is not this PR

  • Four tests fail on both sides in the diagnostics build: timeline::report::tests::real_waits_are_recorded_with_who_ended_them, 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. None of them is in book.rs, which is the only file this pull request touches; the three watch ones fail identically on the base of the other three pull requests I verified (same merge base family) and are environment failures of the guard-page machinery under Wine without a real GPU. timeline::report::tests::real_waits_are_recorded_with_who_ended_them is a timing-sensitive test that also fails on the base (it is one of the four "fail on both sides" of the run).
  • The default-feature run of the tool hung once, on the base's test binary. One run of tools/wine_red_green.py 3005 --crate leonida-gpu sat in a spinning leonida_gpu-*.exe for 30 minutes and had to be killed (the tool's own timeout is one hour). I identified what it was: the binary was the red side — the base's code — and I copied it out and ran it under Wine on its own, where it finished in 14.8 s (parallel) and 38.8 s (single-threaded) with the same 3 failures as every other run. So the hang is a pre-existing flake of the base's test suite under Wine, in code this pull request does not touch and, in that build, does not even compile into. An earlier run of the same command reported the verdict "NOT red-then-green" with three watch regressions, which the repeat runs show to be the usual watch flakiness (those same tests fail at the same rates on the base).
  • A note on the branch's age: the merge base is 124 commits behind main. The reviewer checklist asks for main to be merged into the branch before merging, and that is the maintainer's step, not the author's. I checked that main has not changed book.rs since that merge base (0 commits touch it), so the diff still applies to main's book.rs as it stands; I did not merge main into the branch and did not test the merged result.

5. What I did not check

  • The repository's CI configuration as it will run this pull request: the finding in section 2 (the test is not run by cargo test --workspace --locked) is read from d3d12/.github/workflows/ci.yml; I did not run the workflow itself, and I did not check whether some other job in the repository runs the crate's tests with the feature enabled.
  • The other three saturating changes (bases, walk, at_loss) are unexercised by any test, here or in the pull request; I checked them by reading and by reasoning about where their operands come from (decode, a millisecond timestamp, mapping sizes), not by measurement.
  • No GPU, no game files, no title: book.rs exists to explain a faulting address in a running title ("what was at this address"). I could not check that the diagnostics answer is right for a real fault at the top of the address space, only that the arithmetic no longer overflows.
  • No Windows build and no MSVC: everything is cargo test --target x86_64-pc-windows-gnu under Wine 11.21 on Fedora 45, in both the default and the diagnostics feature set. The release-build half of the "no wrap" claim (the old code wrapping to 0 instead of panicking) is reasoning from the code — I only ran the debug build.
  • The at_loss text output: the change alters only the arithmetic inside the string the diagnostics print; I did not compare the printed text before and after for any address.
  • The other crates of the workspace and the repository's Python test suite were not run; only leonida-gpu was, because the change is confined to it.
  • The PR's GitHub discussion (comments, review threads, the coordination issue, the Depends on: line) was not read: I was asked not to touch GitHub.
<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7338807016 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3005#issuecomment-7338807016). Originally posted by [imShangLi](https://github.com/imShangLi) on 2026-12-02T07:56:41Z. --- ## VERIFY-3005 — 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, with one thing the maintainer should know about the test's reach.** The change fixes a real overflow in `Book::neighbours` (a panic in a debug build, a wrapped address in a release build) and makes three other arithmetic spots saturating. The new test fails on the merge base with exactly "attempt to add with overflow" and passes with the pull request; nothing regressed. The thing to know: `book.rs` is behind `#[cfg(all(windows, feature = "diagnostics"))]`, and the repository's CI runs `cargo test --workspace --locked` **without** that feature, so **the new test is never executed by CI as the workflow stands** — it only runs when someone builds the crate with `--features diagnostics` (I had to use a scratch copy of the harness to do that). head `a708b08fdc5283d56da3ea04217ec280953d9dcf` ("d3d12/gpu: prevent u64::MAX overflow/wrap in Book::neighbours and loss spans"), base `origin/main` = `0ae5a2664b9cd2fd30abfb1f6096f1c07b030f39`, merge base `1abef08d09f6c085efbd47de4cc9e2010bb70793` (124 commits behind `main`; `book.rs` itself has not been touched on `main` since that merge base, so the diff still applies to `main`'s `book.rs` unchanged). One file, +21/−6: `d3d12/crates/leonida-gpu/src/book.rs`. ### 1. What it changes `book.rs` is the diagnostics-only book of what the title has mapped (`lib.rs:52`: `#[cfg(all(windows, feature = "diagnostics"))] mod book;`). Four arithmetic expressions are made overflow-safe: 1. **`Book::neighbours(at)` (book.rs:149)** — the important one. Old: `let above = self.by_start.range((at + 1, 0)..).next();`. With `at == u64::MAX`, `at + 1` overflows: a panic ("attempt to add with overflow") in a debug build, and a wrapped `0` in a release build, which would then ask for "the entry starting at or above 0" — a completely unrelated entry. New: `let above = at.checked_add(1).and_then(|next| self.by_start.range((next, 0)..).next());` — at `u64::MAX` there is no address above, so the answer is "no entry above". `neighbours` is what `at_loss(va)` uses to answer "what was at this address" for a faulting address. 2. **`bases()` (book.rs:474)** — `base + bytes - 1` becomes `base.saturating_add(bytes.saturating_sub(1))`, for the "buffer's end" entry. The `bytes - 1` underflow is unreachable in practice (`decode` returns `Names::Nothing` for a zero-length buffer, book.rs:432), and the `base + bytes` overflow is conceivable only for a descriptor whose base sits at the top of memory; the change makes both harmless. 3. **`walk()` (book.rs:527)** — `now >= s.2 + 400` becomes `now >= s.2.saturating_add(400)`. `s.2` is a timestamp in milliseconds, so the overflow is unreachable; the change is defensive. 4. **`at_loss()` (book.rs:626-634)** — `e.start + e.size - base` becomes `e.start.saturating_add(e.size).saturating_sub(base)` (twice), and `len.unwrap_or(64 << 20) + (64 << 10)` becomes `len.unwrap_or(64 << 20).saturating_add(64 << 10)`. Same values in every reachable case; no overflow. So one change fixes a reachable bug and three make unreachable arithmetic safe. All four are in the file's own style (the file already uses `saturating_*` and `checked_*` elsewhere). ### 2. The new test checks the property that matters `book::tests::neighbours_handles_u64_max_without_overflow_or_wrap` is exactly the property that was broken: ```rust let mut b = Book::default(); b.add(1, 0x1000_0000, 0x1000, "low".into(), 1); let [below, above] = b.neighbours(u64::MAX); assert_eq!(below.map(|e| e.what.as_str()), Some("low")); assert!(above.is_none(), "u64::MAX must have no 'above' neighbour"); ``` - The **"no overflow"** half: on the merge base the call panics before it can answer anything. - The **"no wrap"** half: at `u64::MAX` there is no address above, so "no entry above" is the correct answer — and it is the answer the release build of the old code got *wrong* (it wrapped to 0 and would have reported the entry at the lowest address). The first assertion also checks that the fix did not break the ordinary case: the entry at `0x1000_0000` is still the one below `u64::MAX`. **The test body really runs here; it is not a no-op.** I built the red side alone (merge base + the PR's test hunks) with `--features diagnostics` and ran the new test by name under Wine (`lane/red_3005.log`): the binary reported `1 failed; 784 filtered out` with ``` thread 'book::tests::neighbours_handles_u64_max_without_overflow_or_wrap' panicked at crates/leonida-gpu/src/book.rs:149:42: attempt to add with overflow ``` Line 149 column 42 is the `at + 1` of `self.by_start.range((at + 1, 0)..)` — the overflow the pull request removes. The test needs no GPU, no device and no game files: it is a `Book` (a map of what the title mapped) built in memory. **What the test does not cover.** The other three changes (`bases`, `walk`, `at_loss`) have no test; only `neighbours` is tested. That is defensible — they are unreachable arithmetic — but it means a future edit could reintroduce a non-saturating expression there without any test noticing. **The test's reach is limited by the feature gate.** `book.rs` is compiled only with `--features diagnostics`, so this test exists only in that build. The repository's CI (`d3d12/.github/workflows/ci.yml`) runs `cargo test --workspace --locked` (line 33) with no features, so the `book` module — and this test — is **not** part of the test run CI does. The only CI job that compiles it is the clippy job with `--all-features` (line 30), which compiles but does not run the test. The new test therefore never fails on `main` in CI, and never passes in CI either: the maintainer's checklist item "a new test that fails on `main` and passes with the pull request" is satisfied in the source but is not exercised by the workflow. Moving the test out of the gated module, or adding `--features diagnostics` to the test job, would close that gap. ### 3. What the tests do here The crate has to be built twice for this pull request to mean anything, because the whole change lives behind a feature gate. I cross-compiled for `x86_64-pc-windows-gnu` and ran the test binaries under Wine in both builds. **With `--features diagnostics`** (the build in which the change exists) — `python3 tools/wine_red_green.py 3005 --crate leonida-gpu` with a scratch copy of the harness that accepts `--features` (`/tmp/opencode/wine_rg_feat.py`; the same red-side rule as the repository's `scripts/red_green.py`): | side | commit | tests | new test | regressions | |---|---|---|---|---| | red | merge base `1abef08d` + the PR's test hunks | 787 | **FAILED** — "attempt to add with overflow" at `book.rs:149:42` | — | | green | `a708b08f` (PR head) | 787 | **ok** | **0** | The tool's verdict: **"red then green"** — 1 red→green (the new test), 0 regressions, 4 failing on both sides, 722 passing on both sides, no test on one side only. **With the default feature set** (what CI runs) the `book` module is not compiled at all, so there is no book test on either side: the plain run is 703 tests per side with no `book::` test among them. I checked the two sides of that build by hand as well, running the base's and the head's test binary under Wine single-threaded: | side | tests | result | |---|---|---| | base `1abef08d` (plain) | 644 ran, 59 ignored | 641 passed, 3 failed (the three `watch` tests) | | head `a708b08f` (plain) | 644 ran, 59 ignored | 641 passed, 3 failed (the same three `watch` tests) | Identical. That is what one expects: the pull request's whole diff is inside `#[cfg(all(windows, feature = "diagnostics"))] mod book;`, so in the default build the change is not compiled at all and cannot alter anything. ### 4. Any failure I saw and why it is not this PR - **Four tests fail on both sides in the `diagnostics` build**: `timeline::report::tests::real_waits_are_recorded_with_who_ended_them`, `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`. None of them is in `book.rs`, which is the only file this pull request touches; the three `watch` ones fail identically on the base of the other three pull requests I verified (same merge base family) and are environment failures of the guard-page machinery under Wine without a real GPU. `timeline::report::tests::real_waits_are_recorded_with_who_ended_them` is a timing-sensitive test that also fails on the base (it is one of the four "fail on both sides" of the run). - **The default-feature run of the tool hung once, on the base's test binary.** One run of `tools/wine_red_green.py 3005 --crate leonida-gpu` sat in a spinning `leonida_gpu-*.exe` for 30 minutes and had to be killed (the tool's own timeout is one hour). I identified what it was: the binary was the **red** side — the base's code — and I copied it out and ran it under Wine on its own, where it finished in 14.8 s (parallel) and 38.8 s (single-threaded) with the same 3 failures as every other run. So the hang is a pre-existing flake of the base's test suite under Wine, in code this pull request does not touch and, in that build, does not even compile into. An earlier run of the same command reported the verdict "NOT red-then-green" with three `watch` regressions, which the repeat runs show to be the usual `watch` flakiness (those same tests fail at the same rates on the base). - **A note on the branch's age**: the merge base is 124 commits behind `main`. The reviewer checklist asks for `main` to be merged into the branch before merging, and that is the maintainer's step, not the author's. I checked that `main` has not changed `book.rs` since that merge base (0 commits touch it), so the diff still applies to `main`'s `book.rs` as it stands; I did not merge `main` into the branch and did not test the merged result. ### 5. What I did not check - **The repository's CI configuration as it will run this pull request**: the finding in section 2 (the test is not run by `cargo test --workspace --locked`) is read from `d3d12/.github/workflows/ci.yml`; I did not run the workflow itself, and I did not check whether some other job in the repository runs the crate's tests with the feature enabled. - **The other three saturating changes** (`bases`, `walk`, `at_loss`) are unexercised by any test, here or in the pull request; I checked them by reading and by reasoning about where their operands come from (`decode`, a millisecond timestamp, mapping sizes), not by measurement. - **No GPU, no game files, no title**: `book.rs` exists to explain a faulting address in a running title ("what was at this address"). I could not check that the diagnostics answer is right for a real fault at the top of the address space, only that the arithmetic no longer overflows. - **No Windows build and no MSVC**: everything is `cargo test --target x86_64-pc-windows-gnu` under Wine 11.21 on Fedora 45, in both the default and the `diagnostics` feature set. The release-build half of the "no wrap" claim (the old code wrapping to 0 instead of panicking) is reasoning from the code — I only ran the debug build. - **The `at_loss` text output**: the change alters only the arithmetic inside the string the diagnostics print; I did not compare the printed text before and after for any address. - **The other crates of the workspace** and the repository's Python test suite were not run; only `leonida-gpu` was, because the change is confined to it. - **The PR's GitHub discussion** (comments, review threads, the coordination issue, the `Depends on:` line) was not read: I was asked not to touch GitHub.
MoonEyes commented 2026-12-02 18:02:34 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-12-02T18:02:34Z.


Code review only, not built (Windows-only leonida-gpu). Ready.

  • Head: a708b08fd, merge base 1abef08d0, 326 behind current main 45dc41f95. A trial merge is clean. CI on the head: all 6 checks pass.
  • Already verified on this head, with no commits since:
    • andrew-ai: independent oracle for neighbours.
    • imShangLi (VERIFY-3005): the new test fails on the merge base with "attempt to add with overflow" and passes with the PR.

Review of d3d12/crates/leonida-gpu/src/book.rs:

  • neighbours: at.checked_add(1).and_then(..) is the root-cause fix. At u64::MAX there is no "above". The old at + 1 panicked in debug and wrapped to 0 in release, which returned the lowest entry as "above".
  • bases (Names::Buffer): base.saturating_add(bytes.saturating_sub(1)) also covers bytes == 0, which underflowed before.
  • walk (s.2.saturating_add(400)) and at_loss (saturating_add and saturating_sub on extents) are defensive. They only run on the device-loss and diagnostics path, so the cost does not matter.
  • neighbours_handles_u64_max_without_overflow_or_wrap pins the real bug. The other saturating spots have no test, which is acceptable for diagnostics arithmetic.
  • Not render-path behaviour in practice (bookkeeping for loss reports). MoonEyes's gate was not requested here.

Verdict: ready.

AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.


Generated by Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7353886904 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3005#issuecomment-7353886904). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T18:02:34Z. --- **Code review only, not built (Windows-only `leonida-gpu`). Ready.** - Head: `a708b08fd`, merge base `1abef08d0`, 326 behind current `main` `45dc41f95`. A trial merge is clean. CI on the head: all 6 checks pass. - Already verified on this head, with no commits since: - andrew-ai: independent oracle for `neighbours`. - imShangLi (VERIFY-3005): the new test fails on the merge base with "attempt to add with overflow" and passes with the PR. **Review of `d3d12/crates/leonida-gpu/src/book.rs`:** - `neighbours`: `at.checked_add(1).and_then(..)` is the root-cause fix. At `u64::MAX` there is no "above". The old `at + 1` panicked in debug and wrapped to 0 in release, which returned the lowest entry as "above". - `bases` (`Names::Buffer`): `base.saturating_add(bytes.saturating_sub(1))` also covers `bytes == 0`, which underflowed before. - `walk` (`s.2.saturating_add(400)`) and `at_loss` (`saturating_add` and `saturating_sub` on extents) are defensive. They only run on the device-loss and diagnostics path, so the cost does not matter. - `neighbours_handles_u64_max_without_overflow_or_wrap` pins the real bug. The other saturating spots have no test, which is acceptable for diagnostics arithmetic. - Not render-path behaviour in practice (bookkeeping for loss reports). MoonEyes's gate was not requested here. Verdict: **ready**. AI-assisted verification: Claude Opus (Claude Code), separate agent per batch. --- _Generated by [Claude Code](https://claude.ai/code)_
MoonEyes commented 2026-12-02 22:01:30 +00:00 (Migrated from github.com)

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


This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists).

Could you, or anyone with a working setup, post a run report on the current head merged onto current main:

  • the head SHA and the main SHA it was merged onto;
  • GPU, driver and OS;
  • at least 300 s in the world after loading;
  • device lost / crashes (count), and rendered fps (median) if you have them;
  • the same run on main alone for comparison, if you can.

Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7360116513 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3005#issuecomment-7360116513). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T22:01:30Z. --- This pull request touches the render path, so it needs an in-game run before it can be merged: unit tests and CI do not catch rendering regressions (a device loss after an earlier merge is why this gate exists). Could you, or anyone with a working setup, post a run report on the **current head** merged onto current `main`: - the head SHA and the `main` SHA it was merged onto; - GPU, driver and OS; - at least 300 s in the world after loading; - device lost / crashes (count), and rendered fps (median) if you have them; - the same run on `main` alone for comparison, if you can. Please do not attach logs or screenshots that show game content. If a run on this exact head is already posted, a link to it in a reply is enough. AI-assisted (Claude Code).
fiestorra commented 2026-12-02 22:13:43 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-02T22:13:43Z.


VERIFY-3005 — Windows nativo: red then green, y el módulo solo existe con la feature diagnostics

Head (this PR)
Merge base 1abef08d0 (well behind main b41763227)
Merged onto main — merge-tree clean, git merge --no-ff clean

Ran

cargo test -p leonida-gpu --lib --features diagnostics book::
  book::tests::neighbours_handles_u64_max_without_overflow_or_wrap ... ok
  4 passed; 0 failed

The trap that costs ten minutes and is worth writing down: mod book is #[cfg(all(windows, feature = "diagnostics"))] (lib.rs:52). Without --features diagnostics the module — and this pull request's test — is not compiled at all, and cargo test -p leonida-gpu --lib u64_max reports 0 passed; 762 filtered out with exit 0. A verifier who runs the obvious command would record "no test" for a test that exists.

Negative control (synthetic — the test ships with the change, in the same file): I put the old self.by_start.range((at + 1, 0)..).next() back and rebuilt:

FAILED: neighbours_handles_u64_max_without_overflow_or_wrap
panicked at crates\leonida-gpu\src\book.rs   (attempt to add with overflow)

The test bites on exactly the arithmetic this PR replaces with checked_add/saturating_add.

What the change is, from the diff: five expressions that could wrap at u64::MAX — a buffer's end (base + bytes - 1), a suspect's due frame, two end - base distances, and a size cap — now go through checked_add/saturating_add. The new test drives neighbours(..) at u64::MAX. The other three tests in the module still pass.

What I could not test

  • A title address at u64::MAX: the fixture asks the book about it synthetically; no game run, and no such address exists in a real process.
  • The rest of the crate with diagnostics: only the module was run (840 filtered out), not the whole suite under that feature.

Written with an AI assistant.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7360402851 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3005#issuecomment-7360402851). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-02T22:13:43Z. --- ## VERIFY-3005 — Windows nativo: `red then green`, y **el módulo solo existe con la feature `diagnostics`** | | | |---|---| | Head | `(this PR)` | | Merge base | `1abef08d0` (well behind `main` `b41763227`) | | Merged onto | `main` — `merge-tree` clean, `git merge --no-ff` clean | **Ran** ``` cargo test -p leonida-gpu --lib --features diagnostics book:: book::tests::neighbours_handles_u64_max_without_overflow_or_wrap ... ok 4 passed; 0 failed ``` **The trap that costs ten minutes and is worth writing down**: `mod book` is `#[cfg(all(windows, feature = "diagnostics"))]` (`lib.rs:52`). Without `--features diagnostics` the module — and this pull request's test — is not compiled at all, and `cargo test -p leonida-gpu --lib u64_max` reports **`0 passed; 762 filtered out`** with exit 0. A verifier who runs the obvious command would record "no test" for a test that exists. **Negative control (synthetic — the test ships with the change, in the same file)**: I put the old `self.by_start.range((at + 1, 0)..).next()` back and rebuilt: ``` FAILED: neighbours_handles_u64_max_without_overflow_or_wrap panicked at crates\leonida-gpu\src\book.rs (attempt to add with overflow) ``` **The test bites on exactly the arithmetic this PR replaces with `checked_add`/`saturating_add`.** **What the change is, from the diff**: five expressions that could wrap at `u64::MAX` — a buffer's end (`base + bytes - 1`), a suspect's due frame, two `end - base` distances, and a size cap — now go through `checked_add`/`saturating_add`. The new test drives `neighbours(..)` at `u64::MAX`. The other three tests in the module still pass. ## What I could not test - **A title address at `u64::MAX`**: the fixture asks the book about it synthetically; no game run, and no such address exists in a real process. - **The rest of the crate with `diagnostics`**: only the module was run (840 filtered out), not the whole suite under that feature. Written with an AI assistant.
EdenBendheim commented 2026-12-03 11:48:28 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by EdenBendheim on 2026-12-03T11:48:28Z.


RUN (in game, RTX 3090 24 GB) — stock compatibility PASS, with two earlier present-gap failures retained.

  • Head a708b08fdc5283d56da3ea04217ec280953d9dcf merged locally onto main 6e979905054be3ba9737883fe8e205501a2183b7 as 9f07ff0f6e1585a0007a80c544db11b4e629092e. Executable SHA-256 94caed878bc47034257cf09a76a4d7585aab73dc9163fcc162ec787403f4f0e9, diagnostics,dlss,mimalloc. Clean-room scan passed.
  • Windows 11 Home build 26200, Ryzen 9 5900X, 32 GiB RAM, NVIDIA RTX 3090, driver 610.88 (Profile L). Series S, no FG/precompile, LEONIDA_BOOK=1 in all runs. Stock gate.
MEASURED Full DRED + slot check Fault-only DRED + slot check Fault-only DRED, slot check unset
World seconds 302.251 302.628 305.284
Actual exit / device losses / crashes 0 / 0 / 0 0 / 0 / 0 0 / 0 / 0
Stock gate FAIL (present gap) FAIL (present gap) PASS
Median FPS 3.40 8.53 16.08
Longest world present gap (s) 12.506 11.480 1.634
Peak private / min commit left (MiB) 21149 / 8260 20665 / 8784 20598 / 8785

The initial two runs accidentally copied the large pipeline seed into the cache root rather than its expected pipelines subdirectory, so they were effectively cold. The third run corrected the seed layout. It measured 3,119 present intervals from world+60 s, p5 FPS 5.98, p95/p99 167.36/350.15 ms, VRAM peak 5,058 MiB against 23,558 MiB budget. All three completed a target stop and actual clean exit; no loss marker.

Book activity was confirmed in the first two runs by 143/131 slot-check rounds, with alive/gone counts advancing 21/1→11135/2496 and 19/1→11902/2941. The third run had Book enabled but no slot-check telemetry. Initial native placement succeeded in the first two legs and was later lost; control and placement were not established in the third. This is renderer compatibility evidence with those limitations; workload, cache and instrumentation differ, and no matched main live control was run.

Synthetic red/green: all four diagnostics book tests passed before and after restoration. Replacing only the checked neighbour increment with the old increment made the exact maximum-address test panic with integer overflow (exit 101); fixed source restored byte-for-byte then four passed. The conditional pooled-texture ownership assertion had no reported address on this NVIDIA adapter, so that assertion was not exercised. No real hardware fault was induced.

AI-assisted: Codex GPT-6.2 Sol (tester and independent numerical verification). No game content attached.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7377204383 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/3005#issuecomment-7377204383). Originally posted by [EdenBendheim](https://github.com/EdenBendheim) on 2026-12-03T11:48:28Z. --- **RUN (in game, RTX 3090 24 GB) — stock compatibility PASS, with two earlier present-gap failures retained.** - Head `a708b08fdc5283d56da3ea04217ec280953d9dcf` merged locally onto main `6e979905054be3ba9737883fe8e205501a2183b7` as `9f07ff0f6e1585a0007a80c544db11b4e629092e`. Executable SHA-256 `94caed878bc47034257cf09a76a4d7585aab73dc9163fcc162ec787403f4f0e9`, diagnostics,dlss,mimalloc. Clean-room scan passed. - Windows 11 Home build 26200, Ryzen 9 5900X, 32 GiB RAM, NVIDIA RTX 3090, driver 610.88 (Profile L). Series S, no FG/precompile, `LEONIDA_BOOK=1` in all runs. Stock gate. | MEASURED | Full DRED + slot check | Fault-only DRED + slot check | Fault-only DRED, slot check unset | |---|---:|---:|---:| | World seconds | 302.251 | 302.628 | 305.284 | | Actual exit / device losses / crashes | 0 / 0 / 0 | 0 / 0 / 0 | 0 / 0 / 0 | | Stock gate | FAIL (present gap) | FAIL (present gap) | PASS | | Median FPS | 3.40 | 8.53 | 16.08 | | Longest world present gap (s) | 12.506 | 11.480 | 1.634 | | Peak private / min commit left (MiB) | 21149 / 8260 | 20665 / 8784 | 20598 / 8785 | The initial two runs accidentally copied the large pipeline seed into the cache root rather than its expected pipelines subdirectory, so they were effectively cold. The third run corrected the seed layout. It measured 3,119 present intervals from world+60 s, p5 FPS 5.98, p95/p99 167.36/350.15 ms, VRAM peak 5,058 MiB against 23,558 MiB budget. All three completed a target stop and actual clean exit; no loss marker. Book activity was confirmed in the first two runs by 143/131 slot-check rounds, with alive/gone counts advancing 21/1→11135/2496 and 19/1→11902/2941. The third run had Book enabled but no slot-check telemetry. Initial native placement succeeded in the first two legs and was later lost; control and placement were not established in the third. This is renderer compatibility evidence with those limitations; workload, cache and instrumentation differ, and no matched main live control was run. **Synthetic red/green:** all four diagnostics book tests passed before and after restoration. Replacing only the checked neighbour increment with the old increment made the exact maximum-address test panic with integer overflow (exit 101); fixed source restored byte-for-byte then four passed. The conditional pooled-texture ownership assertion had no reported address on this NVIDIA adapter, so that assertion was not exercised. No real hardware fault was induced. AI-assisted: Codex GPT-6.2 Sol (tester and independent numerical verification). No game content attached.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3005:upstream-pr/3005'
git switch 'upstream-pr/3005'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/3005'
git switch 'upstream-pr/3005'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3005'
git switch 'upstream-pr/3005'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3005'
git switch 'main'
git merge --squash 'upstream-pr/3005'
git switch 'main'
git merge --ff-only 'upstream-pr/3005'
git switch 'main'
git merge 'upstream-pr/3005'
git push origin 'main'
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!3005
No description provided.