Skip to content

HLE: a save of the old layout is not moved without a file it cannot read - #3329

Open
Creaa wants to merge 1 commit into
Marvisak:mainfrom
Creaa:hle/xgamesave-migrate-unreadable
Open

Creaa wants to merge 1 commit into
Marvisak:mainfrom
Creaa:hle/xgamesave-migrate-unreadable

Conversation

@Creaa

@Creaa Creaa commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

xgamesave::migrate moves a container of the old (pre-versioned) layout into a committed version, then removes the old folder. A .display it could not read became an empty display name, and a blob it could not read was skipped, so a file another process held open (no sharing) was committed without and then lost with the old folder. This keeps the old layout when a file that is there cannot be read; a later listing moves it whole. Covers NEW-215 and NEW-216 from #1633 (their earlier base #2525 is closed).

What is in it

  • crates/victory-hle/src/modules/xgamesave.rs: in migrate, .display not found is still an empty name; any other error reading .display, a blob or an entry of the folder listing logs a warning and returns before commit, leaving the old folder for the next listing.
  • Same file: new old_moved(root, name); Update::submit and delete call it first and return NO_ACCESS while the container's old layout cannot be moved yet, so no version is committed that migrate would then take for its own before removing the old folder.
  • Test an_unreadable_old_display_or_blob_leaves_the_old_layout_for_later: for .display and for a blob held with share_mode(0), the old layout stays and nothing is committed, and an update and a delete of the container are refused without committing or removing anything; after the handle is dropped, the next Provider::open moves both blobs and the display name Chapter 1.

Tested

  • Windows 11 build 26300, i7-13700F, Rust 1.98.1 (pinned); on main 63bcca4.
  • The new test passes (#[cfg(windows)], like the other Windows-only test here); with main's migrate it fails at ".display held: nothing committed", and with old_moved always true at ".display held: update".
  • cargo test -q --locked -p victory-hle --lib --no-fail-fast: 153 passed, 0 failed (the_old_layout_moves_over unchanged and passing).
  • cargo clippy --workspace --all-targets --locked -- -D warnings and with --all-features: clean. cargo xtask policy: 191 files ok.

Not tested

  • With the title (synthetic save folders only; no game data). Other locking cases than a share-none handle.

AI use

  • Claude Code (Claude Opus 5.5) wrote the change and the test, ran the checks and drafted this description; I checked it.

🤖 Generated with Claude Code

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — verified on Windows against origin/main (63bcca4).

  • Bailing out of migrate on non-NotFound .display read errors or any blob read error prevents committing an incomplete save and deleting the old layout while another process holds a file.
  • cargo test -p victory-hle --lib modules::xgamesave:: -- --test-threads=1: 12 passed, 0 failed (including an_unreadable_old_display_or_blob_leaves_the_old_layout_for_later).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

@borosf

borosf commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Independent local verification on Windows 11 x64, Intel Arc B580 12 GB (12 cores), at this PR's head e419c04:

cargo test -p victory-hle --lib --locked --no-fail-fast -- --test-threads=1
cargo clippy -p victory-hle --all-targets --locked -- -D warnings
cargo clippy -p victory-hle --all-targets --all-features --locked -- -D warnings

Result: victory-hle lib: fully green (exit 0) apart from modules::dstorage::tests::a_page_list_filled_after_its_request_starts, which passed on 2x --exact --test-threads=1 re-runs (flake); the PR's new bounds test and all xgamesave tests pass.

Both clippy runs exit 0 (-D warnings, both feature sets). The B580 baseline failures pristine main also hits are: victory-gpu descriptor::host::tests::dynamic_slots_are_held_until_released + memory::tests::lists_share_a_table_and_copies_keep_their_views (#1744/#1829); victory-shader emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros + emit::valu_tests::fspx_programs_run_with_the_hardwares_dot_products. No PR regressions.

Synthetic tests only; no game data used. Full log kept locally. — borosf

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for guarding old-layout migration against unreadable .display/blob files — keeping the legacy directory on sharing violations is the right direction. However, a few issues remain in crates/victory-hle/src/modules/xgamesave.rs:

  1. High — An Update::submit while legacy migration is deferred can lead to permanent data loss (xgamesave.rs:343, 377, 484, 525):

    • Suppose migrate defers because a legacy file is locked (v1 does not exist yet), and the title then runs Update::submit on that container.
    • Update::submit reads current(&self.dir) as None (484), checks used_bytes(root) (525, where migrate either defers again or commits v1 mid-update while submit still plans number = 1), and can commit a v1 containing only the update's changes (531), returning S_OK.
    • Once the lock is later released, the next migrate sees current_named(&dir, name)?.is_some() == true (343) and executes std::fs::remove_dir_all(old) (377), permanently deleting any un-migrated blobs and .display from the old layout. (Updates/containers should refuse or wait until pending legacy migration completes, rather than treating an update-created v1 as proof migration already happened.)
  2. Medium — read_dir(old).ok()?.flatten() still ignores mid-iteration directory errors (xgamesave.rs:358):

    • While opening read_dir(old) checks .ok()?, .flatten() silently drops Err items yielded during directory iteration, which can still commit a partial container and remove old. Iterating explicitly over Result entries and bailing out on Err like the file reads do closes this path cleanly.
  3. Non-Windows test compilation break (xgamesave.rs:1239):

    • modules/mod.rs:38 does not gate pub mod xgamesave behind #[cfg(windows)] (the sibling Windows-only test at xgamesave.rs:1131 carries #[cfg(windows)]), so use std::os::windows::fs::OpenOptionsExt; inside an_unreadable_old_display_or_blob_leaves_the_old_layout_for_later will fail cargo test -p victory-hle on non-Windows targets unless gated with #[cfg(windows)].

Minor formatting nit: rustfmt --edition 2024 --check flags two lines exceeding 100 columns at xgamesave.rs:1242 and 1256.

Local checks on head e419c04b cleanly merged onto main (63bcca43):

  • cargo run -p xtask -- policy: 191 files ok.
  • cargo clippy --locked -p victory-hle --all-targets -- -D warnings (default and --all-features): clean.
  • cargo test --locked -p victory-hle --lib modules::xgamesave::: 12 passed; 0 failed (1.29s).

`migrate` moves a container of the pre-versioned layout into a committed
version and then removes the old folder. A `.display` it could not read
became an empty display name, and a blob it could not read was skipped,
so a file another process held open (no sharing) was committed without
and then lost with the old folder (NEW-215, NEW-216 in Marvisak#1633).

Now a missing `.display` is still an empty name, but any other read
failure of the display, of a blob or of the folder listing leaves the
old layout untouched and returns, so a later listing moves the container
whole. While it waits, an update or a delete of that container moves it
first and is refused if it still cannot: `migrate` takes a committed
version for its own (a crash after its commit) and removes the old
folder, so a version an update committed meanwhile would have cost the
old blobs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Creaa
Creaa force-pushed the hle/xgamesave-migrate-unreadable branch from e419c04 to 80e854a Compare November 26, 2026 20:18
@Creaa

Creaa commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

@fuzeofficlal thanks, all three were real. Fixed in 80e854a (squashed):

  1. Update::submit and delete now call old_moved(root, name) first (under the same saves_lock): if the container's old layout is still there it is moved now, and if it still cannot be, they return NO_ACCESS and commit/remove nothing. So no version can exist that migrate would take for its own before removing the old folder. The test now checks, for a held .display and a held blob, that an update and a delete are refused and leave the old folder; it fails at ".display held: update" with old_moved forced to true.
  2. The folder listing is iterated over its Results; an entry error leaves the old layout like a read error.
  3. The test is #[cfg(windows)], and its long lines are formatted (rustfmt reports no new lines over main for the file).

Rerun on Windows 11, RTX 4070 machine: cargo test -q --locked -p victory-hle --lib --no-fail-fast 153 passed, 0 failed; cargo clippy --workspace --all-targets --locked -- -D warnings clean; cargo xtask policy 191 files ok.

AI use: Claude Code (Claude Opus 5.5) made the fix and drafted this reply.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants