startup: persist game-save containers and blobs under the storage path #1246

Manually merged
github merged 8 commits from gh-pr/1246/head into gh-pr/1246/base 2026-11-26 22:52:00 +00:00
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:09 UTC · original
tedin7:x2w-c3-xgamesave-persist → main · +1646 −12 · 10 files · 8 commits · merged 2026-11-24 09:05 UTC

What

  • Adds src/startup_stubs/save_store.h: a small standard-C++ store with one directory per container and one file per blob below <X2W_STORAGE_PATH>/x2w-gamesave. An existing container directory counts as success. Blob writes go through a side file and a rename. Names are one plain path component (no separators, :, .., control characters, device names or trailing dot/space), at most 128 bytes, blobs at most 64 MiB. Symlinks are never followed.
  • src/startup_stubs/runtime_proxy.cpp: the game-save slots use the store. Container and update handles keep their fixed base values, with the low bits indexing a small table. Persisted: create container (16), delete container (10, 11), create and close update (23, 24), blob write and blob delete through an open update (25, 26; applied at once, so submit stays a no-op).
  • Not changed, because their argument layout is not established by the code or docs: blob reads (20 to 22) still answer "blob not found", and the enumerations and queries (12 to 15, 18, 19) still report nothing. No new slots, no ABI change. Slots 10, 25 and 26 take the public-header argument shapes, which remains a hypothesis.
  • Adds tests/startup_gamesave_persist.cpp (CTest startup_gamesave_persist) and a "Game saves" section in docs/startup-runtime.md.

Why

Refs #1200. The first-run state most likely goes through the game-save API and the stand-in dropped it. This is the storage half. Reading the stored bytes back through slots 20 to 22 needs the blob record layout, which is a follow-up; the done-when condition (a startup run twice in a row skips first-run setup) is therefore not shown here.

Tested

Windows (not run by me, please run):

ctest --preset dev --no-tests=error -R '^startup_gamesave_persist$' -V
ctest --preset release --no-tests=error -R '^startup_gamesave_persist$' -V

The test writes a blob in one process, starts itself again to read it in a second process, and covers an existing container directory, a missing blob and container, 17 traversal-style names, the size cap, overwrite, blob delete and container delete. Negative controls: the reader finds nothing before the first write, and it rejects different bytes.

Run on Linux: save_store.h and the test compiled with g++ -std=c++17 and -std=c++20 (-Wall -Wextra, no warnings) and passed. Two mutations of the header (dropping the .. check; not renaming the side file) made it fail. Also run: python3 -B tests/docs_links_check.py and tests/bidi_controls_check.py, both pass.

Not run: MSVC. runtime_proxy.cpp was not compiled at all on Linux (Windows headers and intrinsics), and the slot code paths were not exercised. The test drives the storage code the slots call, not the slots through the runtime proxy; no existing test loads the proxy.

**@⁠tedin7** on GitHub · 2026-11-24 05:09 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246) `tedin7:x2w-c3-xgamesave-persist` → `main` · +1646 −12 · 10 files · 8 commits · merged 2026-11-24 09:05 UTC ## What - Adds `src/startup_stubs/save_store.h`: a small standard-C++ store with one directory per container and one file per blob below `<X2W_STORAGE_PATH>/x2w-gamesave`. An existing container directory counts as success. Blob writes go through a side file and a rename. Names are one plain path component (no separators, `:`, `..`, control characters, device names or trailing dot/space), at most 128 bytes, blobs at most 64 MiB. Symlinks are never followed. - `src/startup_stubs/runtime_proxy.cpp`: the game-save slots use the store. Container and update handles keep their fixed base values, with the low bits indexing a small table. Persisted: create container (16), delete container (10, 11), create and close update (23, 24), blob write and blob delete through an open update (25, 26; applied at once, so submit stays a no-op). - Not changed, because their argument layout is not established by the code or docs: blob reads (20 to 22) still answer "blob not found", and the enumerations and queries (12 to 15, 18, 19) still report nothing. No new slots, no ABI change. Slots 10, 25 and 26 take the public-header argument shapes, which remains a hypothesis. - Adds `tests/startup_gamesave_persist.cpp` (CTest `startup_gamesave_persist`) and a "Game saves" section in `docs/startup-runtime.md`. ## Why Refs #1200. The first-run state most likely goes through the game-save API and the stand-in dropped it. This is the storage half. Reading the stored bytes back through slots 20 to 22 needs the blob record layout, which is a follow-up; the done-when condition (a startup run twice in a row skips first-run setup) is therefore not shown here. ## Tested Windows (not run by me, please run): ```powershell ctest --preset dev --no-tests=error -R '^startup_gamesave_persist$' -V ctest --preset release --no-tests=error -R '^startup_gamesave_persist$' -V ``` The test writes a blob in one process, starts itself again to read it in a second process, and covers an existing container directory, a missing blob and container, 17 traversal-style names, the size cap, overwrite, blob delete and container delete. Negative controls: the reader finds nothing before the first write, and it rejects different bytes. Run on Linux: `save_store.h` and the test compiled with `g++ -std=c++17` and `-std=c++20` (-Wall -Wextra, no warnings) and passed. Two mutations of the header (dropping the `..` check; not renaming the side file) made it fail. Also run: `python3 -B tests/docs_links_check.py` and `tests/bidi_controls_check.py`, both pass. Not run: MSVC. `runtime_proxy.cpp` was not compiled at all on Linux (Windows headers and intrinsics), and the slot code paths were not exercised. The test drives the storage code the slots call, not the slots through the runtime proxy; no existing test loads the proxy.
Readers and the publication of an update now share one lock per container
(LockFileEx on Windows, flock elsewhere, a file beside the container directory),
so a second process sees the whole previous generation or the whole new one.
The wait is bounded and returns busy; a dead holder's lock is dropped by the
system. Adds read_blobs for a one-generation multi-blob read.

