HLE: with no process task queue, a call given no queue fails with E_NO_TASK_QUEUE #2075

Open
github-bot wants to merge 3 commits from github-bot/gh-2075 into main AGit
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 04:23 UTC · original
0xkn0wh3r3:hle/xasync-no-task-queue → main · +345 −40 · 3 files · 3 commits · open

The problem

A title that sets the process task queue to null and then begins an async call with no queue got S_OK, and the call's work then had nowhere to go.

XTaskQueueSetCurrentProcessTaskQueue documents that the process queue can be set to null, and that GDK APIs then fail with E_NO_TASK_QUEUE (0x800701AB) when given a null queue. In xasync.rs, a null queue handle stands for the process queue:

  • XAsyncBegin (and XAsyncRun, and the runtime's own calls begun for the title through it) checked nothing and returned S_OK.
  • XTaskQueueSubmit*, XTaskQueueTerminate, XTaskQueueRegisterMonitor and XAsyncSchedule, which substitute the process queue for a null handle, returned E_INVALIDARG.

Found by the conformance title in #2057, which lists this check as a known divergence.

The fix

  • XAsyncBegin now refuses the call with E_NO_TASK_QUEUE before touching the block, when its queue is null and there is no process queue.
  • XTaskQueueSubmit*, XTaskQueueTerminate, XTaskQueueRegisterMonitor and XAsyncSchedule return E_NO_TASK_QUEUE there instead of E_INVALIDARG. A missing callback is still E_INVALIDARG.

Nothing changes while a process queue exists.

Testing

  • New test a_null_process_queue_refuses_calls_given_no_queue in crates/victory-hle/tests/no_task_queue.rs. It is a binary of its own: the process queue is process-wide, and the unit tests begin calls with null queues on other threads. With the process queue set to null, it checks that XAsyncRun, XAsyncBegin, a call the runtime starts for the title, and XTaskQueueSubmitDelayedCallback fail with E_NO_TASK_QUEUE and that nothing runs. It then checks that a queue of the title's own still works, and that once the process queue is restored a null queue means it again.
  • cargo test -p victory-hle: all pass. cargo clippy -p victory-hle --all-targets: clean.
  • With this and the other conformance fixes merged onto #2057's branch, its suite passes 151 of 152 checks (the remaining one, the console id, is #1717).
  • Not run with a title (no game data here).
  • #503 (pins a call's queue at XAsyncBegin) also returns E_NO_TASK_QUEUE from XAsyncBegin. This one covers the other entry points that stand the process queue in for a null handle, and tests it through the process queue. Whichever merges second resolves the overlap.
  • #2057: whichever of the two merges second takes the entry off the test's KNOWN list (a listed check that passes fails that test).

Rebased onto f3578e3

main gained 30a5202 (#114): the first completion claims a call with an atomic flag (claimed) and runs the provider's cleanup without holding a lock. This branch keeps that. The call's stage (pending, completed, delivered), which replaced the done flag in 8440297, is now set only after the cleanup and after the status is published, as done is on main. XAsyncCancel checks claimed, as on main. Upstream's cleanup_runs_without_the_completion_lock now checks stage.

After the rebase: cargo test -p victory-hle passes, tests/no_task_queue.rs passed 150 runs in a row with no exit crash, and process_queue_change passed 50. cargo clippy -p victory-hle --all-targets is clean, and so is cargo xtask policy.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 04:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/2075) `0xkn0wh3r3:hle/xasync-no-task-queue` → `main` · +345 −40 · 3 files · 3 commits · open ## The problem A title that sets the process task queue to null and then begins an async call with no queue got S_OK, and the call's work then had nowhere to go. `XTaskQueueSetCurrentProcessTaskQueue` documents that the process queue can be set to null, and that GDK APIs then fail with `E_NO_TASK_QUEUE` (0x800701AB) when given a null queue. In `xasync.rs`, a null queue handle stands for the process queue: - `XAsyncBegin` (and `XAsyncRun`, and the runtime's own calls begun for the title through it) checked nothing and returned S_OK. - `XTaskQueueSubmit*`, `XTaskQueueTerminate`, `XTaskQueueRegisterMonitor` and `XAsyncSchedule`, which substitute the process queue for a null handle, returned `E_INVALIDARG`. Found by the conformance title in #2057, which lists this check as a known divergence. ## The fix - `XAsyncBegin` now refuses the call with `E_NO_TASK_QUEUE` before touching the block, when its queue is null and there is no process queue. - `XTaskQueueSubmit*`, `XTaskQueueTerminate`, `XTaskQueueRegisterMonitor` and `XAsyncSchedule` return `E_NO_TASK_QUEUE` there instead of `E_INVALIDARG`. A missing callback is still `E_INVALIDARG`. Nothing changes while a process queue exists. ## Testing - New test `a_null_process_queue_refuses_calls_given_no_queue` in `crates/victory-hle/tests/no_task_queue.rs`. It is a binary of its own: the process queue is process-wide, and the unit tests begin calls with null queues on other threads. With the process queue set to null, it checks that `XAsyncRun`, `XAsyncBegin`, a call the runtime starts for the title, and `XTaskQueueSubmitDelayedCallback` fail with `E_NO_TASK_QUEUE` and that nothing runs. It then checks that a queue of the title's own still works, and that once the process queue is restored a null queue means it again. - `cargo test -p victory-hle`: all pass. `cargo clippy -p victory-hle --all-targets`: clean. - With this and the other conformance fixes merged onto #2057's branch, its suite passes 151 of 152 checks (the remaining one, the console id, is #1717). ## Not covered / Related - Not run with a title (no game data here). - #503 (pins a call's queue at `XAsyncBegin`) also returns `E_NO_TASK_QUEUE` from `XAsyncBegin`. This one covers the other entry points that stand the process queue in for a null handle, and tests it through the process queue. Whichever merges second resolves the overlap. - #2057: whichever of the two merges second takes the entry off the test's `KNOWN` list (a listed check that passes fails that test). ### Rebased onto f3578e3 `main` gained 30a5202 (#114): the first completion claims a call with an atomic flag (`claimed`) and runs the provider's cleanup without holding a lock. This branch keeps that. The call's `stage` (pending, completed, delivered), which replaced the `done` flag in 8440297, is now set only after the cleanup and after the status is published, as `done` is on `main`. `XAsyncCancel` checks `claimed`, as on `main`. Upstream's `cleanup_runs_without_the_completion_lock` now checks `stage`. After the rebase: `cargo test -p victory-hle` passes, `tests/no_task_queue.rs` passed 150 runs in a row with no exit crash, and `process_queue_change` passed 50. `cargo clippy -p victory-hle --all-targets` is clean, and so is `cargo xtask policy`.
XTaskQueueSetCurrentProcessTaskQueue documents that the process queue can
be set to null, and that GDK APIs then fail with E_NO_TASK_QUEUE
(0x800701AB) when given a null queue. XAsyncBegin (and XAsyncRun, and the
runtime's own calls begun for the title through it) checked nothing and
returned S_OK; the call's work then had nowhere to go. It now refuses the
call before touching the block. XTaskQueueSubmit*, Terminate,
RegisterMonitor and XAsyncSchedule, which substitute the process queue for
a null handle, return E_NO_TASK_QUEUE there instead of E_INVALIDARG.
Nothing changes while a process queue exists.

The test is a binary of its own: the process queue is process-wide and
the unit tests begin calls with null queues on other threads.
A call given no queue runs on the process task queue, which the title
can change while the call is in flight. Begin checked that a queue
exists, but scheduling and completion looked the process queue up again,
so a call begun on queue A delivered its completion on B once the title
had made B the process queue. Microsoft's libHttpClient stores the queue
it resolved at begin and uses it for the call's work and completion
(`Source/Task/AsyncLib.cpp`), as does #503 here.

The call now keeps the queue it resolved at `XAsyncBegin` (which also
keeps it alive for the call) and schedules and completes on it.

New test `process_queue_change` (a binary of its own: the process queue
is process-wide): a call begun with no queue while A is the process
queue, B set as the process queue in flight, then work and completion
must arrive on A and none on B. Before the change the completion came on
B, as reported in review.
XAsyncGetStatus with wait returned as soon as the result was recorded,
while the completion routine was still queued on the completion port.
A title that waited and then freed the block (a stack block going out of
scope, say) left the queued routine to read the block's callback and
call it with freed memory. Microsoft's libHttpClient signals the wait
only after the routine returns (`CompletionCallback` in
`Source/Task/AsyncLib.cpp` calls the routine, then `SignalWait`).

The no_task_queue test did exactly this: its last call runs on the
process queue's pool, it waits, and the test returns. The wait returned
before the routine had run in 200 of 200 runs (checked by counting the
routine's calls after the wait), and the routine then read the test's
finished stack frame: about 1 in 100 runs ended in an access violation
at exit (2 of 200 in a loop of the built binary).

A call now goes from pending to completed (result recorded, routine
queued) to delivered (routine returned, or there is none), and a wait
ends at delivered. A call that fails or has no result leaves the calls
filed by block as it completes, so it is also filed as completing until
its routine returns, and a wait still finds it. The routine itself may
wait on its own block without waiting for itself. The queued routine
now carries what it calls, rather than reading the block again.

New unit test: a waiter on another thread does not return before a
manual completion port is dispatched. async_calls_complete_and_return_results
waited before dispatching its manual completion, which now blocks as it
would in libHttpClient; it polls instead. no_task_queue now checks the
routine has run once its wait returns: 0 failures in 700 runs, and 0 in
400 of process_queue_change.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:54:04 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-25 04:29 UTC · original

Triage verdict — Keep the no-queue fix and preserve #503’s queue pinning (7f53379)

Evidence

  • @⁠0xkn0wh3r3 and @⁠Quat3rnion’s #503 both reject an async begin with no available task queue. This PR also covers direct task-queue wrappers. #503 separately retains the resolved queue for the life of the call. Here, begin checks the queue, but schedule and completion still resolve it again, so a process-default change during a call remains a separate case. Begin and schedule · Completion · #503 patch

Checks and limits

  • Compared the patches with the GDK no-process-queue rule. This pass was source review. The isolated no-queue integration result is author-reported. GDK process task queue

Next step

  • Keep the direct-wrapper tests and carry forward #503’s manual-queue change-during-call case. Use one begin-time refusal when reconciling the two PRs, and remove the matching known divergence when integrating with #2057.

This verification was AI-assisted.

**@⁠jeremygold02** on GitHub · 2026-11-25 04:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/2075#issuecomment-7152889627) **Triage verdict — Keep the no-queue fix and preserve #503’s queue pinning** (`7f53379`) **Evidence** - @⁠0xkn0wh3r3 and @⁠Quat3rnion’s #503 both reject an async begin with no available task queue. This PR also covers direct task-queue wrappers. #503 separately retains the resolved queue for the life of the call. Here, begin checks the queue, but schedule and completion still resolve it again, so a process-default change during a call remains a separate case. [Begin and schedule](https://github.com/Marvisak/VIctory/blob/7f53379654e3f52cf43731de5dacfb89351d52bc/crates/victory-hle/src/modules/xasync.rs#L570-L656) · [Completion](https://github.com/Marvisak/VIctory/blob/7f53379654e3f52cf43731de5dacfb89351d52bc/crates/victory-hle/src/modules/xasync.rs#L676-L711) · [#503 patch](https://git.gtahub.st/github/Marvisak--VIctory/pulls/503/files) **Checks and limits** - Compared the patches with the GDK no-process-queue rule. This pass was source review. The isolated no-queue integration result is author-reported. [GDK process task queue](https://learn.microsoft.com/en-us/xbox/gdk/docs/features/common/async/async-task-queue-design-howto/using-process-task-queue) **Next step** - Keep the direct-wrapper tests and carry forward #503’s manual-queue change-during-call case. Use one begin-time refusal when reconciling the two PRs, and remove the matching known divergence when integrating with #2057. This verification was AI-assisted.
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 04:50 UTC · original

I reproduced the process-default switch raised in the review above. I used two manually dispatched queues, set A as the process default, and started an operation with a null block queue. After begin returned I set B as the process default, dispatched work on A, then polled both completion ports with timeout zero. The block was left untouched. The callback ran exactly once in every run.

Revision Queue that delivered completion
Parent of #2075 (940d32f) and #2075 (7f53379) B
Parent of #503 (ffe310e) B
#503 (4371039) A

That makes queue retention a separate behavior worth preserving when reconciling the two patches. The switch predates #2075. Microsoft's public libHttpClient implementation also stores the resolved process queue and uses it for completion. These were synthetic Windows HLE tests, one run per revision. AI-assisted.

**@⁠Dathinel** on GitHub · 2026-11-25 04:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/2075#issuecomment-7153206893) I reproduced the process-default switch raised in the review above. I used two manually dispatched queues, set A as the process default, and started an operation with a null block queue. After begin returned I set B as the process default, dispatched work on A, then polled both completion ports with timeout zero. The block was left untouched. The callback ran exactly once in every run. | Revision | Queue that delivered completion | | --- | --- | | Parent of #2075 (940d32f) and #2075 (7f53379) | B | | Parent of #503 (ffe310e) | B | | #503 (4371039) | A | That makes queue retention a separate behavior worth preserving when reconciling the two patches. The switch predates #2075. Microsoft's public libHttpClient implementation also [stores the resolved process queue](https://github.com/microsoft/libHttpClient/blob/c5007fd9cbdc785518ea6dccc5751b125d451cc1/Source/Task/AsyncLib.cpp#L437-L439) and [uses it for completion](https://github.com/microsoft/libHttpClient/blob/c5007fd9cbdc785518ea6dccc5751b125d451cc1/Source/Task/AsyncLib.cpp#L545-L549). These were synthetic Windows HLE tests, one run per revision. AI-assisted.
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 06:02 UTC · original

Thanks @⁠jeremygold02 and @⁠Dathinel, and thanks for the reproduction table and the libHttpClient pointer.

b6e635c keeps the queue a call resolves at XAsyncBegin, the block's own or the process queue at that moment. The call's work and completion both use that queue, which also stays alive for the length of the call. That matches libHttpClient's AsyncLib.cpp and #503's queue pinning.

The new test process_queue_change (its own binary, since the process queue is process-wide) is your scenario. It begins with no queue while A is the process queue, sets B in flight, and checks that work and completion arrive on A and nothing on B. On the previous head it fails with the completion on B, as you measured. With this, the two patches agree on refusing at begin and on keeping the queue, so whichever lands second should rebase cleanly. Removing the matching known divergence in #2057 still applies.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 06:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2075#issuecomment-7154373135) Thanks @⁠jeremygold02 and @⁠Dathinel, and thanks for the reproduction table and the libHttpClient pointer. `b6e635c` keeps the queue a call resolves at `XAsyncBegin`, the block's own or the process queue at that moment. The call's work and completion both use that queue, which also stays alive for the length of the call. That matches libHttpClient's `AsyncLib.cpp` and #503's queue pinning. The new test `process_queue_change` (its own binary, since the process queue is process-wide) is your scenario. It begins with no queue while A is the process queue, sets B in flight, and checks that work and completion arrive on A and nothing on B. On the previous head it fails with the completion on B, as you measured. With this, the two patches agree on refusing at begin and on keeping the queue, so whichever lands second should rebase cleanly. Removing the matching known divergence in #2057 still applies.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:28 UTC · original · edited 2026-11-26 01:24 UTC

Automated triage for the maintainers.

Merge candidate (kept). The new head is a rebase onto main after #114. I checked how it combines with that change in crates/victory-hle/src/modules/xasync.rs:

  • complete_call still claims the call through claimed and runs release (the provider's cleanup) with no lock held. The block goes into COMPLETING before release, so waited (which locks CALLS, then COMPLETING) can't miss it, and stage is set only after the status is published.
  • XAsyncCancel checks claimed, as on main. cleanup_runs_without_the_completion_lock now checks stage.
  • The no-queue refusal, the queue pinned at XAsyncBegin, and the wait that lasts until the completion routine has returned are unchanged from the last review. queue() returns None only for a null handle with no process queue, so the new E_NO_TASK_QUEUE returns don't affect bad non-null handles.

The overlap with #503 still needs the maintainer to pick one, and #2057's KNOWN list loses its no-queue entry when this lands.

CI: passing (check).


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 10:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/2075#issuecomment-7159746496) · edited 2026-11-26 01:24 UTC <!-- victory-triage v1 head=c0b4ea14553f8f8348ea38cb168f33bbc99d30d2 verdict=merge-candidate at=2026-11-26T01:24:17Z --> Automated triage for the maintainers. **Merge candidate (kept).** The new head is a rebase onto `main` after #114. I checked how it combines with that change in `crates/victory-hle/src/modules/xasync.rs`: - `complete_call` still claims the call through `claimed` and runs `release` (the provider's cleanup) with no lock held. The block goes into `COMPLETING` before `release`, so `waited` (which locks `CALLS`, then `COMPLETING`) can't miss it, and `stage` is set only after the status is published. - `XAsyncCancel` checks `claimed`, as on `main`. `cleanup_runs_without_the_completion_lock` now checks `stage`. - The no-queue refusal, the queue pinned at `XAsyncBegin`, and the wait that lasts until the completion routine has returned are unchanged from the last review. `queue()` returns `None` only for a null handle with no process queue, so the new `E_NO_TASK_QUEUE` returns don't affect bad non-null handles. The overlap with #503 still needs the maintainer to pick one, and #2057's `KNOWN` list loses its no-queue entry when this lands. CI: passing (`check`). --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 19:03 UTC · original

One more fix, 8440297, found by checking this branch against current main.

tests/no_task_queue.rs sometimes crashed at exit (2 of 200 runs, access violation). The cause is in the runtime, not the test. XAsyncGetStatus(block, wait=true) returned as soon as the result was stored, while the completion routine was still queued, and the queued task then read (*block).callback from the block. A title that waits and then frees the block, like the test's stack block, leaves that task reading freed memory.

libHttpClient's AsyncLib.cpp signals the wait only after the routine returns (CompletionCallback calls asyncBlock->callback, then SignalWait). It now does the same here:

  • A call goes Pending → Completed (result recorded, routine queued) → Delivered (routine returned, or there is none). A wait ends only at Delivered.
  • The queued completion carries its own call, block and routine, so nothing in the runtime touches the block after the routine returns.
  • A routine that waits on its own block doesn't wait for itself.

New test a_wait_lasts_until_the_completion_routine_has_run. no_task_queue now asserts that the routine ran before the wait returned. Before the fix that assertion failed in 200 of 200 runs; after it, the test has 0 failures in 700 runs and process_queue_change 0 in 400. cargo test -p victory-hle, clippy and policy pass.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 19:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2075#issuecomment-7171753331) One more fix, 8440297, found by checking this branch against current `main`. `tests/no_task_queue.rs` sometimes crashed at exit (2 of 200 runs, access violation). The cause is in the runtime, not the test. `XAsyncGetStatus(block, wait=true)` returned as soon as the result was stored, while the completion routine was still queued, and the queued task then read `(*block).callback` from the block. A title that waits and then frees the block, like the test's stack block, leaves that task reading freed memory. libHttpClient's `AsyncLib.cpp` signals the wait only after the routine returns (`CompletionCallback` calls `asyncBlock->callback`, then `SignalWait`). It now does the same here: - A call goes Pending → Completed (result recorded, routine queued) → Delivered (routine returned, or there is none). A wait ends only at Delivered. - The queued completion carries its own call, block and routine, so nothing in the runtime touches the block after the routine returns. - A routine that waits on its own block doesn't wait for itself. New test `a_wait_lasts_until_the_completion_routine_has_run`. `no_task_queue` now asserts that the routine ran before the wait returned. Before the fix that assertion failed in 200 of 200 runs; after it, the test has 0 failures in 700 runs and `process_queue_change` 0 in 400. `cargo test -p victory-hle`, clippy and policy pass.
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/2075/head:github-bot/gh-2075'
git switch 'github-bot/gh-2075'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2075'
git switch 'github-bot/gh-2075'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2075'
git switch 'github-bot/gh-2075'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2075'
git switch 'main'
git merge --squash 'github-bot/gh-2075'
git switch 'main'
git merge --ff-only 'github-bot/gh-2075'
git switch 'main'
git merge 'github-bot/gh-2075'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2075
No description provided.