Recover interrupted offline save updates before readback #2003

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

@⁠lgr123 on GitHub · 2026-11-25 17:55 UTC · original
lgr123:lgr123/gamesave-interrupted-update-recovery → main · +434 −104 · 4 files · 1 commits · open

Claimed as RT-GAMESAVE-INTERRUPTED-UPDATE-RECOVERY.

A native synthetic checkpoint had two blobs at generation 1. I ended the save process after the first successful file replacement in public main. A new process reopened it via the save API and returned inventory at generation 2 with player state at generation 1. The uninterrupted control returned 2/2. The earlier rollback for an error returned by the current process remains covered.

Stage new bytes and undo data before touching live files. A same-volume journal records which operations need rollback. If an update is interrupted, restore the complete previous generation before the normal read, enumeration, quota, or next write proceeds. A completed commit retains its new generation. Recovery can be interrupted and retried. It keeps the existing container and blob paths, display metadata, and legacy backup files.

This addresses process interruption in one runtime on the same volume. It does not establish power-loss durability or synchronize multiple runtime processes and an external importer.

Reviewer check

Build the Windows xgameruntime_gamesave_test target and run it with no arguments. The test spawns synthetic child processes and uses disposable save folders. No game files or existing saves are needed.

Tested

  • Native Windows x64, MSVC, public main b9320a1 plus this patch. 156 of 156 checks passed. Coverage includes seven interruption points, interruption during rollback, first-save cleanup, blocked recovery, metadata and quota, legacy backups, and synchronous and asynchronous reads.
  • Compiled the production shim separately with test failure hooks disabled.
  • Source-only check and git diff --check passed. A local merge-tree check with #1952 found no conflict.

GPUs tested: n/a.

AI-assisted: yes.

Checklist

  • Based on public main.
  • One topic.
  • No game data, keys or protection workarounds.
**@⁠lgr123** on GitHub · 2026-11-25 17:55 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2003) `lgr123:lgr123/gamesave-interrupted-update-recovery` → `main` · +434 −104 · 4 files · 1 commits · open Claimed as [RT-GAMESAVE-INTERRUPTED-UPDATE-RECOVERY](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/1608). A native synthetic checkpoint had two blobs at generation 1. I ended the save process after the first successful file replacement in public main. A new process reopened it via the save API and returned inventory at generation **2** with player state at generation **1**. The uninterrupted control returned **2/2**. The earlier rollback for an error returned by the current process remains covered. Stage new bytes and undo data before touching live files. A same-volume journal records which operations need rollback. If an update is interrupted, restore the complete previous generation before the normal read, enumeration, quota, or next write proceeds. A completed commit retains its new generation. Recovery can be interrupted and retried. It keeps the existing container and blob paths, display metadata, and legacy backup files. This addresses process interruption in one runtime on the same volume. It does not establish power-loss durability or synchronize multiple runtime processes and an external importer. ### Reviewer check Build the Windows `xgameruntime_gamesave_test` target and run it with no arguments. The test spawns synthetic child processes and uses disposable save folders. No game files or existing saves are needed. ### Tested - Native Windows x64, MSVC, public main `b9320a1` plus this patch. **156 of 156 checks passed**. Coverage includes seven interruption points, interruption during rollback, first-save cleanup, blocked recovery, metadata and quota, legacy backups, and synchronous and asynchronous reads. - Compiled the production shim separately with test failure hooks disabled. - Source-only check and `git diff --check` passed. A local merge-tree check with #1952 found no conflict. GPUs tested: n/a. AI-assisted: yes. ### Checklist - [x] Based on public main. - [x] One topic. - [x] No game data, keys or protection workarounds.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:14:27 +00:00
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-26 13:04 UTC · original · approved these changes

Reviewed by Claude Code (AI-assisted) on my behalf. I read the commit and recovery paths step by step and found no
hole for a process kill. Approving.

  • Undo works from the journal alone: a write is applied when its w<i> file has been consumed, a delete when its
    b<i> exists. A restore goes through restore and keeps b<i>, so recovery can itself be interrupted and rerun.
  • The update commits when active is renamed to retired. A crash after that leaves nothing to undo. A crash after
    every op but before the retire is rolled back as a whole, and the title never saw S_OK for it, so that is correct.
  • The test kills a child process at each of the seven checkpoints, which is the right way to test this.

Non-blocking, possibly for a follow-up:

  1. Power loss: the staged blobs and prepare are never flushed (FlushFileBuffers) before the publishing rename.
    NTFS journals the rename but not the file data, so after a power cut a published blob can come back zero-filled.
    The header says power loss is out of scope; flushing the staged files and the manifest before the rename would
    close it for little cost.
  2. delete_container is still a plain remove_all, so a kill in the middle leaves a container with only some of its
    blobs. Renaming the container folder to a hidden name first, then removing it, makes the delete all-or-nothing as
    well.
  3. The branch is 417 commits behind main. It merges cleanly, but CI ran on the old base.

Not built or run here: the shim and its test are Windows-only, so this review is from reading the code.


Generated by Claude Code

**@⁠kawaii-shakal** on GitHub · 2026-11-26 13:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/2003#pullrequestreview-6074605316) · **approved these changes** Reviewed by Claude Code (AI-assisted) on my behalf. I read the commit and recovery paths step by step and found no hole for a process kill. Approving. - Undo works from the journal alone: a write is applied when its `w<i>` file has been consumed, a delete when its `b<i>` exists. A restore goes through `restore` and keeps `b<i>`, so recovery can itself be interrupted and rerun. - The update commits when `active` is renamed to `retired`. A crash after that leaves nothing to undo. A crash after every op but before the retire is rolled back as a whole, and the title never saw S_OK for it, so that is correct. - The test kills a child process at each of the seven checkpoints, which is the right way to test this. Non-blocking, possibly for a follow-up: 1. Power loss: the staged blobs and `prepare` are never flushed (`FlushFileBuffers`) before the publishing rename. NTFS journals the rename but not the file data, so after a power cut a published blob can come back zero-filled. The header says power loss is out of scope; flushing the staged files and the manifest before the rename would close it for little cost. 2. `delete_container` is still a plain `remove_all`, so a kill in the middle leaves a container with only some of its blobs. Renaming the container folder to a hidden name first, then removing it, makes the delete all-or-nothing as well. 3. The branch is 417 commits behind main. It merges cleanly, but CI ran on the old base. Not built or run here: the shim and its test are Windows-only, so this review is from reading the code. --- _Generated by [Claude Code](https://claude.ai/code)_
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/2003/head:github-bot/gh-2003'
git switch 'github-bot/gh-2003'

Merge

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