A deterministic two-process test pauses a writer at each step of a two-blob
publication through file handshakes, with the second-action failure control and
a lock holder that ends without unlocking. The same test on a generated copy
without the lock must be caught. The crash-recovery limit stays documented.
A Windows node reported busy-expectation failures in startup_gamesave_publish_locked: a reader
that cannot wait, and a commit/read/delete while another process holds the lock, did not get
Status::busy. The lock mapped only ERROR_LOCK_VIOLATION to busy; any other code from
LockFileEx(LOCKFILE_FAIL_IMMEDIATELY) (sharing violation, ERROR_IO_PENDING) became an error and so
Status::io_error.

- file_lock.h: win_lock_error_is_busy maps lock violation, sharing violation and IO_PENDING to
  busy; a pending request is cancelled and awaited before the stack OVERLAPPED goes away;
  FileLock::last_error() keeps the system error of the last failed attempt.
- startup_gamesave_publish: failure messages print the reader exit code and the real
  commit/read/delete Status, and a bare zero-wait lock probe prints its LockResult and system error.
- startup_gamesave_lock_errors: the mapping is tested on every platform with Windows codes.
std::rand() without srand() returns the same value on some runtimes and ctest --parallel can start two tests in the same second, so the locked and unlocked publish runs shared one directory and removed it under each other. Both tests now name the directory from the process id and a steady-clock reading.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:51:59 +00:00
github manually merged commit 2f9c55d9f6 into gh-pr/1246/base 2026-11-26 22:52:00 +00:00
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:17 UTC · original

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit cfb42a1f9c301c868d29d1650839fc2164f09700:

  • Debug (--preset dev):
    • Build (cmake --build --preset dev --target startup_gamesave_persist startup_stub_gameinput -- -j 6): 4.85s (configure 1.97s)
    • Test (ctest --preset dev -R '^startup_gamesave_persist$' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.19s, total CTest 0.27s)
  • Release /O2 (--preset release):
    • Build (cmake --build --preset release --target startup_gamesave_persist startup_stub_gameinput -- -j 6): 3.63s (configure 1.9s)
    • Test (ctest --preset release -R '^startup_gamesave_persist$' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.20s, total CTest 0.29s)
**@⁠tedin7** on GitHub · 2026-11-24 05:17 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7122812823) Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit `cfb42a1f9c301c868d29d1650839fc2164f09700`: - **Debug (`--preset dev`)**: - Build (`cmake --build --preset dev --target startup_gamesave_persist startup_stub_gameinput -- -j 6`): `4.85s` (configure `1.97s`) - Test (`ctest --preset dev -R '^startup_gamesave_persist$' --parallel 4 --no-tests=error --output-on-failure`): **1/1 passed** (`0.19s`, total CTest `0.27s`) - **Release `/O2` (`--preset release`)**: - Build (`cmake --build --preset release --target startup_gamesave_persist startup_stub_gameinput -- -j 6`): `3.63s` (configure `1.9s`) - Test (`ctest --preset release -R '^startup_gamesave_persist$' --parallel 4 --no-tests=error --output-on-failure`): **1/1 passed** (`0.20s`, total CTest `0.29s`)
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 05:25 UTC · original · edited 2026-11-24 05:33 UTC

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-24T05:33:46.176228Z cfb42a1 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.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 05:25 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7122928640) · edited 2026-11-24 05:33 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"cfb42a1f9c301c868d29d1650839fc2164f09700","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-24T05:33:46.176228Z">2026-11-24T05:33:46.176228Z</relative-time> | `cfb42a1` | 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>
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 05:33 UTC · original

P1 Badge Refuse existing links when opening the staging file

If profile.dat.x2w-part already exists as a symlink to a writable file outside the store, this truncating ofstream follows the link before any rename happens. The symlink check above covers only the final blob path, so write_blob("slot-a", "profile.dat", ...) can return ok after overwriting an unrelated host file. A Linux helper probe reproduced this and left the final blob as a symlink. Create the staging file exclusively without following links instead of opening an existing predictable path.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 05:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675926998) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Refuse existing links when opening the staging file** If `profile.dat.x2w-part` already exists as a symlink to a writable file outside the store, this truncating `ofstream` follows the link before any rename happens. The symlink check above covers only the final blob path, so `write_blob("slot-a", "profile.dat", ...)` can return `ok` after overwriting an unrelated host file. A Linux helper probe reproduced this and left the final blob as a symlink. Create the staging file exclusively without following links instead of opening an existing predictable path. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 05:33 UTC · original

P1 Badge Use a separate staging file for each concurrent write

