XGameSave: an update that fails leaves the container as it was (#324) #543

Open
github-bot wants to merge 1 commit from github-bot/gh-543 into main AGit
Owner

@⁠Rednaxeh on GitHub · 2026-11-24 01:35 UTC · original
Rednaxeh:gamesave-atomic-update → main · +124 −25 · 1 files · 1 commits · open

apply in gamesave.rs wrote an update's display name and then each blob in turn, each replaced atomically on its own. When one write failed partway it returned E_FAIL, but the display name and every blob before the failing one were already replaced, so a title that writes a header blob and a data blob in one update was left with the new header and the old data after any write error (disk full, a path over the limit, a locked file). The GDK documents XGameSaveSubmitUpdate as all or nothing. Fixes #324.

What is in it

  • crates/xcl/src/hle/xgameruntime/gamesave.rs: write_atomic becomes temp_path / write_temp (temp file written and flushed); the move into place is apply's. apply writes every temp first, then moves the files the update replaces or deletes aside and the temps into place; a failure anywhere moves the files back and removes the temps, so the container stays as it was. Only the last op on a blob name counts, as when the ops ran in order (write then delete deletes; delete then write writes), with names compared without case, since Meta and META are one file on NTFS (oni-swr's point on the issue). A restore that fails during the rollback logs the blob and the backup it is left under (oni-swr's review). A new test, a_failed_update_leaves_the_container_as_it_was: an update whose second blob cannot be written (a folder is in its place) returns E_FAIL and leaves the first blob, the display name and the folder free of temp files; then write-then-delete, delete-then-write and write Meta / delete META in one update.

Opened at oni-swr's request after they claimed the issue (their review and branch: see #324). #491 covers the same issue with the staged writes only (no rollback of a rename that fails, and ops are not folded).

Tested

  • AMD Radeon RX 7800 XT (RDNA3), driver 32.0.32029.2010; Ryzen 7 7800X3D, 32 GB; Windows 11 Pro 26300; Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug (release for the regression run); DXC 1.9.2602.17.
  • Without the change (the new test on main's apply): fails at the first check after the failed update, blob a reads "new" instead of "old" (left: [110, 101, 119], right: [111, 108, 100]).
  • With the change: cargo test -p xcl --lib -- hle::xgameruntime::gamesave::: 11 passed, 0 failed (the existing atomic_writes_preserve_xcltmp_blobs_and_skip_leftover_temps now checks the temp cleanup through apply).
  • .\scripts\test.ps1 (cargo build --workspace + cargo test --workspace -- --test-threads=4) with XCL_REQUIRE_GPU=wave64,mesh: 677 passed, 0 failed, 41 ignored, 0 SKIPPED (lib 637 / 0 / 21); no new compiler warning.

Regression run
scripts/smoke.ps1 -Game <folder> on a retail title, release builds, no uncommitted changes, one after the other on the machine above (a warm-up run of main first, not shown). Both blocks unedited.

main 2997c9a:

xcl-smoke v1
commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21
gpu: AMD  Radeon RX 7800 XT
title: retail-game6
seconds: 60
exit: 0x0
frames shown: 380 (PresentX 380)
presents per 2 s (last 3): 8 8 8
device removals: 0
crashes: 0
peak commit: 15286 MB

this PR's head 897f5ef:

xcl-smoke v1
commit: 897f5ef85df0d37bdf0dd84b14ccc70558a5d261
gpu: AMD  Radeon RX 7800 XT
title: retail-game6
seconds: 60
exit: 0x0
frames shown: 393 (PresentX 393)
presents per 2 s (last 3): 8 8 8
device removals: 0
crashes: 0
peak commit: 15294 MB

Not tested

  • NVIDIA / Intel. A title's own saves: the regression run gives the title no input in 60 s, so it does not reach a save (it is in its intro movie, whose 8 presents / 2 s on this card are the known cost discussed on #283); it checks that nothing else changed.
  • A crash between moving the files aside and placing the temps leaves the old blobs under their ~xcltmp.* names, which enumeration skips, where before the same crash left a half-applied but visible container. The window is a few renames long; a recovery pass on open would be a change of its own.

AI use

  • Claude Code with Claude Fable 5.1: wrote the change, the test and this description from the issue; the runs are from the machine above.

🤖 Generated with Claude Code

**@⁠Rednaxeh** on GitHub · 2026-11-24 01:35 UTC · [original](https://github.com/xcl-dev/xcl/pull/543) `Rednaxeh:gamesave-atomic-update` → `main` · +124 −25 · 1 files · 1 commits · open `apply` in `gamesave.rs` wrote an update's display name and then each blob in turn, each replaced atomically on its own. When one write failed partway it returned `E_FAIL`, but the display name and every blob before the failing one were already replaced, so a title that writes a header blob and a data blob in one update was left with the new header and the old data after any write error (disk full, a path over the limit, a locked file). The GDK documents `XGameSaveSubmitUpdate` as all or nothing. Fixes #324. **What is in it** - `crates/xcl/src/hle/xgameruntime/gamesave.rs`: `write_atomic` becomes `temp_path` / `write_temp` (temp file written and flushed); the move into place is `apply`'s. `apply` writes every temp first, then moves the files the update replaces or deletes aside and the temps into place; a failure anywhere moves the files back and removes the temps, so the container stays as it was. Only the last op on a blob name counts, as when the ops ran in order (write then delete deletes; delete then write writes), with names compared without case, since `Meta` and `META` are one file on NTFS (oni-swr's point on the issue). A restore that fails during the rollback logs the blob and the backup it is left under (oni-swr's review). A new test, `a_failed_update_leaves_the_container_as_it_was`: an update whose second blob cannot be written (a folder is in its place) returns `E_FAIL` and leaves the first blob, the display name and the folder free of temp files; then write-then-delete, delete-then-write and write `Meta` / delete `META` in one update. Opened at oni-swr's request after they claimed the issue (their review and branch: see #324). #491 covers the same issue with the staged writes only (no rollback of a rename that fails, and ops are not folded). **Tested** - AMD Radeon RX 7800 XT (RDNA3), driver 32.0.32029.2010; Ryzen 7 7800X3D, 32 GB; Windows 11 Pro 26300; Rust 1.100.0 `stable-x86_64-pc-windows-msvc`, debug (release for the regression run); DXC 1.9.2602.17. - Without the change (the new test on `main`'s `apply`): fails at the first check after the failed update, blob `a` reads `"new"` instead of `"old"` (`left: [110, 101, 119], right: [111, 108, 100]`). - With the change: `cargo test -p xcl --lib -- hle::xgameruntime::gamesave::`: 11 passed, 0 failed (the existing `atomic_writes_preserve_xcltmp_blobs_and_skip_leftover_temps` now checks the temp cleanup through `apply`). - `.\scripts\test.ps1` (`cargo build --workspace` + `cargo test --workspace -- --test-threads=4`) with `XCL_REQUIRE_GPU=wave64,mesh`: **677 passed, 0 failed, 41 ignored, 0 SKIPPED** (lib 637 / 0 / 21); no new compiler warning. **Regression run** `scripts/smoke.ps1 -Game <folder>` on a retail title, release builds, no uncommitted changes, one after the other on the machine above (a warm-up run of `main` first, not shown). Both blocks unedited. `main` `2997c9a`: ``` xcl-smoke v1 commit: 2997c9aca6ebf4577fed34ebdb3cb0a77dd9ec21 gpu: AMD Radeon RX 7800 XT title: retail-game6 seconds: 60 exit: 0x0 frames shown: 380 (PresentX 380) presents per 2 s (last 3): 8 8 8 device removals: 0 crashes: 0 peak commit: 15286 MB ``` this PR's head `897f5ef`: ``` xcl-smoke v1 commit: 897f5ef85df0d37bdf0dd84b14ccc70558a5d261 gpu: AMD Radeon RX 7800 XT title: retail-game6 seconds: 60 exit: 0x0 frames shown: 393 (PresentX 393) presents per 2 s (last 3): 8 8 8 device removals: 0 crashes: 0 peak commit: 15294 MB ``` **Not tested** - NVIDIA / Intel. A title's own saves: the regression run gives the title no input in 60 s, so it does not reach a save (it is in its intro movie, whose 8 presents / 2 s on this card are the known cost discussed on #283); it checks that nothing else changed. - A crash between moving the files aside and placing the temps leaves the old blobs under their `~xcltmp.*` names, which enumeration skips, where before the same crash left a half-applied but visible container. The window is a few renames long; a recovery pass on open would be a change of its own. **AI use** - Claude Code with Claude Fable 5.1: wrote the change, the test and this description from the issue; the runs are from the machine above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`apply` wrote the display name and then each blob in turn, each replaced atomically on
its own. When a write failed partway it returned E_FAIL, but the display name and the
blobs before it were already replaced: a title that writes a header blob and a data blob
in one update was left with the new header and the old data after any write error. The
GDK says an update succeeds or fails as a whole.

Every write now goes to a temp file first; then the files the update replaces or deletes
are moved aside and the temps moved into place; a failure anywhere puts the files moved
aside back and removes the temps. Only the last op on a blob counts, as it did when the
ops ran in order, with names compared without case (one file on NTFS). Fixes #324.

Not covered: a crash between moving the files aside and placing the temps leaves the old
blobs under their `~xcltmp.*` names, which enumeration skips; recovering those on open
would be a change of its own.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:25:09 +00:00
Author
Owner

@⁠Rednaxeh on GitHub · 2026-11-24 10:18 UTC · original

@⁠oni-swr thank you for the review and the run. Taken as follows:

  1. A failed restore now logs a warning with the backup's path and the blob it belongs to (d2e70ef → new head), so a blob that "vanished" after a failed save can be found and put back by hand. Smoke pair rerun on the new head, in the description.
  2. Agreed that the window should go, and the hard link is the right tool: dest then always holds the old or the new contents. Please send it as the follow-up once this is in – your branch has it and the tests; I'd rather not fold it into this PR after the reviews it has had.

Marked ready for review. AI use: Claude Code (Claude Fable 5.1) wrote the change and this reply; the run was mine.

**@⁠Rednaxeh** on GitHub · 2026-11-24 10:18 UTC · [original](https://github.com/xcl-dev/xcl/pull/543#issuecomment-7128598965) @⁠oni-swr thank you for the review and the run. Taken as follows: 2. A failed restore now logs a warning with the backup's path and the blob it belongs to (`d2e70ef` → new head), so a blob that "vanished" after a failed save can be found and put back by hand. Smoke pair rerun on the new head, in the description. 1. Agreed that the window should go, and the hard link is the right tool: `dest` then always holds the old or the new contents. Please send it as the follow-up once this is in – your branch has it and the tests; I'd rather not fold it into this PR after the reviews it has had. Marked ready for review. AI use: Claude Code (Claude Fable 5.1) wrote the change and this reply; the run was mine.
Author
Owner

@⁠Belox17 on GitHub · 2026-11-24 18:48 UTC · original

Test report for 897f5ef8 on Windows (RTX 3060 Ti): passes on its base and merged into current main; the test fails without the fix

Tested

  • Ryzen 5 5600X, NVIDIA GeForce RTX 3060 Ti; Windows 11 build 26300 (NTFS); rustc 1.98.1 MSVC; debug build. PR head as is, clean tree.
  • cargo test -p xcl --lib a_failed_update_leaves_the_container: 1 passed.
  • cargo test --workspace -- --test-threads=4 on the head: 677 passed, 0 failed, 41 ignored (its base 2997c9ac: 676).
  • Merged into current main 9e3831e (clean merge): 777 passed, 0 failed, 41 ignored (main alone: 776).
  • With gamesave.rs from 2997c9ac plus only the new test, the test fails: blob a is new (left [110, 101, 119]) instead of old after the failed update.
  • The same test, run against #1531's gamesave.rs (same issue), fails at the Meta / META case: there, an update that writes Meta and then deletes META keeps the blob, as GonZiin's review on #1531 found. This PR handles it.

Not tested

  • The crash window described in the commit message; a title's save path; AMD.

AI use: Claude Code (Claude Opus 5.5) ran the commands and wrote this report; I checked it before posting.

**@⁠Belox17** on GitHub · 2026-11-24 18:48 UTC · [original](https://github.com/xcl-dev/xcl/pull/543#issuecomment-7141188291) **Test report for `897f5ef8` on Windows (RTX 3060 Ti): passes on its base and merged into current main; the test fails without the fix** **Tested** - Ryzen 5 5600X, NVIDIA GeForce RTX 3060 Ti; Windows 11 build 26300 (NTFS); rustc 1.98.1 MSVC; debug build. PR head as is, clean tree. - `cargo test -p xcl --lib a_failed_update_leaves_the_container`: 1 passed. - `cargo test --workspace -- --test-threads=4` on the head: 677 passed, 0 failed, 41 ignored (its base `2997c9ac`: 676). - Merged into current `main` `9e3831e` (clean merge): **777 passed, 0 failed, 41 ignored** (`main` alone: 776). - With `gamesave.rs` from `2997c9ac` plus only the new test, the test fails: blob `a` is `new` (left `[110, 101, 119]`) instead of `old` after the failed update. - The same test, run against #1531's `gamesave.rs` (same issue), fails at the `Meta` / `META` case: there, an update that writes `Meta` and then deletes `META` keeps the blob, as GonZiin's review on #1531 found. This PR handles it. **Not tested** - The crash window described in the commit message; a title's save path; AMD. **AI use:** Claude Code (Claude Opus 5.5) ran the commands and wrote this report; I checked it before posting.
Author
Owner

@⁠luckyteagirl on GitHub · 2026-11-25 03:15 UTC · original

Tested

  • Exact PR head 897f5ef85df0d37bdf0dd84b14ccc70558a5d261 on Windows 11 build 26200, Ryzen 9 5980HX, Rust 1.99.0 MSVC. This is a filesystem and GameSave test; it did not exercise the RX 6800M GPU.
  • cargo test --locked -p xcl --lib -j 2 hle::xgameruntime::gamesave:: -- --test-threads=1 --show-output: 11 passed, 0 failed, 0 ignored, no explicit skips. a_failed_update_leaves_the_container_as_it_was passed, including preservation of the old blob and display name when the second write fails, temp cleanup, and last-operation behavior for case variants of a blob name.
  • cargo build --locked --workspace -j 2: passed.

Not tested

  • A title's save or load flow, the full workspace suite, other filesystems or operating systems, or interruption between moving old files aside and putting new files in place. The last case is the crash window already described in the PR.

AI use

OpenAI Codex (GPT-6, exact variant not exposed in this session) reviewed the exact diff, ran the GameSave suite and build, checked the logs, and drafted this report.

**@⁠luckyteagirl** on GitHub · 2026-11-25 03:15 UTC · [original](https://github.com/xcl-dev/xcl/pull/543#issuecomment-7151740302) **Tested** - Exact PR head `897f5ef85df0d37bdf0dd84b14ccc70558a5d261` on Windows 11 build 26200, Ryzen 9 5980HX, Rust 1.99.0 MSVC. This is a filesystem and GameSave test; it did not exercise the RX 6800M GPU. - `cargo test --locked -p xcl --lib -j 2 hle::xgameruntime::gamesave:: -- --test-threads=1 --show-output`: **11 passed, 0 failed, 0 ignored**, no explicit skips. `a_failed_update_leaves_the_container_as_it_was` passed, including preservation of the old blob and display name when the second write fails, temp cleanup, and last-operation behavior for case variants of a blob name. - `cargo build --locked --workspace -j 2`: passed. **Not tested** - A title's save or load flow, the full workspace suite, other filesystems or operating systems, or interruption between moving old files aside and putting new files in place. The last case is the crash window already described in the PR. **AI use** OpenAI Codex (GPT-6, exact variant not exposed in this session) reviewed the exact diff, ran the GameSave suite and build, checked the logs, and drafted this report.
Author
Owner

@⁠DavidM1911 on GitHub · 2026-11-25 13:43 UTC · original

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

  • cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)

Thanks!

**@⁠DavidM1911** on GitHub · 2026-11-25 13:43 UTC · [original](https://github.com/xcl-dev/xcl/pull/543#issuecomment-7164190506) Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.) Thanks!
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/543/head:github-bot/gh-543'
git switch 'github-bot/gh-543'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-543'
git switch 'github-bot/gh-543'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-543'
git switch 'github-bot/gh-543'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-543'
git switch 'main'
git merge --squash 'github-bot/gh-543'
git switch 'main'
git merge --ff-only 'github-bot/gh-543'
git switch 'main'
git merge 'github-bot/gh-543'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.