fix(victory): carry DirectStorage page-array snapshots per request to prevent leaks and stale-wait desync #293

Closed
github-bot wants to merge 2 commits from github-bot/gh-293 into main AGit
Owner

@⁠mauroalvare on GitHub · 2026-11-26 01:29 UTC · original
mauroalvare:fix/victory-dstorage-enqueued-pages → main · +129 −41 · 1 files · 2 commits · closed without merging

## Change

In third_party/victory/crates/victory-hle/src/modules/dstorage.rs, enqueue_request snapshotted PAGE_DESTINATION page arrays into a global HashMap<usize, VecDeque<Vec<usize>>> (ENQUEUED) keyed by array address, and only popped an entry inside filled() (called from into_destination()).

Whenever a PAGE_DESTINATION request never reached into_destination() — for example:

  • enqueued on a queue that was already closed or closed before submission (close_lane clears unsubmitted and reads), or
  • failed before into_destination() (such as END_OF_FILE / read_source failure, E_INVALIDARG, E_NOTIMPL, or a zlib stage before BCPack) —

its snapshot stayed at the head of ENQUEUED[array] indefinitely:

  1. Leaking the snapshot Vec<usize> in ENQUEUED.
  2. Permanently shifting ENQUEUED[array] by +1 for every subsequent request reusing that page-array slot. When a later request is enqueued while the slot still holds stale page numbers from its last run and the title fills the new page numbers asynchronously after enqueue, filled() pops the mismatched stale snapshot from the failed/closed request, skips the stale-array wait, and silently overwrites the previous texture/model's physical pages instead of the new destination pages.

This change removes the global ENQUEUED map and carries each request's Option<Vec<usize>> enqueue-time snapshot directly on Command::Read, Lane::reads, and Job, passing it through execute() → into_destination() → filled(). Closed/failed requests drop their snapshot automatically, stale-array detection stays synchronized per request, and global ENQUEUED mutex contention is eliminated.

Verification

Base SHA: c4c93bdc413191a9dc909998d2d53080a3f0c880
Host: Windows x64, Ryzen 7 9700X, RTX 5070 Ti, Rust 1.98.1.

Commands run from third_party/victory:

cargo test --locked -p victory-hle --lib modules::dstorage::tests::failed_or_closed_page_requests_do_not_desync_late_page_array_wait -- --exact --nocapture  → 1 passed; 0 failed (0.01s)
cargo test --locked -p victory-hle --lib modules::dstorage::tests                                                                                            → 16 passed; 0 failed (0.11s)
cargo test --locked -p victory-hle --lib                                                                                                                     → 111 passed; 0 failed (1.72s)
cargo clippy --locked -p victory-hle --tests                                                                                                                 → 0 warnings in dstorage.rs
cargo xtask policy                                                                                                                                           → asset policy: 199 files ok

Note: Python tests (pytest / ruff) were not modified because this PR only touches third_party/victory.

Oracle and test data

  • Synthetic physical-page streaming test (modules::dstorage::tests::failed_or_closed_page_requests_do_not_desync_late_page_array_wait) built from xmem::XMemAllocatePhysicalPages and a temporary file.
  • Exact failure on base (c4c93bd): fails with stale page 'pages_a' must not be overwritten (left: [192, 199, 206, ...], right: [0, 7, 14, ...]), confirming the later request popped a stale snapshot from the closed/failed requests and silently overwrote pages_a instead of waiting for pages_c.

Checklist

  • The PR covers a single reviewable behaviour.
  • A test fails without this change and passes with it.
  • The commands and results of each check are given above.
  • An unimplemented function returns an error (E_NOTIMPL), never a fake success.
  • README: no test count hundred crossed / no README change needed.
  • No game, console or SDK file, no key, no dump, no download link.
  • Findings drawn from a title: none (synthetic physical-page DirectStorage test).
  • Code taken from another project: none.

Made with AI assistance (Antigravity / Gemini).

