XGameSave: an old version another process holds open no longer fails the save #1838

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

@⁠adamMasMusic on GitHub · 2026-11-24 23:11 UTC · original
adamMasMusic:xgamesave-held-old-version → main · +70 −5 · 1 files · 1 commits · open

current removes unfinished (v<N>.new) and superseded versions of a container whenever it reads one, and passed any failure on with ?. So while another process had a file of an old version open, every read and every update of that container failed with NO_ACCESS, though the newest version was intact.

On Windows that happens in ordinary use. A virus scanner or the search indexer opens files right after they are written, typically shared for reading but not for deletion. Unchanged blobs are hard links to the previous version's files, so a scanner reading the new version also blocks deleting the old one. On one Windows 10 machine (Defender on, data folder on an NTFS volume) the title's saves failed this way in every run, with os error 32 (sharing violation) and, beside it, os error 4395 (ERROR_REPARSE_POINT_ENCOUNTERED) from remove_dir_all. The containers kept growing stale v<N> folders that never went away. In 3 of 8 runs the title then stayed on its loading screen for good, right after the save at world entry failed. That is a correlation only, I have not traced the title's side.

Change (crates/victory-hle/src/modules/xgamesave.rs only)

  • current: removing an unfinished or superseded version is best effort (remove_stale). A failure is logged at debug level and the folder is left for a later look. The newest committed version is the container either way, so nothing the title sees changes.
  • commit: removing a leftover staging folder and the final rename retry for up to a second (20 × 50 ms) while Windows refuses them with an open-handle error (5, 32, 4395). Any other error, or one that outlasts the retries, fails the update as before.
  • Unchanged: the all-or-nothing guarantee. The kill-at-any-step test passes unchanged.

Tests

New Windows test a_held_old_version_does_not_cost_the_save. It holds v1's manifest open the way a scanner does (shared for reading and writing, not for deletion) while an update commits v2. The container then still reads, takes another update, keeps v1 meanwhile, and removes it once the file is let go. Without the change the read fails (Os { code: 32 }).

cargo test -p victory-hle passes, including the kill-at-any-step test, and cargo clippy -p victory-hle --all-targets -- -D warnings reports nothing.

#1729 also changes current (which folders count as versions); the two should combine without trouble, one deciding what to remove and this one what a failed removal costs.

🤖 Generated with Claude Code

**@⁠adamMasMusic** on GitHub · 2026-11-24 23:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/1838) `adamMasMusic:xgamesave-held-old-version` → `main` · +70 −5 · 1 files · 1 commits · open `current` removes unfinished (`v<N>.new`) and superseded versions of a container whenever it reads one, and passed any failure on with `?`. So while another process had a file of an old version open, every read and every update of that container failed with `NO_ACCESS`, though the newest version was intact. On Windows that happens in ordinary use. A virus scanner or the search indexer opens files right after they are written, typically shared for reading but not for deletion. Unchanged blobs are hard links to the previous version's files, so a scanner reading the new version also blocks deleting the old one. On one Windows 10 machine (Defender on, data folder on an NTFS volume) the title's saves failed this way in every run, with os error 32 (sharing violation) and, beside it, os error 4395 (`ERROR_REPARSE_POINT_ENCOUNTERED`) from `remove_dir_all`. The containers kept growing stale `v<N>` folders that never went away. In 3 of 8 runs the title then stayed on its loading screen for good, right after the save at world entry failed. That is a correlation only, I have not traced the title's side. ## Change (`crates/victory-hle/src/modules/xgamesave.rs` only) - **`current`:** removing an unfinished or superseded version is best effort (`remove_stale`). A failure is logged at debug level and the folder is left for a later look. The newest committed version is the container either way, so nothing the title sees changes. - **`commit`:** removing a leftover staging folder and the final rename retry for up to a second (20 × 50 ms) while Windows refuses them with an open-handle error (5, 32, 4395). Any other error, or one that outlasts the retries, fails the update as before. - **Unchanged:** the all-or-nothing guarantee. The kill-at-any-step test passes unchanged. ## Tests New Windows test `a_held_old_version_does_not_cost_the_save`. It holds `v1`'s manifest open the way a scanner does (shared for reading and writing, not for deletion) while an update commits `v2`. The container then still reads, takes another update, keeps `v1` meanwhile, and removes it once the file is let go. Without the change the read fails (`Os { code: 32 }`). `cargo test -p victory-hle` passes, including the kill-at-any-step test, and `cargo clippy -p victory-hle --all-targets -- -D warnings` reports nothing. #1729 also changes `current` (which folders count as versions); the two should combine without trouble, one deciding what to remove and this one what a failed removal costs. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Reading a container removed unfinished and superseded versions and
passed any failure on, so every read and update of the container failed
while another process had a file of an old version open. On Windows a
virus scanner or indexer opening what was just written does exactly
that (os errors 32 and 4395, seen on one machine): the title's saves
failed with NO_ACCESS, and in the runs that stopped on the loading
screen for good, its world-entry save failed that way just before.