When two open updates write the same container/blob concurrently, they share this single .x2w-part file; the runtime's save_lock protects the handle tables but is released before write_blob runs. One call can rename the staging file while the other continues writing to it and subsequently fails to rename. A two-thread Linux probe with distinct 16 MiB payloads repeatedly returned one ok and one io_error, but the final blob contained the failed writer's payload rather than the successful writer's. Use exclusively created per-write staging files or serialize the complete write/rename sequence across callers.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 05:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675927007) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Use a separate staging file for each concurrent write** When two open updates write the same container/blob concurrently, they share this single `.x2w-part` file; the runtime's `save_lock` protects the handle tables but is released before `write_blob` runs. One call can rename the staging file while the other continues writing to it and subsequently fails to rename. A two-thread Linux probe with distinct 16 MiB payloads repeatedly returned one `ok` and one `io_error`, but the final blob contained the failed writer's payload rather than the successful writer's. Use exclusively created per-write staging files or serialize the complete write/rename sequence across callers. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 05:33 UTC · original

P2 Badge Reserve the staging suffix case-insensitively on Windows

On a normal case-insensitive Windows filesystem, valid_name("profile.X2W-PART") returns true even though that file aliases the staging name used for blob profile. Writing profile.X2W-PART and then profile therefore truncates and renames the first blob away, even though both names pass validation and both writes can succeed. Reserve the suffix case-insensitively on Windows, or move staging files outside the blob namespace.

AGENTS.md reference: AGENTS.md:L9-L10

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 05:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675927014) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Reserve the staging suffix case-insensitively on Windows** On a normal case-insensitive Windows filesystem, `valid_name("profile.X2W-PART")` returns true even though that file aliases the staging name used for blob `profile`. Writing `profile.X2W-PART` and then `profile` therefore truncates and renames the first blob away, even though both names pass validation and both writes can succeed. Reserve the suffix case-insensitively on Windows, or move staging files outside the blob namespace. AGENTS.md reference: [AGENTS.md:L9-L10](https://github.com/R0Y00/Xbox2Windows/blob/cfb42a1f9c301c868d29d1650839fc2164f09700/AGENTS.md#L9-L10) Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 05:33 UTC · original

P2 Badge Reclaim closed container entries before exhausting the table

With the fake-user proxy enabled, opening and closing 64 distinct container names permanently exhausts this table: save_container_count only grows, while close-provider, close-container and delete-container never release entries. The 65th distinct container returns E_OUTOFMEMORY even if every earlier container and update was closed and deleted, so rotating save-container names eventually stop working until the process restarts. Reclaim entries when no live handle/update uses them, or avoid capping the handle table by all names ever opened.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 05:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675927021) **<sub><sub>![P2 Badge](https://img.shields.io/badge/P2-yellow?style=flat)</sub></sub> Reclaim closed container entries before exhausting the table** With the fake-user proxy enabled, opening and closing 64 distinct container names permanently exhausts this table: `save_container_count` only grows, while close-provider, close-container and delete-container never release entries. The 65th distinct container returns `E_OUTOFMEMORY` even if every earlier container and update was closed and deleted, so rotating save-container names eventually stop working until the process restarts. Reclaim entries when no live handle/update uses them, or avoid capping the handle table by all names ever opened. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:37 UTC · original

Fixed in eeda5404: the staging file is no longer a predictable name. Each write creates <blob>.<counter>-<clock>.x2w-part and refuses to open it if anything (a link included) already exists at that name. A link left at the old <blob>.x2w-part name is never opened: the test plants one and checks the outside file stays untouched (skipped where symlink creation is not permitted). Limit: this is an unguessable name plus a pre-check, not an exclusive-create open; the standard library offers none here.

**@⁠tedin7** on GitHub · 2026-11-24 05:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675950439) Fixed in eeda5404: the staging file is no longer a predictable name. Each write creates `<blob>.<counter>-<clock>.x2w-part` and refuses to open it if anything (a link included) already exists at that name. A link left at the old `<blob>.x2w-part` name is never opened: the test plants one and checks the outside file stays untouched (skipped where symlink creation is not permitted). Limit: this is an unguessable name plus a pre-check, not an exclusive-create open; the standard library offers none here.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:37 UTC · original

Fixed in eeda5404: one staging file per write (unique counter + clock reading in the name), so two writers never share one. New test: two threads write 1 MiB payloads to the same blob 20 times; both always succeed, the blob holds one whole payload and no staging file is left. With the old fixed name the same test fails.

**@⁠tedin7** on GitHub · 2026-11-24 05:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675950702) Fixed in eeda5404: one staging file per write (unique counter + clock reading in the name), so two writers never share one. New test: two threads write 1 MiB payloads to the same blob 20 times; both always succeed, the blob holds one whole payload and no staging file is left. With the old fixed name the same test fails.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:37 UTC · original

Fixed in eeda5404: valid_name now compares the staging suffix case-insensitively (.X2W-PART, .x2W-Part are refused on every OS). A near miss such as .x2w-par stays valid. Covered in the test.

**@⁠tedin7** on GitHub · 2026-11-24 05:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675950919) Fixed in eeda5404: `valid_name` now compares the staging suffix case-insensitively (`.X2W-PART`, `.x2W-Part` are refused on every OS). A near miss such as `.x2w-par` stays valid. Covered in the test.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:37 UTC · original

