startup: implement XGameSaveInitializeProviderAsync and its result in xgameruntime #2171

Merged
tedin7 merged 7 commits from upstream-pr/2179 into main 2026-11-25 04:14:55 +00:00
tedin7 commented 2026-11-25 03:00:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:00:45Z.


Part of #1334

What this unblocks: a title-like caller can start the game-save provider through XGameSaveInitializeProviderAsync on an explicit queue contract and claim it with XGameSaveInitializeProviderResult instead of getting E_NOTIMPL.

What changed:

  • Queue contract: block.queue == nullptr calls back once, inline, before the call returns. A manual queue made by the shim's own XTaskQueueCreate (Manual/Manual) fires ZERO callbacks until XTaskQueueDispatch(queue, completion port), which then runs exactly one. Any other non-null queue (or a non-manual XTaskQueueCreate mode) returns E_NOTIMPL before the block or provider capacity is touched.
  • XTaskQueueDispatch and XTaskQueueCloseHandle are new; closing a queue with a waiting callback is refused. Thread-pool and immediate queues are not modeled.
  • XGameSaveInitializeProviderResult hands the provider over exactly once (second claim is E_INVALIDARG).
  • Argument errors return from the call and leave the block untouched. Reusing an unclaimed block returns E_ILLEGAL_STATE_CHANGE; exhausted provider storage returns E_OUTOFMEMORY and consumes no async state.
  • State lives in a side table keyed by block address; only the leading queue, context and callback fields are read.
  • XAsyncGetStatus, XUserAddAsync, XPackageMountWithUiAsync stay E_NOTIMPL stubs.
  • xgameruntime_gamesave_async now covers: manual queue with zero callbacks before dispatch, one callback that claims the provider after dispatch, an inline early-callback negative control, and an unsupported queue that leaves the block and all four provider slots untouched. xgameruntime_thunks and xgameruntime_table_check.py updated. Docs updated. This is a queue-contract fixture only, separate from the #870 startup trace.

Verification:

  • Linux: python3 -B tests/xgameruntime_table_check.py -> PASS; python3 -B tests/docs_links_check.py -> PASS; python3 -B tests/run_checks_parallel_check.py -> ok
  • Linux: MinGW -fsyntax-only on the shim and both touched tests -> clean
  • Win2025 (head 69132806, default 3-slot pool): python3 x2w_pipe.py win2025 2179 --targets xgameruntime_shim,xgameruntime_shim_check,xgameruntime_contracts_check,xgameruntime_pls_xpackage_check,xgameruntime_identity_check,xgameruntime_gamesave_async_check --regex "^xgameruntime_" -> dev 5/5 PASS, release 5/5 PASS (incl. xgameruntime_gamesave_async)

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6596195019 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2179). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T03:00:45Z. --- Part of #1334 What this unblocks: a title-like caller can start the game-save provider through `XGameSaveInitializeProviderAsync` on an explicit queue contract and claim it with `XGameSaveInitializeProviderResult` instead of getting `E_NOTIMPL`. What changed: - Queue contract: `block.queue == nullptr` calls back once, inline, before the call returns. A manual queue made by the shim's own `XTaskQueueCreate` (Manual/Manual) fires ZERO callbacks until `XTaskQueueDispatch(queue, completion port)`, which then runs exactly one. Any other non-null queue (or a non-manual `XTaskQueueCreate` mode) returns `E_NOTIMPL` before the block or provider capacity is touched. - `XTaskQueueDispatch` and `XTaskQueueCloseHandle` are new; closing a queue with a waiting callback is refused. Thread-pool and immediate queues are not modeled. - `XGameSaveInitializeProviderResult` hands the provider over exactly once (second claim is `E_INVALIDARG`). - Argument errors return from the call and leave the block untouched. Reusing an unclaimed block returns `E_ILLEGAL_STATE_CHANGE`; exhausted provider storage returns `E_OUTOFMEMORY` and consumes no async state. - State lives in a side table keyed by block address; only the leading queue, context and callback fields are read. - `XAsyncGetStatus`, `XUserAddAsync`, `XPackageMountWithUiAsync` stay `E_NOTIMPL` stubs. - `xgameruntime_gamesave_async` now covers: manual queue with zero callbacks before dispatch, one callback that claims the provider after dispatch, an inline early-callback negative control, and an unsupported queue that leaves the block and all four provider slots untouched. `xgameruntime_thunks` and `xgameruntime_table_check.py` updated. Docs updated. This is a queue-contract fixture only, separate from the #870 startup trace. Verification: - Linux: `python3 -B tests/xgameruntime_table_check.py` -> PASS; `python3 -B tests/docs_links_check.py` -> PASS; `python3 -B tests/run_checks_parallel_check.py` -> ok - Linux: MinGW `-fsyntax-only` on the shim and both touched tests -> clean - Win2025 (head 69132806, default 3-slot pool): `python3 x2w_pipe.py win2025 2179 --targets xgameruntime_shim,xgameruntime_shim_check,xgameruntime_contracts_check,xgameruntime_pls_xpackage_check,xgameruntime_identity_check,xgameruntime_gamesave_async_check --regex "^xgameruntime_"` -> dev 5/5 PASS, release 5/5 PASS (incl. `xgameruntime_gamesave_async`) AI-assisted; commands listed were executed locally.
R0Y00 commented 2026-11-25 04:04:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T03:32:57Z.

Review: CHANGES_REQUESTED


Windows Release passed the six registered xgameruntime checks at 69132806, but a source-built variation of the manual-queue case found a lost completion. Start on Manual/Manual, retrieve the completed provider before pumping, then dispatch. The result was S_OK with a provider, followed by dispatch=0, callbacks=0. Result clears the whole slot while its callback is still pending. Please preserve the queued completion if early result retrieval succeeds, or refuse early retrieval without deleting it in this intentionally restricted implementation. In either case test that one callback still dispatches, the provider is delivered at most once, and the second dispatch finds nothing. Closing or recycling a queue while a start is in flight also needs a lifetime check, since a reserved slot does not set callback_pending until after synchronous initialization returns.

