DirectStorage: report queue read failures #624

Closed
broccolize wants to merge 3 commits from upstream-pr/624 into main
broccolize commented 2026-11-24 05:48:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by broccolize on 2026-11-24T05:48:53Z.


Implement GetErrorEvent and RetrieveErrorRecord for DirectStorage queues. Each queue signals its own error event and gives callers a handle they can close independently. Retrieval returns the first failed read in enqueue order and the failure count since the previous retrieval, then clears the record and resets the event.

Synthetic Windows tests cover two failed reads, a successful read, out-of-order worker completion, and a status entry submitted after error retrieval. All 15 DirectStorage tests passed with and without diagnostics.

The Windows GNU workspace run passed 265 tests with four ignored. It excluded loads_binds_and_calls_probe because of a toolchain failure reproducible on main. Asset-policy checks passed.

Related to #577, which touches file lifetime in the same worker path. AI-assisted with Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6575546535 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/624). Originally posted by [broccolize](https://github.com/broccolize) on 2026-11-24T05:48:53Z. --- Implement `GetErrorEvent` and `RetrieveErrorRecord` for DirectStorage queues. Each queue signals its own error event and gives callers a handle they can close independently. Retrieval returns the first failed read in enqueue order and the failure count since the previous retrieval, then clears the record and resets the event. Synthetic Windows tests cover two failed reads, a successful read, out-of-order worker completion, and a status entry submitted after error retrieval. All 15 DirectStorage tests passed with and without diagnostics. The Windows GNU workspace run passed 265 tests with four ignored. It excluded `loads_binds_and_calls_probe` because of a toolchain failure reproducible on `main`. Asset-policy checks passed. Related to #577, which touches file lifetime in the same worker path. AI-assisted with Codex.
LAKSHYA-cmd-tech commented 2026-11-24 06:54:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T05:59:25Z.

Review: APPROVED


Tested on Windows 11 with Rust 1.98.1 (x86_64-pc-windows-msvc).

  • cargo test -p victory-hle: all 88 tests in ictory_hle and integration test
    o_dll_planting passed cleanly.
  • queue_reports_and_retrieves_read_errors and error_event_reports_failures_in_enqueue_order_without_status_entries both passed.
  • cargo xtask policy: 152 files ok.
  • Verified GetErrorEvent and RetrieveErrorRecord DirectStorage queue semantics and binary layout alignment checks.
<!-- greyfinch-sync:Marvisak/VIctory:review:6034410413 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/624#pullrequestreview-6034410413). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T05:59:25Z. **Review:** APPROVED --- Tested on Windows 11 with Rust 1.98.1 (x86_64-pc-windows-msvc). - cargo test -p victory-hle: all 88 tests in ictory_hle and integration test o_dll_planting passed cleanly. - queue_reports_and_retrieves_read_errors and error_event_reports_failures_in_enqueue_order_without_status_entries both passed. - cargo xtask policy: 152 files ok. - Verified GetErrorEvent and RetrieveErrorRecord DirectStorage queue semantics and binary layout alignment checks.
mercuryVM commented 2026-11-24 12:04:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T11:15:59Z.

Review: APPROVED


Tested 8632869 on Windows 11, RTX 5070, MSVC: cargo test -p victory-hle 89 passed, including the 15 DirectStorage tests (two new error-record ones). Clippy's 1 warning is the existing field_reassign_with_default at xmem.rs:747.

  • Ordering: failures are deferred by sequence number and published only up to the next status entry (publish_before). So the first record is the first failed read in enqueue order, even when workers finish out of order, which is what RetrieveErrorRecord documents.
  • GetErrorEvent hands out a duplicated handle, so a title that closes its copy can't close the queue's event. take resets the event together with clearing the record.
  • ReadFailure::new copies request.name when the read fails, on the worker thread. That relies on the title keeping the name valid until the request completes, which is the documented DSTORAGE_REQUEST::Name contract, so it's fine. A one-line comment there would help the next reader.
  • Lane::new failing on CreateEventW now fails CreateQueue with the HRESULT instead of panicking later. Good.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6038226036 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/624#pullrequestreview-6038226036). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T11:15:59Z. **Review:** APPROVED --- Tested 8632869 on Windows 11, RTX 5070, MSVC: `cargo test -p victory-hle` 89 passed, including the 15 DirectStorage tests (two new error-record ones). Clippy's 1 warning is the existing `field_reassign_with_default` at xmem.rs:747. - Ordering: failures are deferred by sequence number and published only up to the next status entry (`publish_before`). So the first record is the first failed read in enqueue order, even when workers finish out of order, which is what `RetrieveErrorRecord` documents. - `GetErrorEvent` hands out a duplicated handle, so a title that closes its copy can't close the queue's event. `take` resets the event together with clearing the record. - `ReadFailure::new` copies `request.name` when the read fails, on the worker thread. That relies on the title keeping the name valid until the request completes, which is the documented `DSTORAGE_REQUEST::Name` contract, so it's fine. A one-line comment there would help the next reader. - `Lane::new` failing on `CreateEventW` now fails `CreateQueue` with the HRESULT instead of panicking later. Good. AI-assisted (Claude Code).
geiyiliyabumo commented 2026-11-24 13:02:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T12:19:31Z.


Independent verification & code review on Windows 11 x64 MSVC (merged onto main ffe310e):

Checks Run

  • cargo xtask policy: PASS (155 files ok)
  • cargo clippy -p victory-hle --all-targets --locked -- -D warnings (default + --features diagnostics): PASS (0 warnings)
  • cargo test -p victory-hle --locked -- dstorage: PASS (15/15 tests, including queue_reports_and_retrieves_read_errors and error_event_reports_failures_in_enqueue_order_without_status_entries)

