gdk rt: Cleanup after the completion callback for a call completed in Begin, XAsyncSchedule on a completed call (2 conformance scenarios) #271

Closed
github-bot wants to merge 1 commit from gh-pr/271/head into gh-pr/271/base
Owner

@⁠QuentinDanblon on GitHub · 2026-11-23 10:28 UTC · original
QuentinDanblon:pr/xasync-begin-cleanup → main · +147 −4 · 2 files · 1 commits · closed without merging

Library / area: compat-common, GDK runtime XAsync (src/gdk/rt.rs), conformance scenarios (tests/support/xtq.rs)

Exports changed (exports.txt rows): none

Source of the behaviour: measured on the PC xgameruntime.dll 10.0.26100.9656 (Gaming Services) through gdk_xtaskqueue_conformance_real. No third-party code.

This answers the question on #270 about a Begin op that fails. It is XAsync, not task queues, so it is not in #270. The two branches merge without conflict (git merge-tree).

What the PC runtime does after a failed Begin op

XAsyncBegin returns S_OK. XAsyncGetStatus(wait = false) and XAsyncGetResultSize return the Begin failure as soon as XAsyncBegin has returned. No work is queued. The completion callback is queued on the completion port and reads the same status.

Our runtime already did that. Two things next to it differed.

1. When Cleanup runs for a call completed during its Begin op

call completed completion callback PC runtime ours before
by the Begin result (failure) yes Cleanup after the callback Cleanup at once
by XAsyncComplete inside Begin, same thread yes Cleanup after the callback Cleanup at once
by XAsyncComplete from another thread while Begin runs yes Cleanup after the callback Cleanup at once
any of the three above no Cleanup at once same
in DoWork, no payload yes or no Cleanup at once same
in DoWork, payload not fetched yes or no no Cleanup yet same

Now the three first rows match.

2. XAsyncSchedule on a completed call

call PC runtime ours before
failed the failure of the call, nothing queued S_OK before the completion callback had run, E_INVALIDARG after
succeeded without payload E_INVALIDARG, nothing queued same after the callback; before it, S_OK by the same code path (read, not run)
succeeded with a payload not fetched S_OK, DoWork runs again same

Now the rows match. XAsyncSchedule(null) returns E_INVALIDARG before the block is read.

Scenarios

  • verify_failed_begin_reports_its_failure: the sequence described above, with the op counts the provider saw (Begin once, Cleanup once).
  • verify_cleanup_waits_for_the_callback_when_begin_completes: 18 cases (five ways to complete, failure or success, with or without a callback). Each checks the number of Cleanup ops before the completion port is dispatched, the number the completion callback saw, the number after it, and what XAsyncSchedule returns and queues afterwards.

Without the change to rt.rs, on de1e1da: the first fails on the XAsyncSchedule code (left: 0, right: 0x80091234), the second on the Cleanup count before dispatch (left: 1, right: 0).

A Begin op returning E_PENDING is covered by your verify_pending_begin_stays_pending in r32j. I added nothing for it.

Tests

On 4299f39 (base de1e1da), RTX 5090 PC, Windows 11:

  • cargo test -p compat-common --release --test gdk_xtaskqueue_conformance_real: 63 passed.
  • --test gdk_xtaskqueue_conformance: 5 runs, 63 passed each.
  • --lib: 4 runs, 147 passed each.
  • pr_gate.py --base origin/main: 0 problems.
  • Before writing the scenarios I compared the PC runtime and ours on 33 combinations (way to complete, result, callback or not, XAsyncSchedule before or after the completion dispatch): the printed lines were identical.

Not run green: cargo test -p compat-common --release as a whole stops at tests/gdk_fs_redirect.rs (new in r32j), which ends with STATUS_STACK_OVERFLOW on this PC. Plain de1e1da does the same here, 2 runs of 2, so it does not come from this PR.

