DirectStorage: complete work when a queue worker cannot start #2502

Open
github-bot wants to merge 1 commit from github-bot/gh-2502 into main AGit
Owner

@⁠jeroenhaentjens on GitHub · 2026-11-25 20:54 UTC · original
jeroenhaentjens:dstorage/complete-failed-submissions → main · +361 −22 · 2 files · 1 commits · draft

When Windows cannot start a DirectStorage queue worker, Submit drops its batch, leaving status slots pending and losing fence notifications. This change records a permanent worker-start failure separately from Close: accepted requests fail without executing reads, status entries receive the first error in their interval, and fences complete in order. Later submissions use the same failure path instead of silently disappearing.

What is in it

  • dstorage.rs: one failure drainer preserves FIFO order and status intervals across submissions. Re-entrant submissions queue behind it; entries enqueued without Submit stay pending. Notification callbacks run outside queue locks with an owned queue reference, and concurrent Close waits for retirement.
  • Three deterministic tests cover Windows error translation, cancellation, error events, later submissions, interval errors after error-record retrieval, fence ownership, re-entrant submission/final COM release, and concurrent enqueue/close.
  • README documents the failed-but-open queue lifetime. Addresses Oliwettoo's review.

Tested

  • Windows 11 Pro (26200), Intel i7-9750H / 32 GB, NVIDIA Quadro RTX 3000 6 GB (597.06), Rust 1.100.0 MSVC, DXC 1.9.2609.5; debug/unoptimized, incremental and debug info disabled, XCL_ADAPTER=nvidia.
  • Clean committed head ca341274fd526c87c864731bd37868df1a17a350, rebased onto main e1d84b7d9153f86a97d2ec5d209d196046fc0bea: cargo build --workspace --locked succeeded; cargo test --workspace --locked --no-fail-fast -- --test-threads=4 exited 0: 1,426 reported passes, 0 failures, 46 ignored across 37 completed suites.
  • The full run emitted 29 SKIPPED records: 21 unavailable native-wave64 cases; 3 refused per-lane FP16/conversion cases; 1 driver-cache-control case; 2 title/debug-layer cases; 1 unavailable heap-window case; 1 texture-state/debug-layer case. Reported passes include skipped cases; these are not coverage. Unset game sample inputs are not game coverage either.
  • During iteration, cargo test --locked -p xcl --lib hle::dstorage:: -- --test-threads=4 --nocapture: 34 passed, 0 failed / ignored / explicit skips. All 34 also passed in the clean-head full run.
  • Review negative control: on published 6950978, the revised later-submission regression (cargo test --locked -p xcl --lib a_failed_worker_start_completes_requests_statuses_and_fences -- --test-threads=4 --nocapture) failed: a later enqueued status returned S_OK instead of E_PENDING. The fixed test verifies the eventual failure HRESULT and fence 99 completion. The original main negative control also failed with an initially submitted status left incomplete.
  • git diff --check passed. Two independent subagents reviewed FIFO/Submit boundaries, queue lifetime, and concurrent Close ordering.

Regression run
Not run: no suitable game package is available. This runtime change remains draft pending paired main/head scripts/smoke.ps1 runs.

Not tested

  • No retail title, AMD adapter, or real OS resource exhaustion. Startup failures are injected through the same error branch used by thread::Builder::spawn.
  • This is not evidence that worker startup caused any reported retail world-load stall. Worker/channel failure after successful startup and Close re-entered from its own notification callback are outside this change.

AI use

  • OpenAI Codex, GPT-6 (exact deployment variant unavailable), with subagents: wrote the fix and tests, reviewed concurrency/lifetime handling, and ran the reported checks.
