loader: content-address PreparedImage with cached hash and synced staging (D3D12-LOADER-CONTENT-ADDRESSED-IMAGE) #2890

Open
djrolfes wants to merge 1 commit from upstream-pr/2890 into main
djrolfes commented 2026-12-01 15:36:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by djrolfes on 2026-12-01T15:36:58Z.


Claimed in the coordination issue as: D3D12-LOADER-CONTENT-ADDRESSED-IMAGE.

What and why

Content-address PreparedImage::file_name() by a cached full BLAKE3 hash of the prepared bytes, sync staging files to disk before the atomic rename, and add a content-addressed fast path in publish::write_content_addressed() (d3d12/crates/leonida-loader/src/{prepare.rs,publish.rs,windows.rs}).

  • Why:
    1. On main, PreparedImage::file_name() keys the cached DLL on the first 16 hex chars of original_hash (leonida-image-<16hex>.dll). If loader preparation bytes change for the same title build, the cached filename collides with the stale DLL.
    2. On every launch, publish::write_if_changed() reads the entire ~115–200 MB prepared DLL back from disk into a Vec<u8> just to byte-compare it against prepared.bytes.
  • Change:
    • prepare.rs: computes and caches pub prepared_hash: blake3::Hash once inside prepare(). PreparedImage::file_name(&self) delegates to crate::publish::content_addressed_name(&self.prepared_hash) (leonida-image-<64hex>.dll), so neither windows.rs::load nor apps/leonida/src/run.rs re-hashes prepared.bytes.
    • publish.rs:
      • Writes staging files via write_staging() (File::create → write_all → sync_all, cleaning up the staging file on error) BEFORE publish_staging() performs the atomic rename, preventing crash/power-loss from leaving a same-size zero-filled file at the content-addressed path.
      • Adds write_content_addressed(path, bytes, hash) which skips re-reading disk when the filename matches content_addressed_name(hash) and metadata(path) confirms a regular file of the exact byte length, falling back to write_if_changed() otherwise.
    • windows.rs: passes &prepared.prepared_hash into crate::publish::write_content_addressed, ensuring prepared.bytes is hashed exactly once per launch.
  • Notes: Existing LEONIDA_WRITE_SITES caches keyed by the old 16-hex image_name will regenerate once under the new 64-hex name; prior leonida-image-*.dll cache entries from earlier builds remain untouched in the cache directory.
  • Scope discipline: Strictly one topic; per-page IAT VirtualProtect batching is split into its own separate PR (D3D12-LOADER-BATCHED-IAT-PROTECT, verified clean merge via git merge-tree).
  • Evidence classification: READ IN CODE (prepare.rs, publish.rs, windows.rs) + fresh red→green unit tests + MEASURED 300 s in-world game gate.

Tested

  • python3 -I scripts/check_no_game_data.py d3d12/crates/leonida-loader/src/prepare.rs d3d12/crates/leonida-loader/src/publish.rs d3d12/crates/leonida-loader/src/windows.rs → exit 0.
  • Freshly compiled (cargo clean -p leonida-loader --target x86_64-pc-windows-msvc) leonida-loader unit test binary (x86_64-pc-windows-msvc) and ran under Wine:
    • RED on origin/main (only the new test prepare::tests::file_name_uses_full_blake3_of_prepared_bytes applied):
      running 1 test
      thread 'prepare::tests::file_name_uses_full_blake3_of_prepared_bytes' panicked:
      assertion `left == right` failed
        left: "leonida-image-46f298c60d91a73a.dll"
       right: "leonida-image-52c5ecc3199b3152e1e0d4817abdafa261e5ed83a82b8936fb2d5dc35e28c214.dll"
      test result: FAILED. 0 passed; 1 failed; 0 ignored
      
    • GREEN on PR head 262439781 (rebased onto 3e7b34a52):
      test prepare::tests::file_name_uses_full_blake3_of_prepared_bytes ... ok
      test publish::tests::content_addressed_fast_path_requires_matching_name_and_size ... ok
      test result: ok. 86 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
      
  • git merge-tree --write-tree HEAD pr/loader-batched-iat-protect → clean merge (zero conflicts with D3D12-LOADER-BATCHED-IAT-PROTECT).
  • 300 s in-world game gate (MEASURED on exact PR head 262439781, Series S + DLSS Quality 1280×720 → 1920×1080, Option A mods/gate_driver mode = roam loaded):
    • Verdict: PASS (310.03 s in-world after world entry at 68.77 s; also passed an earlier cold-cache 310.18 s run with 0 errors).
    • Frames & pacing: 3,275 frames after +60 s (3,382 total world presents), 15.98 median FPS (16.37 end median FPS), 111.22 ms p95 frame time, 4.433 s longest present gap (<= 10.0 s).
    • Memory & stability: 6,686 MiB peak VRAM (<= 7,400 MiB), 0 device losses (0x887A0005), 0 crashes, 0 panics, 0 faults before stop, 0 kernel NVRM: Xid errors.
    • Option A gate_driver note: mods/gate_driver loaded in mode = roam with 0 GATE FAIL; its 10 s menu-press cadence missed the brief world-entry probe window so the 310.03 s run stayed on the in-world camera cleanly at 15.98 FPS.

GPUs tested: NVIDIA GeForce RTX 3070 Ti 8 GB, driver 620.73.04, Arch Linux (Wine 11.22 + VKD3D-Proton 3.2.0).

AI-assisted: yes (authored by Gemini 4 Neon; independent fresh review pass by a separate Gemini 4 Neon agent requested File::sync_all() before rename and caching prepared_hash once on PreparedImage to eliminate triple hashing, addressed and approved in re-review).

Checklist

  • Based on current main (3e7b34a52) and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (check_no_game_data.py clean on both source and PR description).
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a — loader image cache naming & synced content-addressed publish fast path)
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5589003881 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2890). Originally posted by [djrolfes](https://github.com/djrolfes) on 2026-12-01T15:36:58Z. --- Claimed in the coordination issue as: [`D3D12-LOADER-CONTENT-ADDRESSED-IMAGE`](https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7313472550). ### What and why Content-address `PreparedImage::file_name()` by a cached full BLAKE3 hash of the *prepared* bytes, sync staging files to disk before the atomic rename, and add a content-addressed fast path in `publish::write_content_addressed()` (`d3d12/crates/leonida-loader/src/{prepare.rs,publish.rs,windows.rs}`). - **Why:** 1. On `main`, `PreparedImage::file_name()` keys the cached DLL on the first 16 hex chars of `original_hash` (`leonida-image-<16hex>.dll`). If loader preparation bytes change for the same title build, the cached filename collides with the stale DLL. 2. On every launch, `publish::write_if_changed()` reads the entire ~115–200 MB prepared DLL back from disk into a `Vec<u8>` just to byte-compare it against `prepared.bytes`. - **Change:** - `prepare.rs`: computes and caches `pub prepared_hash: blake3::Hash` once inside `prepare()`. `PreparedImage::file_name(&self)` delegates to `crate::publish::content_addressed_name(&self.prepared_hash)` (`leonida-image-<64hex>.dll`), so neither `windows.rs::load` nor `apps/leonida/src/run.rs` re-hashes `prepared.bytes`. - `publish.rs`: - Writes staging files via `write_staging()` (`File::create` → `write_all` → `sync_all`, cleaning up the staging file on error) BEFORE `publish_staging()` performs the atomic rename, preventing crash/power-loss from leaving a same-size zero-filled file at the content-addressed path. - Adds `write_content_addressed(path, bytes, hash)` which skips re-reading disk when the filename matches `content_addressed_name(hash)` and `metadata(path)` confirms a regular file of the exact byte length, falling back to `write_if_changed()` otherwise. - `windows.rs`: passes `&prepared.prepared_hash` into `crate::publish::write_content_addressed`, ensuring `prepared.bytes` is hashed exactly once per launch. - **Notes:** Existing `LEONIDA_WRITE_SITES` caches keyed by the old 16-hex `image_name` will regenerate once under the new 64-hex name; prior `leonida-image-*.dll` cache entries from earlier builds remain untouched in the cache directory. - **Scope discipline:** Strictly one topic; per-page IAT `VirtualProtect` batching is split into its own separate PR (`D3D12-LOADER-BATCHED-IAT-PROTECT`, verified clean merge via `git merge-tree`). - **Evidence classification:** **READ IN CODE** (`prepare.rs`, `publish.rs`, `windows.rs`) + fresh red→green unit tests + **MEASURED** 300 s in-world game gate. ### Tested - `python3 -I scripts/check_no_game_data.py d3d12/crates/leonida-loader/src/prepare.rs d3d12/crates/leonida-loader/src/publish.rs d3d12/crates/leonida-loader/src/windows.rs` → exit 0. - Freshly compiled (`cargo clean -p leonida-loader --target x86_64-pc-windows-msvc`) `leonida-loader` unit test binary (`x86_64-pc-windows-msvc`) and ran under Wine: - **RED on `origin/main`** (only the new test `prepare::tests::file_name_uses_full_blake3_of_prepared_bytes` applied): ```text running 1 test thread 'prepare::tests::file_name_uses_full_blake3_of_prepared_bytes' panicked: assertion `left == right` failed left: "leonida-image-46f298c60d91a73a.dll" right: "leonida-image-52c5ecc3199b3152e1e0d4817abdafa261e5ed83a82b8936fb2d5dc35e28c214.dll" test result: FAILED. 0 passed; 1 failed; 0 ignored ``` - **GREEN on PR head `262439781` (rebased onto `3e7b34a52`)**: ```text test prepare::tests::file_name_uses_full_blake3_of_prepared_bytes ... ok test publish::tests::content_addressed_fast_path_requires_matching_name_and_size ... ok test result: ok. 86 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out ``` - `git merge-tree --write-tree HEAD pr/loader-batched-iat-protect` → clean merge (zero conflicts with `D3D12-LOADER-BATCHED-IAT-PROTECT`). - **300 s in-world game gate (MEASURED on exact PR head `262439781`, Series S + DLSS Quality `1280×720 → 1920×1080`, Option A `mods/gate_driver` `mode = roam` loaded):** - **Verdict:** **PASS** (`310.03 s` in-world after world entry at `68.77 s`; also passed an earlier cold-cache 310.18 s run with `0` errors). - **Frames & pacing:** `3,275` frames after +60 s (`3,382` total world presents), `15.98` median FPS (`16.37` end median FPS), `111.22 ms` p95 frame time, `4.433 s` longest present gap (`<= 10.0 s`). - **Memory & stability:** `6,686 MiB` peak VRAM (`<= 7,400 MiB`), `0` device losses (`0x887A0005`), `0` crashes, `0` panics, `0` faults before stop, `0` kernel `NVRM: Xid` errors. - **Option A `gate_driver` note:** `mods/gate_driver` loaded in `mode = roam` with `0` `GATE FAIL`; its 10 s menu-press cadence missed the brief world-entry probe window so the 310.03 s run stayed on the in-world camera cleanly at `15.98` FPS. GPUs tested: NVIDIA GeForce RTX 3070 Ti 8 GB, driver 620.73.04, Arch Linux (Wine 11.22 + VKD3D-Proton 3.2.0). AI-assisted: yes (authored by Gemini 4 Neon; independent fresh review pass by a separate Gemini 4 Neon agent requested `File::sync_all()` before rename and caching `prepared_hash` once on `PreparedImage` to eliminate triple hashing, addressed and approved in re-review). ### Checklist - [x] Based on current `main` (`3e7b34a52`) and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (`check_no_game_data.py` clean on both source and PR description). - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a — loader image cache naming & synced content-addressed publish fast path)
merzleckeier commented 2026-12-01 16:10:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-12-01T16:10:12Z.


Independent prepared-image publication and retry check at 26243978 + 0ff8a532f, using the Win64 test binary under Wine 11.22. The 7 prepare tests including my integration case and all 5 publish tests passed.

I used the linked test executable as input. Two originals with different checksum bytes converge to identical prepared bytes and the same content-addressed name. Two distinct prepared payloads of exactly the same length instead publish to separate names. Four concurrent writers, two per name, left both payloads byte-for-byte correct and no staging files.

I then truncated one published file and held it open without delete sharing. Publishing returned PermissionDenied and left no staging file. Closing the reader and retrying repaired the truncated file while the other cache entry stayed byte-identical. This exercises the recovery path for a size mismatch with live Windows sharing semantics under Wine. Same-length corruption and power-loss durability were outside the fixture.

MEASURED with synthetic inputs. AI-assisted (Codex).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7317150700 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2890#issuecomment-7317150700). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-12-01T16:10:12Z. --- Independent prepared-image publication and retry check at 26243978 + 0ff8a532f, using the Win64 test binary under Wine 11.22. The 7 prepare tests including my integration case and all 5 publish tests passed. I used the linked test executable as input. Two originals with different checksum bytes converge to identical prepared bytes and the same content-addressed name. Two distinct prepared payloads of exactly the same length instead publish to separate names. Four concurrent writers, two per name, left both payloads byte-for-byte correct and no staging files. I then truncated one published file and held it open without delete sharing. Publishing returned PermissionDenied and left no staging file. Closing the reader and retrying repaired the truncated file while the other cache entry stayed byte-identical. This exercises the recovery path for a size mismatch with live Windows sharing semantics under Wine. Same-length corruption and power-loss durability were outside the fixture. MEASURED with synthetic inputs. AI-assisted (Codex).
KelboLive commented 2026-12-01 17:32:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T17:32:29Z.

Review: COMMENTED


Content-addressing checks out: the key is blake3(prepared bytes) (prepare.rs:112-118, publish.rs:16-18), so it covers the original image plus any change in prepare(), and the LEONIDA_* options only patch mapped memory after LoadLibraryExW (windows.rs:90-110) — correctly not part of the file key. The old 16-hex collision is gone, and I confirmed the mutation that shrinks the key to 16 hex fails file_name_uses_full_blake3_of_prepared_bytes. 86/86 lib tests here, and the three-way merge with #2889/#2891 compiles and passes 89/89.

Two things to tighten:

  1. The fast path trusts (name, size) alone (publish.rs:30-34), so a same-length corruption — bit rot, AV rewrite, interrupted copy, a hand-placed file — is served forever and never healed, unlike the previous byte-compare. Your own test encodes that deliberately (publish.rs:93-98). That is a reasonable trade for the scale win, but it should be stated in the doc comment, or a small hash.ok sidecar written after the rename would restore self-repair.
  2. The safety argument rests on sync_all before rename (publish.rs:59), and deleting that line leaves all 86 tests green. A test hook that asserts the flush happens would pin the one invariant the whole design leans on.

Nit: a crash mid-write leaves .<64hex>.dll.<pid>.<n>.tmp (up to ~200 MB) unreaped — no startup sweep, no age-based reaping. Pre-existing pattern, but this is the cache-hygiene PR, so a stale .*.tmp sweep would close the staging lifecycle.

Merge is clean against current main (the three touched files are byte-identical upstream), and clean paired with #2889 and #2891. CI's red check/linux-python-and-viewer are untouched Python tool tests, not this diff.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6136525145 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2890#pullrequestreview-6136525145). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-01T17:32:29Z. **Review:** COMMENTED --- Content-addressing checks out: the key is `blake3(prepared bytes)` (`prepare.rs:112-118`, `publish.rs:16-18`), so it covers the original image plus any change in `prepare()`, and the `LEONIDA_*` options only patch mapped memory after `LoadLibraryExW` (`windows.rs:90-110`) — correctly not part of the file key. The old 16-hex collision is gone, and I confirmed the mutation that shrinks the key to 16 hex fails `file_name_uses_full_blake3_of_prepared_bytes`. 86/86 lib tests here, and the three-way merge with #2889/#2891 compiles and passes 89/89. Two things to tighten: 1. **The fast path trusts (name, size) alone** (`publish.rs:30-34`), so a same-length corruption — bit rot, AV rewrite, interrupted copy, a hand-placed file — is served forever and never healed, unlike the previous byte-compare. Your own test encodes that deliberately (`publish.rs:93-98`). That is a reasonable trade for the scale win, but it should be stated in the doc comment, or a small `hash.ok` sidecar written after the rename would restore self-repair. 2. **The safety argument rests on `sync_all` before rename** (`publish.rs:59`), and deleting that line leaves all 86 tests green. A test hook that asserts the flush happens would pin the one invariant the whole design leans on. Nit: a crash mid-write leaves `.<64hex>.dll.<pid>.<n>.tmp` (up to ~200 MB) unreaped — no startup sweep, no age-based reaping. Pre-existing pattern, but this is the cache-hygiene PR, so a stale `.*.tmp` sweep would close the staging lifecycle. Merge is clean against current main (the three touched files are byte-identical upstream), and clean paired with #2889 and #2891. CI's red `check`/`linux-python-and-viewer` are untouched Python tool tests, not this diff.
Kal0s-design commented 2026-12-01 17:35:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-12-01T17:35:04Z.


Verified on native Windows 11 (MSVC target, rustc 1.98.1, NTFS), since the runs in the description are under Wine.

Head 262439781 merged with main d2a564b66 (clean merge):

  • cargo test -p leonida-loader --lib: 86 passed, 0 failed, including the three rename_denied_* / staging tests that matter most on Windows.
  • cargo clippy -p leonida-loader --all-targets: no warnings in the loader.

Both new tests catch their change:

  • with the old original_hash[..16] name put back, file_name_uses_full_blake3_of_prepared_bytes fails (left: "leonida-image-4976ea11133df67f.dll");
  • with the m.len() == bytes.len() check removed from the fast path, content_addressed_fast_path_requires_matching_name_and_size fails at publish.rs:103 (the short file is kept).

What the fast path saves here. I timed the two paths on a 114.7 MB file (the size run.rs mentions), release build, file already in the OS cache, three runs:

time
main's write_if_changed (read back + compare) 31-38 ms
write_content_addressed (metadata only) 0.14-0.20 ms
first publish (write + sync_all + rename) 68 ms
the new blake3::hash of the prepared bytes, once per launch 15 ms

So with a warm cache the launch saves about 15-20 ms net, since the new hash costs about half of what the skipped read-back cost. With a cold cache the read-back costs more, so the saving should be larger. I did not measure that.

Two notes, neither blocking:

  1. The fast path trusts any regular file with the right name and length. The test shows this on purpose (the same-length sentinel is kept). sync_all before the rename covers a crash during publish. It does not cover a file changed later by something else, but a hash check would mean reading the file again.
  2. Old images are never removed. main reused one name per title build, so a loader change to prepare() overwrote the old copy. Now each distinct prepared image keeps its own ~115 MB file in images/. prepare.rs has changed twice this month, so it grows slowly. A cleanup of other leonida-image-*.dll files after a successful publish might be worth a follow-up.

Not checked: the game, and a cold-cache launch.

GPUs tested: n/a (CPU and file system tests only).

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7319529720 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2890#issuecomment-7319529720). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-12-01T17:35:04Z. --- Verified on native Windows 11 (MSVC target, rustc 1.98.1, NTFS), since the runs in the description are under Wine. Head `262439781` merged with `main` `d2a564b66` (clean merge): - `cargo test -p leonida-loader --lib`: 86 passed, 0 failed, including the three `rename_denied_*` / staging tests that matter most on Windows. - `cargo clippy -p leonida-loader --all-targets`: no warnings in the loader. Both new tests catch their change: - with the old `original_hash[..16]` name put back, `file_name_uses_full_blake3_of_prepared_bytes` fails (`left: "leonida-image-4976ea11133df67f.dll"`); - with the `m.len() == bytes.len()` check removed from the fast path, `content_addressed_fast_path_requires_matching_name_and_size` fails at `publish.rs:103` (the short file is kept). **What the fast path saves here.** I timed the two paths on a 114.7 MB file (the size `run.rs` mentions), release build, file already in the OS cache, three runs: | | time | |---|---| | `main`'s `write_if_changed` (read back + compare) | 31-38 ms | | `write_content_addressed` (metadata only) | 0.14-0.20 ms | | first publish (write + `sync_all` + rename) | 68 ms | | the new `blake3::hash` of the prepared bytes, once per launch | 15 ms | So with a warm cache the launch saves about 15-20 ms net, since the new hash costs about half of what the skipped read-back cost. With a cold cache the read-back costs more, so the saving should be larger. I did not measure that. Two notes, neither blocking: 1. The fast path trusts any regular file with the right name and length. The test shows this on purpose (the same-length sentinel is kept). `sync_all` before the rename covers a crash during publish. It does not cover a file changed later by something else, but a hash check would mean reading the file again. 2. Old images are never removed. `main` reused one name per title build, so a loader change to `prepare()` overwrote the old copy. Now each distinct prepared image keeps its own ~115 MB file in `images/`. `prepare.rs` has changed twice this month, so it grows slowly. A cleanup of other `leonida-image-*.dll` files after a successful publish might be worth a follow-up. Not checked: the game, and a cold-cache launch. GPUs tested: n/a (CPU and file system tests only). AI-assisted: yes (Claude Code).
MoonEyes commented 2026-12-02 12:30:29 +00:00 (Migrated from github.com)

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


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:7345444023 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2890#issuecomment-7345444023). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T12:30:29Z. --- 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).
MoonEyes commented 2026-12-02 18:03:00 +00:00 (Migrated from github.com)

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


Code review only, not built (leonida-loader's windows.rs path is Windows-only). CI is red, but not because of this change. There is one design concern.

  • Head: 262439781, merge base 3e7b34a52, 493 behind current main 45dc41f95. A trial merge is clean.
  • CI on the head: linux-python-and-viewer and check failed, while d3d12 (windows-latest) passed. The failures are in tests/test_wave_diff.py, test_piecewise_parse.py, test_wave_trace.py and test_x64_recomp*.py, with TypeError: WaveRef._check_vgpr_dst() missing 1 required positional argument: 'dst' from tools/cpu_ref.py. These are Python tools this PR does not touch, so main was broken when the run started (1 December 15:37). On current main 45dc41f95, python3 -I tests/test_wave_diff.py passes here. Rebasing or re-running CI should clear it.
  • Earlier verification by merzleckeier (publication and retry check) and Kal0s-design (native Windows 11) is on this head. MoonEyes asked for an in-game run (12:30), which has not been posted.

Review (prepare.rs, publish.rs, windows.rs):

  • write_staging now calls sync_all before the atomic rename and removes the staging file on a write or sync error. That is an improvement on its own.
  • The file name becomes the full BLAKE3 of the prepared bytes instead of the first 16 hex characters of the original's hash. Prepared bytes depend only on the original, so the same name is produced run after run.
  • Concern: write_content_addressed skips the content check when the name matches and len matches. The test content_addressed_fast_path_requires_matching_name_and_size pins that a same-length different file is kept. That is an executable image the runtime then LoadLibrarys. main re-read the file and rewrote it on any difference, so a damaged or tampered copy healed itself. Now one with the right length persists until the user clears the cache. The saving is one sequential read of an image already in the page cache. I would hash the file on disk (BLAKE3 is fast at hundreds of MB/s), or keep write_if_changed's comparison, rather than trust the name.
  • Old leonida-image-<16 hex>.dll files from earlier builds are left behind in the cache folder. A one-line cleanup or a note would help.

Verdict: blocked-CI (re-run needed; the failure is unrelated). On the code, the fast path should verify content or be dropped before merge.

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


Generated by Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7353893803 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2890#issuecomment-7353893803). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T18:03:00Z. --- **Code review only, not built (`leonida-loader`'s `windows.rs` path is Windows-only). CI is red, but not because of this change. There is one design concern.** - Head: `262439781`, merge base `3e7b34a52`, 493 behind current `main` `45dc41f95`. A trial merge is clean. - **CI on the head:** `linux-python-and-viewer` and `check` failed, while `d3d12 (windows-latest)` passed. The failures are in `tests/test_wave_diff.py`, `test_piecewise_parse.py`, `test_wave_trace.py` and `test_x64_recomp*.py`, with `TypeError: WaveRef._check_vgpr_dst() missing 1 required positional argument: 'dst'` from `tools/cpu_ref.py`. These are Python tools this PR does not touch, so `main` was broken when the run started (1 December 15:37). On current `main` `45dc41f95`, `python3 -I tests/test_wave_diff.py` passes here. Rebasing or re-running CI should clear it. - Earlier verification by merzleckeier (publication and retry check) and Kal0s-design (native Windows 11) is on this head. MoonEyes asked for an in-game run (12:30), which has not been posted. **Review (`prepare.rs`, `publish.rs`, `windows.rs`):** - `write_staging` now calls `sync_all` before the atomic rename and removes the staging file on a write or sync error. That is an improvement on its own. - The file name becomes the full BLAKE3 of the prepared bytes instead of the first 16 hex characters of the original's hash. Prepared bytes depend only on the original, so the same name is produced run after run. - **Concern:** `write_content_addressed` skips the content check when the name matches and `len` matches. The test `content_addressed_fast_path_requires_matching_name_and_size` pins that a same-length different file is kept. That is an executable image the runtime then `LoadLibrary`s. `main` re-read the file and rewrote it on any difference, so a damaged or tampered copy healed itself. Now one with the right length persists until the user clears the cache. The saving is one sequential read of an image already in the page cache. I would hash the file on disk (BLAKE3 is fast at hundreds of MB/s), or keep `write_if_changed`'s comparison, rather than trust the name. - Old `leonida-image-<16 hex>.dll` files from earlier builds are left behind in the cache folder. A one-line cleanup or a note would help. Verdict: **blocked-CI** (re-run needed; the failure is unrelated). On the code, the fast path should verify content or be dropped before merge. AI-assisted verification: Claude Opus (Claude Code), separate agent per batch. --- _Generated by [Claude Code](https://claude.ai/code)_
MoonEyes commented 2026-12-02 21:34:58 +00:00 (Migrated from github.com)

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


RUN (independent run on Windows, head 2624397813775c1cdd7e09154852d776aedacb6a, merged into main b41763227aeed2d23c98af84bcbc1bddc7acdc90 with git merge --no-ff)

The merge was clean (no conflict). The PR changes only d3d12/crates/leonida-loader/src/{prepare,publish,windows}.rs, so the leonida-gpu suite and the diagnostics feature are not touched by it. I ran the loader instead. No Python test is touched.

Green

  • cargo test -p leonida-loader --release --locked --lib on the merge: 92 passed, 0 failed. This includes file_name_uses_full_blake3_of_prepared_bytes and content_addressed_fast_path_requires_matching_name_and_size, plus the existing rename_denied_* and concurrent-publisher tests.
  • cargo check --release --locked -p leonida (the app that calls PreparedImage::file_name() in run.rs): builds, no error.
  • I did not run leonida-gpu: nothing in this change reaches it.

Red

The two new tests only cover prepare.rs and publish.rs, and a straight swap of those files back to main's version does not compile with them (prepared_hash and write_content_addressed do not exist on main), so I used targeted mutations of the new code instead. Each was run alone and reverted.

Mutation Result
file_name() back to the first 16 hex of original_hash killed by file_name_uses_full_blake3_of_prepared_bytes
prepared_hash computed over original instead of the prepared bytes killed by the same test
fast path without the len check killed by content_addressed_fast_path_requires_matching_name_and_size
fast path without the file-name check killed by the same test
sync_all() removed from write_staging SURVIVES (92 passed)
staging file no longer removed when the write or sync fails SURVIVES (92 passed)

So the naming and the fast-path guard are pinned. The two durability properties are not: nothing checks that the flush happens before the rename, nor that the staging file is cleaned up after a failed write. This agrees with the existing review comment about sync_all.

Review

  • Default-off switches: no switch is added, so docs/switches.md does not need regenerating. The change is always on, but it only affects the cache file name and how the cached copy is published, not rendering.
  • Ordering: prepared_hash is computed once at the end of prepare() from the final bytes, and windows.rs::load writes the file before LoadLibraryExW. write_staging syncs before publish_staging renames. Correct as written.
  • Lifetimes and fences: none involved (no GPU object, no fence). Staging names stay unique per process and call, and the concurrent-publisher test still passes.
  • Trust in (name, size): the fast path keeps any regular file with the right name and length, and the test pins that on purpose. A damaged or replaced same-length image is therefore never healed, where main re-read and rewrote it. This is a real behaviour change for an image that is then loaded as code. Three reviewers already raised it (hash on disk, a sidecar, or at least a doc comment). It is not resolved on this head.
  • Old leonida-image-<16hex>.dll files and stale .tmp staging files are never removed, and every distinct prepared image keeps its own copy of roughly 115 MB. Already raised in the thread; a follow-up cleanup is the natural place.
  • Claim: the PR names D3D12-LOADER-CONTENT-ADDRESSED-IMAGE, linked to a comment on issues/2570. I did not re-read the coordination tables.
  • Overlap: a reviewer reports a clean three-way merge with #2889 and #2891 and 89/89 tests. I did not repeat that.
  • Reviewer questions still open: the same-length corruption trade-off (see above) and the unreaped staging files. The author has not replied to either.
  • CI: the earlier red linux-python-and-viewer and check runs come from Python tools this PR does not touch, as noted in the thread (main was broken when the run started). The d3d12 (windows-latest) job passed.
  • In-game runs on this exact head: the description reports a 300 s world run with no device loss, from a Linux, Wine and VKD3D-Proton setup. MoonEyes asked for a run on the current head merged onto current main, with a comparison against main. None is posted for a native Windows run or on the current main.

Not covered

  • No in-game run, no cold-cache launch, no timing of the fast path (a reviewer measured about 15 to 20 ms saved on a warm cache).
  • No power-loss or crash test of the sync_all ordering, and no test for same-length corruption beyond the one that pins keeping it.
  • Python tests and leonida-gpu not run, because the PR does not touch them.
  • The merge with #2889 and #2891 was not re-checked.

Verdict

PARTIAL. The code does what it says and the new tests catch the naming and fast-path changes, but the sync_all ordering is unpinned, the same-length corruption trade-off is still open, and in-game run still required (none posted on this head merged onto current main).

AI-assisted (Claude Code), models: Claude Opus 5.5 (checker), separate Claude Opus 5.5 judge.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7359484542 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2890#issuecomment-7359484542). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-12-02T21:34:58Z. --- RUN (independent run on Windows, head `2624397813775c1cdd7e09154852d776aedacb6a`, merged into `main` `b41763227aeed2d23c98af84bcbc1bddc7acdc90` with `git merge --no-ff`) The merge was clean (no conflict). The PR changes only `d3d12/crates/leonida-loader/src/{prepare,publish,windows}.rs`, so the `leonida-gpu` suite and the diagnostics feature are not touched by it. I ran the loader instead. No Python test is touched. ### Green - `cargo test -p leonida-loader --release --locked --lib` on the merge: 92 passed, 0 failed. This includes `file_name_uses_full_blake3_of_prepared_bytes` and `content_addressed_fast_path_requires_matching_name_and_size`, plus the existing `rename_denied_*` and concurrent-publisher tests. - `cargo check --release --locked -p leonida` (the app that calls `PreparedImage::file_name()` in `run.rs`): builds, no error. - I did not run `leonida-gpu`: nothing in this change reaches it. ### Red The two new tests only cover `prepare.rs` and `publish.rs`, and a straight swap of those files back to `main`'s version does not compile with them (`prepared_hash` and `write_content_addressed` do not exist on `main`), so I used targeted mutations of the new code instead. Each was run alone and reverted. | Mutation | Result | |---|---| | `file_name()` back to the first 16 hex of `original_hash` | killed by `file_name_uses_full_blake3_of_prepared_bytes` | | `prepared_hash` computed over `original` instead of the prepared bytes | killed by the same test | | fast path without the `len` check | killed by `content_addressed_fast_path_requires_matching_name_and_size` | | fast path without the file-name check | killed by the same test | | `sync_all()` removed from `write_staging` | SURVIVES (92 passed) | | staging file no longer removed when the write or sync fails | SURVIVES (92 passed) | So the naming and the fast-path guard are pinned. The two durability properties are not: nothing checks that the flush happens before the rename, nor that the staging file is cleaned up after a failed write. This agrees with the existing review comment about `sync_all`. ### Review - Default-off switches: no switch is added, so `docs/switches.md` does not need regenerating. The change is always on, but it only affects the cache file name and how the cached copy is published, not rendering. - Ordering: `prepared_hash` is computed once at the end of `prepare()` from the final bytes, and `windows.rs::load` writes the file before `LoadLibraryExW`. `write_staging` syncs before `publish_staging` renames. Correct as written. - Lifetimes and fences: none involved (no GPU object, no fence). Staging names stay unique per process and call, and the concurrent-publisher test still passes. - Trust in (name, size): the fast path keeps any regular file with the right name and length, and the test pins that on purpose. A damaged or replaced same-length image is therefore never healed, where `main` re-read and rewrote it. This is a real behaviour change for an image that is then loaded as code. Three reviewers already raised it (hash on disk, a sidecar, or at least a doc comment). It is not resolved on this head. - Old `leonida-image-<16hex>.dll` files and stale `.tmp` staging files are never removed, and every distinct prepared image keeps its own copy of roughly 115 MB. Already raised in the thread; a follow-up cleanup is the natural place. - Claim: the PR names `D3D12-LOADER-CONTENT-ADDRESSED-IMAGE`, linked to a comment on issues/2570. I did not re-read the coordination tables. - Overlap: a reviewer reports a clean three-way merge with #2889 and #2891 and 89/89 tests. I did not repeat that. - Reviewer questions still open: the same-length corruption trade-off (see above) and the unreaped staging files. The author has not replied to either. - CI: the earlier red `linux-python-and-viewer` and `check` runs come from Python tools this PR does not touch, as noted in the thread (`main` was broken when the run started). The `d3d12 (windows-latest)` job passed. - In-game runs on this exact head: the description reports a 300 s world run with no device loss, from a Linux, Wine and VKD3D-Proton setup. MoonEyes asked for a run on the current head merged onto current `main`, with a comparison against `main`. None is posted for a native Windows run or on the current `main`. ### Not covered - No in-game run, no cold-cache launch, no timing of the fast path (a reviewer measured about 15 to 20 ms saved on a warm cache). - No power-loss or crash test of the `sync_all` ordering, and no test for same-length corruption beyond the one that pins keeping it. - Python tests and `leonida-gpu` not run, because the PR does not touch them. - The merge with #2889 and #2891 was not re-checked. ### Verdict PARTIAL. The code does what it says and the new tests catch the naming and fast-path changes, but the `sync_all` ordering is unpinned, the same-length corruption trade-off is still open, and in-game run still required (none posted on this head merged onto current `main`). AI-assisted (Claude Code), models: Claude Opus 5.5 (checker), separate Claude Opus 5.5 judge.
enlight3d commented 2026-12-03 00:54:32 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by enlight3d on 2026-12-03T00:54:32Z.


RUN (in game, gate-style): head 262439781 tested in a batch of nine pull requests: #2609 (3fbcacc4e), #2654 (f4ae7b922), #2686 (4ce795127), #2823 (854796496), #2841 (24ff8f24c), #2890 (262439781), #3154 (854fc3441), #2588 (598930e5b) and #3119 (6097c033c), merged in that order with git merge --no-ff onto main f3865cae8. One conflict, in the credit table of d3d12/README.md when #2588 went in (both rows kept); no code conflict. Files touched by more than one of the nine: d3d12/docs/switches.md (#2686, #3119, #3154) and d3d12/README.md (#2588, #3119). Built with diagnostics,mimalloc, target x86_64-pc-windows-msvc. RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro (build 26300).

Launcher defaults except -PrecompileUsed, Series S settings, -NoDlss -NoFrameGen, standing at the save. On this main the launcher precompiles every recorded pipeline by default (88,671 here: a first warm-up with the plain defaults had made 9,000 of them after 660 s when it was stopped), so the runs use -PrecompileUsed (the 2,455 pipelines earlier runs drew with). A warm-up run first (#2686 changes the translator, so everything was translated again), then one run with the memory safety stop, ended 330 s after reaching the world:

Reached the world 75 s
Time in the world 331 s
Device losses 0
Crashes 0
Frame median 35.0 ms (28.2 fps rendered)
Card busy 85 %
Private memory, max 28.1 GB

Warnings: only kinds that a run on the same main with another pull request (#3128) printed too, in about the same numbers; no new kind. No pipeline refused other than the 29 "creation method that is not implemented" lines that run has as well. The last frame saved (8192) shows the world drawn normally.

This pull request's own lines: the prepared images are now named by their full content hash: the six images mapped in the run all have 64-hex names (leonida-image-<64 hex>.dll), beside the 16-hex names an older build had left in the copied data folder. With shaders and pipelines already made, the game process started 12 s after the launcher.

Verdict: PASS for the batch (a pass covers each of the nine; a failure would not have said which). Not covered here: -RayTracing, DLSS and frame generation, other GPUs, Wine/Proton.

AI-assisted: Claude Code (Claude Opus 5.5)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7363731697 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2890#issuecomment-7363731697). Originally posted by [enlight3d](https://github.com/enlight3d) on 2026-12-03T00:54:32Z. --- RUN (in game, gate-style): head 262439781 tested **in a batch** of nine pull requests: #2609 (3fbcacc4e), #2654 (f4ae7b922), #2686 (4ce795127), #2823 (854796496), #2841 (24ff8f24c), #2890 (262439781), #3154 (854fc3441), #2588 (598930e5b) and #3119 (6097c033c), merged in that order with `git merge --no-ff` onto `main` f3865cae8. One conflict, in the credit table of `d3d12/README.md` when #2588 went in (both rows kept); no code conflict. Files touched by more than one of the nine: `d3d12/docs/switches.md` (#2686, #3119, #3154) and `d3d12/README.md` (#2588, #3119). Built with `diagnostics,mimalloc`, target `x86_64-pc-windows-msvc`. RTX 3090 24 GB, NVIDIA 621.40, Windows 11 Pro (build 26300). Launcher defaults except `-PrecompileUsed`, Series S settings, `-NoDlss -NoFrameGen`, standing at the save. On this `main` the launcher precompiles every recorded pipeline by default (88,671 here: a first warm-up with the plain defaults had made 9,000 of them after 660 s when it was stopped), so the runs use `-PrecompileUsed` (the 2,455 pipelines earlier runs drew with). A warm-up run first (#2686 changes the translator, so everything was translated again), then one run with the memory safety stop, ended 330 s after reaching the world: | | | |---|---| | Reached the world | 75 s | | Time in the world | 331 s | | Device losses | 0 | | Crashes | 0 | | Frame median | 35.0 ms (28.2 fps rendered) | | Card busy | 85 % | | Private memory, max | 28.1 GB | Warnings: only kinds that a run on the same `main` with another pull request (#3128) printed too, in about the same numbers; no new kind. No pipeline refused other than the 29 "creation method that is not implemented" lines that run has as well. The last frame saved (8192) shows the world drawn normally. This pull request's own lines: the prepared images are now named by their full content hash: the six images mapped in the run all have 64-hex names (`leonida-image-<64 hex>.dll`), beside the 16-hex names an older build had left in the copied data folder. With shaders and pipelines already made, the game process started 12 s after the launcher. Verdict: **PASS** for the batch (a pass covers each of the nine; a failure would not have said which). Not covered here: `-RayTracing`, DLSS and frame generation, other GPUs, Wine/Proton. AI-assisted: Claude Code (Claude Opus 5.5)
fiestorra commented 2026-12-03 03:56:40 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by fiestorra on 2026-12-03T03:56:40Z.


VERIFY-2890 — leonida-loader en verde, y el cambio es de los que se pueden contar

Tres ficheros, prepare.rs +22, publish.rs +66, windows.rs −6, cinco días abierto:

cargo test -p leonida-loader --lib     86 passed; 0 failed

El cambio, por su título: direcciona por contenido el PreparedImage con un hash cacheado y prepara el staging de forma sincronizada — dos cosas que en un caché van juntas: la clave (hash) y la escritura (staging). Un cache keyed by content without a synchronised write produces the classic race, y el windows.rs que pierde seis líneas sugiere que la sincronización estaba en otro sitio y se movió al que corresponde.

Lo que verifiqué: 86 tests del crate en su head, y que el diff toca tres ficheros con el mismo tema.

Lo que no: la carrera de verdad — un test de concurrencia en un caché de ficheros necesita dos procesos peleando por el mismo directorio, y un #[test] no lo hace. Si el autor tiene un test que lanza dos hilos contra el mismo publish, es el que importa y está en los 86; si no lo tiene, esto es un cambio de plomería verificado por su forma y no por su comportamiento.

Y la pregunta que le haría, en una línea: si el hash cacheado se invalida cuando el PreparedImage cambia en sitio — porque un hash que se guarda y no se recalcula es un caché que devuelve la imagen anterior, que es peor que el que no cachea.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7367099107 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2890#issuecomment-7367099107). Originally posted by [fiestorra](https://github.com/fiestorra) on 2026-12-03T03:56:40Z. --- ## VERIFY-2890 — `leonida-loader` en verde, y el cambio es de los que se pueden contar **Tres ficheros, `prepare.rs` +22, `publish.rs` +66, `windows.rs` −6, cinco días abierto**: ``` cargo test -p leonida-loader --lib 86 passed; 0 failed ``` **El cambio, por su título**: **direcciona por contenido el `PreparedImage` con un hash cacheado y prepara el *staging* de forma sincronizada** — **dos cosas que en un caché van juntas**: **la clave (hash) y la escritura (staging).** **Un cache keyed by content without a synchronised write produces the classic race**, **y el `windows.rs` que pierde seis líneas sugiere que la sincronización estaba en otro sitio y se movió al que corresponde.** **Lo que verifiqué**: **86 tests del crate en su head**, **y que el diff toca tres ficheros con el mismo tema**. **Lo que no**: **la carrera de verdad** — **un test de concurrencia en un caché de ficheros necesita dos procesos peleando por el mismo directorio, y un `#[test]` no lo hace.** **Si el autor tiene un test que lanza dos hilos contra el mismo `publish`, es el que importa y está en los 86; si no lo tiene, esto es un cambio de plomería verificado por su forma y no por su comportamiento.** **Y la pregunta que le haría, en una línea**: **si el hash cacheado se invalida cuando el `PreparedImage` cambia en sitio** — **porque un hash que se guarda y no se recalcula es un caché que devuelve la imagen anterior**, **que es peor que el que no cachea.**
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/2890:upstream-pr/2890'
git switch 'upstream-pr/2890'

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