XAsync: canceling a call that already completed leaves it alone, as documented #1098

Manually merged
github merged 1 commit from gh-pr/1098/head into gh-pr/1098/base 2026-11-26 04:19:46 +00:00
Owner

@⁠BastienRodz on GitHub · 2026-11-24 15:43 UTC · original
BastienRodz:hle/cancel-after-completion → main · +66 −1 · 1 files · 1 commits · merged 2026-11-25 00:12 UTC

What's wrong

Microsoft's XAsyncCancel reference states:

If the XAsyncCancel function is invoked for an asynchronous call that has already completed, nothing happens.

In crates/victory-hle/src/modules/xasync.rs, XAsyncCancel unconditionally dispatches OP_CANCEL whenever the call is still registered:

pub fn XAsyncCancel(block: *mut AsyncBlock) {
    if let Some(call) = call(block) {
        call.provider(OP_CANCEL, block, 0, std::ptr::null_mut());
        XAsyncComplete(block, E_ABORT, 0);
    }
}

A call that completed successfully with a nonempty result stays in CALLS until the title consumes the payload via XAsyncGetResult.

Sequence:

  1. A provider completes a call with S_OK and a 1-byte result.
  2. XAsyncGetStatus(block, false) returns S_OK.
  3. XAsyncCancel(block) is called before XAsyncGetResult.
  • Expected: the provider never receives OP_CANCEL; status stays S_OK; XAsyncGetResult returns the byte.
  • Actual: the provider receives OP_CANCEL once (then XAsyncComplete returns early because call.done is already true, so the status and result survive).

What the fix does

In XAsyncCancel, checks *lock(&call.done) before invoking the provider and returns immediately if the call has already completed. The lock guard is dropped at the end of the if condition before call.provider(...) runs, avoiding deadlock if a provider calls XAsyncComplete during OP_CANCEL. Updates XAsyncCancel's doc comment accordingly.

How it behaves after the fix

Calling XAsyncCancel on a call that has already completed returns without sending OP_CANCEL to the provider, leaving the status (S_OK) and unread result intact for XAsyncGetResult. In-flight calls still receive OP_CANCEL and complete with E_ABORT.

Tests

  • Added modules::xasync::tests::canceling_a_completed_call_leaves_it_alone in crates/victory-hle/src/modules/xasync.rs: completes a call with S_OK and a 1-byte result (0x5a), calls XAsyncCancel, checks that the provider's OP_CANCEL count stays 0, checks that XAsyncGetStatus stays S_OK, and verifies XAsyncGetResult still returns 0x5a (used == 1).
  • Fails on main before the fix:
    thread 'modules::xasync::tests::canceling_a_completed_call_leaves_it_alone' panicked at crates/victory-hle/src/modules/xasync.rs:1230:9:
    assertion `left == right` failed
      left: 1
     right: 0
    
  • Local Linux + Wine (cargo xwin, x86_64-pc-windows-msvc):
    • cargo xwin test -p victory-hle --target x86_64-pc-windows-msvc modules::xasync::tests: 8 passed, 0 failed.
    • cargo xwin test -p victory-hle --target x86_64-pc-windows-msvc: 92 passed, 3 failed (the 3 known Wine baseline failures: modules::lifecycle::tests::hooked_windows_still_reach_the_title_procedure, modules::lifecycle::tests::the_keyboard_menu_never_reaches_the_title, modules::net::tests::only_loopback_is_reachable).
    • cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings: pass.
    • cargo xwin clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-msvc -- -D warnings: pass.
    • cargo xtask policy: pass (asset policy: 154 files ok).
  • On GitHub's windows-latest with the upstream CI's commands (clippy -D warnings with and without --all-features, then cargo test --workspace --locked), everything passes; victory-hle 95 passed, 0 failed: https://github.com/BastienRodz/VIctory/actions/runs/45428269761

Not tested: a title's teardown path.

Related: #122, #236 (both touch XAsyncCancel's completion line; this change sits before it).

No game data used. AI-assisted: found with GPT-6.2 Astra, implemented with Gemini 4 Neon, reviewed and verified with Claude Code.

🤖 Generated with Claude Code

**@⁠BastienRodz** on GitHub · 2026-11-24 15:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/1098) `BastienRodz:hle/cancel-after-completion` → `main` · +66 −1 · 1 files · 1 commits · merged 2026-11-25 00:12 UTC ## What's wrong Microsoft's [`XAsyncCancel`](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xasync/functions/xasynccancel) reference states: > If the `XAsyncCancel` function is invoked for an asynchronous call that has already completed, nothing happens. In `crates/victory-hle/src/modules/xasync.rs`, `XAsyncCancel` unconditionally dispatches `OP_CANCEL` whenever the call is still registered: ```rust pub fn XAsyncCancel(block: *mut AsyncBlock) { if let Some(call) = call(block) { call.provider(OP_CANCEL, block, 0, std::ptr::null_mut()); XAsyncComplete(block, E_ABORT, 0); } } ``` A call that completed successfully with a nonempty result stays in `CALLS` until the title consumes the payload via `XAsyncGetResult`. Sequence: 1. A provider completes a call with `S_OK` and a 1-byte result. 2. `XAsyncGetStatus(block, false)` returns `S_OK`. 3. `XAsyncCancel(block)` is called before `XAsyncGetResult`. - Expected: the provider never receives `OP_CANCEL`; status stays `S_OK`; `XAsyncGetResult` returns the byte. - Actual: the provider receives `OP_CANCEL` once (then `XAsyncComplete` returns early because `call.done` is already `true`, so the status and result survive). ## What the fix does In `XAsyncCancel`, checks `*lock(&call.done)` before invoking the provider and returns immediately if the call has already completed. The lock guard is dropped at the end of the `if` condition before `call.provider(...)` runs, avoiding deadlock if a provider calls `XAsyncComplete` during `OP_CANCEL`. Updates `XAsyncCancel`'s doc comment accordingly. ## How it behaves after the fix Calling `XAsyncCancel` on a call that has already completed returns without sending `OP_CANCEL` to the provider, leaving the status (`S_OK`) and unread result intact for `XAsyncGetResult`. In-flight calls still receive `OP_CANCEL` and complete with `E_ABORT`. ## Tests - Added `modules::xasync::tests::canceling_a_completed_call_leaves_it_alone` in `crates/victory-hle/src/modules/xasync.rs`: completes a call with `S_OK` and a 1-byte result (`0x5a`), calls `XAsyncCancel`, checks that the provider's `OP_CANCEL` count stays `0`, checks that `XAsyncGetStatus` stays `S_OK`, and verifies `XAsyncGetResult` still returns `0x5a` (`used == 1`). - Fails on `main` before the fix: ```text thread 'modules::xasync::tests::canceling_a_completed_call_leaves_it_alone' panicked at crates/victory-hle/src/modules/xasync.rs:1230:9: assertion `left == right` failed left: 1 right: 0 ``` - Local Linux + Wine (`cargo xwin`, `x86_64-pc-windows-msvc`): - `cargo xwin test -p victory-hle --target x86_64-pc-windows-msvc modules::xasync::tests`: 8 passed, 0 failed. - `cargo xwin test -p victory-hle --target x86_64-pc-windows-msvc`: 92 passed, 3 failed (the 3 known Wine baseline failures: `modules::lifecycle::tests::hooked_windows_still_reach_the_title_procedure`, `modules::lifecycle::tests::the_keyboard_menu_never_reaches_the_title`, `modules::net::tests::only_loopback_is_reachable`). - `cargo xwin clippy --workspace --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings`: pass. - `cargo xwin clippy --workspace --all-targets --all-features --locked --target x86_64-pc-windows-msvc -- -D warnings`: pass. - `cargo xtask policy`: pass (`asset policy: 154 files ok`). - On GitHub's `windows-latest` with the upstream CI's commands (clippy `-D warnings` with and without `--all-features`, then `cargo test --workspace --locked`), everything passes; `victory-hle` 95 passed, 0 failed: https://github.com/BastienRodz/VIctory/actions/runs/45428269761 Not tested: a title's teardown path. Related: #122, #236 (both touch XAsyncCancel's completion line; this change sits before it). No game data used. AI-assisted: found with GPT-6.2 Astra, implemented with Gemini 4 Neon, reviewed and verified with Claude Code. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Microsoft's XAsyncCancel reference says: "If the XAsyncCancel function
is invoked for an asynchronous call that has already completed, nothing
happens."