Fixed in eeda5404: container handles now come from a small ContainerTable (in save_store.h) with a reference count per entry. Close-container releases it, and an entry with an open update is kept until CloseUpdate. The test runs 300 open/close rounds of distinct names without exhausting the table, and keeps the full-table refusal and the open-update case as controls. runtime_proxy.cpp only uses the table under save_lock; it was not compiled on Linux.

**@⁠tedin7** on GitHub · 2026-11-24 05:37 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#discussion_r4675951117) Fixed in eeda5404: container handles now come from a small `ContainerTable` (in `save_store.h`) with a reference count per entry. Close-container releases it, and an entry with an open update is kept until `CloseUpdate`. The test runs 300 open/close rounds of distinct names without exhausting the table, and keeps the full-table refusal and the open-update case as controls. `runtime_proxy.cpp` only uses the table under `save_lock`; it was not compiled on Linux.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 05:50 UTC · original

Verified on Windows Server 2025 (Build 26100, MSVC 14.44) at commit 0b2b078f57078c248ba499bdd31a14c136e472fa:

  • cmake --preset dev + cmake --build --preset dev --target startup_gamesave_persist startup_stub_gameinput + ctest --preset dev -R "^(startup_gamesave_persist|startup_stub_gameinput)$": 1/1 passed (startup_gamesave_persist, 0.21s)
  • cmake --preset release + cmake --build --preset release --target startup_gamesave_persist startup_stub_gameinput + ctest --preset release -R "^(startup_gamesave_persist|startup_stub_gameinput)$": 1/1 passed (startup_gamesave_persist, 0.19s)
**@⁠tedin7** on GitHub · 2026-11-24 05:50 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7123332074) Verified on Windows Server 2025 (Build 26100, MSVC 14.44) at commit `0b2b078f57078c248ba499bdd31a14c136e472fa`: - `cmake --preset dev` + `cmake --build --preset dev --target startup_gamesave_persist startup_stub_gameinput` + `ctest --preset dev -R "^(startup_gamesave_persist|startup_stub_gameinput)$"`: 1/1 passed (`startup_gamesave_persist`, 0.21s) - `cmake --preset release` + `cmake --build --preset release --target startup_gamesave_persist startup_stub_gameinput` + `ctest --preset release -R "^(startup_gamesave_persist|startup_stub_gameinput)$"`: 1/1 passed (`startup_gamesave_persist`, 0.19s)
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 07:08 UTC · original

Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) after rebase at 5b05c67a:

  • Debug (--preset dev): ctest --preset dev -R "^(startup_gamesave_persist|startup_stub_gameinput)$" — 1/1 PASS (0.21s)
  • Release /O2 (--preset release): ctest --preset release -R "^(startup_gamesave_persist|startup_stub_gameinput)$" — 1/1 PASS (0.18s, build 0.39s)
**@⁠tedin7** on GitHub · 2026-11-24 07:08 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7124658982) Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) after rebase at `5b05c67a`: - Debug (`--preset dev`): `ctest --preset dev -R "^(startup_gamesave_persist|startup_stub_gameinput)$"` — **1/1 PASS** (`0.21s`) - Release `/O2` (`--preset release`): `ctest --preset release -R "^(startup_gamesave_persist|startup_stub_gameinput)$"` — **1/1 PASS** (`0.18s`, build `0.39s`)
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 07:48 UTC · original

Addressed both points in d4de15eb:

  1. Atomic update staging until submit: XGameSaveSubmitBlobWrite / XGameSaveSubmitBlobDelete now stage actions in memory and apply them atomically on XGameSaveSubmitUpdate, leaving disk state unchanged if closed without submit or if a later action fails. Added the three controls in tests/startup_gamesave_persist.cpp (close-without-submit, failure of a second action, and a second process observing only committed state).
  2. Consistent container path boundary: redirected container directories (reparse points / junctions) are refused consistently across read, write, delete, and enumeration, with a negative test covering a redirected container directory.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at d4de15eb:

  • Debug (--preset dev): ctest --preset dev -R "^(startup_gamesave_persist|startup_stub_gameinput)$" — 1/1 PASS (0.54s)
  • Release /O2 (--preset release): ctest --preset release -R "^(startup_gamesave_persist|startup_stub_gameinput)$" — 1/1 PASS (0.49s)
**@⁠tedin7** on GitHub · 2026-11-24 07:48 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7125390326) Addressed both points in `d4de15eb`: 1. **Atomic update staging until submit**: `XGameSaveSubmitBlobWrite` / `XGameSaveSubmitBlobDelete` now stage actions in memory and apply them atomically on `XGameSaveSubmitUpdate`, leaving disk state unchanged if closed without submit or if a later action fails. Added the three controls in `tests/startup_gamesave_persist.cpp` (close-without-submit, failure of a second action, and a second process observing only committed state). 2. **Consistent container path boundary**: redirected container directories (reparse points / junctions) are refused consistently across read, write, delete, and enumeration, with a negative test covering a redirected container directory. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at `d4de15eb`: - Debug (`--preset dev`): `ctest --preset dev -R "^(startup_gamesave_persist|startup_stub_gameinput)$"` — **1/1 PASS** (`0.54s`) - Release `/O2` (`--preset release`): `ctest --preset release -R "^(startup_gamesave_persist|startup_stub_gameinput)$"` — **1/1 PASS** (`0.49s`)
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 08:16 UTC · original