Not covered, not claimed

  • This changes when a provider's Cleanup op runs on a path Trackmania uses at boot. I have no game dump, so no title was run.

  • The PC runtime is the reference here, not a console. I have no console measurement.

  • Between the return of the Begin op and the next instruction of XAsyncBegin, a completion from another thread is still counted as "during Begin". Cleanup then runs after the callback instead of at once. I did not measure what the PC runtime does in that window.

  • What XAsyncSchedule does on a call whose payload was already fetched is not measured.

  • cargo test -p compat-common passes for what is listed above

  • No game or console files and no binaries included

  • No fake success; anything not possible is left missing with a note

🤖 Generated with Claude Code

**@⁠QuentinDanblon** on GitHub · 2026-11-23 10:28 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/271) `QuentinDanblon:pr/xasync-begin-cleanup` → `main` · +147 −4 · 2 files · 1 commits · closed without merging **Library / area:** `compat-common`, GDK runtime XAsync (`src/gdk/rt.rs`), conformance scenarios (`tests/support/xtq.rs`) **Exports changed (exports.txt rows):** none **Source of the behaviour:** measured on the PC `xgameruntime.dll` 10.0.26100.9656 (Gaming Services) through `gdk_xtaskqueue_conformance_real`. No third-party code. This answers the question on #270 about a Begin op that fails. It is XAsync, not task queues, so it is not in #270. The two branches merge without conflict (`git merge-tree`). ### What the PC runtime does after a failed Begin op `XAsyncBegin` returns `S_OK`. `XAsyncGetStatus(wait = false)` and `XAsyncGetResultSize` return the Begin failure as soon as `XAsyncBegin` has returned. No work is queued. The completion callback is queued on the completion port and reads the same status. Our runtime already did that. Two things next to it differed. ### 1. When Cleanup runs for a call completed during its Begin op | call completed | completion callback | PC runtime | ours before | |---|---|---|---| | by the Begin result (failure) | yes | Cleanup after the callback | Cleanup at once | | by `XAsyncComplete` inside Begin, same thread | yes | Cleanup after the callback | Cleanup at once | | by `XAsyncComplete` from another thread while Begin runs | yes | Cleanup after the callback | Cleanup at once | | any of the three above | no | Cleanup at once | same | | in DoWork, no payload | yes or no | Cleanup at once | same | | in DoWork, payload not fetched | yes or no | no Cleanup yet | same | Now the three first rows match. ### 2. `XAsyncSchedule` on a completed call | call | PC runtime | ours before | |---|---|---| | failed | the failure of the call, nothing queued | `S_OK` before the completion callback had run, `E_INVALIDARG` after | | succeeded without payload | `E_INVALIDARG`, nothing queued | same after the callback; before it, `S_OK` by the same code path (read, not run) | | succeeded with a payload not fetched | `S_OK`, DoWork runs again | same | Now the rows match. `XAsyncSchedule(null)` returns `E_INVALIDARG` before the block is read. ### Scenarios - `verify_failed_begin_reports_its_failure`: the sequence described above, with the op counts the provider saw (Begin once, Cleanup once). - `verify_cleanup_waits_for_the_callback_when_begin_completes`: 18 cases (five ways to complete, failure or success, with or without a callback). Each checks the number of Cleanup ops before the completion port is dispatched, the number the completion callback saw, the number after it, and what `XAsyncSchedule` returns and queues afterwards. Without the change to `rt.rs`, on `de1e1da`: the first fails on the `XAsyncSchedule` code (`left: 0, right: 0x80091234`), the second on the Cleanup count before dispatch (`left: 1, right: 0`). A Begin op returning `E_PENDING` is covered by your `verify_pending_begin_stays_pending` in r32j. I added nothing for it. ### Tests On `4299f39` (base `de1e1da`), RTX 5090 PC, Windows 11: - `cargo test -p compat-common --release --test gdk_xtaskqueue_conformance_real`: 63 passed. - `--test gdk_xtaskqueue_conformance`: 5 runs, 63 passed each. - `--lib`: 4 runs, 147 passed each. - `pr_gate.py --base origin/main`: 0 problems. - Before writing the scenarios I compared the PC runtime and ours on 33 combinations (way to complete, result, callback or not, `XAsyncSchedule` before or after the completion dispatch): the printed lines were identical. Not run green: `cargo test -p compat-common --release` as a whole stops at `tests/gdk_fs_redirect.rs` (new in r32j), which ends with `STATUS_STACK_OVERFLOW` on this PC. Plain `de1e1da` does the same here, 2 runs of 2, so it does not come from this PR. ### Not covered, not claimed - This changes when a provider's Cleanup op runs on a path Trackmania uses at boot. I have no game dump, so no title was run. - The PC runtime is the reference here, not a console. I have no console measurement. - Between the return of the Begin op and the next instruction of `XAsyncBegin`, a completion from another thread is still counted as "during Begin". Cleanup then runs after the callback instead of at once. I did not measure what the PC runtime does in that window. - What `XAsyncSchedule` does on a call whose payload was already fetched is not measured. - [x] `cargo test -p compat-common` passes for what is listed above - [x] No game or console files and no binaries included - [x] No fake success; anything not possible is left `missing` with a note 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Two differences from xgameruntime.dll, found while measuring what a
failed Begin op does.

