reprend #2003: Recover interrupted offline save updates before readback #2740

Closed
OreoFR wants to merge 3 commits from upstream-pr/2740 into main
OreoFR commented 2026-11-30 13:40:02 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T13:40:02Z.


Carries #2003 by @lgr123, because it conflicts with main after #2566 and the reminder to merge main (https://github.com/ProjectLeonida/mandy/pull/2003#issuecomment-7232661059) got no answer within the delay of the carry rule. If the author comes back, this carry is dropped.

Item: RT-GAMESAVE-INTERRUPTED-UPDATE-RECOVERY-CARRY (claimed in https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7280119323; original item RT-GAMESAVE-INTERRUPTED-UPDATE-RECOVERY).

What this branch is

  • The author's branch at d64641bcf, unchanged (no rebase, author commits kept).
  • A merge of main (from the carry preparation of 29/11) that resolves the conflict, then a merge of current main f9f3ec4c6 (no new conflict). Both merge commits carry Co-authored-by the author.
  • Nothing else: the change itself is the original PR's; see #2003 for what and why, and the verifications posted there.

What conflicted and how it was resolved

  • runtime/shims/xgameruntime_gamesave.cpp (3 hunks): the PR's journal functions with main's copy_blob through CopyFileW (Wine); recover_update() before main's prefix enumeration; ByName goes through main's traced path.
  • runtime/test/xgameruntime_gamesave_test.cpp (2 hunks): both test entry points and both sets of helpers kept.

The save mechanism is rewritten (journal + recovery) and merged with main's Wine copy path: please read it. gta6rt gains 2 msvcp imports (ios_base::bad, ios_base::eof) from the journal's std::ifstream.

Tests

  • On this branch (main f9f3ec4c6 merged), Windows 11, Python 3.12, no GPU used: C++ only: left to this PR's CI (no local C++ build in this run).
  • Earlier merge: ctest 501 tests, xgameruntime_gamesave passes; red: link fails on main (xgameruntime_gamesave_test_interrupt_after absent); big_compile_gate timed out on the loaded PC, to check on the runners.
  • python -I scripts/check_no_game_data.py on every file this PR changes: clean.
  • CI on this PR covers the rest (C++ build and ctest, the full translator suite).

Depends on: none.

Needs a careful human read of the resolution and an independent verifier before merge (red/green on another machine).

AI-assisted (Claude Code, oreofr-agent).

🤖 Generated with Claude Code

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5566400750 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2740). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T13:40:02Z. --- Carries #2003 by @lgr123, because it conflicts with `main` after #2566 and the reminder to merge `main` (https://github.com/ProjectLeonida/mandy/pull/2003#issuecomment-7232661059) got no answer within the delay of the carry rule. If the author comes back, this carry is dropped. Item: `RT-GAMESAVE-INTERRUPTED-UPDATE-RECOVERY-CARRY` (claimed in https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7280119323; original item `RT-GAMESAVE-INTERRUPTED-UPDATE-RECOVERY`). ### What this branch is - The author's branch at `d64641bcf`, unchanged (no rebase, author commits kept). - A merge of `main` (from the carry preparation of 29/11) that resolves the conflict, then a merge of current `main` `f9f3ec4c6` (no new conflict). Both merge commits carry `Co-authored-by` the author. - Nothing else: the change itself is the original PR's; see #2003 for what and why, and the verifications posted there. ### What conflicted and how it was resolved - `runtime/shims/xgameruntime_gamesave.cpp` (3 hunks): the PR's journal functions with `main`'s `copy_blob` through `CopyFileW` (Wine); `recover_update()` before `main`'s prefix enumeration; `ByName` goes through `main`'s traced path. - `runtime/test/xgameruntime_gamesave_test.cpp` (2 hunks): both test entry points and both sets of helpers kept. **The save mechanism is rewritten** (journal + recovery) and merged with `main`'s Wine copy path: please read it. `gta6rt` gains 2 msvcp imports (`ios_base::bad`, `ios_base::eof`) from the journal's `std::ifstream`. ### Tests - On this branch (`main` `f9f3ec4c6` merged), Windows 11, Python 3.12, no GPU used: C++ only: left to this PR's CI (no local C++ build in this run). - Earlier merge: `ctest` 501 tests, `xgameruntime_gamesave` passes; red: link fails on `main` (`xgameruntime_gamesave_test_interrupt_after` absent); `big_compile_gate` timed out on the loaded PC, to check on the runners. - `python -I scripts/check_no_game_data.py` on every file this PR changes: clean. - CI on this PR covers the rest (C++ build and `ctest`, the full translator suite). Depends on: none. **Needs a careful human read of the resolution and an independent verifier before merge** (red/green on another machine). AI-assisted (Claude Code, oreofr-agent). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
merzleckeier commented 2026-11-30 13:53:11 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by merzleckeier on 2026-11-30T13:53:11Z.


