feat(xgameruntime): implement XGameSave on a per-title save folder #14

Manually merged
github merged 1 commit from gh-pr/14/head into gh-pr/14/base 2026-11-26 19:14:01 +00:00
Owner

@⁠Callimann8 on GitHub · 2026-11-21 12:14 UTC · original
Callimann8:claude/project-thread-7i52ws → main · +1181 −60 · 13 files · 1 commits · merged 2026-11-21 12:25 UTC

What

Implements XGameSave on top of a per-title save folder (issue #3).

  • New GameSave.cpp with the provider, container, blob and update functions and their async variants: XGameSaveInitializeProvider[Async/Result], CloseProvider, GetRemainingQuota[Async/Result], DeleteContainer[Async/Result], CreateContainer, CloseContainer, GetContainerInfo, EnumerateContainerInfo[ByName], EnumerateBlobInfo[ByName], ReadBlobData[Async/Result], CreateUpdate, CloseUpdate, SubmitBlobWrite, SubmitBlobDelete, SubmitUpdate[Async/Result]. The declarations get their real signatures and the types (XGameSave*Handle, XGameSaveContainerInfo, XGameSaveBlobInfo, XGameSaveBlob, the two callbacks, XUserHandle) go in Types.hpp. The XGameSaveFiles* exports stay stubbed.
  • Each container is one file, <name with / as %>.xgs, in %LOCALAPPDATA%\AnyBox\<TitleId>\XGameSave. An update is written to a temporary file and moved over the container, so it applies atomically.
  • The async variants are XAsync providers that run the same code as the sync calls on the work port.
  • Errors and limits from the GDK docs: E_GS_INVALID_CONTAINER_NAME with the documented name rules, E_GS_UPDATE_TOO_BIG above 16 MiB, E_GS_QUOTA_EXCEEDED above 256 MiB, E_GS_BLOB_NOT_FOUND, E_GS_PROVIDED_BUFFER_TOO_SMALL, E_GS_HANDLE_EXPIRED for an update used after submit, E_GS_OUT_OF_LOCAL_STORAGE for a full disk.
  • New e2e_gamesave scenario: invalid names, a container hidden until its first update, write, reread, enumerate (with and without prefix, stopping early), read all and by name, buffer too small, missing blob, a 16 MiB+1 update, quota, async read, update, quota, init and delete, and on-disk persistence checked by e2e.py. e2e.py points LOCALAPPDATA at the scenario's work folder.
  • Debt fragment feat-xgamesave.md records what is ignored (user, SCID, sync) and everything the docs don't specify. gdk-inventory.md, README and ARCHITECTURE are updated to match.

Tested

Linux (Ubuntu 24.04): cross-built every library and test with MinGW-w64 GCC (posix) with no warnings. check_conventions.py and debt_fold.py --check pass, and the relinker-only build passes all 20 CTest tests. I could not run the e2e scenarios here because Wine crashes on start in my environment, so e2e_gamesave has not run yet. The Windows CI job is the first real run.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • python tools/check_conventions.py passes (no comments in code, one declaration per export, Conventional Commit subjects)
  • Unimplemented paths stop (AbxNotImplemented / AbxUnsupported); silent stubs are listed under Silent stubs through a debt fragment
  • Known gaps added, changed or removed through docs/dev/debt/changes/<branch>.md
  • Generic behaviour, not specific to one title
  • No game files, keys, notes or logs added to the repository
  • Depends on: none
  • Fixes: Fixes #3
  • Unblocks: none
  • Source of behaviour: public GDK documentation, XGameSave members and game save errors; everything else is recorded in debt
  • AI-assisted: yes
**@⁠Callimann8** on GitHub · 2026-11-21 12:14 UTC · [original](https://github.com/Dark3581/AnyBox/pull/14) `Callimann8:claude/project-thread-7i52ws` → `main` · +1181 −60 · 13 files · 1 commits · merged 2026-11-21 12:25 UTC ### What Implements XGameSave on top of a per-title save folder (issue #3). - New `GameSave.cpp` with the provider, container, blob and update functions and their async variants: `XGameSaveInitializeProvider[Async/Result]`, `CloseProvider`, `GetRemainingQuota[Async/Result]`, `DeleteContainer[Async/Result]`, `CreateContainer`, `CloseContainer`, `GetContainerInfo`, `EnumerateContainerInfo[ByName]`, `EnumerateBlobInfo[ByName]`, `ReadBlobData[Async/Result]`, `CreateUpdate`, `CloseUpdate`, `SubmitBlobWrite`, `SubmitBlobDelete`, `SubmitUpdate[Async/Result]`. The declarations get their real signatures and the types (`XGameSave*Handle`, `XGameSaveContainerInfo`, `XGameSaveBlobInfo`, `XGameSaveBlob`, the two callbacks, `XUserHandle`) go in `Types.hpp`. The `XGameSaveFiles*` exports stay stubbed. - Each container is one file, `<name with / as %>.xgs`, in `%LOCALAPPDATA%\AnyBox\<TitleId>\XGameSave`. An update is written to a temporary file and moved over the container, so it applies atomically. - The async variants are XAsync providers that run the same code as the sync calls on the work port. - Errors and limits from the GDK docs: `E_GS_INVALID_CONTAINER_NAME` with the documented name rules, `E_GS_UPDATE_TOO_BIG` above 16 MiB, `E_GS_QUOTA_EXCEEDED` above 256 MiB, `E_GS_BLOB_NOT_FOUND`, `E_GS_PROVIDED_BUFFER_TOO_SMALL`, `E_GS_HANDLE_EXPIRED` for an update used after submit, `E_GS_OUT_OF_LOCAL_STORAGE` for a full disk. - New `e2e_gamesave` scenario: invalid names, a container hidden until its first update, write, reread, enumerate (with and without prefix, stopping early), read all and by name, buffer too small, missing blob, a 16 MiB+1 update, quota, async read, update, quota, init and delete, and on-disk persistence checked by `e2e.py`. `e2e.py` points `LOCALAPPDATA` at the scenario's work folder. - Debt fragment `feat-xgamesave.md` records what is ignored (user, SCID, sync) and everything the docs don't specify. `gdk-inventory.md`, README and ARCHITECTURE are updated to match. ### Tested Linux (Ubuntu 24.04): cross-built every library and test with MinGW-w64 GCC (posix) with no warnings. `check_conventions.py` and `debt_fold.py --check` pass, and the relinker-only build passes all 20 CTest tests. I could not run the e2e scenarios here because Wine crashes on start in my environment, so `e2e_gamesave` has not run yet. The Windows CI job is the first real run. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] `python tools/check_conventions.py` passes (no comments in code, one declaration per export, Conventional Commit subjects) - [x] Unimplemented paths stop (`AbxNotImplemented` / `AbxUnsupported`); silent stubs are listed under Silent stubs through a debt fragment - [x] Known gaps added, changed or removed through `docs/dev/debt/changes/<branch>.md` - [x] Generic behaviour, not specific to one title - [x] No game files, keys, notes or logs added to the repository - [x] Depends on: none - [x] Fixes: Fixes #3 - [x] Unblocks: none - [x] Source of behaviour: public GDK documentation, [XGameSave members](https://learn.microsoft.com/gaming/gdk/docs/reference/system/xgamesave/xgamesave_members) and [game save errors](https://learn.microsoft.com/gaming/gdk/docs/features/common/game-save/game-saves-errors); everything else is recorded in debt - [x] AI-assisted: yes
Implement the XGameSave provider, container, blob and update functions,
with their async variants, in GameSave.cpp. Each container is one file in
%LOCALAPPDATA%\AnyBox\<TitleId>\XGameSave, rewritten through a temporary
file so an update is applied atomically. Signatures, structures, error
codes, container name rules, the 16 MiB update limit and the 256 MiB quota
follow the public GDK documentation. The async variants run on XAsync.
An e2e scenario covers writing, reading, enumerating and deleting
containers and blobs, sync and async. Gaps are recorded in debt.

Fixes #3.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01YZ2PrCgr5k9mMRsxSgH5WA
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 19:13:59 +00:00
github manually merged commit 5d9bb196c4 into gh-pr/14/base 2026-11-26 19:14:01 +00:00
Author
Owner

@⁠github-actions[bot] on GitHub · 2026-11-21 12:17 UTC · original

Progress report (395947f → 5d9bb19)

📈 Libraries: 22.77% (+6.0268%, +27 implemented functions)

✅ 27 implemented
Library Name
xgameruntime XGameSaveCloseContainer
xgameruntime XGameSaveCloseProvider
xgameruntime XGameSaveCloseUpdate
xgameruntime XGameSaveCreateContainer
xgameruntime XGameSaveCreateUpdate
xgameruntime XGameSaveDeleteContainer
xgameruntime XGameSaveDeleteContainerAsync
xgameruntime XGameSaveDeleteContainerResult
xgameruntime XGameSaveEnumerateBlobInfo
xgameruntime XGameSaveEnumerateBlobInfoByName
xgameruntime XGameSaveEnumerateContainerInfo
xgameruntime XGameSaveEnumerateContainerInfoByName
xgameruntime XGameSaveGetContainerInfo
xgameruntime XGameSaveGetRemainingQuota
xgameruntime XGameSaveGetRemainingQuotaAsync
xgameruntime XGameSaveGetRemainingQuotaResult
xgameruntime XGameSaveInitializeProvider
xgameruntime XGameSaveInitializeProviderAsync
xgameruntime XGameSaveInitializeProviderResult
xgameruntime XGameSaveReadBlobData
xgameruntime XGameSaveReadBlobDataAsync
xgameruntime XGameSaveReadBlobDataResult
xgameruntime XGameSaveSubmitBlobDelete
xgameruntime XGameSaveSubmitBlobWrite
xgameruntime XGameSaveSubmitUpdate
xgameruntime XGameSaveSubmitUpdateAsync
xgameruntime XGameSaveSubmitUpdateResult

Changed libraries

Library Before After Change
xgameruntime 29/391 (7.42%) 56/391 (14.32%) +6.91%
**@⁠github-actions[bot]** on GitHub · 2026-11-21 12:17 UTC · [original](https://github.com/Dark3581/AnyBox/pull/14#issuecomment-7062460224) <!-- progress-report --> ### Progress report (395947f → 5d9bb19) 📈 **Libraries**: 22.77% (+6.0268%, +27 implemented functions) <details> <summary>✅ 27 implemented</summary> | Library | Name | | - | - | | xgameruntime | `XGameSaveCloseContainer` | | xgameruntime | `XGameSaveCloseProvider` | | xgameruntime | `XGameSaveCloseUpdate` | | xgameruntime | `XGameSaveCreateContainer` | | xgameruntime | `XGameSaveCreateUpdate` | | xgameruntime | `XGameSaveDeleteContainer` | | xgameruntime | `XGameSaveDeleteContainerAsync` | | xgameruntime | `XGameSaveDeleteContainerResult` | | xgameruntime | `XGameSaveEnumerateBlobInfo` | | xgameruntime | `XGameSaveEnumerateBlobInfoByName` | | xgameruntime | `XGameSaveEnumerateContainerInfo` | | xgameruntime | `XGameSaveEnumerateContainerInfoByName` | | xgameruntime | `XGameSaveGetContainerInfo` | | xgameruntime | `XGameSaveGetRemainingQuota` | | xgameruntime | `XGameSaveGetRemainingQuotaAsync` | | xgameruntime | `XGameSaveGetRemainingQuotaResult` | | xgameruntime | `XGameSaveInitializeProvider` | | xgameruntime | `XGameSaveInitializeProviderAsync` | | xgameruntime | `XGameSaveInitializeProviderResult` | | xgameruntime | `XGameSaveReadBlobData` | | xgameruntime | `XGameSaveReadBlobDataAsync` | | xgameruntime | `XGameSaveReadBlobDataResult` | | xgameruntime | `XGameSaveSubmitBlobDelete` | | xgameruntime | `XGameSaveSubmitBlobWrite` | | xgameruntime | `XGameSaveSubmitUpdate` | | xgameruntime | `XGameSaveSubmitUpdateAsync` | | xgameruntime | `XGameSaveSubmitUpdateResult` | </details> #### Changed libraries | Library | Before | After | Change | | - | - | - | - | | xgameruntime | 29/391 (7.42%) | 56/391 (14.32%) | +6.91% |
Author
Owner

@⁠Dark3581 on GitHub · 2026-11-21 12:25 UTC · original · approved these changes

Reviewed — looks good

Merging as it is. The first real run of e2e_gamesave is green here, the format and the atomic replace are clean, and the debt fragment is thorough.

What I ran

Head 5d9bb19, based on current main (395947f). MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory.

Results

Check Result Note
MinGW full build passed no warnings
CTest passed 39/39
e2e_gamesave, repeated passed 30/30
All e2e scenarios, repeated passed 10 rounds of the 18 scenarios, 4 in parallel, no failure
tools/check_conventions.py, tools/debt_fold.py --check passed 8 fragments apply cleanly
tools/progress.py passed xgameruntime 29 → 56 implemented of 391
CI passed Windows, relinker on Linux and macOS, conventions, progress

I also checked the two places I expected trouble. XGameSaveReadBlobDataResult derives the count from the first laid-out name pointer, which holds because XAsyncGetResult hands the caller's buffer straight to the provider's GetResult. And Start deleting the operation after a failed XAsyncBegin is not a double free, because XAsyncBegin only fails before the provider is attached.

Findings

Blocking

None.

Non-blocking

  • core/libs/xdll/xgameruntime/GameSave.cpp:312 (called from :469 and :363): Used reads and parses every container in the folder in full, under the storage mutex, on every XGameSaveSubmitUpdate and every quota query. Near the 256 MiB quota, each save re-reads up to 256 MiB from disk while blocking every other XGameSave call. Keeping the blob total in the file header, or summing file sizes from the FindFirstFileW data, would make it proportional to the number of containers. Not a correctness problem.
  • core/libs/xdll/xgameruntime/GameSave.cpp:847: XGameSaveSubmitUpdateAsync checks submitted when called, but only the work sets it, on a worker thread. Two async submits of one update before the first completes both pass and both apply, and submitted is a plain bool read and written on different threads. Suggest marking the update busy (atomically) once Start succeeds, with an e2e case for the second call, and recording in debt what that call returns, since the docs don't say.
  • E_GS_QUOTA_EXCEEDED is not exercised by e2e_gamesave, which checks the remaining quota values only. Reaching it takes 17 updates of 16 MiB, so it is fine to leave as is.
  • The README row says XGameSave is implemented while the XGameSaveFiles* exports are still stubs. I'll adjust that line in a follow-up on main.

Not verified

Reading the saves back from a second run of the title (e2e checks the file on disk), the full-disk path, the MSVC build locally (CI covers it), and behaviour on a console, as recorded in debt.

Thanks, this is a careful implementation, and it closes #3.

**@⁠Dark3581** on GitHub · 2026-11-21 12:25 UTC · [original](https://github.com/Dark3581/AnyBox/pull/14#pullrequestreview-6005168095) · **approved these changes** # Reviewed — looks good Merging as it is. The first real run of `e2e_gamesave` is green here, the format and the atomic replace are clean, and the debt fragment is thorough. ## What I ran Head `5d9bb19`, based on current `main` (`395947f`). MinGW (WinLibs GCC 15.2 UCRT, Ninja, Release) on Windows 10, clean build directory. ## Results | Check | Result | Note | | - | - | - | | MinGW full build | passed | no warnings | | CTest | passed | 39/39 | | `e2e_gamesave`, repeated | passed | 30/30 | | All e2e scenarios, repeated | passed | 10 rounds of the 18 scenarios, 4 in parallel, no failure | | `tools/check_conventions.py`, `tools/debt_fold.py --check` | passed | 8 fragments apply cleanly | | `tools/progress.py` | passed | xgameruntime 29 → 56 implemented of 391 | | CI | passed | Windows, relinker on Linux and macOS, conventions, progress | I also checked the two places I expected trouble. `XGameSaveReadBlobDataResult` derives the count from the first laid-out name pointer, which holds because `XAsyncGetResult` hands the caller's buffer straight to the provider's `GetResult`. And `Start` deleting the operation after a failed `XAsyncBegin` is not a double free, because `XAsyncBegin` only fails before the provider is attached. ## Findings ### Blocking None. ### Non-blocking - `core/libs/xdll/xgameruntime/GameSave.cpp:312` (called from `:469` and `:363`): `Used` reads and parses every container in the folder in full, under the storage mutex, on every `XGameSaveSubmitUpdate` and every quota query. Near the 256 MiB quota, each save re-reads up to 256 MiB from disk while blocking every other XGameSave call. Keeping the blob total in the file header, or summing file sizes from the `FindFirstFileW` data, would make it proportional to the number of containers. Not a correctness problem. - `core/libs/xdll/xgameruntime/GameSave.cpp:847`: `XGameSaveSubmitUpdateAsync` checks `submitted` when called, but only the work sets it, on a worker thread. Two async submits of one update before the first completes both pass and both apply, and `submitted` is a plain `bool` read and written on different threads. Suggest marking the update busy (atomically) once `Start` succeeds, with an e2e case for the second call, and recording in debt what that call returns, since the docs don't say. - `E_GS_QUOTA_EXCEEDED` is not exercised by `e2e_gamesave`, which checks the remaining quota values only. Reaching it takes 17 updates of 16 MiB, so it is fine to leave as is. - The README row says XGameSave is implemented while the `XGameSaveFiles*` exports are still stubs. I'll adjust that line in a follow-up on `main`. ## Not verified Reading the saves back from a second run of the title (e2e checks the file on disk), the full-disk path, the MSVC build locally (CI covers it), and behaviour on a console, as recorded in debt. Thanks, this is a careful implementation, and it closes #3.
Author
Owner

@⁠Dark3581 on GitHub · 2026-11-21 12:30 UTC · original

Follow-up landed in ddd30ef: the README row now lists XGameSaveFiles among the stubs. The other two non-blocking points (the full re-read in Used, and a second XGameSaveSubmitUpdateAsync on one update) are open for a follow-up PR if you'd like to take them.

**@⁠Dark3581** on GitHub · 2026-11-21 12:30 UTC · [original](https://github.com/Dark3581/AnyBox/pull/14#issuecomment-7062619543) Follow-up landed in ddd30ef: the README row now lists `XGameSaveFiles` among the stubs. The other two non-blocking points (the full re-read in `Used`, and a second `XGameSaveSubmitUpdateAsync` on one update) are open for a follow-up PR if you'd like to take them.
This discussion has been locked. Commenting is limited to contributors.
No description provided.