1. Cleanup of a call completed while its Begin op runs.
   When the call has a completion callback and is completed during the
   Begin op (Begin returns a failure, or XAsyncComplete is called before
   Begin returns, from the same thread or from another one), the PC
   runtime calls the Cleanup op after the completion callback, in the
   dispatch of the completion port. We called Cleanup at once, before
   the callback.
   Unchanged, and the same on the PC runtime: without a completion
   callback Cleanup runs at once; a call completed from DoWork is
   cleaned up at once; a call completed with a payload is not cleaned
   up while its result has not been fetched.

2. XAsyncSchedule on a completed call.
   The PC runtime returns the failure of the call when the call failed,
   and E_INVALIDARG when it succeeded without a payload. It queues
   nothing. We returned E_INVALIDARG for a failed call once its callback
   had run, and S_OK before the callback had run.
   Unchanged, and the same on the PC runtime: a call completed with a
   payload that has not been fetched can be scheduled again.
   XAsyncSchedule(null) now returns E_INVALIDARG before the block is
   read.

Scenarios, expected values measured on xgameruntime.dll 10.0.26100.9656
(gdk_xtaskqueue_conformance_real) before the change:

- verify_failed_begin_reports_its_failure: XAsyncBegin returns S_OK,
  XAsyncGetStatus and XAsyncGetResultSize return the Begin failure as
  soon as XAsyncBegin has returned, no work is queued, the completion
  callback is queued on the completion port and reads the same status,
  XAsyncSchedule returns the failure before and after the callback, the
  provider saw Begin once and Cleanup once.
- verify_cleanup_waits_for_the_callback_when_begin_completes: 18 cases
  (completed by the Begin result, inside Begin, from another thread
  during Begin, in DoWork, in DoWork with a payload; failure or success;
  with or without a completion callback). Each checks how many Cleanup
  ops ran before the completion port was dispatched, how many the
  completion callback saw, how many ran after it, and what
  XAsyncSchedule returns and queues on the completed call.

Both failed on our runtime before the change: the first on the
XAsyncSchedule code, the second on the Cleanup count before dispatch.

A Begin op returning E_PENDING is already covered by
verify_pending_begin_stays_pending (r32j), nothing added for it.

Source: measured behaviour of the PC xgameruntime.dll. No third-party
code.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:16:43 +00:00
github-bot closed this pull request 2026-11-26 06:16:44 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-23 13:31 UTC · original

Its commit is included in #210, which is being applied; this will be closed when that ships.

**@⁠omonkeyz** on GitHub · 2026-11-23 13:31 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/271#issuecomment-7102656549) Its commit is included in #210, which is being applied; this will be closed when that ships.
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-25 13:09 UTC · original

Applied on main (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

**@⁠omonkeyz** on GitHub · 2026-11-25 13:09 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/271#issuecomment-7163373911) Applied on main (cherry-picked onto the current history with your authorship kept; comment lines stripped per CONTRIBUTING). Thank you.

Pull request closed

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