startup: persist game-save containers and blobs under the storage path #1239
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1246"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:09:16Z.
What
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).tests/startup_gamesave_persist.cpp(CTeststartup_gamesave_persist) and a "Game saves" section indocs/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):
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.hand the test compiled withg++ -std=c++17and-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.pyandtests/bidi_controls_check.py, both pass.Not run: MSVC.
runtime_proxy.cppwas 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.Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:33:43Z.
Review: COMMENTED
💡 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
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".
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:26Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:28Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:30Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:32Z.
Review: COMMENTED
No description provided.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:17:44Z.
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at commit
cfb42a1f9c301c868d29d1650839fc2164f09700:--preset dev):cmake --build --preset dev --target startup_gamesave_persist startup_stub_gameinput -- -j 6):4.85s(configure1.97s)ctest --preset dev -R '^startup_gamesave_persist$' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.19s, total CTest0.27s)/O2(--preset release):cmake --build --preset release --target startup_gamesave_persist startup_stub_gameinput -- -j 6):3.63s(configure1.9s)ctest --preset release -R '^startup_gamesave_persist$' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.20s, total CTest0.29s)Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:25:08Z.
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
cfb42a1ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:50:56Z.
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)Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:33:43Z.
Code review location:
src/startup_stubs/save_store.h; line 89If
profile.dat.x2w-partalready exists as a symlink to a writable file outside the store, this truncatingofstreamfollows the link before any rename happens. The symlink check above covers only the final blob path, sowrite_blob("slot-a", "profile.dat", ...)can returnokafter 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 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:33:43Z.
Code review location:
src/startup_stubs/save_store.h; line 87When two open updates write the same container/blob concurrently, they share this single
.x2w-partfile; the runtime'ssave_lockprotects the handle tables but is released beforewrite_blobruns. 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 oneokand oneio_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 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:33:43Z.
Code review location:
src/startup_stubs/save_store.h; line 38On a normal case-insensitive Windows filesystem,
valid_name("profile.X2W-PART")returns true even though that file aliases the staging name used for blobprofile. Writingprofile.X2W-PARTand thenprofiletherefore 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 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by chatgpt-codex-connector[bot] on 2026-11-24T05:33:43Z.
Code review location:
src/startup_stubs/runtime_proxy.cpp; line 340With the fake-user proxy enabled, opening and closing 64 distinct container names permanently exhausts this table:
save_container_countonly grows, while close-provider, close-container and delete-container never release entries. The 65th distinct container returnsE_OUTOFMEMORYeven 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 👍 / 👎.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:26Z.
Code review location:
src/startup_stubs/save_store.h; line 89Fixed in
eeda5404: the staging file is no longer a predictable name. Each write creates<blob>.<counter>-<clock>.x2w-partand refuses to open it if anything (a link included) already exists at that name. A link left at the old<blob>.x2w-partname 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.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:28Z.
Code review location:
src/startup_stubs/save_store.h; line 87Fixed 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.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:30Z.
Code review location:
src/startup_stubs/save_store.h; line 38Fixed in
eeda5404:valid_namenow compares the staging suffix case-insensitively (.X2W-PART,.x2W-Partare refused on every OS). A near miss such as.x2w-parstays valid. Covered in the test.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T05:37:32Z.
Code review location:
src/startup_stubs/runtime_proxy.cpp; line 340Fixed in
eeda5404: container handles now come from a smallContainerTable(insave_store.h) with a reference count per entry. Close-container releases it, and an entry with an open update is kept untilCloseUpdate. 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.cpponly uses the table undersave_lock; it was not compiled on Linux.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T07:40:36Z.
Review: CHANGES_REQUESTED
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
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:08:18Z.
Re-verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) after rebase at
5b05c67a:--preset dev):ctest --preset dev -R "^(startup_gamesave_persist|startup_stub_gameinput)$"— 1/1 PASS (0.21s)/O2(--preset release):ctest --preset release -R "^(startup_gamesave_persist|startup_stub_gameinput)$"— 1/1 PASS (0.18s, build0.39s)Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T07:48:17Z.
Addressed both points in
d4de15eb:XGameSaveSubmitBlobWrite/XGameSaveSubmitBlobDeletenow stage actions in memory and apply them atomically onXGameSaveSubmitUpdate, leaving disk state unchanged if closed without submit or if a later action fails. Added the three controls intests/startup_gamesave_persist.cpp(close-without-submit, failure of a second action, and a second process observing only committed state).Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207) at
d4de15eb:--preset dev):ctest --preset dev -R "^(startup_gamesave_persist|startup_stub_gameinput)$"— 1/1 PASS (0.54s)/O2(--preset release):ctest --preset release -R "^(startup_gamesave_persist|startup_stub_gameinput)$"— 1/1 PASS (0.49s)Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T08:19:18Z.
Review: CHANGES_REQUESTED
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.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T08:16:39Z.
@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.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T08:31:59Z.
@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.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T08:39:31Z.
@tedin7 I pushed
97a63a54to 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.
#1334 now consumes this commit. Its separate two-process readback passes after either synchronous or asynchronous submit.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:46:03Z.
AI-assisted reply to the second review, in
8b82ced3(one new commit on top of97a63a54, no history change).What changed
<container>.x2w-lockbeside the container directory (LockFileExon Windows,flockelsewhere;src/startup_stubs/file_lock.h). Publication holds it exclusively until the last blob is in place;read_blobtakes it shared and the newread_blobsreads 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.Storeparameter). On timeout the call returns the newbusystatus 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 withbusywhile 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.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)
.x2w-old/.x2w-partfiles can remain. No recovery pass yet.read_blobs/read_blobto stay under the lock.Verified here (Linux, not the Windows node)
startup_gamesave_persistok;startup_gamesave_publishlocked variant ok 5/5 runs, unlocked variant caught.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).Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:52:56Z.
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 ina43e9f8f: 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.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T08:59:00Z.
Found the cause of the remaining failure on the Windows node in
startup_gamesave_publish_locked: both publish tests named their temp directory fromstd::rand()(constant whensrandis not called on some runtimes) andtime(nullptr), andctest --parallelstarted the locked and unlocked runs in the same second, so they shared one directory and removed it under each other.2f9c55d9names the directory from the process id and a steady-clock reading (same change instartup_gamesave_persist). Locally two simultaneous locked runs pass 2/2 with 0 failures. Not run on MSVC or NTFS. AI-assisted.Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T09:02:12Z.
@R0Y00 Addressed on top of
97a63a54in8b82ced3..2f9c55d9:src/startup_stubs/file_lock.h,LockFileExon Windows /flockon POSIX) acquired shared byread_blob/read_blobsand exclusively bycommit/delete_blob/delete_container, so readers in other processes observe one complete generation rather than mixed or missing blobs.tests/startup_gamesave_publish.cpp, built asstartup_gamesave_publish_lockedand the lock-disabled negative controlstartup_gamesave_publish_unlockedthat verifies"reader saw a mixed generation"), covering a two-blob update, the second-operation failure control, and dead-holder lock release, plusstartup_gamesave_lock_errors.docs/startup-runtime.mdandsave_store.h.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207, NTFS) at
2f9c55d9f684c49ee737ccf99686aaaa677b5246:--preset dev):ctest --preset dev -R '^startup_gamesave_' --parallel 4 --no-tests=error --output-on-failure: 5/6 passed (startup_gamesave_persist0.66s,startup_gamesave_publish_locked2.05s,startup_gamesave_publish_unlocked0.96s,startup_gamesave_lock_errors0.02s,startup_gamesave_submit_controlled0.12s); skipped (capability):startup_gamesave_submit_system/O2(--preset release):ctest --preset release -R '^startup_gamesave_' --parallel 4 --no-tests=error --output-on-failure: 5/6 passed (startup_gamesave_persist0.63s,startup_gamesave_publish_locked2.03s,startup_gamesave_publish_unlocked0.90s,startup_gamesave_lock_errors0.02s,startup_gamesave_submit_controlled0.11s); skipped (capability):startup_gamesave_submit_systemImported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-24T09:05:02Z.
Review: APPROVED
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.