**@⁠mauroalvare** on GitHub · 2026-11-26 01:29 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/293) `mauroalvare:fix/victory-dstorage-enqueued-pages` → `main` · +129 −41 · 1 files · 2 commits · closed without merging ## Change In `third_party/victory/crates/victory-hle/src/modules/dstorage.rs`, `enqueue_request` snapshotted `PAGE_DESTINATION` page arrays into a global `HashMap<usize, VecDeque<Vec<usize>>>` (`ENQUEUED`) keyed by array address, and only popped an entry inside `filled()` (called from `into_destination()`). Whenever a `PAGE_DESTINATION` request never reached `into_destination()` — for example: - enqueued on a queue that was already closed or closed before submission (`close_lane` clears `unsubmitted` and `reads`), or - failed before `into_destination()` (such as `END_OF_FILE` / `read_source` failure, `E_INVALIDARG`, `E_NOTIMPL`, or a zlib stage before BCPack) — its snapshot stayed at the head of `ENQUEUED[array]` indefinitely: 1. Leaking the snapshot `Vec<usize>` in `ENQUEUED`. 2. Permanently shifting `ENQUEUED[array]` by +1 for every subsequent request reusing that page-array slot. When a later request is enqueued while the slot still holds stale page numbers from its last run and the title fills the new page numbers asynchronously after enqueue, `filled()` pops the mismatched stale snapshot from the failed/closed request, skips the stale-array wait, and silently overwrites the previous texture/model's physical pages instead of the new destination pages. This change removes the global `ENQUEUED` map and carries each request's `Option<Vec<usize>>` enqueue-time snapshot directly on `Command::Read`, `Lane::reads`, and `Job`, passing it through `execute()` → `into_destination()` → `filled()`. Closed/failed requests drop their snapshot automatically, stale-array detection stays synchronized per request, and global `ENQUEUED` mutex contention is eliminated. ## Verification Base SHA: `c4c93bdc413191a9dc909998d2d53080a3f0c880` Host: Windows x64, Ryzen 7 9700X, RTX 5070 Ti, Rust `1.98.1`. Commands run from `third_party/victory`: ``` cargo test --locked -p victory-hle --lib modules::dstorage::tests::failed_or_closed_page_requests_do_not_desync_late_page_array_wait -- --exact --nocapture → 1 passed; 0 failed (0.01s) cargo test --locked -p victory-hle --lib modules::dstorage::tests → 16 passed; 0 failed (0.11s) cargo test --locked -p victory-hle --lib → 111 passed; 0 failed (1.72s) cargo clippy --locked -p victory-hle --tests → 0 warnings in dstorage.rs cargo xtask policy → asset policy: 199 files ok ``` Note: Python tests (`pytest` / `ruff`) were not modified because this PR only touches `third_party/victory`. ## Oracle and test data - Synthetic physical-page streaming test (`modules::dstorage::tests::failed_or_closed_page_requests_do_not_desync_late_page_array_wait`) built from `xmem::XMemAllocatePhysicalPages` and a temporary file. - Exact failure on base (`c4c93bd`): fails with `stale page 'pages_a' must not be overwritten` (`left: [192, 199, 206, ...]`, `right: [0, 7, 14, ...]`), confirming the later request popped a stale snapshot from the closed/failed requests and silently overwrote `pages_a` instead of waiting for `pages_c`. ## Checklist - [x] The PR covers a single reviewable behaviour. - [x] A test fails without this change and passes with it. - [x] The commands and results of each check are given above. - [x] An unimplemented function returns an error (`E_NOTIMPL`), never a fake success. - [x] README: no test count hundred crossed / no README change needed. - [x] No game, console or SDK file, no key, no dump, no download link. - [x] Findings drawn from a title: none (synthetic physical-page DirectStorage test). - [x] Code taken from another project: none. Made with AI assistance (Antigravity / Gemini).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:42:12 +00:00
github-bot closed this pull request 2026-11-27 00:37:03 +00:00
Author
Owner

@⁠mauroalvare on GitHub · 2026-11-26 23:31 UTC · original

Closing after #454. The Neptune fix moved snapshots out of a global queue keyed by page-list address so that a failed or closed request could not leave snapshots for the next request. Vice-Tay has no such queue. It keeps trace information on the request itself and reads the current physical page list when the request runs. The 18 runnable DirectStorage tests passed on the new base.

**@⁠mauroalvare** on GitHub · 2026-11-26 23:31 UTC · [original](https://github.com/LooperSalty/AnyXboxX/pull/293#issuecomment-7205614257) Closing after #454. The Neptune fix moved snapshots out of a global queue keyed by page-list address so that a failed or closed request could not leave snapshots for the next request. Vice-Tay has no such queue. It keeps trace information on the request itself and reads the current physical page list when the request runs. The 18 runnable DirectStorage tests passed on the new base.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.