@⁠tedin7 I am taking the read-side follow-up to your staged store at d4de15eb. The source-built second process will start at container enumeration, use the returned container and blob names, then verify the synchronous read and short-buffer/missing-blob cases. I will keep your storage and submit work on this PR and send the follow-up separately. If you already have a read-side change, please link it here so we can reuse it.

The independent XCL table at 64b3f355 identifies slots 13 (exact container), 14 (all containers), 18 (blob metadata) and 20 (sync read) on the same provider. Microsoft documents the enumeration callback and read buffer contract.

**@⁠R0Y00** on GitHub · 2026-11-24 08:16 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7125939148) @⁠tedin7 I am taking the read-side follow-up to your staged store at d4de15eb. The source-built second process will start at container enumeration, use the returned container and blob names, then verify the synchronous read and short-buffer/missing-blob cases. I will keep your storage and submit work on this PR and send the follow-up separately. If you already have a read-side change, please link it here so we can reuse it. The independent [XCL table at 64b3f355](https://github.com/ivall/xcl/blob/64b3f35599bb7102f55d640e1a791e7d6dd3b175/crates/xcl/src/hle/xgameruntime/gdk_table.rs#L261-L270) identifies slots 13 (exact container), 14 (all containers), 18 (blob metadata) and 20 (sync read) on the same provider. Microsoft documents the [enumeration callback](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xgamesave/functions/xgamesaveenumeratecontainerinfo) and [read buffer contract](https://learn.microsoft.com/en-us/gaming/gdk/docs/reference/system/xgamesave/functions/xgamesavereadblobdata).
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 08:31 UTC · original

@⁠tedin7 We reproduced a write-side ordering issue on d4de15eb: when slot 28 rejects the supplied async block, its staged bytes have already replaced the committed value. A second result can also overwrite the first block's status. I am preparing a focused fix on this PR for rejected starts, inline completion and independent results. I will keep the synchronous read follow-up (#1334) separate.

**@⁠R0Y00** on GitHub · 2026-11-24 08:31 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7126249856) @⁠tedin7 We reproduced a write-side ordering issue on d4de15eb: when slot 28 rejects the supplied async block, its staged bytes have already replaced the committed value. A second result can also overwrite the first block's status. I am preparing a focused fix on this PR for rejected starts, inline completion and independent results. I will keep the synchronous read follow-up (#1334) separate.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 08:39 UTC · original

@⁠tedin7 I pushed 97a63a54 to this PR's existing branch using maintainer edits. A rejected asynchronous start now leaves the committed file and staged actions intact. Slots 28 and 29 use Windows XAsyncBegin/Complete/GetResult with the submit operation's identity. File publication still runs in slot 28, before its completion callback.

Debug and Release on Windows 11 build 26200.9974 each passed 3/3 (0 skips). The controlled scheduler rejected the first start, let the same update retry, and held one block pending while a second returned its own error. An inline callback read the committed file and its own result before slot 28 returned. The independent system case used the installed Gaming Runtime and an immediate queue: the callback read 0x77 and S_OK, while the other block returned 0x80830008.

cmake --build --preset release --target startup_stub_gameinput startup_gamesave_submit startup_gamesave_persist
ctest --preset release --no-tests=error --output-on-failure -R '^startup_gamesave_(submit|persist)'

#1334 now consumes this commit. Its separate two-process readback passes after either synchronous or asynchronous submit.

**@⁠R0Y00** on GitHub · 2026-11-24 08:39 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7126402583) @⁠tedin7 I pushed 97a63a54 to this PR's existing branch using maintainer edits. A rejected asynchronous start now leaves the committed file and staged actions intact. Slots 28 and 29 use Windows XAsyncBegin/Complete/GetResult with the submit operation's identity. File publication still runs in slot 28, before its completion callback. Debug and Release on Windows 11 build 26200.9974 each passed 3/3 (0 skips). The controlled scheduler rejected the first start, let the same update retry, and held one block pending while a second returned its own error. An inline callback read the committed file and its own result before slot 28 returned. The independent system case used the installed Gaming Runtime and an immediate queue: the callback read 0x77 and S_OK, while the other block returned 0x80830008. ```powershell cmake --build --preset release --target startup_stub_gameinput startup_gamesave_submit startup_gamesave_persist ctest --preset release --no-tests=error --output-on-failure -R '^startup_gamesave_(submit|persist)' ``` #1334 now consumes this commit. Its separate two-process readback passes after either synchronous or asynchronous submit.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 08:46 UTC · original

AI-assisted reply to the second review, in 8b82ced3 (one new commit on top of 97a63a54, no history change).

What changed

  • Readers and publication now share one cross-process lock per container: <container>.x2w-lock beside the container directory (LockFileEx on Windows, flock elsewhere; src/startup_stubs/file_lock.h). Publication holds it exclusively until the last blob is in place; read_blob takes it shared and the new read_blobs reads several blobs under one hold, so another process sees the whole previous generation or the whole new one. Blob and container deletes take it too.
  • Chosen over a manifest/generation directory because it keeps the layout the earlier commits of this PR already write (one directory per container, one file per blob). Staging files are written before the lock, so readers wait only for the renames.
  • The wait is bounded (5 s default, a Store parameter). On timeout the call returns the new busy status and changes nothing. A holder that dies is harmless: the system drops the lock when its handle closes.
  • tests/startup_gamesave_publish.cpp: a writer process pauses at each step of a two-blob publication (old blob moved aside, new blob in place, for each blob) through file handshakes with deadlines, no sleeps as synchronisation. A second process must be refused with busy while paused, never shown a mix or a missing blob, and a reader that waits sees the whole new generation. It also covers the existing failing-second-action control (previous generation whole for another process, lock free afterwards) and a lock holder that ends without unlocking.
  • Negative control: the same test is built from a generated copy of the headers whose lock does nothing (startup_gamesave_publish_unlocked); it must be caught, and is: the reader sees a mixed generation at pause points 0 to 2. The pause points exist only in the generated test copies, not in the production headers.

What remains (kept explicit in docs/startup-runtime.md)

  • Crash recovery is a separate limitation: if the writer is killed mid-replacement the lock is released but nothing rolls the update back or completes it, so a mixed state and .x2w-old/.x2w-part files can remain. No recovery pass yet.
  • A program that reads the files without this store is not covered by the lock.
  • #1334 adds reads; it should go through read_blobs/read_blob to stay under the lock.

Verified here (Linux, not the Windows node)

  • g++ native: startup_gamesave_persist ok; startup_gamesave_publish locked variant ok 5/5 runs, unlocked variant caught.
  • MinGW (x86_64-w64-mingw32-g++) binaries under Wine: persist ok, publish locked ok (3 runs), unlocked caught. Wine is not NTFS and MSVC was not used.
  • git diff --check, docs_links_check.py, bidi_controls_check.py pass; x2w_pipe preflight: WARN only (behind base, overlap with #1334 and docs edits by others).

To run on Windows Server 2025 / NTFS with MSVC: ctest --preset dev -R startup_gamesave (also --preset release).

**@⁠tedin7** on GitHub · 2026-11-24 08:46 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7126537390) AI-assisted reply to the second review, in 8b82ced3 (one new commit on top of 97a63a54, no history change). What changed - Readers and publication now share one cross-process lock per container: `<container>.x2w-lock` beside the container directory (`LockFileEx` on Windows, `flock` elsewhere; `src/startup_stubs/file_lock.h`). Publication holds it exclusively until the last blob is in place; `read_blob` takes it shared and the new `read_blobs` reads several blobs under one hold, so another process sees the whole previous generation or the whole new one. Blob and container deletes take it too. - Chosen over a manifest/generation directory because it keeps the layout the earlier commits of this PR already write (one directory per container, one file per blob). Staging files are written before the lock, so readers wait only for the renames. - The wait is bounded (5 s default, a `Store` parameter). On timeout the call returns the new `busy` status and changes nothing. A holder that dies is harmless: the system drops the lock when its handle closes. - `tests/startup_gamesave_publish.cpp`: a writer process pauses at each step of a two-blob publication (old blob moved aside, new blob in place, for each blob) through file handshakes with deadlines, no sleeps as synchronisation. A second process must be refused with `busy` while paused, never shown a mix or a missing blob, and a reader that waits sees the whole new generation. It also covers the existing failing-second-action control (previous generation whole for another process, lock free afterwards) and a lock holder that ends without unlocking. - Negative control: the same test is built from a generated copy of the headers whose lock does nothing (`startup_gamesave_publish_unlocked`); it must be caught, and is: the reader sees a mixed generation at pause points 0 to 2. The pause points exist only in the generated test copies, not in the production headers. What remains (kept explicit in docs/startup-runtime.md) - Crash recovery is a separate limitation: if the writer is killed mid-replacement the lock is released but nothing rolls the update back or completes it, so a mixed state and `.x2w-old`/`.x2w-part` files can remain. No recovery pass yet. - A program that reads the files without this store is not covered by the lock. - #1334 adds reads; it should go through `read_blobs`/`read_blob` to stay under the lock. Verified here (Linux, not the Windows node) - g++ native: `startup_gamesave_persist` ok; `startup_gamesave_publish` locked variant ok 5/5 runs, unlocked variant caught. - MinGW (x86_64-w64-mingw32-g++) binaries under Wine: persist ok, publish locked ok (3 runs), unlocked caught. Wine is not NTFS and MSVC was not used. - `git diff --check`, docs_links_check.py, bidi_controls_check.py pass; x2w_pipe preflight: WARN only (behind base, overlap with #1334 and docs edits by others). To run on Windows Server 2025 / NTFS with MSVC: `ctest --preset dev -R startup_gamesave` (also `--preset release`).
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 08:52 UTC · original

AI-assisted. Windows Server 2025 node (MSVC 14.44, Debug) on 8b82ced3: startup_gamesave_publish_locked failed 7 checks, all of them expecting Status::busy while another process holds the lock (4x reader at pause points 0..3, 3x commit/read/delete). The lock mapped only ERROR_LOCK_VIOLATION to "busy"; any other code from LockFileEx(LOCKFILE_FAIL_IMMEDIATELY) became Status::io_error. Fix in a43e9f8f: lock violation, sharing violation and ERROR_IO_PENDING all mean busy (a pending request is cancelled and awaited before the stack OVERLAPPED is released). The exact code the node returned is not known; it was not reproducible here (Linux and MinGW under Wine pass, and Wine is not NTFS). The test messages now print the real Status, the reader exit code and the system error of a zero-wait lock probe, and a new startup_gamesave_lock_errors test checks the mapping on every platform. To re-run on the Windows node: ctest -R startup_gamesave, Debug and release.