Independent interrupted-save red/green on Wine. I merged 38b0b9c1 onto main 20fe0c75 (tree 898b1a41). Its runtime/ tree matches GitHub’s merge 155107e3. CachyOS x86-64, Wine 11.22, clang-cl/xwin x64 Release. Synthetic offline saves only.

MEASURED. The unmodified xgameruntime_gamesave_test passed 176/176 checks, including all seven update checkpoints, interruption during recovery, blocked recovery and retry, sync/async reads, prefix enumeration, metadata, and quota.

For the A/B, I ran the same public-API driver against both builds. The main control only adds the test-only exit hook after the first successful replacement. The PR arm uses its existing checkpoint 3, after two staging/publication checkpoints. The writer was a child process. After it exited with code 83, the controller verified that the old and new files were mixed on disk and then opened a fresh provider.

Revision Bytes on disk before reopen Public ReadBlobData after reopen
main new A / old B in 3/3 new A / old B in 3/3
PR + main new A / old B in 3/3 old A / old B in 3/3

All three PR runs removed the journal after recovery. A second agent checked the raw logs and final file bytes. This exercises controlled process exit and same-volume recovery under Wine. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7280512718 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2740#issuecomment-7280512718). Originally posted by [merzleckeier](https://github.com/merzleckeier) on 2026-11-30T13:53:11Z. --- **Independent interrupted-save red/green on Wine.** I merged `38b0b9c1` onto `main` `20fe0c75` (tree `898b1a41`). Its `runtime/` tree matches GitHub’s merge `155107e3`. CachyOS x86-64, Wine 11.22, clang-cl/xwin x64 Release. Synthetic offline saves only. **MEASURED.** The unmodified `xgameruntime_gamesave_test` passed **176/176 checks**, including all seven update checkpoints, interruption during recovery, blocked recovery and retry, sync/async reads, prefix enumeration, metadata, and quota. For the A/B, I ran the same public-API driver against both builds. The `main` control only adds the test-only exit hook after the first successful replacement. The PR arm uses its existing checkpoint 3, after two staging/publication checkpoints. The writer was a child process. After it exited with code 83, the controller verified that the old and new files were mixed on disk and then opened a fresh provider. | Revision | Bytes on disk before reopen | Public `ReadBlobData` after reopen | | --- | --- | --- | | `main` | new A / old B in 3/3 | new A / old B in 3/3 | | PR + `main` | new A / old B in 3/3 | old A / old B in 3/3 | All three PR runs removed the journal after recovery. A second agent checked the raw logs and final file bytes. This exercises controlled process exit and same-volume recovery under Wine. AI-assisted.
Kal0s-design commented 2026-11-30 14:25:50 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Kal0s-design on 2026-11-30T14:25:50Z.