Stale versions are now removed where possible and otherwise left for a
later look; the newest committed version is the container either way.
Committing a version retries removing a leftover staging folder and the
final rename for up to a second while Windows refuses them for an open
handle.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:46:15 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:37 UTC · original

Automated triage for the maintainers.

Needs rebase. This pull request conflicts with main (conflicting: crates/victory-hle/src/modules/xgamesave.rs). It will be reviewed once it is rebased onto the current main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/1838#issuecomment-7149755019) <!-- victory-triage v1 head=5b40efdaa3ee420a5b0d106b066c737605e42e2b verdict=needs-rebase at=2026-11-25T01:37:00Z --> Automated triage for the maintainers. **Needs rebase.** This pull request conflicts with `main` (conflicting: `crates/victory-hle/src/modules/xgamesave.rs`). It will be reviewed once it is rebased onto the current `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠WerG0D on GitHub · 2026-11-25 01:56 UTC · original · edited 2026-11-25 02:15 UTC

I tested this on Windows with an NTFS volume and a synthetic save container. On the original base (70564ae), holding the v1 manifest open allowed the v2 write to finish, but the next read failed with Windows error 32. On your patch (5b40efd), I could read v2, write v3 while the handle was still open, and read v3 after releasing it.

I also rebased your change onto 940d32f and added a regression test for the interaction with the newer recovery code. With v1 held open, a valid v2, and a malformed v3 manifest, the test reads the data from v2, writes and reopens v4, then verifies that v1 is cleaned up after the handle is released.

cargo test --locked -p victory-hle --lib passed all 145 tests, including all 13 XGameSave tests. This covers container recovery; in-game checkpoint loading remains unverified.

The integration branch is available if it helps with the rebase. a750c55 preserves your commit and resolves the conflict. 451c654 adds the combined test. Feel free to take either.

**@⁠WerG0D** on GitHub · 2026-11-25 01:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/1838#issuecomment-7150132675) · edited 2026-11-25 02:15 UTC I tested this on Windows with an NTFS volume and a synthetic save container. On the original base (`70564ae`), holding the `v1` manifest open allowed the `v2` write to finish, but the next read failed with Windows error 32. On your patch (`5b40efd`), I could read `v2`, write `v3` while the handle was still open, and read `v3` after releasing it. I also rebased your change onto `940d32f` and added a regression test for the interaction with the newer recovery code. With `v1` held open, a valid `v2`, and a malformed `v3` manifest, the test reads the data from `v2`, writes and reopens `v4`, then verifies that `v1` is cleaned up after the handle is released. `cargo test --locked -p victory-hle --lib` passed all 145 tests, including all 13 XGameSave tests. This covers container recovery; in-game checkpoint loading remains unverified. The [integration branch](https://github.com/WerG0D/VIctory/tree/fix/xgamesave-held-version) is available if it helps with the rebase. `a750c55` preserves your commit and resolves the conflict. `451c654` adds the combined test. Feel free to take either.
This pull request has changes conflicting with the target branch.
  • crates/victory-hle/src/modules/xgamesave.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1838/head:github-bot/gh-1838'
git switch 'github-bot/gh-1838'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1838'
git switch 'github-bot/gh-1838'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1838'
git switch 'github-bot/gh-1838'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1838'
git switch 'main'
git merge --squash 'github-bot/gh-1838'
git switch 'main'
git merge --ff-only 'github-bot/gh-1838'
git switch 'main'
git merge 'github-bot/gh-1838'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1838
No description provided.