feat(xgameruntime): implement XAsync #10
No reviewers
Labels
No labels
accessibility
bug
ci
docs
documentation
duplicate
enhancement
fixes issue
good first issue
help wanted
invalid
library request
libs
needs rebase
question
relinker
stale
tools
unblocks title
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Dark3581--AnyBox!10
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/10/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@CaseReed on GitHub · 2026-11-21 06:41 UTC · original
CaseReed:feat/xasync→main· +1172 −25 · 13 files · 2 commits · merged 2026-11-21 08:37 UTCWhat
Implements XAsync (#1):
XAsyncBegin,XAsyncRun,XAsyncSchedule,XAsyncComplete,XAsyncCancel,XAsyncGetStatus,XAsyncGetResultandXAsyncGetResultSize, in a newAsync.cppbuilt on the existing XTaskQueue exports.TaskQueue.cppis unchanged.Rebased onto
mainnow that #8 and #9 are merged: two commits, the implementation and the review fix below.Provenance. The code is written for AnyBox, not adapted, so the file carries no upstream notice. Signatures, the
XAsyncBlocklayout, return codes and the order of provider ops follow the public MIT sources inmicrosoft/libHttpClient:Include/XAsync.h,Include/XAsyncProvider.h,Source/Task/AsyncLib.cpp,Tests/UnitTests/Tests/AsyncBlockTests.cppandInclude/httpClient/pal.h(forE_NO_TASK_QUEUE). The headers are not copied; types are redeclared inTypes.hpp. No GDK binary was opened.Design.
Callobject. The 32internalbytes of the title's block hold 24 bytes: a signature, the final status, a pointer to theCalland a serial number. A block is trusted only if its pointer is in a registry, its serial matches and theCallpoints back at it, so arbitrary bytes are never taken for a live call.static_asserts pin the size and offsets ofXAsyncBlockandXAsyncProviderData.Immediatedispatch mode.Call, as in the reference, so it can still schedule or complete after the title has released its own block.Cleanupruns once, when the last reference to the call is dropped, never during another op.Where it stops, and where it differs from the reference (all in the debt fragment, each with a
Closes when:where one is measurable):AbxUnsupported. The reference holds termination until outstanding calls finish; XTaskQueue cannot do that today.XAsyncBeginon an already terminated queue does not returnE_ABORTup front, because XTaskQueue exposes no termination state. Fixing either of these two needs a change inTaskQueue.cpp, which I left alone; tell me if you want it.XAsyncCancelfollowsXAsync.h("does nothing if the call has already completed"), whereAsyncLib.cppstill invokesCancelon a call completed with a payload not yet retrieved.Cleanupcan run later than in the reference.XAsyncCancelandXAsyncComplete, and stops for the four functions where the reference would return whatever its status field holds.Supporting changes: the eight stubs leave
Inventory.cpp;FakeXGameRuntime.cppgets eight deliberately wrong exports so a misrouted call fails;e2e.pygets a per-scenario table for the expected stop function;README.md,ARCHITECTURE.mdand the pendinggdk-inventory.mdfragment are updated where this change made a sentence untrue.Review fix (second commit). When
XTaskQueueSubmitDelayedCallbackfailed,XAsyncScheduleleftworkScheduledset, so the next call returnedE_UNEXPECTEDinstead of the queue's error. The flag is now cleared under the registry mutex before the reference is released.e2e_asyncschedules twice on a terminated queue and expectsE_ABORTboth times; with the fix removed that case fails. The reference keeps its flag set after a failed submit, so the divergence is recorded in debt.Tested
Windows 11, MSVC 19.38 (VS 2022), CMake 4.4.4, Ninja 1.13.2, clean build directory, on
mainat60b902f.ctest: 34/34 (30 existing, 4 new:e2e_async,e2e_async_null,e2e_async_terminated,e2e_async_begin_terminated), each under 0.4 s.e2e_asynccovers:XAsyncRunwith a completion callback;XAsyncGetStatuswith and without wait, including from the call's own callback; a full provider (Begin,Schedule,DoWork,Completewith payload,GetResultSize,GetResult,Cleanup), also withGetResultcalled inside the callback; delayed work;DoWorkreturningE_PENDINGand rescheduling; cancellation in both dispatch orders; wrong identity; zeroed blocks; no process task queue; a completion still queued when the queue is terminated; 1000 concurrent calls.e2e_async200/200 sequential and 200/200 with four processes in parallel; the two stop scenarios 50/50 each.Async.cpp, each caught by a test, the file restored and rebuilt after each.python tools/check_conventions.py: ok.python tools/debt_fold.py --check: 3 fragments apply cleanly.python tools/progress.py --module xgameruntime: 15 → 23 implemented, 376 → 368 stubs.Async.cpp(with the project headers inlined),FakeTitle.cppandFakeXGameRuntime.cppcompile without error or warning under-std=c++20 -Wall -Wextrawith MinGW GCC 13.1, 15.2 and 16.2 on Compiler Explorer (after the review fix: 15.2 only).Not tested: the full MinGW build and its test run (no GCC on this machine; relies on CI), the
E_OUTOFMEMORYpaths (no way to inject an allocation failure), a non-zero block that no call owns passed to the four functions that stop, and anything on a console. Two checks ine2e_async(a waiting status must not return before the completion callback; the block must not be written after a wait returns) are timing-dependent: they catch their mutant in practice but cannot fail deterministically without a sleep. A blocked scenario fails after 20 s through a watchdog, under the 30 s limit.Self-review. Before opening this, an independent read of the first version found one real defect (scheduled work could still run
DoWorkon a call canceled while it had a completion callback, hidden by the dispatch order of the test), a stop where the result is defined (E_NO_TASK_QUEUE), a stop on a zeroed block that the reference ignores, and missing test cases. All are fixed in this commit and each fix has a mutation that fails a test.Checklist
main; no other open PR implements the same functionspython tools/check_conventions.pypasses (no comments in code, one declaration per export, Conventional Commit subjects)AbxNotImplemented/AbxUnsupported); silent stubs are listed under Silent stubs through a debt fragment (no silent stub added)docs/dev/debt/changes/<branch>.md(feat-xasync.md;debt_fold.pyreadschanges/*.mdonly)Include/XAsync.h,Include/XAsyncProvider.h,Source/Task/AsyncLib.cpp,Tests/UnitTests/Tests/AsyncBlockTests.cpp,Include/httpClient/pal.h)🤖 Generated with Claude Code
@Dark3581 on GitHub · 2026-11-21 07:00 UTC · original · requested changes
Changes requested
One small defect in
XAsyncScheduleblocks this. The rest is careful work and passes everything I ran, including repeated stress runs.What I ran
Reviewed head
1080b4a. Built it with MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10 from a clean build directory. #8 and #9 are now squash-merged onmain.Results
e2e_asyncande2e_taskqueue, repeatedtools/check_conventions.pytools/debt_fold.py --checktools/progress.py --module xgameruntimeFindings
Blocking
core/libs/xdll/xgameruntime/Async.cpp:389: whenXTaskQueueSubmitDelayedCallbackfails,XAsyncScheduledrops its reference but leavescall->workScheduledset totrue(set at line 384). NoWorkCallbackwill ever run to clear it (line 258), so every laterXAsyncScheduleon that call returnsE_UNEXPECTEDat line 380 instead of the queue's own error. Concretely: a provider whose queue was terminated callsXAsyncScheduleand getsE_ABORT. If it callsXAsyncScheduleagain, it getsE_UNEXPECTED, which reads as "work is already scheduled" when nothing is.Fix: on failure, clear
workScheduledunder the registry mutex before releasing, for example and add a case toe2e_async: schedule twice on a terminated queue and expectE_ABORTboth times.Non-blocking
None.
Not verified
The
E_OUTOFMEMORYpaths and anything on a console, as you noted. I did not repeat your mutation check.To get this to a good state
Fix the flag reset with its test, and rebase onto
mainso the PR shows only the XAsync commit. Happy to merge right after.@ -0,0 +390,4 @@std::lock_guard lock(registry.mutex);call->workScheduled = false;}Release(call);@Dark3581 on GitHub · 2026-11-21 07:00 UTC · original
workScheduledstaystruehere when the submit fails, so the nextXAsyncScheduleon this call returnsE_UNEXPECTEDinstead of the queue's error. Clear it under the registry mutex beforeRelease(call). Details in the review.@github-actions[bot] on GitHub · 2026-11-21 07:14 UTC · original
This pull request conflicts with
main. Rebase it on currentmainand force-push the branch; the label is removed automatically once it merges cleanly.@github-actions[bot] on GitHub · 2026-11-21 08:32 UTC · original
Progress report (
60b902f→f79f11d)📈 Libraries: 15.54% (+1.8018%, +8 implemented functions)
✅ 8 implemented
XAsyncBeginXAsyncCancelXAsyncCompleteXAsyncGetResultXAsyncGetResultSizeXAsyncGetStatusXAsyncRunXAsyncScheduleChanged libraries
@CaseReed on GitHub · 2026-11-21 08:35 UTC · original
Thanks for the review and for running the MinGW build. Fixed in
f79f11d:XAsyncSchedulenow clearsworkScheduledunder the registry mutex when the submit fails, ande2e_asyncschedules twice on a terminated queue and expectsE_ABORTboth times (the case fails with the fix removed). The reference keeps its flag set there, so I recorded the divergence in the debt fragment. Rebased ontomain: the PR now shows the XAsync commit and this fix. Rebuilt with MSVC 19.38, 34/34, and CI is green on the new head.@Dark3581 on GitHub · 2026-11-21 08:37 UTC · original · approved these changes
Reviewed — looks good
Merging as it is. The one open point,
XAsyncScheduleafter a failed submit, is mine to settle: I'll restore the reference behaviour (E_UNEXPECTEDon the second call) in a follow-up commit onmain, with your scenario adjusted and the debt entry removed, so you don't need another round.What I ran
Head
f79f11d, rebased onmain(60b902f). MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory.Results
e2e_async, repeatedtools/check_conventions.py,tools/debt_fold.py --checkFindings
Blocking
None.
Non-blocking
XAsyncScheduleclears its scheduled flag after a failed submit, whereAsyncLib.cppkeeps it set. Follow-up onmain, as above.Not verified
The
E_OUTOFMEMORYpaths and console behaviour, as recorded in debt.Thanks for a careful and very well tested implementation.
@Dark3581 on GitHub · 2026-11-21 08:39 UTC · original
Follow-up landed in
81a02cc:XAsyncSchedulekeeps its flag set after a refused submit, asAsyncLib.cppdoes. Your scenario now expectsE_ABORTand thenE_UNEXPECTED(it fails if the flag is cleared again), and the debt entry is gone. Thanks again.