gdk rt: XAsyncCancel leaves completion to the provider, GetResult errors end the call, never-started blocks (4 conformance scenarios) #321

Closed
github-bot wants to merge 4 commits from gh-pr/321/head into gh-pr/321/base
Owner

@⁠QuentinDanblon on GitHub · 2026-11-23 18:40 UTC · original
QuentinDanblon:pr/xasync-reference-gaps → main · +591 −50 · 5 files · 4 commits · closed without merging

Library / area: compat-common GDK runtime rt.rs (XAsync only, no XTaskQueue code), conformance scenarios in tests/support/xtq.rs, DIFFERS in gdk_xtaskqueue_conformance.rs, one assertion in gdk_minecraft_slots.rs.

Exports changed (exports.txt rows): none

Source of the behaviour: measured on the PC xgameruntime.dll 10.0.26100.9656 with the existing conformance harness (each scenario runs on the PC runtime and on ours). Cross-checked with microsoft/libHttpClient (MIT), Source/Task/AsyncLib.cpp at c5007fd9. No code taken.

Stacked on #210 and #271, which you applied locally: the branch carries their three commits (cherry-picked unchanged) and one new commit, a3e827a. Once they are on main, only a3e827a remains.

What changes (each confirmed on the PC runtime first)

PC runtime and reference Before After
XAsyncCancel calls only the provider's Cancel op; the call stays pending until the provider completes it; DoWork still runs if scheduled; Cleanup is not called inside the Cancel op we completed with E_ABORT, skipped DoWork, ran Cleanup inside the Cancel op same as PC
Work canceled by a terminating queue calls the Cancel op, then E_ABORT if still pending E_ABORT without the Cancel op same as PC
Never-started block zeroed block: S_OK for GetStatus (wait or not), GetResultSize (0), GetResult (used 0). Status field E_PENDING: E_PENDING without wait, E_INVALIDARG with wait E_INVALIDARG everywhere same as PC
XAsyncGetResult errors identity must match, null included; wrong identity or null buffer E_INVALIDARG, short buffer E_NOT_SUFFICIENT_BUFFER; each error ends the call (Cleanup, then E_ILLEGAL_METHOD_CALL on a correct retry) null identity accepted; the call stayed alive and a retry succeeded same as PC

Three DIFFERS rows leave: verify_cancellation, verify_cleanup_waits_for_work, verify_cleanup_waits_for_work_distributed.

gdk_minecraft_slots: the XGameUi text-entry result size on a zeroed block asserted a failure, i.e. the old behaviour. On the PC runtime it is S_OK and size 0 for IIDs fc0b9bd0, 72c4e70f and 6eeaa73e (measured with a temporary probe, not committed), so the assertion now expects that.

Checked, already identical, unchanged: XAsyncBegin on a terminated queue (E_ABORT), on a block in use (E_INVALIDARG), without any queue (E_NO_TASK_QUEUE); XAsyncBegin returning S_OK when the Begin op fails.

Not covered, not claimed

  • verify_terminate_waits_for_async_in_flight passes on the PC and still fails here. The fix belongs in q_terminate, which #270 and #307 rewrite, so it is left for after them.
  • E_NOT_SUPPORTED (a successful call with a state and no payload) cannot be reached through the API on either runtime; not implemented.
  • No console measurement; PC runtime only.

Tests

On a3e827a, Windows 11:

  • gdk_xtaskqueue_conformance (ours): 67 passed, 6 runs in a row.
  • gdk_xtaskqueue_conformance_real (PC runtime): 67 passed, 6 runs in a row. A first version of verify_result_errors_end_the_call failed 1 run in 4 on the PC because Cleanup lands slightly later there; the scenario now waits up to 2 s for it.
  • With TOMBOX_XTQ_ALL=1, the three removed DIFFERS rows pass. verify_pending_begin_stays_pending and verify_periodic_pattern fail in that mode with or without this change and pass alone: the other DIFFERS scenarios running in parallel disturb them.
  • --lib and every gdk_* test of compat-common pass. iat::tests::finds_the_bound_slot_of_an_import_of_this_binary failed once under load and passed alone; not touched here.
  • Mutations, each restored: Cancel completing by itself, no Cancel op on canceled work, Cleanup inside the Cancel op, never-started block returning E_INVALIDARG, null identity accepted, errors not ending the call, result-read flag set only on success. Each makes its scenario fail.
  • pr_gate.py --base origin/main: 0 problems.

Conflicts to expect with #270 and #307: line additions and removals in DIFFERS and in the xtq_tests! list only, no logic overlap.

  • cargo test -p compat-common passes for what is listed above
  • No game or console files and no binaries included
  • No fake success: every change follows a PC runtime measurement; what is not done is listed

🤖 Generated with Claude Code