**@⁠tedin7** on GitHub · 2026-11-24 08:52 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7126680781) AI-assisted. Windows Server 2025 node (MSVC 14.44, Debug) on 8b82ced3: startup_gamesave_publish_locked failed 7 checks, all of them expecting Status::busy while another process holds the lock (4x reader at pause points 0..3, 3x commit/read/delete). The lock mapped only ERROR_LOCK_VIOLATION to "busy"; any other code from LockFileEx(LOCKFILE_FAIL_IMMEDIATELY) became Status::io_error. Fix in a43e9f8f: lock violation, sharing violation and ERROR_IO_PENDING all mean busy (a pending request is cancelled and awaited before the stack OVERLAPPED is released). The exact code the node returned is not known; it was not reproducible here (Linux and MinGW under Wine pass, and Wine is not NTFS). The test messages now print the real Status, the reader exit code and the system error of a zero-wait lock probe, and a new startup_gamesave_lock_errors test checks the mapping on every platform. To re-run on the Windows node: ctest -R startup_gamesave, Debug and release.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 08:59 UTC · original

Found the cause of the remaining failure on the Windows node in startup_gamesave_publish_locked: both publish tests named their temp directory from std::rand() (constant when srand is not called on some runtimes) and time(nullptr), and ctest --parallel started the locked and unlocked runs in the same second, so they shared one directory and removed it under each other. 2f9c55d9 names the directory from the process id and a steady-clock reading (same change in startup_gamesave_persist). Locally two simultaneous locked runs pass 2/2 with 0 failures. Not run on MSVC or NTFS. AI-assisted.

**@⁠tedin7** on GitHub · 2026-11-24 08:59 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7126805926) Found the cause of the remaining failure on the Windows node in `startup_gamesave_publish_locked`: both publish tests named their temp directory from `std::rand()` (constant when `srand` is not called on some runtimes) and `time(nullptr)`, and `ctest --parallel` started the locked and unlocked runs in the same second, so they shared one directory and removed it under each other. `2f9c55d9` names the directory from the process id and a steady-clock reading (same change in `startup_gamesave_persist`). Locally two simultaneous locked runs pass 2/2 with 0 failures. Not run on MSVC or NTFS. AI-assisted.
Author
Owner

@⁠tedin7 on GitHub · 2026-11-24 09:02 UTC · original

@⁠R0Y00 Addressed on top of 97a63a54 in 8b82ced3..2f9c55d9:

  • Added a cross-process container publication lock (src/startup_stubs/file_lock.h, LockFileEx on Windows / flock on POSIX) acquired shared by read_blob/read_blobs and exclusively by commit/delete_blob/delete_container, so readers in other processes observe one complete generation rather than mixed or missing blobs.
  • Added the deterministic two-process check paused at every publication step (tests/startup_gamesave_publish.cpp, built as startup_gamesave_publish_locked and the lock-disabled negative control startup_gamesave_publish_unlocked that verifies "reader saw a mixed generation"), covering a two-blob update, the second-operation failure control, and dead-holder lock release, plus startup_gamesave_lock_errors.
  • Kept the separate crash-recovery limitation explicit in docs/startup-runtime.md and save_store.h.

Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207, NTFS) at 2f9c55d9f684c49ee737ccf99686aaaa677b5246:

  • Debug (--preset dev): ctest --preset dev -R '^startup_gamesave_' --parallel 4 --no-tests=error --output-on-failure: 5/6 passed (startup_gamesave_persist 0.66s, startup_gamesave_publish_locked 2.05s, startup_gamesave_publish_unlocked 0.96s, startup_gamesave_lock_errors 0.02s, startup_gamesave_submit_controlled 0.12s); skipped (capability): startup_gamesave_submit_system
  • Release /O2 (--preset release): ctest --preset release -R '^startup_gamesave_' --parallel 4 --no-tests=error --output-on-failure: 5/6 passed (startup_gamesave_persist 0.63s, startup_gamesave_publish_locked 2.03s, startup_gamesave_publish_unlocked 0.90s, startup_gamesave_lock_errors 0.02s, startup_gamesave_submit_controlled 0.11s); skipped (capability): startup_gamesave_submit_system