Review Findings

The ABI layout assertions for ErrorRecord (0x290) and ReadFailure, enqueue-ordered publish_before deferral, caller-owned duplicated event handles, and out.is_null() guards look very clean.

One safety edge case to tighten before merge:

  1. ReadFailure::new dereferences request.source as Instance<File> on unsupported-option failures (crates/victory-hle/src/modules/dstorage/errors.rs:92-102):
    • execute() rejects unsupported option bits with E_NOTIMPL before touching request.source (dstorage.rs:843) — including bit 23 (physical-pages source, documented at dstorage.rs:691), where request.source points to a page-number array rather than an Instance<File> COM object.
    • Because work() immediately calls ReadFailure::new(&job.request, hr) on that Err(E_NOTIMPL), and ReadFailure::new checks only request.options & MEMORY_SOURCE != 0, a bit-23 request enters the else branch and casts request.source to &Instance<File> to copy file.state.filename (Box<[u16]>), which is UB / an access violation on a non-File pointer.
    • Fix: Only treat request.source as Instance<File> when no unsupported option bits are set (or at minimum when bit 23 is clear) in addition to request.options & MEMORY_SOURCE == 0.
  2. (Minor semantic note) QueueErrors::new creates an auto-reset event (bManualReset = 0), while take() also calls ResetEvent. If a title polls WaitForSingleObject(event, 0) more than once before calling RetrieveErrorRecord (or duplicates the handle across watchers), auto-reset consumes the signal on the first wait; a manual-reset event (bManualReset = 1) stays signaled until RetrieveErrorRecord resets it (if matching the Win32 DirectStorage contract is preferred).

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7131279841 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/624#issuecomment-7131279841). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T12:19:31Z. --- Independent verification & code review on Windows 11 x64 MSVC (merged onto `main` `ffe310e`): ### Checks Run - `cargo xtask policy`: **PASS** (`155 files ok`) - `cargo clippy -p victory-hle --all-targets --locked -- -D warnings` (default + `--features diagnostics`): **PASS** (0 warnings) - `cargo test -p victory-hle --locked -- dstorage`: **PASS** (`15/15` tests, including `queue_reports_and_retrieves_read_errors` and `error_event_reports_failures_in_enqueue_order_without_status_entries`) ### Review Findings The ABI layout assertions for `ErrorRecord` (`0x290`) and `ReadFailure`, enqueue-ordered `publish_before` deferral, caller-owned duplicated event handles, and `out.is_null()` guards look very clean. One safety edge case to tighten before merge: 1. **`ReadFailure::new` dereferences `request.source` as `Instance<File>` on unsupported-option failures (`crates/victory-hle/src/modules/dstorage/errors.rs:92-102`)**: - `execute()` rejects unsupported option bits with `E_NOTIMPL` before touching `request.source` (`dstorage.rs:843`) — including **bit 23** (physical-pages source, documented at `dstorage.rs:691`), where `request.source` points to a page-number array rather than an `Instance<File>` COM object. - Because `work()` immediately calls `ReadFailure::new(&job.request, hr)` on that `Err(E_NOTIMPL)`, and `ReadFailure::new` checks only `request.options & MEMORY_SOURCE != 0`, a bit-23 request enters the `else` branch and casts `request.source` to `&Instance<File>` to copy `file.state.filename` (`Box<[u16]>`), which is UB / an access violation on a non-`File` pointer. - **Fix**: Only treat `request.source` as `Instance<File>` when no unsupported option bits are set (or at minimum when bit 23 is clear) in addition to `request.options & MEMORY_SOURCE == 0`. 2. *(Minor semantic note)* `QueueErrors::new` creates an **auto-reset** event (`bManualReset = 0`), while `take()` also calls `ResetEvent`. If a title polls `WaitForSingleObject(event, 0)` more than once before calling `RetrieveErrorRecord` (or duplicates the handle across watchers), auto-reset consumes the signal on the first wait; a manual-reset event (`bManualReset = 1`) stays signaled until `RetrieveErrorRecord` resets it (if matching the Win32 DirectStorage contract is preferred). *AI-assisted; synthetic tests only, no game files.*
upstream-sync closed this pull request 2026-11-25 01:04:31 +00:00
Marvisak commented 2026-11-25 01:07:48 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T00:26:22Z.


Automated triage for the maintainers. Closing because it breaks a repository rule (see docs/asset-policy.md and the project rules): nothing taken from the console SDK or the game, no weakening of the asset policy, and the title stays offline.

If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7148510587 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/624#issuecomment-7148510587). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T00:26:22Z. --- Automated triage for the maintainers. Closing because it breaks a repository rule (see `docs/asset-policy.md` and the project rules): nothing taken from the console SDK or the game, no weakening of the asset policy, and the title stays offline. If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
broccolize commented 2026-11-25 04:07:02 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by broccolize on 2026-11-25T03:43:53Z.


Thanks for reviewing. The diff is limited to two Rust source files for DirectStorage error reporting and synthetic tests. I checked the ABI locally against Microsoft's public documentation and public Xbox compatibility sample. The verification probe was kept local.

Could you point me to the file or line that triggered the policy closure so I can address it?

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152189391 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/624#issuecomment-7152189391). Originally posted by [broccolize](https://github.com/broccolize) on 2026-11-25T03:43:53Z. --- Thanks for reviewing. The diff is limited to two Rust source files for DirectStorage error reporting and synthetic tests. I checked the ABI locally against Microsoft's public documentation and public Xbox compatibility sample. The verification probe was kept local. Could you point me to the file or line that triggered the policy closure so I can address it?

Pull request closed

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
Marvisak/VIctory!624
No description provided.