startup: discover and read committed save containers synchronously #2151
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2159"
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 NiiRoZz on 2026-11-25T01:53:16Z.
Change
This answers the synchronous game-save queries from the persisted store. Until now a caller could write saves but not discover or read them back on a second start. It applies to provider
704c3f58-e629-4cc2-b197-30511b996fe2and interface1bfff3af-f14a-40a3-8e35-9ada906593f9; other interface identities keep the empty results.list_blobscall under its shared publication lock. No store lock is held while a callback runs. A container created through slot 16 but never submitted exists and is reported with 0 blobs.list_blobscall. Before this change, slot 19 returned success without calling back, so a populated container looked empty.read_blobs. A count of 0 means every blob; that case lists and reads under the same lock throughlist_blobs(..., &payloads, read_if), optional arguments this PR adds tosave_store.h. With a count of 0, the needed size is computed from the listing and checked against the capacity before any payload is read. The records are packed with the existingsave_blob_pack.h(shared with slots 21 and 22). The caller's buffer is written only on success, so a short buffer, a missing blob or a lock timeout leave it untouched. A closed container handle is refused.0x80830010without calling back. That code, and the absence of a callback, are not verified against the platform API; the previous stub returned 0. Follow-up issue draft: see below.This supersedes draft #1334 by rebasing its read side onto current
main; its author is credited withCo-authored-byon the commit that carries that code. The persistence and asynchronous read written since then are reused as they are. It reads what the existing save work produces: the persisted store from tedin7 (#1246) and its locked container and blob listing (#1761), and the closed-container rule from avt0m4t48 (#1976).The four points from the review note on #1334:
startup_gamesave_read_async_systemname is already used onmain(startup_gamesave_read_async_{controlled,system}), so that variant is registered asstartup_gamesave_read_after_async_submit.read_blobsand no process-local mutex.startup_gamesave_read_publish_lockedis a new source-built control with two kinds of case.save_store.halso gets a reader hook, at each store read and between two blob reads. The hook is null unless this test sets it; production builds keep only the anchor comments. While the reader is stopped there, a second process commits a whole new generation. Slot 20 (by name, and for every blob) and slot 14 must stay on the old generation.startup_gamesave_read_publish_unlockedruns the same checks on the copy whose lock is a no-op and must be caught (reader saw a mixed generation).The existing restart test stays.
Refs #1200
Verification
Base
6fb434d8, branch head63d38093(merges cleanly with origin/main94337881), Windows 11 x64, MSVC 14.44, Ninja, Release:Result: 18 passed, 0 failed, 0 skipped (
100% tests passed, 0 tests failed out of 18). The two_systemvariants andstartup_gamesave_read_after_async_submitran (no 77 skip) on this machine.Negative controls:
startup_gamesave_readfails with exit code 14.save_read.inland ranstartup_gamesave_read_publish_lockedagainst them; each was caught, and the file was then restored:read_blobonce per name: racing named, exit 22 (mixed);read_blobs: racing all, exit 21 (new generation);The paused-writer cases alone pass all three mutants, which is why the racing cases were added.
startup_gamesave_read_publish_unlockedpasses only through its required failure text: at pause point 0 a read without the lock returns0x80830008for a blob that is mid-publication, and at point 1 it returns a mix of the two generations.Evidence and follow-up
The fixtures are source-built with synthetic payloads (two short preference blobs; two 4096-byte generated blobs per generation). No platform files or captures are used.
An independent two-start check was run locally (counts and codes only):
mainwithout saves.This shows the stand-in returns committed data on a restart. It does not establish full-game startup.
Assumptions and follow-up:
0x80830010, no callback) needs a platform check. A follow-up issue proposes how to pin it with a fixture.AI-assisted (Claude Code).
Checklist
docs/startup-runtime.md).🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:08:44Z.
Review: COMMENTED
Review of head
63d38093652de9afd8e988f9cfc3fde592c5d49e(comment only, no approval).Scope read:
src/startup_stubs/save_read.inl(new),save_store.h(list_blobspayload/read_ifoverload and two seams),runtime_proxy.cpp(interface gating),CMakeLists.txt(seam anchors, new tests), docs, tests.Checked, no problem found
list_blobscall.read_ifruns before any payload is read, andpayloadsstays empty when it returns false. The caller buffer is written only after every check passes (capacity, writable, alignment).not_found). A container that was created but never submitted is reported with 0 blobs.public_save_interface) keeps other interface identities on the old empty results. The per-kind proxy cache fixes the repeated allocation and log noise.FATAL_ERRORif they go missing. The seams compile to nothing in the production header.Findings
src/startup_stubs/save_read.inlinblobs():static_cast<std::uint32_t>(entry.bytes)truncates a blob over 4 GiB. The count in slot 13/14 is guarded (blobs.size() > UINT32_MAX), but the size is not. The platform blob limit is far lower, so this is theoretical. A guard returninge_failwould make it consistent.save_read.inlmodified_time(): on error it returns the current time, so a failed stat looks like "just modified". Fine for a stand-in, but the comment could say so.Commands executed locally (Linux worktree at the head SHA)
git diff --stat origin/main...HEAD: 8 files, +734 -15.python3 tests/docs_links_check.py: self-test passed, 18 Markdown files, 395 links OK.python3 tests/bidi_controls_check.py: 1427 files, no bidirectional controls.git diff --check origin/main...HEAD: clean.gh pr checks 2159: Windows build/test, Linux Python checks and gfx1013 fixtures pass.x86_64-w64-mingw32-g++ -fsyntax-only tests/startup_gamesave_read.cpp: fails on MSVC-only__tryinlocal_log.h. This is pre-existing and not caused by this PR.Not done: the new tests need the MSVC Windows toolchain, so I could not run them or a logic mutation on Linux. I did not run the Windows 2025 job, because the CI Windows job already built and ran these tests at this head and the PR touches no shader or HLSL code. A mutation check (for example dropping the
fitscapacity check or theread_ifcall) on Windows is still open.AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:20:00Z.
Review: COMMENTED
Review of head
8aa0244bcb0c88a9eeb393e4bae8d8fda641c998(comment only, no approval).Scope read:
save_read.inl(slots 13, 14, 18, 19, 20), theproxy_query/forwardrouting for the public save interface, thelist_blobspayload/read_ifextension insave_store.h, the new seams inCMakeLists.txt, and both new tests.Commands run locally (Linux worktree of the PR head)
git diff --stat origin/main...HEAD: 8 files, +731 / -15.python3 tests/docs_links_check.py: self-test passed, 18 Markdown files / 395 links OK.python3 tests/bidi_controls_check.py: self-test passed, 1427 files, no bidirectional controls.git diff --check origin/main...HEAD: clean.gh pr checks: Linux Python checks, Windows build and test, and gfx1013 fixtures are all green. The/O2job and the chart publish job were skipped.tests/startup_gamesave_read.cpp. It fails becauselocal_log.huses MSVC__try/__except, so these C++ tests cannot be run on Linux. I did not run them locally and I did not do a mutation run. The only evidence that they pass is the Windows CI job above. I did not request a separate Win2025 run.Findings
P1: none. P2: none.
What I checked and found correct:
requested > capacity / sizeof(Blob)is rejected before allocation, andnamesis validated as readable before thepiecesandwantedvectors are sized. A hostile*countis therefore bounded by real memory, andbad_allocmaps toe_outofmemory.list_blobslock, and the capacity predicate runs before any payload is read. That gives a single-generation snapshot, which is what the publish tests exercise.by_kind[public_save][index]keeps one cached proxy per interface kind. Other interface revisions keep the old empty answers throughsave_call. This is consistent with the updated comment inruntime_proxy.cppanddocs/startup-runtime.md.static_cast<std::uint32_t>(entry.bytes)in slots 18/19 cannot truncate, sincemax_blob_bytesis 64 MiB.Nits (non-blocking):
save_read.inl,containers(): the container list and each container'slist_blobsare separate lock acquisitions, so the enumeration is not one cross-container generation. Thenot_foundskip handles deletions. A one-line note that per-container consistency is the intended guarantee would help.save_read.inl,modified_time(): onlast_write_timefailure it returns "now", which can hide an error. A short comment saying that this is deliberate would help.runtime_proxy.cpp,by_kindcache: it is a plain static array with no lock, asproxies[]already is. This matches existing behavior, but it is worth keeping in mind if proxy queries ever become multi-threaded.store-read,blob-read) are checked by the existing anchor loop, which is good. The test hook is null outsidestartup_gamesave_read_publish.Clean-room, MIT and a neutral title look fine. The PR is mergeable.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T02:16:02Z.
I kept the existing empty result for an absent container instead of assigning an undocumented platform HRESULT. The local Windows Release selection passed 4/4: synchronous and async-submitted restart readbacks, the locked publication test, and the unlocked mixed-generation control. The published read and enumeration paths remain covered. The platform missing-name HRESULT can be compared independently if a native result becomes available.