Skip to content

XGameRuntime: a save read sees all of an update or none of it - #2132

Open
dhillonjagdeep650-boop wants to merge 1 commit into
xcl-dev:mainfrom
dhillonjagdeep650-boop:xgamesave-read-during-update
Open

dhillonjagdeep650-boop wants to merge 1 commit into
xcl-dev:mainfrom
dhillonjagdeep650-boop:xgamesave-read-during-update

Conversation

@dhillonjagdeep650-boop

@dhillonjagdeep650-boop dhillonjagdeep650-boop commented Nov 25, 2026 •

Copy link
Copy Markdown

XGameSaveReadBlobData and XGameSaveReadBlobDataAsync read a container's blobs without the lock that XGameSaveSubmitUpdate holds while it replaces them one file at a time. A read that runs during an update can return some blobs from before the update and some from after it. It can also make the update fail: while the read has a blob open, MoveFileExW cannot replace that file, and apply returns E_FAIL with part of the update written (the half-applied state of #324, reached without a disk error). Found by reading the code and reproduced with a unit test; not seen in a title.

What is in it

  • crates/xcl/src/hle/xgameruntime/gamesave.rs: read_layout takes SAVE_MUTATION, as apply and delete_container do (one line, plus the lock's comment).
  • Same file, test reads_during_an_update_see_all_of_it_or_none: one thread reads two blobs in a loop while another rewrites both in 30 updates. It counts failed updates, reads whose two blobs come from different updates, and failed reads; all three must be 0.

Tested

  • NVIDIA GeForce RTX 3080 Ti 12 GB (32-lane waves), driver 617.42 (32.0.16.1742); Ryzen 7 5800X; 48 GB RAM; Windows 11 Pro 26300.9974; rustc 1.98.1 msvc; DXC 1.8.2502.11 (Windows SDK 10.0.26100.0); tests in debug, smoke runs in release; no XCL_* variable set for the tests (LOCALAPPDATA pointed at an empty folder, so that they could not touch a real XCL data folder).
  • The new test without the read_layout line: fails 5 of 5 runs (failed updates / mixed reads per run: 13 / 37, 9 / 53, 5 / 42, 8 / 49, 8 / 25). With it: passes 5 of 5.
  • cargo test --workspace --locked --no-fail-fast -- --test-threads=4 on the tree of a18c180 (run before it was committed, unchanged since): 1155 passed, 0 failed, 46 ignored. main 6020a33: 1154 passed, 0 failed, 46 ignored.
  • SKIPPED (25 lines, the same in both runs): 20 no wave64 cases, 3 per-lane cases refused as unsupported (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows), pso_measurement_compiles_an_exact_synthetic_record (needs Windows Developer Mode).

Regression run
scripts/smoke.ps1 -Game <retail title> -Seconds 60, each run with an empty data root and its own copy of the same DXIL cache. main first. Corrected 2026-11-25: this said "no input". The input was not controlled, and the logs show a press of A at 45 s in the PR's run and none in main's, so the two frame counts are not of the same scene.

xcl-smoke v1
commit: 6020a33b16ba2de25b3aef5947552f2dc1831f09
gpu: NVIDIA GeForce RTX 3080 Ti
title: ab97764d
seconds: 60
exit: 0x0
frames shown: 979 (PresentX 979)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17286 MB
xcl-smoke v1
commit: a18c180ce39a1b407e964e541be7c68a8bf94f50
gpu: NVIDIA GeForce RTX 3080 Ti
title: ab97764d
seconds: 60
exit: 0x0
frames shown: 873 (PresentX 873)
presents per 2 s (last 3): 39 39 40
device removals: 0
crashes: 0
peak commit: 17633 MB

A second run of each, in the opposite order, gave 447 frames for a18c180 (first press at 57 s) and 845 for main 6020a33 (first press at 34 s), both exit: 0x0 with 0 device removals and 0 crashes. 447 is under 80 % of 845. That run presents nothing from 26 to 52 s, before its press; so does a run of unmodified cbc296a on this machine (22 to 48 s, 434 frames), and the other runs have such a gap of 16 to 20 s, so I do not think it is this change, but one run each does not show it. I first put the spread down to pipelines compiling in the background; the logs have no large driver compile in those gaps. A pair with the same scripted input (XCL_PRESS_A_AT) is to follow.

Whether the title reads a save in these 60 s is not known: I first wrote that it makes no XGameSave call, but those calls write nothing to the log. No file was written under gamesave in any of the four runs.

Not tested

AI use

  • Claude Code. Claude Opus 5.5 found the race, wrote the fix and the test, and ran the fail-before / pass-after runs. Claude Fable 5.2 ran the full-suite and smoke runs and wrote this description; Claude Opus 5.5 wrote the corrections of 2026-11-25.

🤖 Generated with Claude Code

XGameSaveSubmitUpdate replaces an update's blobs one file at a time under
SAVE_MUTATION, but XGameSaveReadBlobData (and its Async form) read the
blobs without it. A read that ran during an update could return one blob
from before the update and another from after it, and while it had a blob
open, MoveFileExW could not replace that file, so the update failed with
E_FAIL partway through.

read_layout now takes SAVE_MUTATION, like apply and delete_container.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent native Windows check of exact PR head a18c180ce39a1b407e964e541be7c68a8bf94f50.

Tested

  • Windows 11 build 26200, Ryzen 9 5980HX, Radeon RX 6800M driver 30.0.13002.13003, Rust 1.99.0 MSVC, DXC/DXIL 1.9.2609.5. These are save-file tests; the GPU was not used.
  • cargo test --locked -p xcl --lib -j 2 gamesave -- --test-threads=1 --show-output: 11 passed, 0 failed, 0 ignored, including reads_during_an_update_see_all_of_it_or_none.
  • The concurrent read/update regression was then run in a separate cargo test process 20 times, sequentially, with --test-threads=1: 20/20 runs passed, each reporting 1 passed, 0 failed and no SKIPPED line. The test performs its 30 update/read rounds each time, so this is 600 rounds across the repeated runs.

This checks the race regression and neighboring GameSave tests on this Windows machine. I did not run a pre-fix negative control here, the full workspace suite, or a retail title save operation. The short title startup available on this machine does not reach GameSave calls. No game data was used or uploaded.

AI-assisted testing and report drafting with OpenAI Codex (GPT-6); I checked the exact revision, per-run log, and aggregate counts before posting.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@raylitebull

Copy link
Copy Markdown
Member

Code review on a18c180:

  • Acquiring SAVE_MUTATION inside read_layout (crates/xcl/src/hle/xgameruntime/gamesave.rs) cleanly prevents concurrent apply() updates from producing torn multi-blob reads, verified by reads_during_an_update_see_all_of_it_or_none.
  • Complementary to #2165 (1028ba5), which locks SAVE_MUTATION around each_blob enumeration.
  • Diff audited and CI workflow approved (running).

Remaining before merge: Build and test finishing green plus dual-vendor verification on a18c180.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants