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

Open
adamMasMusic wants to merge 1 commit from upstream-pr/1838 into main
adamMasMusic commented 2026-11-24 23:11:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by adamMasMusic on 2026-11-24T23:11:10Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6593282427 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1838). Originally posted by [adamMasMusic](https://github.com/adamMasMusic) on 2026-11-24T23:11:10Z. --- `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)
catminou4 commented 2026-11-25 00:06:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T23:47:46Z.

Review: COMMENTED


Static review only: victory-hle is Windows-only — nothing compiles on macOS; source review of the diff.

XGameSave: old version held open by another process no longer fails…: file-sharing flags on save enumeration. Windows-only.

<!-- greyfinch-sync:Marvisak/VIctory:review:6049283496 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1838#pullrequestreview-6049283496). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T23:47:46Z. **Review:** COMMENTED --- Static review only: victory-hle is Windows-only — nothing compiles on macOS; source review of the diff. XGameSave: old version held open by another process no longer fails…: file-sharing flags on save enumeration. Windows-only.
Marvisak commented 2026-11-25 02:06:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:37:01Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149755019 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1838#issuecomment-7149755019). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:37:01Z. --- <!-- 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)_
WerG0D commented 2026-11-25 02:06:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by WerG0D on 2026-11-25T01:56:17Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7150132675 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1838#issuecomment-7150132675). Originally posted by [WerG0D](https://github.com/WerG0D) on 2026-11-25T01:56:17Z. --- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1838:upstream-pr/1838'
git switch 'upstream-pr/1838'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1838'
git switch 'upstream-pr/1838'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1838'
git switch 'upstream-pr/1838'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1838'
git switch 'main'
git merge --squash 'upstream-pr/1838'
git switch 'main'
git merge --ff-only 'upstream-pr/1838'
git switch 'main'
git merge 'upstream-pr/1838'
git push origin 'main'
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
Marvisak/VIctory!1836
No description provided.