XGameSave: a failed XGameSaveSubmitUpdate leaves the update half applied #324
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
goal:world-load
good first issue
help wanted
invalid
keep-open
off-goal
question
stale
test-only
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/xcl-dev--xcl#324
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@mastrr9 on GitHub · 2026-11-23 23:27 UTC · original
applyincrates/xcl/src/hle/xgameruntime/gamesave.rs(line 564 onmain85bdf21) writes the display name, then each blob in turn, each with its own atomic replace. When one write fails partway, it returnsE_FAIL, but the display name and every blob before the failing one are already replaced.The GDK documents an update as all or nothing: "we want the whole operation to succeed or fail atomically. We don't want to have a partial update where some blob data is inconsistent with other data within the container." (
XGameSaveSubmitUpdate, Remarks). A title that writes a header blob and a data blob in one update can be left with the new header and the old data after any write error (disk full, a path overMAX_PATHfrom a long escaped blob name, or a locked file).Repro (clean-room, Linux):
Copied
apply,write_atomic, andencunchanged into a small standalone test (replace_filetakes itsstd::fs::renamebranch; the order of operations is the same on Windows): container with bloba = "old"and display"Old"; an update writinga = "new"andb, wherebcannot be written. Result:0x80004005, bloba = "new", display"New".Suggested fix:
Stage every write of the update first (each to its own temp file next to its blob), and only after all of them succeed rename them into place and perform the deletes; on any failure, remove the staged temp files and leave the container untouched. A small journal in the container (replayed or discarded on next open) would also close the gap if a rename fails mid-commit. Unit test: an update whose second blob cannot be written leaves the first blob and the display name unchanged.
Not tested: on Windows.
AI use: Initially found and reproduced with Claude Code; re-verified against
main(85bdf21) with Antigravity (Gemini 4 Neon).@oni-swr on GitHub · 2026-11-24 00:43 UTC · original
I'm taking this one. Plan:
apply()first writes every blob (and the display name) to its own temp file next to its destination. Only once all of those writes have succeeded are the files renamed into place and the deletes done. If any write fails, the temp files are removed and the container is left untouched. Unit test ingamesave.rs: an update whose second write fails leaves the first blob and the display name unchanged. A rename failing partway through the commit stays out of scope (no journal).AI use: Claude Code (Claude Opus 5.5) helped read the code and draft this comment.
@Rednaxeh on GitHub · 2026-11-24 00:49 UTC · original
@oni-swr before you start: I had this one done and tested just before your comment (my mistake not to say so here first). It is on my fork, one commit on current
main:github.com/Rednaxeh/xcl@4012cd9258Same shape as your plan, plus the part you scoped out: every write goes to a temp file first; then the files the update replaces or deletes are moved aside (under
~xcltmp.*names) and the temps moved into place; a failure anywhere, a rename included, moves the files back and removes the temps. Only the last op on a blob counts, as when the ops ran in order. Test: an update whose second blob cannot be written (a folder in its place) returnsE_FAILand leaves the first blob and the display name as they were; it fails onmain(areads"new"). Whole suite 677 / 0 / 41 on an RX 7800 XT, and a smoke pair on a retail title.Not covered, as in yours: a crash between moving the files aside and placing the temps leaves the old blobs under their temp names (a recovery pass on open would be a change of its own).
Two ways, your call: I open it as a PR and you review or test it, or you take it from here and I test yours. I will not open the PR unless you say so.
@oni-swr on GitHub · 2026-11-24 00:57 UTC · original
@Rednaxeh thanks, and no harm done. Please open it as the PR; I'll review it and close my branch.
One thing to check while you're at it: the "last op per blob" filter compares names exactly, but on NTFS
MetaandMETAare the same file (seecase_insensitive_blob_and_container_matching_on_ntfs). An update that writesMetaand then deletesMETAseems to leave the blob in place: the delete finds nothing to move aside, since the write's step already moved it, and then the temp is placed. The old in-order code deleted it. I haven't run this, I only read the diff.@Grimkaaah on GitHub · 2026-11-24 01:00 UTC · original
PR opened: stage all writes first, rename only after success; failed submit leaves the container untouched (test included).
Made with Cursor
@Rednaxeh on GitHub · 2026-11-24 01:35 UTC · original
@oni-swr thanks a lot for the catch, and for reading the diff that closely – you were right:
Metathen deleteMETAleft the blob. The last-op filter now compares names without case (eq_ignore_ascii_case, aseach_containerdoes), and the test has that pair. The PR is #543.@lordon1a on GitHub · 2026-11-24 03:57 UTC · original
Comparison of the three open PRs for #324 (#491, #543, #621), to help pick one.
Each one merges cleanly into
mainf4ce27cand touches onlygamesave.rs. I read the diffs before running them and found nothing outside the save folder and the test temp folders. On the merge withmain,cargo test -p xcl --lib -- --test-threads=4gives #491 661 passed, #543 661 passed and #621 662 passed, all with 0 failed.The PRs' own tests only cover a failure while staging, so I added two tests that call
applydirectly. I ran them on each merge and onmain:PR descriptioncheckmainmain, which runs the ops in order. A failure while placing also keeps the files placed before it, so the update is still half applied whenever the failure comes after staging. Its test injects the failure through a global#[cfg(test)]counter (FAIL_STAGE_AFTER), so it never reaches that path.Meta/METAare one file on NTFS). It moves the replaced and deleted files aside, places the temps, and restores everything on failure. Both added tests pass.One point for both #543 and #621: they move the old file aside and then move the new one in.
mainreplaced each blob in a singleMoveFileExW(MOVEFILE_REPLACE_EXISTING). Between those two moves, the blob exists only as a~xcltmp.*file, whichblobs_ofskips and nothing recovers. A crash or power loss at that moment now loses a blob thatmainwould have kept, old or new. Wrapping that window inReplaceFileW(dest, tmp, backup)would narrow it, as would recovering leftover backups when a container is opened. That could be a follow-up rather than a reason to hold the fix.Suggestion: merge #543, which passes the checks and is correct on both added tests, and close #491 (wrong op order) and #621 as duplicates. #621's in-order approach is the simpler model if the maintainer prefers it, but it needs a regression run first.
Tested on an i7-12700H with an RTX 3070 Ti Laptop, Windows 11 build 26200. Toolchain: rustc 1.100.0
x86_64-pc-windows-gnullvm, debug,--libtests only. Not tested: the MSVC toolchain,cargo test --workspace, smoke runs, a real disk-full or locked-file failure.Written with Claude Code (Claude Opus 5.5). I checked each point against the diffs and the runs above.
@pickles976 on GitHub · 2026-11-24 05:01 UTC · original
Empirical adjudication of the two PRs on this issue (2026-11-24; Linux cross-build + Wine, recipe #520). Shared battery, appended as a unit test to each head — the issue's own scenario: container with blob
aand display, one update writinga+ a second blob whose path is too long (the "long escaped blob name" from the issue text):aunchanged?main"New""new""New""Old"oldapply()signature differs, battery doesn't compile#491's staging is real (the display write is staged) — but the failure this issue describes lands where staging can't see it: with a destination whose final path is over-long, the stage can succeed and the rename into place fails after earlier renames already committed, leaving exactly the half-applied state the issue is about; #543's move-aside-then-rollback survives the same sequence. (Suggest #491 validate/rollback the commit phase, or close as superseded.)
Recommendation: #543
ready_for_reviewand merge — it passes the issue's own repro, its description check is already green, and its crash-leftovers cleanup (blobs_ofskipping temps) is a useful extra. #491's injection-test idea (test-only failure counter) is worth cherry-picking into it — nice pattern.Harness:
cargo test -p xcl --lib --target x86_64-pc-windows-gnu zz324revunder Wine 9, per #520; logs kept if useful.