xgameruntime_gamesave: undo a partly applied update instead of leaving it (RT-GAMESAVE-COMMIT-ROLLBACK) #992

Merged
Snooozs merged 1 commit from upstream-pr/992 into main 2026-11-24 22:31:23 +00:00
Snooozs commented 2026-11-24 16:33:23 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Snooozs on 2026-11-24T16:33:23Z.


Claimed in the coordination issue as: RT-GAMESAVE-COMMIT-ROLLBACK (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7137704829)

Depends on: none. #147 changes the quota loop of the same function; whichever lands second may need a small rebase.

What and why

commit() in runtime/shims/xgameruntime_gamesave.cpp replaced blobs one rename at a time. If a later rename failed (another process, such as a backup or antivirus tool, holds the blob open without FILE_SHARE_DELETE), XGameSaveSubmitUpdate returned E_GS_OUT_OF_LOCAL_STORAGE, but the earlier blobs were already new and a ~ file stayed. The container then held blobs of two different updates, against the file's own "a failed write leaves the container as it was".

  • Each op copies its blob to <blob>~b~ before changing it; a failed op undoes the applied ones, newest first, and the same error is returned.
  • Deletes run in the same ordered pass, so a failed write also undoes a delete. A delete that cannot be done now fails the update instead of being ignored.
  • Scratch names end in ~, which encode_name never produces and decode_name rejects, so enumeration and the quota do not see them.
  • A backup whose restore failed is kept, and later commits remove only backups they wrote. Temporaries of a commit that died midway are dropped.

Not covered: there is no journal. A process that dies midway leaves each blob old or new, as before. The path where the undo itself fails has no test. Names that differ only in case are unchanged.

Tested

Windows 10 Pro 22H2 (19045), VS 2022 RelWithDebInfo, ctest -R gamesave: xgameruntime_gamesave_test: 76 checks, 0 failures. The new test with main's shim: 76 checks, 5 failures. tests/test_saves.py (70 OK, 3 skipped) and tests/test_saves_import_args.py pass. check_no_game_data.py on both files: clean. Synthetic saves only.

GPUs tested: n/a

AI-assisted: yes. Claude Code (a Haiku 5.5 subagent found the bug and wrote the change, Claude Opus 5.5 reviewed and corrected it and reran the tests).

Checklist

  • Based on current main and merges cleanly (a conflicting pull request is labeled needs rebase).
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: no translator rule)

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5476253581 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/992). Originally posted by [Snooozs](https://github.com/Snooozs) on 2026-11-24T16:33:23Z. --- Claimed in the coordination issue as: RT-GAMESAVE-COMMIT-ROLLBACK (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7137704829) Depends on: none. #147 changes the quota loop of the same function; whichever lands second may need a small rebase. ### What and why `commit()` in `runtime/shims/xgameruntime_gamesave.cpp` replaced blobs one rename at a time. If a later rename failed (another process, such as a backup or antivirus tool, holds the blob open without `FILE_SHARE_DELETE`), `XGameSaveSubmitUpdate` returned `E_GS_OUT_OF_LOCAL_STORAGE`, but the earlier blobs were already new and a `~` file stayed. The container then held blobs of two different updates, against the file's own "a failed write leaves the container as it was". - Each op copies its blob to `<blob>~b~` before changing it; a failed op undoes the applied ones, newest first, and the same error is returned. - Deletes run in the same ordered pass, so a failed write also undoes a delete. A delete that cannot be done now fails the update instead of being ignored. - Scratch names end in `~`, which `encode_name` never produces and `decode_name` rejects, so enumeration and the quota do not see them. - A backup whose restore failed is kept, and later commits remove only backups they wrote. Temporaries of a commit that died midway are dropped. Not covered: there is no journal. A process that dies midway leaves each blob old or new, as before. The path where the undo itself fails has no test. Names that differ only in case are unchanged. ### Tested Windows 10 Pro 22H2 (19045), VS 2022 RelWithDebInfo, `ctest -R gamesave`: `xgameruntime_gamesave_test: 76 checks, 0 failures`. The new test with `main`'s shim: 76 checks, 5 failures. `tests/test_saves.py` (70 OK, 3 skipped) and `tests/test_saves_import_args.py` pass. `check_no_game_data.py` on both files: clean. Synthetic saves only. GPUs tested: n/a AI-assisted: yes. Claude Code (a Haiku 5.5 subagent found the bug and wrote the change, Claude Opus 5.5 reviewed and corrected it and reran the tests). ### Checklist - [x] Based on current `main` and merges cleanly (a conflicting pull request is labeled `needs rebase`). - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (n/a: no translator rule) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
moffington commented 2026-11-24 17:45:12 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by moffington on 2026-11-24T17:45:12Z.


Reviewed 34e6b2968 under Wine 11.20.

The game-save tests passed all 76 checks, compared with 56 on base. Running the updated tests against the base implementation produced five expected failures.

I also ran additional fault-injection tests covering mixed writes/deletes, blocked file operations, rollback failures, stale temporary/backup files, and post-rollback quota and enumeration behavior:

  • Base: 40 checks, 10 failures.
  • PR: 47 checks, 0 failures.

Verified that Wine enforces the file-sharing restrictions used to trigger these failures. The rollback path correctly retains backups when restoration fails and continues rolling back earlier operations.

No actionable defects found within the PR's scope. The quota changes in #147 appear complementary.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7139653827 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/992#issuecomment-7139653827). Originally posted by [moffington](https://github.com/moffington) on 2026-11-24T17:45:12Z. --- Reviewed `34e6b2968` under Wine 11.20. The game-save tests passed all 76 checks, compared with 56 on base. Running the updated tests against the base implementation produced five expected failures. I also ran additional fault-injection tests covering mixed writes/deletes, blocked file operations, rollback failures, stale temporary/backup files, and post-rollback quota and enumeration behavior: - Base: 40 checks, 10 failures. - PR: 47 checks, 0 failures. Verified that Wine enforces the file-sharing restrictions used to trigger these failures. The rollback path correctly retains backups when restoration fails and continues rolling back earlier operations. No actionable defects found within the PR's scope. The quota changes in #147 appear complementary.
Snooozs commented 2026-11-24 18:00:25 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Snooozs on 2026-11-24T18:00:25Z.


Thanks @moffington, the rollback-failure and stale-backup injections are exactly the path I listed as untested in the description, so it is good to have them covered independently, and on Wine as well.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7140020467 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/992#issuecomment-7140020467). Originally posted by [Snooozs](https://github.com/Snooozs) on 2026-11-24T18:00:25Z. --- Thanks @moffington, the rollback-failure and stale-backup injections are exactly the path I listed as untested in the description, so it is good to have them covered independently, and on Wine as well.
QemmHD commented 2026-11-24 22:31:21 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by QemmHD on 2026-11-24T22:31:21Z.


Merging.

Why merged: RT-GAMESAVE-COMMIT-ROLLBACK: a game-save commit() backs up each blob to "b" and, if a step fails, undoes the applied steps newest-first, so a failed save can't leave a half-written container. At startup it removes the stray "~" temporaries a commit that died midway left behind, only inside the container directory and leaving backups alone. moffington ran it under Wine: 76 checks pass, versus 5 expected failures with the new tests against the old code.

Why it's good: xgameruntime_gamesave passes both plain and under validation.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 4a50cafc7, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative of this batch (13 PRs) on main 540d5111f: the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 316/317 with the usual 11 skips; the only failure is main's pre-existing d3d12_depth_resolve. All d3d12_* tests under validation: 119/120 with 0 VUIDs. The full semantic suite has the same single environment-only failure as main. git merge-tree against current main 51a6074d2: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7146329618 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/992#issuecomment-7146329618). Originally posted by [QemmHD](https://github.com/QemmHD) on 2026-11-24T22:31:21Z. --- Merging. **Why merged:** RT-GAMESAVE-COMMIT-ROLLBACK: a game-save commit() backs up each blob to "<blob>~b~" and, if a step fails, undoes the applied steps newest-first, so a failed save can't leave a half-written container. At startup it removes the stray "~" temporaries a commit that died midway left behind, only inside the container directory and leaving backups alone. moffington ran it under Wine: 76 checks pass, versus 5 expected failures with the new tests against the old code. **Why it's good:** xgameruntime_gamesave passes both plain and under validation. Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 4a50cafc7, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative of this batch (13 PRs) on main 540d5111f: the repo-consistency set gives 573 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 316/317 with the usual 11 skips; the only failure is main's pre-existing d3d12_depth_resolve. All d3d12_* tests under validation: 119/120 with 0 VUIDs. The full semantic suite has the same single environment-only failure as main. git merge-tree against current main 51a6074d2: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes. AI-assisted (Claude Code, Claude Opus 5.5).
Snooozs commented 2026-11-25 12:23:42 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Snooozs on 2026-11-25T12:23:42Z.


My Discord username is snoozs_ (for the developer role request).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7162313924 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/992#issuecomment-7162313924). Originally posted by [Snooozs](https://github.com/Snooozs) on 2026-11-25T12:23:42Z. --- My Discord username is `snoozs_` (for the developer role request).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
ProjectLeonida/mandy!992
No description provided.