A null block queue selects the process task queue in the public API. It cannot be treated as an inline queue for real callers. For the first slice, refuse null before touching block or provider state unless the default is modeled, and keep an early-callback mutant in the test instead. XTaskQueueDispatch also has an observable timeout argument. Please exercise a finite wait and make its behavior explicit before exposing this as a general runtime implementation. XAsyncBlock queue contract · XTaskQueueDispatch

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6051459694 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2179#pullrequestreview-6051459694). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T03:32:57Z. **Review:** CHANGES_REQUESTED --- Windows Release passed the six registered xgameruntime checks at 69132806, but a source-built variation of the manual-queue case found a lost completion. Start on Manual/Manual, retrieve the completed provider before pumping, then dispatch. The result was S_OK with a provider, followed by dispatch=0, callbacks=0. Result clears the whole slot while its callback is still pending. Please preserve the queued completion if early result retrieval succeeds, or refuse early retrieval without deleting it in this intentionally restricted implementation. In either case test that one callback still dispatches, the provider is delivered at most once, and the second dispatch finds nothing. Closing or recycling a queue while a start is in flight also needs a lifetime check, since a reserved slot does not set callback_pending until after synchronous initialization returns. A null block queue selects the process task queue in the public API. It cannot be treated as an inline queue for real callers. For the first slice, refuse null before touching block or provider state unless the default is modeled, and keep an early-callback mutant in the test instead. XTaskQueueDispatch also has an observable timeout argument. Please exercise a finite wait and make its behavior explicit before exposing this as a general runtime implementation. [XAsyncBlock queue contract](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xasync/structs/xasyncblock) · [XTaskQueueDispatch](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xtaskqueue/functions/xtaskqueuedispatch)
chatgpt-codex-connector[bot commented 2026-11-25 04:04:08 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T03:36:40Z.

Review: COMMENTED


💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6913280656

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6051488358 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2179#pullrequestreview-6051488358). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T03:36:40Z. **Review:** COMMENTED --- <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `6913280656` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". </details>
R0Y00 commented 2026-11-25 04:04:17 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T03:09:42Z.


The save-provider result path is worth pursuing. The current inline callback still needs an explicit queue contract before this can cover an application caller. It ignores the supplied completion port, so a manual queue receives a callback on the caller's stack before it has been dispatched. That is exactly the distinction the source-built manual queue from #2170 demonstrates on the installed runtime.

Please reuse the existing async completion service where present, or narrow the first implementation to a queue configuration you can actually recognize and support. Exercise a manual queue with zero callbacks before completion-port dispatch, one callback that claims the provider after dispatch, and an early-callback negative control. If this slice returns unsupported for that queue, check that it leaves the block and provider capacity untouched. Keep the report separate from the actual #870 startup trace.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7151649318 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2179#issuecomment-7151649318). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T03:09:42Z. --- The save-provider result path is worth pursuing. The current inline callback still needs an explicit queue contract before this can cover an application caller. It ignores the supplied completion port, so a manual queue receives a callback on the caller's stack before it has been dispatched. That is exactly the distinction the source-built manual queue from #2170 demonstrates on the installed runtime. Please reuse the existing async completion service where present, or narrow the first implementation to a queue configuration you can actually recognize and support. Exercise a manual queue with zero callbacks before completion-port dispatch, one callback that claims the provider after dispatch, and an early-callback negative control. If this slice returns unsupported for that queue, check that it leaves the block and provider capacity untouched. Keep the report separate from the actual #870 startup trace.
tedin7 commented 2026-11-25 04:04:18 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:27:20Z.


Thanks, this is addressed in 69132806.

Queue contract: no queue calls back once, inline. A manual queue made by the shim's XTaskQueueCreate (Manual/Manual) fires zero callbacks until XTaskQueueDispatch on the completion port, which runs exactly one. Any other queue value returns E_NOTIMPL before the block or provider capacity is touched. The shim has no other queue service to reuse, so it models only this manual queue, and thread-pool and immediate modes are out of scope.

Tests in xgameruntime_gamesave_async:

  • manual queue: zero callbacks before dispatch, and the work port runs nothing
  • one callback after dispatch, claiming the provider; a second dispatch runs nothing
  • early-callback negative control: a block with no queue calls back inline, so the zero-callback check would catch it
  • unsupported queue: refused with E_NOTIMPL, no async state, and all four provider slots still free

The report is a queue-contract fixture and stays separate from the #870 startup trace.

Win2025, default 3-slot pool, head 69132806: x2w_pipe.py win2025 2179 --targets xgameruntime_shim,xgameruntime_shim_check,xgameruntime_contracts_check,xgameruntime_pls_xpackage_check,xgameruntime_identity_check,xgameruntime_gamesave_async_check --regex "^xgameruntime_". Dev 5/5 passed, release 5/5 passed. Linux: table check, docs links and run_checks_parallel all pass.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7151929669 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2179#issuecomment-7151929669). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T03:27:20Z. --- Thanks, this is addressed in 69132806. Queue contract: no queue calls back once, inline. A manual queue made by the shim's `XTaskQueueCreate` (Manual/Manual) fires zero callbacks until `XTaskQueueDispatch` on the completion port, which runs exactly one. Any other queue value returns `E_NOTIMPL` before the block or provider capacity is touched. The shim has no other queue service to reuse, so it models only this manual queue, and thread-pool and immediate modes are out of scope. Tests in `xgameruntime_gamesave_async`: - manual queue: zero callbacks before dispatch, and the work port runs nothing - one callback after dispatch, claiming the provider; a second dispatch runs nothing - early-callback negative control: a block with no queue calls back inline, so the zero-callback check would catch it - unsupported queue: refused with `E_NOTIMPL`, no async state, and all four provider slots still free The report is a queue-contract fixture and stays separate from the #870 startup trace. Win2025, default 3-slot pool, head 69132806: `x2w_pipe.py win2025 2179 --targets xgameruntime_shim,xgameruntime_shim_check,xgameruntime_contracts_check,xgameruntime_pls_xpackage_check,xgameruntime_identity_check,xgameruntime_gamesave_async_check --regex "^xgameruntime_"`. Dev 5/5 passed, release 5/5 passed. Linux: table check, docs links and run_checks_parallel all pass. AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-25 04:04:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T03:27:31Z.


Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T03:36:44.100916Z 6913280 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7151932396 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2179#issuecomment-7151932396). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T03:27:31Z. --- <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"6913280656d8c4ecdf5210a38144f7fdb6fb42a6","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-25T03:36:44.100916Z">2026-11-25T03:36:44.100916Z</relative-time> | `6913280` | Draft marked ready | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@codex review" or "@codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
tedin7 commented 2026-11-25 04:04:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T03:42:12Z.


Thanks, the lost completion reproduces and is fixed at 27d59718.

Root cause and changes:

  • XGameSaveInitializeProviderResult cleared the whole slot, which also dropped callback_pending and the queue link. It now returns E_PENDING (output cleared, nothing consumed) while the completion callback still waits for XTaskQueueDispatch. After the callback runs, the provider is delivered exactly once.
  • XTaskQueueCloseHandle now refuses (E_ILLEGAL_STATE_CHANGE) when any slot on the queue is reserved but not yet completed, or has a callback waiting. This covers the window before callback_pending is set.
  • A null XAsyncBlock.queue is refused with E_NOTIMPL before any block or provider state is touched. The inline-callback path is gone.
  • XTaskQueueDispatch ignores its timeout on purpose, because every start completes before it returns. This is documented in the source and in docs/experiments.md.

Regression tests in xgameruntime_gamesave_async:

  • Manual/Manual start, early result returns E_PENDING with a null provider and no callback. Close is refused, then one dispatch runs one callback, the second dispatch finds nothing, the result then returns the provider once and a repeat gives E_INVALIDARG.
  • Null queue is refused with no callback, no block write and no capacity used.
  • A direct early call of the callback keeps the early-callback mutant visible to the zero-before-dispatch checks.
  • A finite wait (5000 ms) on an empty port returns false without waiting, and with a queued callback it dispatches once.
  • All existing cases now use a queue and pump it.

Not covered by a test: the in-flight close window itself, since the synchronous init cannot be paused from outside. It is covered by the close rule above.

Verification:

  • python3 -B tests/xgameruntime_table_check.py: PASS
  • python3 -B tests/docs_links_check.py: PASS (18 files, 404 links)
  • Win2025 x2w_pipe.py win2025 2179 --targets xgameruntime_shim,xgameruntime_shim_check,xgameruntime_contracts_check,xgameruntime_pls_xpackage_check,xgameruntime_identity_check,xgameruntime_gamesave_async_check,xgameruntime_preflight_exe --regex "^xgameruntime_": dev 7/7 and release 7/7 passed, including xgameruntime_gamesave_async. (xgameruntime_preflight_exe was added to the target list because xgameruntime_preflight_stub_refused needs it.)

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7152163873 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2179#issuecomment-7152163873). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T03:42:12Z. --- Thanks, the lost completion reproduces and is fixed at 27d59718. Root cause and changes: - `XGameSaveInitializeProviderResult` cleared the whole slot, which also dropped `callback_pending` and the queue link. It now returns `E_PENDING` (output cleared, nothing consumed) while the completion callback still waits for `XTaskQueueDispatch`. After the callback runs, the provider is delivered exactly once. - `XTaskQueueCloseHandle` now refuses (`E_ILLEGAL_STATE_CHANGE`) when any slot on the queue is reserved but not yet completed, or has a callback waiting. This covers the window before `callback_pending` is set. - A null `XAsyncBlock.queue` is refused with `E_NOTIMPL` before any block or provider state is touched. The inline-callback path is gone. - `XTaskQueueDispatch` ignores its timeout on purpose, because every start completes before it returns. This is documented in the source and in `docs/experiments.md`. Regression tests in `xgameruntime_gamesave_async`: - Manual/Manual start, early result returns `E_PENDING` with a null provider and no callback. Close is refused, then one dispatch runs one callback, the second dispatch finds nothing, the result then returns the provider once and a repeat gives `E_INVALIDARG`. - Null queue is refused with no callback, no block write and no capacity used. - A direct early call of the callback keeps the early-callback mutant visible to the zero-before-dispatch checks. - A finite wait (5000 ms) on an empty port returns false without waiting, and with a queued callback it dispatches once. - All existing cases now use a queue and pump it. Not covered by a test: the in-flight close window itself, since the synchronous init cannot be paused from outside. It is covered by the close rule above. Verification: - `python3 -B tests/xgameruntime_table_check.py`: PASS - `python3 -B tests/docs_links_check.py`: PASS (18 files, 404 links) - Win2025 `x2w_pipe.py win2025 2179 --targets xgameruntime_shim,xgameruntime_shim_check,xgameruntime_contracts_check,xgameruntime_pls_xpackage_check,xgameruntime_identity_check,xgameruntime_gamesave_async_check,xgameruntime_preflight_exe --regex "^xgameruntime_"`: dev 7/7 and release 7/7 passed, including `xgameruntime_gamesave_async`. (`xgameruntime_preflight_exe` was added to the target list because `xgameruntime_preflight_stub_refused` needs it.) AI-assisted; commands listed were executed locally.
chatgpt-codex-connector[bot commented 2026-11-25 04:04:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T03:36:41Z.

Code review location: docs/experiments.md; line 11184

@@ -11169,10 +11168,25 @@ repeats each call for stability, checks the short-buffer and null-pointer errors
 and asserts that `XUserAddAsync` still logs `E_NOTIMPL`. The DLL remains under
 `out/build/dev/fixture-shims/` and is loaded by explicit path. The exact CTest
 names are `xgameruntime_thunks`, `xgameruntime_contracts`,
-`xgameruntime_pls_xpackage`, and `xgameruntime_identity`.
-
-```powershell
-cmake --build --preset dev --target xgameruntime_shim xgameruntime_shim_check xgameruntime_contracts_check xgameruntime_pls_xpackage_check xgameruntime_identity_check
+`xgameruntime_pls_xpackage`, `xgameruntime_identity`, and
+`xgameruntime_gamesave_async`.
+
+`XGameSaveInitializeProviderAsync` and `XGameSaveInitializeProviderResult` are
+implemented on top of the synchronous provider path. Argument errors (null
+block, null or empty configuration id, null or closed user) return from the call
+and leave the block untouched. A started operation completes before the call
+returns, calls the block's callback once on the calling thread, and the result
+is claimed exactly once (a second claim returns `E_INVALIDARG`). Reusing a block
+whose result is unclaimed returns `E_ILLEGAL_STATE_CHANGE` (0x8000000D). The shim keeps its
+state in a side table keyed by the block address and reads only the leading
+queue, context and callback fields. `XAsyncGetStatus`, `XTaskQueueCreate`,
+`XUserAddAsync` and `XPackageMountWithUiAsync` remain `E_NOTIMPL` stubs, and
+queue dispatch modes are not modeled. `xgameruntime_gamesave_async` covers the

P1 Badge Document the manual-queue completion requirement

For a caller using a shim-created Manual/Manual queue, XTaskQueueCreate now succeeds and the provider callback remains pending until completion-port dispatch. This section instead calls queue creation a stub and dispatch unmodeled, while the preceding sentence promises an inline callback for every operation. These reproduction notes therefore omit the pump required by the new fixture and describe a different completion contract; update the public capability documentation as required by AGENTS.md.

AGENTS.md reference: AGENTS.md:L236-L237

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4690071618 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2179#discussion_r4690071618). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T03:36:41Z. **Code review location:** `docs/experiments.md`; line 11184 ~~~~diff @@ -11169,10 +11168,25 @@ repeats each call for stability, checks the short-buffer and null-pointer errors and asserts that `XUserAddAsync` still logs `E_NOTIMPL`. The DLL remains under `out/build/dev/fixture-shims/` and is loaded by explicit path. The exact CTest names are `xgameruntime_thunks`, `xgameruntime_contracts`, -`xgameruntime_pls_xpackage`, and `xgameruntime_identity`. - -```powershell -cmake --build --preset dev --target xgameruntime_shim xgameruntime_shim_check xgameruntime_contracts_check xgameruntime_pls_xpackage_check xgameruntime_identity_check +`xgameruntime_pls_xpackage`, `xgameruntime_identity`, and +`xgameruntime_gamesave_async`. + +`XGameSaveInitializeProviderAsync` and `XGameSaveInitializeProviderResult` are +implemented on top of the synchronous provider path. Argument errors (null +block, null or empty configuration id, null or closed user) return from the call +and leave the block untouched. A started operation completes before the call +returns, calls the block's callback once on the calling thread, and the result +is claimed exactly once (a second claim returns `E_INVALIDARG`). Reusing a block +whose result is unclaimed returns `E_ILLEGAL_STATE_CHANGE` (0x8000000D). The shim keeps its +state in a side table keyed by the block address and reads only the leading +queue, context and callback fields. `XAsyncGetStatus`, `XTaskQueueCreate`, +`XUserAddAsync` and `XPackageMountWithUiAsync` remain `E_NOTIMPL` stubs, and +queue dispatch modes are not modeled. `xgameruntime_gamesave_async` covers the ~~~~ --- **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Document the manual-queue completion requirement** For a caller using a shim-created Manual/Manual queue, `XTaskQueueCreate` now succeeds and the provider callback remains pending until completion-port dispatch. This section instead calls queue creation a stub and dispatch unmodeled, while the preceding sentence promises an inline callback for every operation. These reproduction notes therefore omit the pump required by the new fixture and describe a different completion contract; update the public capability documentation as required by `AGENTS.md`. AGENTS.md reference: [AGENTS.md:L236-L237](https://github.com/R0Y00/Xbox2Windows/blob/6913280656d8c4ecdf5210a38144f7fdb6fb42a6/AGENTS.md#L236-L237) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 04:04:21 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T03:36:41Z.

Code review location: src/xgameruntime_shim.cpp; line 934

@@ -780,6 +833,175 @@ HRESULT game_save_initialize_provider(XUserHandle requesting_user, const char* c
     return E_OUTOFMEMORY;
 }
 
+ProviderAsyncSlot* find_provider_async(const XAsyncBlock* block) noexcept
+{
+    for (auto& slot : runtime_state.provider_asyncs) {
+        if (slot.live && slot.block == block) return &slot;
+    }
+    return nullptr;
+}
+
+XTaskQueueHandle find_live_task_queue(void* handle) noexcept
+{
+    for (auto& queue : runtime_state.task_queues) {
+        if (queue.live && &queue == handle) return &queue;
+    }
+    return nullptr;
+}
+
+// Only two queue configurations are recognized: no queue (the callback runs
+// inline on the caller's stack) and a live manual queue made by XTaskQueueCreate
+// in this shim (the callback waits for XTaskQueueDispatch on the completion
+// port). Any other queue value is refused with E_NOTIMPL before anything is
+// consumed. Other argument errors come back from the call itself, like the
+// synchronous path, and consume nothing. A started operation always completes
+// before this returns.
+HRESULT game_save_initialize_provider_async(XUserHandle requesting_user, const char* configuration_id,
+                                            bool sync_on_demand, XAsyncBlock* async_block) noexcept
+{
+    if (!async_block) return E_INVALIDARG;
+    AcquireSRWLockExclusive(&runtime_state.lock);
+    XTaskQueueHandle queue = nullptr;
+    if (async_block->queue) {
+        queue = find_live_task_queue(async_block->queue);
+        if (!queue) {
+            ReleaseSRWLockExclusive(&runtime_state.lock);
+            return not_implemented;
+        }
+    }
+    if (find_provider_async(async_block)) {
+        ReleaseSRWLockExclusive(&runtime_state.lock);
+        return e_illegal_state_change;
+    }
+    ProviderAsyncSlot* reserved = nullptr;
+    for (auto& slot : runtime_state.provider_asyncs) {
+        if (!slot.live) {
+            reserved = &slot;
+            break;
+        }
+    }
+    if (!reserved) {
+        ReleaseSRWLockExclusive(&runtime_state.lock);
+        return E_OUTOFMEMORY;
+    }
+    *reserved = ProviderAsyncSlot{};
+    reserved->live = true;
+    reserved->block = async_block;
+    reserved->queue = queue;
+    ReleaseSRWLockExclusive(&runtime_state.lock);
+
+    XGameSaveProviderHandle provider = nullptr;
+    const HRESULT status = game_save_initialize_provider(requesting_user, configuration_id,
+                                                         sync_on_demand, &provider);
+    AcquireSRWLockExclusive(&runtime_state.lock);
+    if (FAILED(status)) {
+        *reserved = ProviderAsyncSlot{};
+        ReleaseSRWLockExclusive(&runtime_state.lock);
+        return status;
+    }
+    reserved->provider = provider;
+    reserved->status = status;
+    reserved->completed = true;
+    XAsyncCompletionRoutine* const callback = async_block->callback;
+    const bool defer = queue && callback;
+    if (defer) {
+        reserved->callback_pending = true;
+        reserved->order = runtime_state.next_async_order++;
+    }
+    ReleaseSRWLockExclusive(&runtime_state.lock);
+    if (!defer && callback) callback(async_block);
+    return S_OK;
+}
+
+HRESULT game_save_initialize_provider_result(XAsyncBlock* async_block,
+                                             XGameSaveProviderHandle* provider) noexcept
+{
+    if (!provider) return E_POINTER;
+    *provider = nullptr;
+    if (!async_block) return E_INVALIDARG;
+    AcquireSRWLockExclusive(&runtime_state.lock);
+    ProviderAsyncSlot* slot = find_provider_async(async_block);
+    if (!slot) {
+        ReleaseSRWLockExclusive(&runtime_state.lock);
+        return E_INVALIDARG;
+    }
+    if (!slot->completed) {
+        ReleaseSRWLockExclusive(&runtime_state.lock);
+        return E_PENDING;
+    }
+    const HRESULT status = slot->status;
+    *provider = slot->provider;
+    *slot = ProviderAsyncSlot{};

P2 Badge Keep queued completion alive after a result claim

When a manual-queue operation is initialized successfully and its result is claimed before the completion port is pumped, resetting the entire slot also deletes callback_pending and the queue/block association. task_queue_dispatch then finds no entry, returns false, and never calls the registered completion routine, despite the operation having promised one deferred callback. Preserve the pending notification independently of the result claim, and only recycle the slot after both are finished.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4690071628 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2179#discussion_r4690071628). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T03:36:41Z. **Code review location:** `src/xgameruntime_shim.cpp`; line 934 ~~~~diff @@ -780,6 +833,175 @@ HRESULT game_save_initialize_provider(XUserHandle requesting_user, const char* c return E_OUTOFMEMORY; } +ProviderAsyncSlot* find_provider_async(const XAsyncBlock* block) noexcept +{ + for (auto& slot : runtime_state.provider_asyncs) { + if (slot.live && slot.block == block) return &slot; + } + return nullptr; +} + +XTaskQueueHandle find_live_task_queue(void* handle) noexcept +{ + for (auto& queue : runtime_state.task_queues) { + if (queue.live && &queue == handle) return &queue; + } + return nullptr; +} + +// Only two queue configurations are recognized: no queue (the callback runs +// inline on the caller's stack) and a live manual queue made by XTaskQueueCreate +// in this shim (the callback waits for XTaskQueueDispatch on the completion +// port). Any other queue value is refused with E_NOTIMPL before anything is +// consumed. Other argument errors come back from the call itself, like the +// synchronous path, and consume nothing. A started operation always completes +// before this returns. +HRESULT game_save_initialize_provider_async(XUserHandle requesting_user, const char* configuration_id, + bool sync_on_demand, XAsyncBlock* async_block) noexcept +{ + if (!async_block) return E_INVALIDARG; + AcquireSRWLockExclusive(&runtime_state.lock); + XTaskQueueHandle queue = nullptr; + if (async_block->queue) { + queue = find_live_task_queue(async_block->queue); + if (!queue) { + ReleaseSRWLockExclusive(&runtime_state.lock); + return not_implemented; + } + } + if (find_provider_async(async_block)) { + ReleaseSRWLockExclusive(&runtime_state.lock); + return e_illegal_state_change; + } + ProviderAsyncSlot* reserved = nullptr; + for (auto& slot : runtime_state.provider_asyncs) { + if (!slot.live) { + reserved = &slot; + break; + } + } + if (!reserved) { + ReleaseSRWLockExclusive(&runtime_state.lock); + return E_OUTOFMEMORY; + } + *reserved = ProviderAsyncSlot{}; + reserved->live = true; + reserved->block = async_block; + reserved->queue = queue; + ReleaseSRWLockExclusive(&runtime_state.lock); + + XGameSaveProviderHandle provider = nullptr; + const HRESULT status = game_save_initialize_provider(requesting_user, configuration_id, + sync_on_demand, &provider); + AcquireSRWLockExclusive(&runtime_state.lock); + if (FAILED(status)) { + *reserved = ProviderAsyncSlot{}; + ReleaseSRWLockExclusive(&runtime_state.lock); + return status; + } + reserved->provider = provider; + reserved->status = status; + reserved->completed = true; + XAsyncCompletionRoutine* const callback = async_block->callback; + const bool defer = queue && callback; + if (defer) { + reserved->callback_pending = true; + reserved->order = runtime_state.next_async_order++; + } + ReleaseSRWLockExclusive(&runtime_state.lock); + if (!defer && callback) callback(async_block); + return S_OK; +} + +HRESULT game_save_initialize_provider_result(XAsyncBlock* async_block, + XGameSaveProviderHandle* provider) noexcept +{ + if (!provider) return E_POINTER; + *provider = nullptr; + if (!async_block) return E_INVALIDARG; + AcquireSRWLockExclusive(&runtime_state.lock); + ProviderAsyncSlot* slot = find_provider_async(async_block); + if (!slot) { + ReleaseSRWLockExclusive(&runtime_state.lock); + return E_INVALIDARG; + } + if (!slot->completed) { + ReleaseSRWLockExclusive(&runtime_state.lock); + return E_PENDING; + } + const HRESULT status = slot->status; + *provider = slot->provider; + *slot = ProviderAsyncSlot{}; ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Keep queued completion alive after a result claim** When a manual-queue operation is initialized successfully and its result is claimed before the completion port is pumped, resetting the entire slot also deletes `callback_pending` and the queue/block association. `task_queue_dispatch` then finds no entry, returns false, and never calls the registered completion routine, despite the operation having promised one deferred callback. Preserve the pending notification independently of the result claim, and only recycle the slot after both are finished. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
chatgpt-codex-connector[bot commented 2026-11-25 04:04:22 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-25T03:36:41Z.

Code review location: src/xgameruntime_shim.cpp; line 997

@@ -780,6 +833,175 @@ HRESULT game_save_initialize_provider(XUserHandle requesting_user, const char* c
     return E_OUTOFMEMORY;
 }
 
+ProviderAsyncSlot* find_provider_async(const XAsyncBlock* block) noexcept
+{
+    for (auto& slot : runtime_state.provider_asyncs) {
+        if (slot.live && slot.block == block) return &slot;
+    }
+    return nullptr;
+}
+
+XTaskQueueHandle find_live_task_queue(void* handle) noexcept
+{
+    for (auto& queue : runtime_state.task_queues) {
+        if (queue.live && &queue == handle) return &queue;
+    }
+    return nullptr;
+}
+
+// Only two queue configurations are recognized: no queue (the callback runs
+// inline on the caller's stack) and a live manual queue made by XTaskQueueCreate
+// in this shim (the callback waits for XTaskQueueDispatch on the completion
+// port). Any other queue value is refused with E_NOTIMPL before anything is
+// consumed. Other argument errors come back from the call itself, like the
+// synchronous path, and consume nothing. A started operation always completes
+// before this returns.
+HRESULT game_save_initialize_provider_async(XUserHandle requesting_user, const char* configuration_id,
+                                            bool sync_on_demand, XAsyncBlock* async_block) noexcept
+{
+    if (!async_block) return E_INVALIDARG;
+    AcquireSRWLockExclusive(&runtime_state.lock);
+    XTaskQueueHandle queue = nullptr;
+    if (async_block->queue) {
+        queue = find_live_task_queue(async_block->queue);
+        if (!queue) {
+            ReleaseSRWLockExclusive(&runtime_state.lock);
+            return not_implemented;
+        }
+    }
+    if (find_provider_async(async_block)) {
+        ReleaseSRWLockExclusive(&runtime_state.lock);
+        return e_illegal_state_change;
+    }
+    ProviderAsyncSlot* reserved = nullptr;
+    for (auto& slot : runtime_state.provider_asyncs) {
+        if (!slot.live) {
+            reserved = &slot;
+            break;
+        }
+    }
+    if (!reserved) {
+        ReleaseSRWLockExclusive(&runtime_state.lock);
+        return E_OUTOFMEMORY;
+    }
+    *reserved = ProviderAsyncSlot{};
+    reserved->live = true;
+    reserved->block = async_block;
+    reserved->queue = queue;
+    ReleaseSRWLockExclusive(&runtime_state.lock);
+
+    XGameSaveProviderHandle provider = nullptr;
+    const HRESULT status = game_save_initialize_provider(requesting_user, configuration_id,
+                                                         sync_on_demand, &provider);
+    AcquireSRWLockExclusive(&runtime_state.lock);
+    if (FAILED(status)) {
+        *reserved = ProviderAsyncSlot{};
+        ReleaseSRWLockExclusive(&runtime_state.lock);
+        return status;
+    }
+    reserved->provider = provider;
+    reserved->status = status;
+    reserved->completed = true;
+    XAsyncCompletionRoutine* const callback = async_block->callback;
+    const bool defer = queue && callback;
+    if (defer) {
+        reserved->callback_pending = true;
+        reserved->order = runtime_state.next_async_order++;
+    }
+    ReleaseSRWLockExclusive(&runtime_state.lock);
+    if (!defer && callback) callback(async_block);
+    return S_OK;
+}
+
+HRESULT game_save_initialize_provider_result(XAsyncBlock* async_block,
+                                             XGameSaveProviderHandle* provider) noexcept
+{
+    if (!provider) return E_POINTER;
+    *provider = nullptr;
+    if (!async_block) return E_INVALIDARG;
+    AcquireSRWLockExclusive(&runtime_state.lock);
+    ProviderAsyncSlot* slot = find_provider_async(async_block);
+    if (!slot) {
+        ReleaseSRWLockExclusive(&runtime_state.lock);
+        return E_INVALIDARG;
+    }
+    if (!slot->completed) {
+        ReleaseSRWLockExclusive(&runtime_state.lock);
+        return E_PENDING;
+    }
+    const HRESULT status = slot->status;
+    *provider = slot->provider;
+    *slot = ProviderAsyncSlot{};
+    ReleaseSRWLockExclusive(&runtime_state.lock);
+    return status;
+}
+
+HRESULT task_queue_create(XTaskQueueDispatchMode work_mode, XTaskQueueDispatchMode completion_mode,
+                          XTaskQueueHandle* queue) noexcept
+{
+    if (!queue) return E_POINTER;
+    *queue = nullptr;
+    if (work_mode != XTaskQueueDispatchMode_Manual || completion_mode != XTaskQueueDispatchMode_Manual) {
+        return not_implemented;
+    }
+    AcquireSRWLockExclusive(&runtime_state.lock);
+    for (auto& slot : runtime_state.task_queues) {
+        if (!slot.live) {
+            slot.live = true;
+            *queue = &slot;
+            ReleaseSRWLockExclusive(&runtime_state.lock);
+            return S_OK;
+        }
+    }
+    ReleaseSRWLockExclusive(&runtime_state.lock);
+    return E_OUTOFMEMORY;
+}
+
+// Runs at most one waiting completion callback, oldest first, on the calling
+// thread, and reports whether it ran one. The work port never holds anything.
+bool task_queue_dispatch(XTaskQueueHandle queue, XTaskQueuePort port, std::uint32_t) noexcept
+{
+    if (port != XTaskQueuePort_Completion) return false;
+    AcquireSRWLockExclusive(&runtime_state.lock);
+    if (!find_live_task_queue(queue)) {
+        ReleaseSRWLockExclusive(&runtime_state.lock);
+        return false;
+    }
+    ProviderAsyncSlot* next = nullptr;
+    for (auto& slot : runtime_state.provider_asyncs) {
+        if (slot.live && slot.callback_pending && slot.queue == queue &&
+            (!next || slot.order < next->order)) {
+            next = &slot;
+        }
+    }
+    if (!next) {
+        ReleaseSRWLockExclusive(&runtime_state.lock);
+        return false;
+    }
+    next->callback_pending = false;
+    XAsyncBlock* const block = const_cast<XAsyncBlock*>(next->block);
+    XAsyncCompletionRoutine* const callback = block->callback;
+    ReleaseSRWLockExclusive(&runtime_state.lock);
+    if (callback) callback(block);
+    return true;
+}
+
+// A queue with callbacks still waiting stays alive, so they are never stranded.
+HRESULT task_queue_close_handle(XTaskQueueHandle queue) noexcept
+{
+    AcquireSRWLockExclusive(&runtime_state.lock);
+    HRESULT result = E_INVALIDARG;
+    if (find_live_task_queue(queue)) {
+        result = S_OK;
+        for (const auto& slot : runtime_state.provider_asyncs) {
+            if (slot.live && slot.callback_pending && slot.queue == queue) result = e_illegal_state_change;

P2 Badge Retain queues while provider initialization is in flight

If one thread closes the queue while another is in game_save_initialize_provider_async between reserving the async slot and publishing callback_pending, this condition lets the close mark the queue dead. The initializer subsequently returns S_OK with a pending callback, but dispatch rejects the closed queue, so the callback is stranded or can be picked up by a later queue reusing that slot. Count the in-flight reservation as a queue user before dropping the initialization lock, rather than protecting only callbacks that are already pending.

Useful? React with 👍 / 👎.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review-comment:4690071637 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2179#discussion_r4690071637). Originally posted by [chatgpt-codex-connector[bot]](https://github.com/chatgpt-codex-connector%5Bbot%5D) on 2026-11-25T03:36:41Z. **Code review location:** `src/xgameruntime_shim.cpp`; line 997 ~~~~diff @@ -780,6 +833,175 @@ HRESULT game_save_initialize_provider(XUserHandle requesting_user, const char* c return E_OUTOFMEMORY; } +ProviderAsyncSlot* find_provider_async(const XAsyncBlock* block) noexcept +{ + for (auto& slot : runtime_state.provider_asyncs) { + if (slot.live && slot.block == block) return &slot; + } + return nullptr; +} + +XTaskQueueHandle find_live_task_queue(void* handle) noexcept +{ + for (auto& queue : runtime_state.task_queues) { + if (queue.live && &queue == handle) return &queue; + } + return nullptr; +} + +// Only two queue configurations are recognized: no queue (the callback runs +// inline on the caller's stack) and a live manual queue made by XTaskQueueCreate +// in this shim (the callback waits for XTaskQueueDispatch on the completion +// port). Any other queue value is refused with E_NOTIMPL before anything is +// consumed. Other argument errors come back from the call itself, like the +// synchronous path, and consume nothing. A started operation always completes +// before this returns. +HRESULT game_save_initialize_provider_async(XUserHandle requesting_user, const char* configuration_id, + bool sync_on_demand, XAsyncBlock* async_block) noexcept +{ + if (!async_block) return E_INVALIDARG; + AcquireSRWLockExclusive(&runtime_state.lock); + XTaskQueueHandle queue = nullptr; + if (async_block->queue) { + queue = find_live_task_queue(async_block->queue); + if (!queue) { + ReleaseSRWLockExclusive(&runtime_state.lock); + return not_implemented; + } + } + if (find_provider_async(async_block)) { + ReleaseSRWLockExclusive(&runtime_state.lock); + return e_illegal_state_change; + } + ProviderAsyncSlot* reserved = nullptr; + for (auto& slot : runtime_state.provider_asyncs) { + if (!slot.live) { + reserved = &slot; + break; + } + } + if (!reserved) { + ReleaseSRWLockExclusive(&runtime_state.lock); + return E_OUTOFMEMORY; + } + *reserved = ProviderAsyncSlot{}; + reserved->live = true; + reserved->block = async_block; + reserved->queue = queue; + ReleaseSRWLockExclusive(&runtime_state.lock); + + XGameSaveProviderHandle provider = nullptr; + const HRESULT status = game_save_initialize_provider(requesting_user, configuration_id, + sync_on_demand, &provider); + AcquireSRWLockExclusive(&runtime_state.lock); + if (FAILED(status)) { + *reserved = ProviderAsyncSlot{}; + ReleaseSRWLockExclusive(&runtime_state.lock); + return status; + } + reserved->provider = provider; + reserved->status = status; + reserved->completed = true; + XAsyncCompletionRoutine* const callback = async_block->callback; + const bool defer = queue && callback; + if (defer) { + reserved->callback_pending = true; + reserved->order = runtime_state.next_async_order++; + } + ReleaseSRWLockExclusive(&runtime_state.lock); + if (!defer && callback) callback(async_block); + return S_OK; +} + +HRESULT game_save_initialize_provider_result(XAsyncBlock* async_block, + XGameSaveProviderHandle* provider) noexcept +{ + if (!provider) return E_POINTER; + *provider = nullptr; + if (!async_block) return E_INVALIDARG; + AcquireSRWLockExclusive(&runtime_state.lock); + ProviderAsyncSlot* slot = find_provider_async(async_block); + if (!slot) { + ReleaseSRWLockExclusive(&runtime_state.lock); + return E_INVALIDARG; + } + if (!slot->completed) { + ReleaseSRWLockExclusive(&runtime_state.lock); + return E_PENDING; + } + const HRESULT status = slot->status; + *provider = slot->provider; + *slot = ProviderAsyncSlot{}; + ReleaseSRWLockExclusive(&runtime_state.lock); + return status; +} + +HRESULT task_queue_create(XTaskQueueDispatchMode work_mode, XTaskQueueDispatchMode completion_mode, + XTaskQueueHandle* queue) noexcept +{ + if (!queue) return E_POINTER; + *queue = nullptr; + if (work_mode != XTaskQueueDispatchMode_Manual || completion_mode != XTaskQueueDispatchMode_Manual) { + return not_implemented; + } + AcquireSRWLockExclusive(&runtime_state.lock); + for (auto& slot : runtime_state.task_queues) { + if (!slot.live) { + slot.live = true; + *queue = &slot; + ReleaseSRWLockExclusive(&runtime_state.lock); + return S_OK; + } + } + ReleaseSRWLockExclusive(&runtime_state.lock); + return E_OUTOFMEMORY; +} + +// Runs at most one waiting completion callback, oldest first, on the calling +// thread, and reports whether it ran one. The work port never holds anything. +bool task_queue_dispatch(XTaskQueueHandle queue, XTaskQueuePort port, std::uint32_t) noexcept +{ + if (port != XTaskQueuePort_Completion) return false; + AcquireSRWLockExclusive(&runtime_state.lock); + if (!find_live_task_queue(queue)) { + ReleaseSRWLockExclusive(&runtime_state.lock); + return false; + } + ProviderAsyncSlot* next = nullptr; + for (auto& slot : runtime_state.provider_asyncs) { + if (slot.live && slot.callback_pending && slot.queue == queue && + (!next || slot.order < next->order)) { + next = &slot; + } + } + if (!next) { + ReleaseSRWLockExclusive(&runtime_state.lock); + return false; + } + next->callback_pending = false; + XAsyncBlock* const block = const_cast<XAsyncBlock*>(next->block); + XAsyncCompletionRoutine* const callback = block->callback; + ReleaseSRWLockExclusive(&runtime_state.lock); + if (callback) callback(block); + return true; +} + +// A queue with callbacks still waiting stays alive, so they are never stranded. +HRESULT task_queue_close_handle(XTaskQueueHandle queue) noexcept +{ + AcquireSRWLockExclusive(&runtime_state.lock); + HRESULT result = E_INVALIDARG; + if (find_live_task_queue(queue)) { + result = S_OK; + for (const auto& slot : runtime_state.provider_asyncs) { + if (slot.live && slot.callback_pending && slot.queue == queue) result = e_illegal_state_change; ~~~~ --- **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Retain queues while provider initialization is in flight** If one thread closes the queue while another is in `game_save_initialize_provider_async` between reserving the async slot and publishing `callback_pending`, this condition lets the close mark the queue dead. The initializer subsequently returns `S_OK` with a pending callback, but dispatch rejects the closed queue, so the callback is stranded or can be picked up by a later queue reusing that slot. Count the in-flight reservation as a queue user before dropping the initialization lock, rather than protecting only callbacks that are already pending. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
upstream-sync closed this pull request 2026-11-25 05:04:45 +00:00
R0Y00 commented 2026-11-25 05:04:46 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T04:07:36Z.

Review: APPROVED


The exact revised source passed all six Windows Release runtime checks and 20 repeated async runs. The shim now refuses the unmodeled default queue, preserves the result across an early E_PENDING, and waits for work or a finite deadline as requested. A poll-only mutation failed both the empty-port expiry and delayed-completion assertions. This remains a source-built Manual/Manual result with no new application startup claim.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6051720322 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2179#pullrequestreview-6051720322). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T04:07:36Z. **Review:** APPROVED --- The exact revised source passed all six Windows Release runtime checks and 20 repeated async runs. The shim now refuses the unmodeled default queue, preserves the result across an early E_PENDING, and waits for work or a finite deadline as requested. A poll-only mutation failed both the empty-port expiry and delayed-completion assertions. This remains a source-built Manual/Manual result with no new application startup claim.
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
R0Y00/Xbox2Windows!2171
No description provided.