**@⁠jeroenhaentjens** on GitHub · 2026-11-25 20:54 UTC · [original](https://github.com/xcl-dev/xcl/pull/2502) `jeroenhaentjens:dstorage/complete-failed-submissions` → `main` · +361 −22 · 2 files · 1 commits · draft When Windows cannot start a DirectStorage queue worker, `Submit` drops its batch, leaving status slots pending and losing fence notifications. This change records a permanent worker-start failure separately from `Close`: accepted requests fail without executing reads, status entries receive the first error in their interval, and fences complete in order. Later submissions use the same failure path instead of silently disappearing. **What is in it** - `dstorage.rs`: one failure drainer preserves FIFO order and status intervals across submissions. Re-entrant submissions queue behind it; entries enqueued without `Submit` stay pending. Notification callbacks run outside queue locks with an owned queue reference, and concurrent `Close` waits for retirement. - Three deterministic tests cover Windows error translation, cancellation, error events, later submissions, interval errors after error-record retrieval, fence ownership, re-entrant submission/final COM release, and concurrent enqueue/close. - README documents the failed-but-open queue lifetime. Addresses [Oliwettoo's review](https://git.gtahub.st/github/xcl-dev--xcl/pulls/2502). **Tested** - Windows 11 Pro (26200), Intel i7-9750H / 32 GB, NVIDIA Quadro RTX 3000 6 GB (597.06), Rust 1.100.0 MSVC, DXC 1.9.2609.5; debug/unoptimized, incremental and debug info disabled, `XCL_ADAPTER=nvidia`. - Clean committed head `ca341274fd526c87c864731bd37868df1a17a350`, rebased onto main `e1d84b7d9153f86a97d2ec5d209d196046fc0bea`: `cargo build --workspace --locked` succeeded; `cargo test --workspace --locked --no-fail-fast -- --test-threads=4` exited 0: 1,426 reported passes, 0 failures, 46 ignored across 37 completed suites. - The full run emitted 29 `SKIPPED` records: 21 unavailable native-wave64 cases; 3 refused per-lane FP16/conversion cases; 1 driver-cache-control case; 2 title/debug-layer cases; 1 unavailable heap-window case; 1 texture-state/debug-layer case. Reported passes include skipped cases; these are not coverage. Unset game sample inputs are not game coverage either. - During iteration, `cargo test --locked -p xcl --lib hle::dstorage:: -- --test-threads=4 --nocapture`: 34 passed, 0 failed / ignored / explicit skips. All 34 also passed in the clean-head full run. - Review negative control: on published `6950978`, the revised later-submission regression (`cargo test --locked -p xcl --lib a_failed_worker_start_completes_requests_statuses_and_fences -- --test-threads=4 --nocapture`) failed: a later enqueued status returned `S_OK` instead of `E_PENDING`. The fixed test verifies the eventual failure HRESULT and fence 99 completion. The original main negative control also failed with an initially submitted status left incomplete. - `git diff --check` passed. Two independent subagents reviewed FIFO/Submit boundaries, queue lifetime, and concurrent Close ordering. **Regression run** Not run: no suitable game package is available. This runtime change remains draft pending paired main/head `scripts/smoke.ps1` runs. **Not tested** - No retail title, AMD adapter, or real OS resource exhaustion. Startup failures are injected through the same error branch used by `thread::Builder::spawn`. - This is not evidence that worker startup caused any reported retail world-load stall. Worker/channel failure after successful startup and `Close` re-entered from its own notification callback are outside this change. **AI use** - OpenAI Codex, GPT-6 (exact deployment variant unavailable), with subagents: wrote the fix and tests, reviewed concurrency/lifetime handling, and ran the reported checks.
Submit removed its batch before spawning the queue worker, then dropped the
batch on a spawn error. Status slots remained pending and queued fence
notifications were lost.

Keep startup failure separate from Close. Retire failed requests and their
notifications in order, including later submissions, while preserving status
interval errors across batches. Serialize re-entrant submissions without
consuming work that has not been submitted. Own the queue and keep concurrent
Close waiting until the active drainer has retired its references.

Add deterministic startup-failure tests for error records, cancellation,
notification order, concurrent enqueue and Close, and re-entrant submission
that releases the final COM reference.

Assisted-by: OpenAI Codex (GPT-6; exact deployment variant unavailable)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:32:17 +00:00
Author
Owner

@⁠SlopTart on GitHub · 2026-11-25 21:08 UTC · original

First cold-cache gpu_ suite run: 163 passed / 4 failed, the trio plus gpu_geometry_wave32_prefix_count_over_a_mask. Second run, same head: 164 passed / 3 failed (baseline trio only). Solo run of the wave32 test on this head: passed. That test is this lane's known flaky family, unrelated to DirectStorage; recording it so nobody chases it here. The new worker-start-failure tests run inside the DirectStorage module and are not part of the gpu_ filter; the suite shows this PR moves nothing GPU-side.

**@⁠SlopTart** on GitHub · 2026-11-25 21:08 UTC · [original](https://github.com/xcl-dev/xcl/pull/2502#issuecomment-7174662314) First cold-cache `gpu_` suite run: `163 passed / 4 failed`, the trio plus `gpu_geometry_wave32_prefix_count_over_a_mask`. Second run, same head: `164 passed / 3 failed` (baseline trio only). Solo run of the wave32 test on this head: passed. That test is this lane's known flaky family, unrelated to DirectStorage; recording it so nobody chases it here. The new worker-start-failure tests run inside the DirectStorage module and are not part of the `gpu_` filter; the suite shows this PR moves nothing GPU-side.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 21:14 UTC · original

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 21:14 UTC · [original](https://github.com/xcl-dev/xcl/pull/2502#issuecomment-7174794659) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
Author
Owner

@⁠Oliwettoo on GitHub · 2026-11-25 22:27 UTC · original

Review on 6950978 (read from the diff, not run). Failing the pending batch is right, but it reuses closed, which so far only the title's own Close set. After a failed start the title still holds an open queue, and every later Enqueue* returns silently (enqueue, queue_enqueue_status and queue_enqueue_signal all check closed first):

  • A status slot enqueued later is never set to E_PENDING or completed. A fresh one keeps reading S_OK; the test asserts status_get_hresult(s, 5) == S_OK for work that never ran. The title sees success and reads a destination that was never written.
  • A fence enqueued later (99 in the test) is never signalled, so a title waiting on it hangs.

Suggestion: a separate "worker failed (hr)" state, in which later entries go straight through fail_unstarted (requests fail with hr, status slots complete with it, fences are signalled), instead of being dropped.

**@⁠Oliwettoo** on GitHub · 2026-11-25 22:27 UTC · [original](https://github.com/xcl-dev/xcl/pull/2502#issuecomment-7176387281) Review on 6950978 (read from the diff, not run). Failing the pending batch is right, but it reuses `closed`, which so far only the title's own `Close` set. After a failed start the title still holds an open queue, and every later `Enqueue*` returns silently (`enqueue`, `queue_enqueue_status` and `queue_enqueue_signal` all check `closed` first): - A status slot enqueued later is never set to `E_PENDING` or completed. A fresh one keeps reading `S_OK`; the test asserts `status_get_hresult(s, 5) == S_OK` for work that never ran. The title sees success and reads a destination that was never written. - A fence enqueued later (`99` in the test) is never signalled, so a title waiting on it hangs. Suggestion: a separate "worker failed (hr)" state, in which later entries go straight through `fail_unstarted` (requests fail with `hr`, status slots complete with it, fences are signalled), instead of being dropped.
Author
Owner

@⁠jeroenhaentjens on GitHub · 2026-11-25 23:07 UTC · original

@⁠Oliwettoo Confirmed, thanks. The revised regression fails on 6950978: the later status still reads S_OK rather than becoming pending. That assertion in my original test was incorrect.

Fixed and squashed in ca341274fd526c87c864731bd37868df1a17a350. Worker-start failure now has its own state; closed is reserved for Close. Later requests fail with the stored HRESULT, status intervals preserve their first error across submissions, and fence 99 is signalled. Normal enqueue/Submit boundaries are retained. A single drainer handles concurrent/re-entrant submissions in FIFO order outside queue locks, including a callback that releases the final queue COM reference.

On the clean revised head, the full Windows/Quadro RTX 3000 build and workspace suite passed: 1,426 reported passes, 0 failures, 46 ignored, 29 explicit SKIPPED records (not coverage). All 34 DirectStorage tests passed. Hardware, exact commands, negative control and limitations are in the updated description. Still draft pending the paired retail smoke runs.

AI assistance: OpenAI Codex, GPT-6 (exact deployment variant unavailable), including two independent subagent reviews.

**@⁠jeroenhaentjens** on GitHub · 2026-11-25 23:07 UTC · [original](https://github.com/xcl-dev/xcl/pull/2502#issuecomment-7177172247) @⁠Oliwettoo Confirmed, thanks. The revised regression fails on `6950978`: the later status still reads `S_OK` rather than becoming pending. That assertion in my original test was incorrect. Fixed and squashed in `ca341274fd526c87c864731bd37868df1a17a350`. Worker-start failure now has its own state; `closed` is reserved for `Close`. Later requests fail with the stored HRESULT, status intervals preserve their first error across submissions, and fence 99 is signalled. Normal enqueue/Submit boundaries are retained. A single drainer handles concurrent/re-entrant submissions in FIFO order outside queue locks, including a callback that releases the final queue COM reference. On the clean revised head, the full Windows/Quadro RTX 3000 build and workspace suite passed: 1,426 reported passes, 0 failures, 46 ignored, 29 explicit SKIPPED records (not coverage). All 34 DirectStorage tests passed. Hardware, exact commands, negative control and limitations are in the updated description. Still draft pending the paired retail smoke runs. AI assistance: OpenAI Codex, GPT-6 (exact deployment variant unavailable), including two independent subagent reviews.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-26 01:36 UTC · original

Re-verification on RTX 3060 Ti (Windows 11), new head merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.

Thanks!

— Devin

**@⁠DavidM1911** on GitHub · 2026-11-26 01:36 UTC · [original](https://github.com/xcl-dev/xcl/pull/2502#issuecomment-7179945609) Re-verification on RTX 3060 Ti (Windows 11), new head merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved. Thanks! — Devin
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 09:18 UTC · original · reviewed

On ca341274, the worker-start failure path appends all current pending.entries to the batch that the first Submit already took. An enqueue on another thread can therefore cross that Submit boundary: thread A takes batch A and blocks in start_worker; thread B enqueues a status and fence below the auto-submit threshold, without calling Submit; then startup fails, and A's batch.append pulls B's entries into fail_unstarted. The status completes and the fence signals even though B's batch was never submitted. The queue's pending lock protects each operation but does not make B's enqueue part of A's earlier Submit.

The IDStorageQueueX contract holds entries until Submit or auto-submit; the revised PR discussion also says normal enqueue/Submit boundaries are retained. Could the startup failure retire only the batch already taken, leaving later pending entries for their own submission (and the failed-worker state to retire them then)? The existing worker_start test seam can pause A, enqueue B's status/fence, fail startup, and assert B stays pending/unsignaled until a second Submit. This is exact-head source review; I did not run that concurrent fixture.

**@⁠luckyteagirl** on GitHub · 2026-11-26 09:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/2502#pullrequestreview-6071394320) · **reviewed** On `ca341274`, the worker-start failure path appends *all current `pending.entries`* to the batch that the first `Submit` already took. An enqueue on another thread can therefore cross that Submit boundary: thread A takes batch A and blocks in `start_worker`; thread B enqueues a status and fence below the auto-submit threshold, without calling `Submit`; then startup fails, and A's `batch.append` pulls B's entries into `fail_unstarted`. The status completes and the fence signals even though B's batch was never submitted. The queue's pending lock protects each operation but does not make B's enqueue part of A's earlier Submit. The [IDStorageQueueX contract](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/dstorage/interfaces/idstoragequeuex/idstoragequeuex?view=gdk-2604) holds entries until `Submit` or auto-submit; the revised PR discussion also says normal enqueue/Submit boundaries are retained. Could the startup failure retire only the batch already taken, leaving later pending entries for their own submission (and the failed-worker state to retire them then)? The existing `worker_start` test seam can pause A, enqueue B's status/fence, fail startup, and assert B stays pending/unsignaled until a second Submit. This is exact-head source review; I did not run that concurrent fixture.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-26 09:31 UTC · original

I reproduced the Submit-boundary race on exact head ca341274fd526c87c864731bd37868df1a17a350 using a local, test-only 39-line fixture (no production edits).

The fixture pauses thread A's first Submit in the existing worker_start hook, after it has taken its batch. Thread B then enqueues a status and mock-fence signal below the auto-submit threshold, without submitting them. The hook returns a forced worker-start error. Before B's later Submit, the status was already S_OK and the fence had signaled 99; expected E_PENDING and 0. This directly exercises the batch.append(&mut pending.entries) path discussed in my review above.

Tested — Windows 11 x64, CPU-only fixture (XCL_ADAPTER=NONE_CPU_ONLY), no D3D12 device:

cargo test --offline --locked -p xcl --lib --target-dir ../target-sol4-pr2502-submit-boundary -j 2 failed_start_does_not_retire_entries_enqueued_after_submit -- --test-threads=1 --nocapture

The rerun exited 101: 0 passed, 1 failed, 0 ignored, 1,327 filtered out; the focused test took 0.02 s. The observed/expected assertion was (S_OK, 99) vs (E_PENDING, 0). A subsequent explicit Submit is part of the fixture's control path, but the assertion checks the state before it. The exact PR code was otherwise unchanged.

Not tested: a game, GPU workload, full workspace suite, or a candidate fix. The worker error and fence are synthetic.

AI use: OpenAI Codex (GPT-6.2 Sol) wrote and ran the local fixture and drafted this report; OpenAI Codex (GPT-6.2 Astra) checked the test flow and results before posting.

**@⁠luckyteagirl** on GitHub · 2026-11-26 09:31 UTC · [original](https://github.com/xcl-dev/xcl/pull/2502#issuecomment-7188110737) I reproduced the Submit-boundary race on exact head `ca341274fd526c87c864731bd37868df1a17a350` using a local, test-only 39-line fixture (no production edits). The fixture pauses thread A's first `Submit` in the existing `worker_start` hook, after it has taken its batch. Thread B then enqueues a status and mock-fence signal below the auto-submit threshold, without submitting them. The hook returns a forced worker-start error. **Before B's later `Submit`, the status was already `S_OK` and the fence had signaled 99; expected `E_PENDING` and 0.** This directly exercises the `batch.append(&mut pending.entries)` path discussed in my review above. **Tested** — Windows 11 x64, CPU-only fixture (`XCL_ADAPTER=NONE_CPU_ONLY`), no D3D12 device: ```powershell cargo test --offline --locked -p xcl --lib --target-dir ../target-sol4-pr2502-submit-boundary -j 2 failed_start_does_not_retire_entries_enqueued_after_submit -- --test-threads=1 --nocapture ``` The rerun exited 101: **0 passed, 1 failed, 0 ignored, 1,327 filtered out**; the focused test took 0.02 s. The observed/expected assertion was `(S_OK, 99)` vs `(E_PENDING, 0)`. A subsequent explicit `Submit` is part of the fixture's control path, but the assertion checks the state *before* it. The exact PR code was otherwise unchanged. **Not tested:** a game, GPU workload, full workspace suite, or a candidate fix. The worker error and fence are synthetic. **AI use:** OpenAI Codex (GPT-6.2 Sol) wrote and ran the local fixture and drafted this report; OpenAI Codex (GPT-6.2 Astra) checked the test flow and results before posting.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2502/head:github-bot/gh-2502'
git switch 'github-bot/gh-2502'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2502'
git switch 'github-bot/gh-2502'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2502'
git switch 'github-bot/gh-2502'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2502'
git switch 'main'
git merge --squash 'github-bot/gh-2502'
git switch 'main'
git merge --ff-only 'github-bot/gh-2502'
git switch 'main'
git merge 'github-bot/gh-2502'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.