**@⁠tedin7** on GitHub · 2026-11-24 09:02 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#issuecomment-7126874410) @⁠R0Y00 Addressed on top of `97a63a54` in `8b82ced3`..`2f9c55d9`: - Added a cross-process container publication lock (`src/startup_stubs/file_lock.h`, `LockFileEx` on Windows / `flock` on POSIX) acquired shared by `read_blob`/`read_blobs` and exclusively by `commit`/`delete_blob`/`delete_container`, so readers in other processes observe one complete generation rather than mixed or missing blobs. - Added the deterministic two-process check paused at every publication step (`tests/startup_gamesave_publish.cpp`, built as `startup_gamesave_publish_locked` and the lock-disabled negative control `startup_gamesave_publish_unlocked` that verifies `"reader saw a mixed generation"`), covering a two-blob update, the second-operation failure control, and dead-holder lock release, plus `startup_gamesave_lock_errors`. - Kept the separate crash-recovery limitation explicit in `docs/startup-runtime.md` and `save_store.h`. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207, NTFS) at `2f9c55d9f684c49ee737ccf99686aaaa677b5246`: - **Debug (`--preset dev`)**: `ctest --preset dev -R '^startup_gamesave_' --parallel 4 --no-tests=error --output-on-failure`: **5/6 passed** (`startup_gamesave_persist` `0.66s`, `startup_gamesave_publish_locked` `2.05s`, `startup_gamesave_publish_unlocked` `0.96s`, `startup_gamesave_lock_errors` `0.02s`, `startup_gamesave_submit_controlled` `0.12s`); skipped (capability): `startup_gamesave_submit_system` - **Release `/O2` (`--preset release`)**: `ctest --preset release -R '^startup_gamesave_' --parallel 4 --no-tests=error --output-on-failure`: **5/6 passed** (`startup_gamesave_persist` `0.63s`, `startup_gamesave_publish_locked` `2.03s`, `startup_gamesave_publish_unlocked` `0.90s`, `startup_gamesave_lock_errors` `0.02s`, `startup_gamesave_submit_controlled` `0.11s`); skipped (capability): `startup_gamesave_submit_system`
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-24 05:33 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cfb42a1f9c

ℹ️ 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".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-24 05:33 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#pullrequestreview-6034203094) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `cfb42a1f9c` <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>
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 07:40 UTC · original · requested changes

The file-level rename tests are useful. The wrapped update has a different lifetime from the public API the implementation uses as its ABI reference. Writes and deletes currently reach disk before submit, so closing an update without submitting it can change a save. A failure on a later action can also leave the earlier action published. The GDK makes the whole update atomic at submit. Please stage actions until submit, or keep this PR at the storage-helper level until the wrapped transaction is ready. The most useful controls are close-without-submit, failure of the second action, and a second process observing only committed state.

There is also a gap in the documented path boundary: the blob read and delete methods check the leaf while traversal may already have passed through a redirected container directory. Refuse redirected containers consistently, or narrow and document the storage-root trust contract. Reference: https://learn.microsoft.com/en-us/gaming/gdk/docs/features/common/game-save/xgamesave?view=gdk-2610

**@⁠R0Y00** on GitHub · 2026-11-24 07:40 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#pullrequestreview-6035385736) · **requested changes** The file-level rename tests are useful. The wrapped update has a different lifetime from the public API the implementation uses as its ABI reference. Writes and deletes currently reach disk before submit, so closing an update without submitting it can change a save. A failure on a later action can also leave the earlier action published. The GDK makes the whole update atomic at submit. Please stage actions until submit, or keep this PR at the storage-helper level until the wrapped transaction is ready. The most useful controls are close-without-submit, failure of the second action, and a second process observing only committed state. There is also a gap in the documented path boundary: the blob read and delete methods check the leaf while traversal may already have passed through a redirected container directory. Refuse redirected containers consistently, or narrow and document the storage-root trust contract. Reference: https://learn.microsoft.com/en-us/gaming/gdk/docs/features/common/game-save/xgamesave?view=gdk-2610
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 08:19 UTC · original · requested changes

The new staging and close-without-submit paths address the earlier immediate-write problem. One acceptance case remains. The commit lock is process-local and read_blob does not take it. During publication a second reader can see a missing old blob or a mix of generations because the update renames each blob separately. Before merging a multi-blob contract, please make readers observe one complete generation through a shared publication point, or arrange compatible reader/writer coordination across processes. Add a deterministic two-process check paused at publication, with a two-blob update and the existing second-operation failure control. Keep the separate crash-recovery limitation explicit.

**@⁠R0Y00** on GitHub · 2026-11-24 08:19 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#pullrequestreview-6035809624) · **requested changes** The new staging and close-without-submit paths address the earlier immediate-write problem. One acceptance case remains. The commit lock is process-local and read_blob does not take it. During publication a second reader can see a missing old blob or a mix of generations because the update renames each blob separately. Before merging a multi-blob contract, please make readers observe one complete generation through a shared publication point, or arrange compatible reader/writer coordination across processes. Add a deterministic two-process check paused at publication, with a two-blob update and the existing second-operation failure control. Keep the separate crash-recovery limitation explicit.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-24 09:05 UTC · original · approved these changes

Windows Release passed all six save tests, including the deterministic locked-reader publication case, the no-lock control, and both async schedulers. The new names keep parallel test runs isolated. This resolves the publication review for cooperating processes. Crash recovery during publication remains outside the documented scope.

**@⁠R0Y00** on GitHub · 2026-11-24 09:05 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/1246#pullrequestreview-6036371069) · **approved these changes** Windows Release passed all six save tests, including the deterministic locked-reader publication case, the no-lock control, and both async schedulers. The new names keep parallel test runs isolated. This resolves the publication review for cooperating processes. Crash recovery during publication remains outside the documented scope.
This discussion has been locked. Commenting is limited to contributors.
No description provided.