Native Windows (NTFS) check of 38b0b9c12 merged onto current main b17b22d33 (no conflict, tree a0ae8f3d3). It complements merzleckeier's Wine run, since the journal and recovery depend on how the real file system renames and copies. Windows 11, MSVC 19.50 x64. xgameruntime_gamesave_test was built from the CMake target's own source list, with /W4 /permissive- /utf-8 /DLEONIDA_GAMESAVE_TEST plus the vendored xtaskqueue, under AddressSanitizer with the debug CRT (/Od /MDd /fsanitize=address). Synthetic saves in a temp folder only.

  • Merged tree: xgameruntime_gamesave_test: 172 checks, 0 failures, exit 0, no ASan report. That includes the update checkpoints and recovery, the async read path, enumeration/metadata on the same generation, and quota excluding the journal scratch, with every handle closed at the end. (merzleckeier's 176 were on an older main.)
  • main's runtime + this test: link fails, LNK2019 on rt::shims::xgameruntime_gamesave_test_interrupt_after, as the description says, so there's no red run.
  • Warnings: 5, the same count on main's build of the same sources: 4 C4996 getenv in test/test_temp_dir.h and 1 C4996 (STL4021) for std::filesystem::u8path.

I didn't read the conflict resolution in xgameruntime_gamesave.cpp line by line. That still needs a human read, as the description asks.

GPUs tested: n/a (CPU/file-system test). AI-assisted: yes.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7281360576 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2740#issuecomment-7281360576). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-11-30T14:25:50Z. --- **Native Windows (NTFS) check** of `38b0b9c12` merged onto current `main` `b17b22d33` (no conflict, tree `a0ae8f3d3`). It complements merzleckeier's Wine run, since the journal and recovery depend on how the real file system renames and copies. Windows 11, MSVC 19.50 x64. `xgameruntime_gamesave_test` was built from the CMake target's own source list, with `/W4 /permissive- /utf-8 /DLEONIDA_GAMESAVE_TEST` plus the vendored `xtaskqueue`, under AddressSanitizer with the debug CRT (`/Od /MDd /fsanitize=address`). Synthetic saves in a temp folder only. - Merged tree: `xgameruntime_gamesave_test: 172 checks, 0 failures`, exit 0, no ASan report. That includes the update checkpoints and recovery, the async read path, enumeration/metadata on the same generation, and quota excluding the journal scratch, with every handle closed at the end. (merzleckeier's 176 were on an older `main`.) - `main`'s runtime + this test: link fails, `LNK2019` on `rt::shims::xgameruntime_gamesave_test_interrupt_after`, as the description says, so there's no red run. - Warnings: 5, the same count on `main`'s build of the same sources: 4 C4996 `getenv` in `test/test_temp_dir.h` and 1 C4996 (STL4021) for `std::filesystem::u8path`. I didn't read the conflict resolution in `xgameruntime_gamesave.cpp` line by line. That still needs a human read, as the description asks. GPUs tested: n/a (CPU/file-system test). AI-assisted: yes.
KelboLive commented 2026-11-30 15:31:39 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-11-30T15:31:39Z.


Independent check on Windows (not the author), at 38b0b9c12.

  • Configured the branch's runtime and built xgameruntime_gamesave_test (MSVC 14.52.37025, Windows SDK 10.0.26100).
  • Ran it: 176 checks, 0 failures — exit 0. That includes the interruption/recovery checkpoints (staging, publication, replace, delete, create, .display, retirement) and the quota/scratch assertions at the end.

Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711.

No regressions seen. Based on f9f3ec4c6; a rebase on current main before merge would keep history linear.

AI-assisted: yes (opencode).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7283142939 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2740#issuecomment-7283142939). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-11-30T15:31:39Z. --- Independent check on Windows (not the author), at `38b0b9c12`. - Configured the branch's `runtime` and built `xgameruntime_gamesave_test` (MSVC 14.52.37025, Windows SDK 10.0.26100). - Ran it: **176 checks, 0 failures** — exit 0. That includes the interruption/recovery checkpoints (staging, publication, replace, delete, create, `.display`, retirement) and the quota/scratch assertions at the end. Environment: Ryzen 9 7950X3D, Windows 11 Pro 10.0.26200.9711. No regressions seen. Based on `f9f3ec4c6`; a rebase on current `main` before merge would keep history linear. AI-assisted: yes (opencode).
OreoFR commented 2026-11-30 15:36:56 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by OreoFR on 2026-11-30T15:36:56Z.


Code read of the save rewrite at head 38b0b9c12 (journal + recovery in runtime/shims/xgameruntime_gamesave.cpp, merged with main's CopyFileW path). OreoFR asked me to read it in his place, so this is an agent read on his behalf, not a human read. Nothing was run for this comment: CI on this head is green.

Commit protocol, checked step by step:

  • Staging writes w<i> (new data) and, for a write over an existing blob, b<i> (a copy of the old one) inside .save-update~, before anything live changes. A failure at this stage removes the journal. Recovery treats a journal without active as unpublished and deletes it.
  • prepare → active (MoveFileExW, write-through) publishes the manifest, and only then does create_directories(dir) and the live renames run.
  • The apply step consumes the markers: a write moves w<i> over the blob, a delete moves the blob to b<i>. Undo reads the same markers: a write whose w<i> is gone was applied, a delete whose b<i> exists was applied. So recovery never touches a blob the update did not change.
  • Undo restores through restore and a rename, so b<i> survives a crash during recovery. Restoring again gives the same result, so a second interrupted recovery is safe. A container the update created is removed (non-recursive fs::remove, so only when it is empty).
  • read_manifest validates the version, the encoded names (through decode_name + valid_*_name, embedded NUL rejected) and the end line before any undo.
  • .display is now part of the atomic set. Before this change it was written after the commit and its failure was ignored.
  • The journal name starts with . and ends with ~, so decode_name rejects it: list_containers, the quota and enumeration never see it.
  • Every caller of recover_update holds g_mutex. open_provider now takes the lock before create_directories, and read_blobs is reached from locked paths (lines 785/789 and 1172/1175).
  • The interruption test runs a child process that stops at each of the 7 checkpoints, covers a second interruption during recovery, and covers a blob held without FILE_SHARE_DELETE.

Not blocking, worth knowing:

  1. If recovery cannot finish (a restore target stays locked), every read, enumeration and quota call returns E_GS_OUT_OF_LOCAL_STORAGE until it succeeds. This is fail-loud by design and test_locked_recovery covers it, but on a real lock the title sees its save as unreadable rather than stale.
  2. If remove_all of a retired or unpublished journal fails (a file in it still open), the next commit refuses with E_GS_OUT_OF_LOCAL_STORAGE at create_directory(journal) until the cleanup works.
  3. Old-format backups <blob>~b~ left by the previous code are no longer removed by a later successful update. The old code removed them; this one keeps them on purpose. They are never counted or listed, but they stay on disk.
  4. The guarantee is per process and per volume, with no power-loss durability, as docs/saves.md and the code comment state.

I did not find a defect that loses or mixes save data in these paths. Not covered: a run of the title saving through this code, and the ByName traced path the conflict resolution routes through, which I did not reread. The independent red/green on another machine is still needed.

AI-assisted (Claude Code, oreofr-agent).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7283284959 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2740#issuecomment-7283284959). Originally posted by [OreoFR](https://github.com/OreoFR) on 2026-11-30T15:36:56Z. --- **Code read of the save rewrite** at head `38b0b9c12` (journal + recovery in `runtime/shims/xgameruntime_gamesave.cpp`, merged with `main`'s `CopyFileW` path). OreoFR asked me to read it in his place, so this is an agent read on his behalf, not a human read. Nothing was run for this comment: CI on this head is green. **Commit protocol, checked step by step:** - Staging writes `w<i>` (new data) and, for a write over an existing blob, `b<i>` (a copy of the old one) inside `.save-update~`, before anything live changes. A failure at this stage removes the journal. Recovery treats a journal without `active` as unpublished and deletes it. - `prepare` → `active` (`MoveFileExW`, write-through) publishes the manifest, and only then does `create_directories(dir)` and the live renames run. - The apply step consumes the markers: a write moves `w<i>` over the blob, a delete moves the blob to `b<i>`. Undo reads the same markers: a write whose `w<i>` is gone was applied, a delete whose `b<i>` exists was applied. So recovery never touches a blob the update did not change. - Undo restores through `restore` and a rename, so `b<i>` survives a crash during recovery. Restoring again gives the same result, so a second interrupted recovery is safe. A container the update created is removed (non-recursive `fs::remove`, so only when it is empty). - `read_manifest` validates the version, the encoded names (through `decode_name` + `valid_*_name`, embedded NUL rejected) and the `end` line before any undo. - `.display` is now part of the atomic set. Before this change it was written after the commit and its failure was ignored. - The journal name starts with `.` and ends with `~`, so `decode_name` rejects it: `list_containers`, the quota and enumeration never see it. - Every caller of `recover_update` holds `g_mutex`. `open_provider` now takes the lock before `create_directories`, and `read_blobs` is reached from locked paths (lines 785/789 and 1172/1175). - The interruption test runs a child process that stops at each of the 7 checkpoints, covers a second interruption during recovery, and covers a blob held without `FILE_SHARE_DELETE`. **Not blocking, worth knowing:** 1. If recovery cannot finish (a restore target stays locked), every read, enumeration and quota call returns `E_GS_OUT_OF_LOCAL_STORAGE` until it succeeds. This is fail-loud by design and `test_locked_recovery` covers it, but on a real lock the title sees its save as unreadable rather than stale. 2. If `remove_all` of a retired or unpublished journal fails (a file in it still open), the next `commit` refuses with `E_GS_OUT_OF_LOCAL_STORAGE` at `create_directory(journal)` until the cleanup works. 3. Old-format backups `<blob>~b~` left by the previous code are no longer removed by a later successful update. The old code removed them; this one keeps them on purpose. They are never counted or listed, but they stay on disk. 4. The guarantee is per process and per volume, with no power-loss durability, as `docs/saves.md` and the code comment state. I did not find a defect that loses or mixes save data in these paths. Not covered: a run of the title saving through this code, and the `ByName` traced path the conflict resolution routes through, which I did not reread. The independent red/green on another machine is still needed. AI-assisted (Claude Code, oreofr-agent).
KelboLive commented 2026-12-01 16:10:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by KelboLive on 2026-12-01T16:10:45Z.

Review: COMMENTED


Approving for the stated process-interruption scope. The sequence is sound: staged w<i> blobs and write backups are complete before prepare is renamed to active, live blobs change only by same-volume MoveFileExW, deletes publish b<i> atomically, and the marker-presence undo with restore+rename is idempotent — so a second interruption during recovery cannot expose a half-written blob or manifest. A truncated or malformed active is rejected before any undo, which is the right fail-closed choice. I rebuilt with MSVC 19.52 and ctest -R xgameruntime_gamesave passes 176/176, and disabling the write-marker undo fails checkpoint 3 with 29 failures, so the interruption test really covers the recovery path.

Two documentation corrections, both worth doing before merge because they are about what the feature promises:

  1. It is not power-loss safe. There is no FlushFileBuffers and no checksum, and MOVEFILE_WRITE_THROUGH covers the rename, not the staged data. docs/saves.md's new paragraph says only "process interruption / same volume", while the code comment says "does not provide power-loss durability" — the PR body claims the doc states the caveat, so make the doc say it explicitly.
  2. The file header is stale: it still describes the old <blob>~ write-then-rename mechanism, not the journal.

Non-blocking: a test for a truncated active (the fail-closed path) would pin the validation, and note the overlap — this is the carry of #2003 (same four files; merging this should close it), and #1952 touches the same test file's main(), so whichever lands second may need a small conflict resolution.

Clean-room and merge are fine: check_no_game_data passes on all four files, merge-tree is clean, and main has not touched the shim, its test or docs/saves.md since the base (only CMakeLists.txt moved).

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6135152677 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2740#pullrequestreview-6135152677). Originally posted by [KelboLive](https://github.com/KelboLive) on 2026-12-01T16:10:45Z. **Review:** COMMENTED --- Approving for the stated process-interruption scope. The sequence is sound: staged `w<i>` blobs and write backups are complete before `prepare` is renamed to `active`, live blobs change only by same-volume `MoveFileExW`, deletes publish `b<i>` atomically, and the marker-presence undo with `restore`+rename is idempotent — so a second interruption during recovery cannot expose a half-written blob or manifest. A truncated or malformed `active` is rejected before any undo, which is the right fail-closed choice. I rebuilt with MSVC 19.52 and `ctest -R xgameruntime_gamesave` passes **176/176**, and disabling the write-marker undo fails checkpoint 3 with 29 failures, so the interruption test really covers the recovery path. Two documentation corrections, both worth doing before merge because they are about what the feature promises: 1. **It is not power-loss safe.** There is no `FlushFileBuffers` and no checksum, and `MOVEFILE_WRITE_THROUGH` covers the rename, not the staged data. `docs/saves.md`'s new paragraph says only "process interruption / same volume", while the code comment says "does not provide power-loss durability" — the PR body claims the doc states the caveat, so make the doc say it explicitly. 2. **The file header is stale**: it still describes the old `<blob>~` write-then-rename mechanism, not the journal. Non-blocking: a test for a truncated `active` (the fail-closed path) would pin the validation, and note the overlap — this is the carry of **#2003** (same four files; merging this should close it), and **#1952** touches the same test file's `main()`, so whichever lands second may need a small conflict resolution. Clean-room and merge are fine: `check_no_game_data` passes on all four files, `merge-tree` is clean, and main has not touched the shim, its test or `docs/saves.md` since the base (only `CMakeLists.txt` moved).
aslan2142 commented 2026-12-01 17:26:31 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T17:26:31Z.


Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7319303540 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2740#issuecomment-7319303540). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T17:26:31Z. --- Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.

Pull request closed

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!2740
No description provided.