XAsync: a new block where a result was left behind begins a call #247

Manually merged
github merged 1 commit from gh-pr/247/head into gh-pr/247/base 2026-11-26 03:56:29 +00:00
Owner

@⁠Maraco91 on GitHub · 2026-11-24 01:46 UTC · original
Maraco91:xasync/new-block-at-abandoned-address → main · +77 −1 · 1 files · 1 commits · merged 2026-11-25 00:10 UTC

What

After a title leaves one result unfetched, every later async call whose block lands on that address fails with E_INVALIDARG.

Calls are filed in CALLS by their block's address. A call that fails, or succeeds with nothing to fetch, is removed when it completes; one that succeeds with a result stays filed until XAsyncGetResult takes it. XAsyncBegin refuses a block if any call is filed under its address:

if block.is_null() || call(block).is_some() {
    return E_INVALIDARG;
}

A title that does not fetch a result (it only wanted the status, it gave up, its fetch failed with too small a buffer) and then frees the block leaves that entry behind for good. Blocks are small heap objects of one size, so the allocator hands the same address out again soon, and from then on a new, zeroed block there cannot begin any call: not the title's own providers', and not ours (finished_with/pending_with go through XAsyncBegin too, so users, saves, the store). The old call's provider never gets its cleanup either.

On the console the state of a call lives in the block's own system area, not in a table by address (as I remember the open-source implementation of this API: it refuses a block whose system area is not zero, and a zeroed block is always a new one). The same test works here: the block of a result left behind holds the result's size in that area, so it never reads zero.

XAsyncBegin now, when a call is filed under the block's address:

  • finished call and a zeroed block: ends the call left behind (its provider gets Cleanup) and begins the new one;
  • call still in flight: E_INVALIDARG, as before, whatever the block holds;
  • block still holding the result (not zeroed): E_INVALIDARG, as before.

I have not seen which results the title leaves unfetched (I have no game files).

Tested

Windows 11 Pro 10.0.26200, rustc 1.98.1 (x86_64-pc-windows-msvc), no game data, no GPU involved.

New unit test a_new_block_where_a_result_was_left_begins_a_call: a provider that completes with one byte to fetch and counts its cleanups.

  1. Control: beginning again on the block as the call left it is refused (E_INVALIDARG), no cleanup.
  2. The block is replaced by a zeroed one at the same address; a call through finished_with begins (S_OK), the call left behind got exactly one cleanup, and the new call's result (9) is fetched and the call ends.
  3. Control: a call that never completes, its block replaced by a zeroed one: beginning there is still refused.

Results:

  • main (d2a4bae) + the test only: cargo test -p victory-hle --lib a_new_block_where fails at step 2: left: -2147024809 (E_INVALIDARG), right: 0. Step 1 passes.
  • with the fix: cargo test -p victory-hle --lib: 87 passed, 0 failed (xasync: 6).
  • cargo clippy -p victory-hle --tests: nothing in xasync.rs. rustfmt --check: nothing in the lines changed (existing differences at pending_with and near it).
  • cargo xtask policy: 151 files ok.
  • Trial merges (git merge-tree) with the open PRs on this file, #114, #122, #132, #236 and #239: all clean. #122 and #236 are about a block reused while a call's work or completion is still on its way; this is the entry a fetched-never call leaves filed, which they do not touch.

Not tested: a title run.

AI-assisted (Claude Code); the tests above were run on the machine described.

🤖 Generated with Claude Code