**@⁠QuentinDanblon** on GitHub · 2026-11-23 18:40 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/321) `QuentinDanblon:pr/xasync-reference-gaps` → `main` · +591 −50 · 5 files · 4 commits · closed without merging **Library / area:** `compat-common` GDK runtime `rt.rs` (XAsync only, no XTaskQueue code), conformance scenarios in `tests/support/xtq.rs`, `DIFFERS` in `gdk_xtaskqueue_conformance.rs`, one assertion in `gdk_minecraft_slots.rs`. **Exports changed (exports.txt rows):** none **Source of the behaviour:** measured on the PC `xgameruntime.dll` 10.0.26100.9656 with the existing conformance harness (each scenario runs on the PC runtime and on ours). Cross-checked with microsoft/libHttpClient (MIT), `Source/Task/AsyncLib.cpp` at [c5007fd9](https://github.com/microsoft/libHttpClient/blob/c5007fd9cbdc785518ea6dccc5751b125d451cc1/Source/Task/AsyncLib.cpp). No code taken. **Stacked on #210 and #271**, which you applied locally: the branch carries their three commits (cherry-picked unchanged) and one new commit, `a3e827a`. Once they are on main, only `a3e827a` remains. ### What changes (each confirmed on the PC runtime first) | | PC runtime and reference | Before | After | |---|---|---|---| | `XAsyncCancel` | calls only the provider's Cancel op; the call stays pending until the provider completes it; DoWork still runs if scheduled; Cleanup is not called inside the Cancel op | we completed with `E_ABORT`, skipped DoWork, ran Cleanup inside the Cancel op | same as PC | | Work canceled by a terminating queue | calls the Cancel op, then `E_ABORT` if still pending | `E_ABORT` without the Cancel op | same as PC | | Never-started block | zeroed block: `S_OK` for `GetStatus` (wait or not), `GetResultSize` (0), `GetResult` (used 0). Status field `E_PENDING`: `E_PENDING` without wait, `E_INVALIDARG` with wait | `E_INVALIDARG` everywhere | same as PC | | `XAsyncGetResult` errors | identity must match, null included; wrong identity or null buffer `E_INVALIDARG`, short buffer `E_NOT_SUFFICIENT_BUFFER`; each error ends the call (Cleanup, then `E_ILLEGAL_METHOD_CALL` on a correct retry) | null identity accepted; the call stayed alive and a retry succeeded | same as PC | Three `DIFFERS` rows leave: `verify_cancellation`, `verify_cleanup_waits_for_work`, `verify_cleanup_waits_for_work_distributed`. `gdk_minecraft_slots`: the XGameUi text-entry result size on a zeroed block asserted a failure, i.e. the old behaviour. On the PC runtime it is `S_OK` and size 0 for IIDs `fc0b9bd0`, `72c4e70f` and `6eeaa73e` (measured with a temporary probe, not committed), so the assertion now expects that. Checked, already identical, unchanged: `XAsyncBegin` on a terminated queue (`E_ABORT`), on a block in use (`E_INVALIDARG`), without any queue (`E_NO_TASK_QUEUE`); `XAsyncBegin` returning `S_OK` when the Begin op fails. ### Not covered, not claimed - `verify_terminate_waits_for_async_in_flight` passes on the PC and still fails here. The fix belongs in `q_terminate`, which #270 and #307 rewrite, so it is left for after them. - `E_NOT_SUPPORTED` (a successful call with a state and no payload) cannot be reached through the API on either runtime; not implemented. - No console measurement; PC runtime only. ### Tests On `a3e827a`, Windows 11: - `gdk_xtaskqueue_conformance` (ours): 67 passed, 6 runs in a row. - `gdk_xtaskqueue_conformance_real` (PC runtime): 67 passed, 6 runs in a row. A first version of `verify_result_errors_end_the_call` failed 1 run in 4 on the PC because Cleanup lands slightly later there; the scenario now waits up to 2 s for it. - With `TOMBOX_XTQ_ALL=1`, the three removed `DIFFERS` rows pass. `verify_pending_begin_stays_pending` and `verify_periodic_pattern` fail in that mode with or without this change and pass alone: the other `DIFFERS` scenarios running in parallel disturb them. - `--lib` and every `gdk_*` test of compat-common pass. `iat::tests::finds_the_bound_slot_of_an_import_of_this_binary` failed once under load and passed alone; not touched here. - Mutations, each restored: Cancel completing by itself, no Cancel op on canceled work, Cleanup inside the Cancel op, never-started block returning `E_INVALIDARG`, null identity accepted, errors not ending the call, result-read flag set only on success. Each makes its scenario fail. - `pr_gate.py --base origin/main`: 0 problems. Conflicts to expect with #270 and #307: line additions and removals in `DIFFERS` and in the `xtq_tests!` list only, no logic overlap. - [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: every change follows a PC runtime measurement; what is not done is listed 🤖 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]>
get_status(wait) looped on the status, which complete() sets before the
completion callback is queued. A waiter that arrived after XAsyncComplete
of a call with a result returned while the callback was still running.
complete() also wrote the block (mark) after the status was visible, so a
waiter could return and then see the block change under it.

Measured on the PC xgameruntime.dll (thread-pool queue, 12 runs per case):
- call with a result, waiter arrives after completion: returns after the
  completion callback has returned;
- call without a result (size 0 or a failure), waiter arrives after
  completion: returns at once, before the callback;
- waiter started while the call was pending: returns after the callback,
  with or without a result;
- completion while Cleanup is still running: the block does not change
  after the wait has returned.

The state now carries a signal that is raised after the completion
callback (or at completion when there is none). A call without a result
leaves the state table at completion, under the status lock, together
with the block marker. The table entry is only removed if it is still
this call's, so a callback that begins a new call on the same block keeps
the new state.

Tests: tests/gdk_xasync_wait.rs, four cases. Two of them fail on the
previous rt.rs on every run.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Measured on the PC xgameruntime.dll (5 runs per case): with a manual
completion port that nobody dispatches, a wait on a call with a result
does not return and does not run the callback itself, whether the waiter
started while the call was pending or after it completed. It returns as
soon as another thread dispatches the port. A completed call without a
result returns at once and leaves its callback queued.

Two tests for these cases. The "after it completed" half fails on the
previous rt.rs.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
Four differences from xgameruntime.dll, each with a conformance scenario
in tests/support/xtq.rs that runs on the PC runtime and on ours.

1. XAsyncCancel only calls the provider's Cancel op.
   The call stays pending until the provider completes it, and DoWork
   still runs if it was scheduled. We completed the call ourselves with
   E_ABORT and skipped the next DoWork. When the provider completes the
   call inside its Cancel op, Cleanup is not called inside that op: it
   runs when XAsyncCancel returns (no completion callback) or after the
   completion callback. verify_cancellation, verify_cleanup_waits_for_work
   and verify_cleanup_waits_for_work_distributed leave DIFFERS.
   Scenario: verify_cancel_leaves_completion_to_the_provider.

2. Work canceled by a terminating queue calls the Cancel op first.
   The canceled DoWork callback calls XAsyncCancel, then completes the
   call with E_ABORT if it is still pending. We completed it without the
   Cancel op. Scenario: verify_canceled_work_cancels_the_provider.

3. A block that was never started.
   A zeroed block reads S_OK from XAsyncGetStatus (with or without wait),
   XAsyncGetResultSize (size 0) and XAsyncGetResult (used 0). A block
   whose status field reads E_PENDING returns E_PENDING without wait and
   E_INVALIDARG with wait. We returned E_INVALIDARG for all of them.
   The XGameUi text entry result size on a zeroed block gives the same
   S_OK and size 0 on the PC runtime, so gdk_minecraft_slots now expects
   that. Scenario: verify_status_of_a_block_never_started.

4. XAsyncGetResult on a call with a result.
   The identity must equal the one given to XAsyncBegin, null included
   (we accepted a null identity). Another identity, a null buffer
   (E_INVALIDARG) and a short buffer (E_NOT_SUFFICIENT_BUFFER) end the
   call: Cleanup runs and a correct retry gets E_ILLEGAL_METHOD_CALL. We
   kept the call alive and let the retry succeed. A call whose result was
   read also refuses a second read when the GetResult op failed.
   Scenario: verify_result_errors_end_the_call.

Checked and unchanged, already the same on both runtimes: XAsyncBegin on
a terminated queue (E_ABORT), on a block in use (E_INVALIDARG), with no
queue and no process queue (E_NO_TASK_QUEUE); XAsyncBegin returning S_OK
when the Begin op fails. E_NOT_SUPPORTED (a successful call with a state
and no payload) cannot be reached from the API on either runtime.

Not changed: verify_terminate_waits_for_async_in_flight passes on the PC
runtime and still fails here; the fix belongs in queue termination,
which open XTaskQueue work rewrites.

Each fix has a mutation that makes its scenario fail on our runtime.

Source of the behaviour: measured on the PC xgameruntime.dll 10.0.26100.9656; cross-checked with microsoft/libHttpClient (MIT) Source/Task/AsyncLib.cpp at c5007fd9, no code taken.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:18:41 +00:00
github-bot closed this pull request 2026-11-26 06:18:41 +00:00
Author
Owner

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

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

**@⁠omonkeyz** on GitHub · 2026-11-25 13:49 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/321#issuecomment-7164347393) Applied on main in 8050509 (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.