Skip to content

hle: bind queued async work to its original call - #80

Merged
fogydes merged 1 commit into
MiamiGame:mainfrom
smecherucarbarou:hle/async-queued-work-prerequisite
Nov 26, 2026
Merged

fogydes merged 1 commit into
MiamiGame:mainfrom
smecherucarbarou:hle/async-queued-work-prerequisite

Conversation

@smecherucarbarou

@smecherucarbarou smecherucarbarou commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

What and why

Prerequisite for #42

Queued async work currently resolves its provider by block address when dispatched. After completion and address reuse, old work can invoke or cancel the newer call. A work callback that completes inline can also let its return value complete the replacement call.

Capture the original call through a weak reference in a task-owned context and complete that call directly. Completed or expired calls are skipped. Context ownership ends on dispatch, canceled delivery, rejected submission or queue disposal. Weak ownership avoids a Call/Queue/Task cycle when #42 introduces runtime-owned provider state.

Only crates/xtp-hle/src/modules/xasync.rs changes: 342 changed lines (+331/-11), comprising 51 production (+40/-11) and 291 test (+291/-0). Provider admission/cleanup ordering and completion-queue ownership remain separate contributions. Existing #30/#44 waiting behavior is preserved.

Fixes: none
Depends on: none

Area

xtp-hle: XAsyncSchedule work identity and queued context lifetime.

Tests

  • cargo xtask pr-check passes on my machine
  • New or changed behaviour has tests that need no game files, or I explain below why it cannot
  • Ran on a title: no

Native Windows x64, pinned Rust 1.98.1; base 9b822f58870e351613666129ca5621c6a4955fb7.

  • Before the fix, deterministic tests on unchanged upstream production demonstrated old work invoking the newer provider and an inline completion's work return completing a reused block. Failure logs are retained locally.
  • Final XAsync suite: 20/20 passed, including all upstream tests. 25 consecutive full focused runs: 500 successful executions, including 75 executions of the three new tests.
  • Synthetic cases cover normal/canceled/delayed dispatch, completed calls retained by waiters, callback-driven reuse, rejected submission, immediate/delayed queue disposal and a weak-ownership cycle model. Child execution markers and 20-second deadlines bound the tests; delayed delivery uses a monitor/thread-exit handshake.
  • HLE default and all-features: each passed 204 unit tests and 8 integration tests; 2 unit tests ignored.
  • Complete cargo xtask pr-check --title "hle: bind queued async work to its original call": 5/6 passed (fmt, clippy, clippy-diagnostics, policy, conventions). Workspace tests fail only in the two GPU tests below; the proposed title passes. No contribution commit exists yet, so the commit convention check covered zero commits.
  • Supplemental cargo test --workspace --locked --no-fail-fast: 1,668 passed, 2 failed, 69 ignored, including doctests. Only xtp-gpu --lib failed.
  • The identical failures reproduce on a clean worktree at the same upstream base with an independent build directory: host::twins::tests::a_24_bit_plane_copied_in_a_query_holds_what_the_pass_draws_for_floats (same 1,412 float differences) and host::twins::tests::a_pass_leaves_no_scissor_where_the_title_set_none (intermittent; reproduced in the first repeat). Clean baseline GPU runs: 632 passed/1 failed/14 ignored, then 631 passed/2 failed/14 ignored. No GPU code or assertions were modified.

Provenance

  • I wrote all of this change myself for XTP, or it only moves code already in XTP.
  • Some of it comes from elsewhere. Each source, its licence and the files concerned are listed here, and every licence is compatible with GPL-3.0-or-later:

Original Rust implementation and synthetic fixtures for XTP. Adapted the applicable task-context ownership pattern and callback-reuse regression from the earlier local XTP contribution 0d455a115e9874585099557410aa0deb52fdb883; replaced its strong call capture with a weak reference. No external implementation code was copied or translated. Maintainer scope approval: #42 (comment).

AI assistance: OpenAI Codex implemented the change and tests, reviewed ownership paths, ran validation, and prepared this description. The contributor remains responsible for every line.

Checklist

  • No game data, keys, console SDK code or headers, and nothing that circumvents DRM (asset policy)
  • No code copied from xcl or AnyPS5 (references only: read them to understand, write your own)
  • I agree to license this contribution under GPL-3.0-or-later
  • Title and every commit follow <area>: <summary>; one topic; under 400 changed lines, or the reason is above
  • Docs updated where behaviour, commands or variables changed (README, docs/)

No command, environment-variable or public API changes require additional documentation; the local ownership contract is documented beside the implementation. No commit has been created yet.

@github-actions github-actions Bot added area/hle touches crates/xtp-hle size/M 100 to 399 changed lines labels Nov 25, 2026

@fogydes fogydes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed exact head 2a2d121 with an independent source review and the current-head CI logs. No correctness blocker found within the agreed queued-work identity prerequisite for #42. Capturing Weak prevents stale queued work from resolving a reused caller address; completing the captured Call also preserves the replacement after inline callback reuse. Task-owned context survives dispatch and is released on rejection/disposal without creating the future Call/Queue cycle. The additional state check releases its lock before provider entry. CI confirms all 20 XAsync tests, 204 HLE unit tests and eight integration tests passed, including the three new regressions. All current PR checks are green. Local contributor stress results were not independently rerun. Provider admission versus cleanup, cooperative cancellation and provider-private/public completion ordering remain explicitly deferred to #42; this approval does not treat those existing races as solved. AI assistance: Codex performed source review and inspected existing CI evidence.

@fogydes
fogydes merged commit 7d0de20 into MiamiGame:main Nov 26, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/hle touches crates/xtp-hle size/M 100 to 399 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants