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

Manually merged
github merged 1 commit from gh-pr/992/head into gh-pr/992/base 2026-11-26 09:32:17 +00:00
Owner

@⁠Snooozs on GitHub · 2026-11-24 16:33 UTC · original
Snooozs:gamesave-commit-rollback → main · +185 −13 · 2 files · 1 commits · merged 2026-11-24 22:31 UTC

Claimed in the coordination issue as: RT-GAMESAVE-COMMIT-ROLLBACK (#14)

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

**@⁠Snooozs** on GitHub · 2026-11-24 16:33 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/992) `Snooozs:gamesave-commit-rollback` → `main` · +185 −13 · 2 files · 1 commits · merged 2026-11-24 22:31 UTC Claimed in the coordination issue as: RT-GAMESAVE-COMMIT-ROLLBACK (https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14) 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)
commit() replaced blobs one rename at a time. When a later rename failed (the blob held open by another
process without FILE_SHARE_DELETE), the earlier renames stayed, the update returned
E_GS_OUT_OF_LOCAL_STORAGE and the container was left half new, with "<blob>~" temporaries behind.

Each op now copies its blob to "<blob>~b~" before it changes the blob. A failed op undoes the applied ones,
newest first. Deletes are applied in the same ordered pass, so a failed write also undoes a delete. The
scratch names end in '~', which encode_name never produces and decode_name rejects, so enumeration and the
quota never see them. A backup whose restore failed is kept, and later commits only remove backups they
wrote themselves. A commit drops the temporaries of one that died midway. A blob never leaves its name, so a
process that dies midway leaves each blob old or new, as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:32:15 +00:00
github manually merged commit 34e6b29682 into gh-pr/992/base 2026-11-26 09:32:17 +00:00
Author
Owner

@⁠moffington on GitHub · 2026-11-24 17:45 UTC · original

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.

**@⁠moffington** on GitHub · 2026-11-24 17:45 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/992#issuecomment-7139653827) 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.
Author
Owner

@⁠Snooozs on GitHub · 2026-11-24 18:00 UTC · original

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.

**@⁠Snooozs** on GitHub · 2026-11-24 18:00 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/992#issuecomment-7140020467) 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.
Author
Owner

@⁠QemmHD on GitHub · 2026-11-24 22:31 UTC · original

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).

**@⁠QemmHD** on GitHub · 2026-11-24 22:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/992#issuecomment-7146329618) 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).
Author
Owner

@⁠Snooozs on GitHub · 2026-11-25 12:23 UTC · original

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

**@⁠Snooozs** on GitHub · 2026-11-25 12:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/992#issuecomment-7162313924) My Discord username is `snoozs_` (for the developer role request).
This discussion has been locked. Commenting is limited to contributors.
No description provided.