**@⁠Maraco91** on GitHub · 2026-11-24 01:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/247) `Maraco91:xasync/new-block-at-abandoned-address` → `main` · +77 −1 · 1 files · 1 commits · merged 2026-11-25 00:10 UTC ## What After a title leaves one result unfetched, every later async call whose block lands on that address fails with `E_INVALIDARG`. Calls are filed in `CALLS` by their block's address. A call that fails, or succeeds with nothing to fetch, is removed when it completes; one that succeeds with a result stays filed until `XAsyncGetResult` takes it. `XAsyncBegin` refuses a block if any call is filed under its address: ```rust if block.is_null() || call(block).is_some() { return E_INVALIDARG; } ``` A title that does not fetch a result (it only wanted the status, it gave up, its fetch failed with too small a buffer) and then frees the block leaves that entry behind for good. Blocks are small heap objects of one size, so the allocator hands the same address out again soon, and from then on a new, zeroed block there cannot begin any call: not the title's own providers', and not ours (`finished_with`/`pending_with` go through `XAsyncBegin` too, so users, saves, the store). The old call's provider never gets its cleanup either. On the console the state of a call lives in the block's own system area, not in a table by address (as I remember the open-source implementation of this API: it refuses a block whose system area is not zero, and a zeroed block is always a new one). The same test works here: the block of a result left behind holds the result's size in that area, so it never reads zero. `XAsyncBegin` now, when a call is filed under the block's address: - finished call and a zeroed block: ends the call left behind (its provider gets `Cleanup`) and begins the new one; - call still in flight: `E_INVALIDARG`, as before, whatever the block holds; - block still holding the result (not zeroed): `E_INVALIDARG`, as before. I have not seen which results the title leaves unfetched (I have no game files). ## Tested Windows 11 Pro 10.0.26200, rustc 1.98.1 (`x86_64-pc-windows-msvc`), no game data, no GPU involved. New unit test `a_new_block_where_a_result_was_left_begins_a_call`: a provider that completes with one byte to fetch and counts its cleanups. 1. Control: beginning again on the block as the call left it is refused (`E_INVALIDARG`), no cleanup. 2. The block is replaced by a zeroed one at the same address; a call through `finished_with` begins (`S_OK`), the call left behind got exactly one cleanup, and the new call's result (9) is fetched and the call ends. 3. Control: a call that never completes, its block replaced by a zeroed one: beginning there is still refused. Results: - `main` (d2a4bae) + the test only: `cargo test -p victory-hle --lib a_new_block_where` **fails** at step 2: `left: -2147024809` (`E_INVALIDARG`), `right: 0`. Step 1 passes. - with the fix: `cargo test -p victory-hle --lib`: **87 passed, 0 failed** (xasync: 6). - `cargo clippy -p victory-hle --tests`: nothing in `xasync.rs`. `rustfmt --check`: nothing in the lines changed (existing differences at `pending_with` and near it). - `cargo xtask policy`: 151 files ok. - Trial merges (`git merge-tree`) with the open PRs on this file, #114, #122, #132, #236 and #239: all clean. #122 and #236 are about a block reused while a call's work or completion is still on its way; this is the entry a fetched-never call leaves filed, which they do not touch. Not tested: a title run. AI-assisted (Claude Code); the tests above were run on the machine described. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Calls are filed by their block's address, and a call that succeeded with
a result stays filed until XAsyncGetResult takes it. XAsyncBegin refused
any block whose address had a call filed. So when a title never took a
result and freed the block, the next block it was given at that address
could not begin a call: E_INVALIDARG, every time, with the old call's
provider never cleaned up.

A zeroed block is a new one: the block of a result left behind holds the
result's size, so it never reads zero. XAsyncBegin now ends a finished
call filed under the address of a zeroed block (its provider gets its
cleanup) and begins the new one. A call still in flight keeps its
address, and a block still holding a result is refused as before.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:56:27 +00:00
github manually merged commit 5cff0007a5 into gh-pr/247/base 2026-11-26 03:56:29 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 05:28 UTC · original

Tested current PR head 5cff0007a525b83f5c69912d7a38f53c6dafcfef.

  • cargo test --locked -p victory-hle --lib xasync -- --test-threads=1: 6 passed. The new a_new_block_where_a_result_was_left_begins_a_call test covers the prior completed call whose result was never fetched, same-address reuse with a zeroed new block, preservation of a result-bearing block, and rejection while a call is still in flight. The same target also passed normal result completion, manual and pool callback dispatch, work-result return, and queued cancellation (XAsyncBegin logic, regression test).
  • git diff --check d2a4bae1f49533ef5cb512fd1b1ba1513f2e1989 HEAD: passed.

These are unit tests using synthetic providers and async blocks; they do not exercise a real title or runtime integration.

**@⁠jeremygold02** on GitHub · 2026-11-24 05:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/247#issuecomment-7122976208) Tested current PR head `5cff0007a525b83f5c69912d7a38f53c6dafcfef`. - `cargo test --locked -p victory-hle --lib xasync -- --test-threads=1`: 6 passed. The new `a_new_block_where_a_result_was_left_begins_a_call` test covers the prior completed call whose result was never fetched, same-address reuse with a zeroed new block, preservation of a result-bearing block, and rejection while a call is still in flight. The same target also passed normal result completion, manual and pool callback dispatch, work-result return, and queued cancellation ([XAsyncBegin logic](https://github.com/Marvisak/VIctory/blob/5cff0007a525b83f5c69912d7a38f53c6dafcfef/crates/victory-hle/src/modules/xasync.rs#L509-L564), [regression test](https://github.com/Marvisak/VIctory/blob/5cff0007a525b83f5c69912d7a38f53c6dafcfef/crates/victory-hle/src/modules/xasync.rs#L1099-L1153)). - `git diff --check d2a4bae1f49533ef5cb512fd1b1ba1513f2e1989 HEAD`: passed. These are unit tests using synthetic providers and async blocks; they do not exercise a real title or runtime integration.
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!247
No description provided.