A call that completed successfully with a nonempty result stays in
CALLS until the title reads the result via XAsyncGetResult, so
XAsyncCancel still found it and invoked the provider with OP_CANCEL
before XAsyncComplete returned early on call.done.

Check call.done under its lock in XAsyncCancel and return immediately
when the call is already complete, dropping the lock before invoking
the provider.

Co-Authored-By: Gemini 4 Neon <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:19:44 +00:00
github manually merged commit 44ce06784b into gh-pr/1098/base 2026-11-26 04:19:46 +00:00
Author
Owner

@⁠Aniseto on GitHub · 2026-11-24 16:13 UTC · original

Ran the new test and the whole xasync module at 44ce067:

Environment: Windows 11 Pro build 26200 x64, Intel Core i5-12400F, 64 GB RAM, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only) driver 32.0.16.2124, Rust 1.98.1 (pinned by rust-toolchain.toml), MSVC 14.44.35207, DXC 1.9.2609.5, debug build.

cargo test -p victory-hle canceling_a_completed
1 passed; 0 failed; 0 ignored      (exit 0)

cargo test -p victory-hle xasync
8 passed; 0 failed; 0 ignored      (exit 0)

modules::xasync::tests::canceling_a_completed_call_leaves_it_alone passes and the rest of the module is unaffected. It is a unit-level test, so the adapter is not the variable; the datapoint is the pinned 1.98.1 toolchain. No test report on this PR yet.

Not tested: the title's own cancellation timing (no game data here), RDNA2/RDNA4 and Intel GPUs, release build.

AI-assisted (OpenCode), model: DeepSeek V4.1 Flash 1017 - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; no game data was used.

**@⁠Aniseto** on GitHub · 2026-11-24 16:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/1098#issuecomment-7137328516) Ran the new test and the whole `xasync` module at `44ce067`: Environment: Windows 11 Pro build 26200 x64, Intel Core i5-12400F, 64 GB RAM, NVIDIA GeForce RTX 5070 Ti (Blackwell, 32-lane waves only) driver 32.0.16.2124, Rust 1.98.1 (pinned by `rust-toolchain.toml`), MSVC 14.44.35207, DXC 1.9.2609.5, debug build. ``` cargo test -p victory-hle canceling_a_completed 1 passed; 0 failed; 0 ignored (exit 0) cargo test -p victory-hle xasync 8 passed; 0 failed; 0 ignored (exit 0) ``` `modules::xasync::tests::canceling_a_completed_call_leaves_it_alone` passes and the rest of the module is unaffected. It is a unit-level test, so the adapter is not the variable; the datapoint is the pinned 1.98.1 toolchain. No test report on this PR yet. Not tested: the title's own cancellation timing (no game data here), RDNA2/RDNA4 and Intel GPUs, release build. AI-assisted (OpenCode), model: **DeepSeek V4.1 Flash 1017** - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; no game data was used.
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 16:29 UTC · original

Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 44ce067: cargo test -p victory-hle passes, 96 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 16:29 UTC · [original](https://github.com/Marvisak/VIctory/pull/1098#issuecomment-7137749526) Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at 44ce067: `cargo test -p victory-hle` passes, 96 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
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!1098
No description provided.