Loader: stage prepared images in per-writer files #560

Merged
Quat3rnion merged 1 commit from upstream-pr/560 into main 2026-11-25 00:20:19 +00:00
Quat3rnion commented 2026-11-24 04:56:11 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Quat3rnion on 2026-11-24T04:56:11Z.


What

write_if_changed staged every prepared image into the same
<hash>.tmp file. Two cold launches of the same title could truncate each
other's staged bytes, or the second rename could fail after the first had
already published a correct image. Publication now lives in a portable
module that stages under a name unique to the process and call, and removes
the staging file if the rename fails. The Windows loader path delegates to
it; the file content and cache layout are unchanged.

An AI tool wrote part of this change.

Tested

  • Linux: cargo test --workspace: 166 passed, 0 failed, 3 ignored. Two hermetic tests: concurrent publishers of the same destination both succeed with the exact bytes and leave no staging files, and a failed publication leaves none behind.
  • Windows cross-build: cargo check --target x86_64-pc-windows-gnu --workspace --tests passes. No Windows host here, so the actual LoadLibraryExW step was not exercised.
  • cargo xtask policy passes (151 files ok). No game files or data from them were added.

Checklist

  • Workspace tests and Windows cross-check pass.
  • cargo xtask policy passes. No game files or data from them were added.
  • AI authorship is disclosed above.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6574932657 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/560). Originally posted by [Quat3rnion](https://github.com/Quat3rnion) on 2026-11-24T04:56:11Z. --- ## What `write_if_changed` staged every prepared image into the same `<hash>.tmp` file. Two cold launches of the same title could truncate each other's staged bytes, or the second rename could fail after the first had already published a correct image. Publication now lives in a portable module that stages under a name unique to the process and call, and removes the staging file if the rename fails. The Windows loader path delegates to it; the file content and cache layout are unchanged. An AI tool wrote part of this change. ## Tested - Linux: `cargo test --workspace`: 166 passed, 0 failed, 3 ignored. Two hermetic tests: concurrent publishers of the same destination both succeed with the exact bytes and leave no staging files, and a failed publication leaves none behind. - Windows cross-build: `cargo check --target x86_64-pc-windows-gnu --workspace --tests` passes. No Windows host here, so the actual `LoadLibraryExW` step was not exercised. - `cargo xtask policy` passes (151 files ok). No game files or data from them were added. ## Checklist - [x] Workspace tests and Windows cross-check pass. - [x] `cargo xtask policy` passes. No game files or data from them were added. - [x] AI authorship is disclosed above.
mercuryVM commented 2026-11-24 10:03:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T10:00:37Z.

Review: APPROVED


Tested 49df7e1 on Windows 11, RTX 5070, MSVC: the workspace passes (197 outside victory-shader), including both publish tests.

  • A per-process, per-call staging name (.<name>.<pid>.<seq>.tmp) removes the shared <hash>.tmp that two cold launches could truncate under each other. A failed rename now removes its staging file instead of leaving it in the cache.
  • Remaining Windows race, not introduced here: if both launches pass the "already equal?" read before either publishes, the second rename replaces a file the first may already have mapped. Windows refuses to replace a mapped file, so the second launch gets an error. That is the same outcome as before. A follow-up could treat a failed rename as success when the destination now reads equal to bytes.

No issues found.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:review:6037151293 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/560#pullrequestreview-6037151293). Originally posted by [mercuryVM](https://github.com/mercuryVM) on 2026-11-24T10:00:37Z. **Review:** APPROVED --- Tested 49df7e1 on Windows 11, RTX 5070, MSVC: the workspace passes (197 outside `victory-shader`), including both `publish` tests. - A per-process, per-call staging name (`.<name>.<pid>.<seq>.tmp`) removes the shared `<hash>.tmp` that two cold launches could truncate under each other. A failed rename now removes its staging file instead of leaving it in the cache. - Remaining Windows race, not introduced here: if both launches pass the "already equal?" read before either publishes, the second `rename` replaces a file the first may already have mapped. Windows refuses to replace a mapped file, so the second launch gets an error. That is the same outcome as before. A follow-up could treat a failed rename as success when the destination now reads equal to `bytes`. No issues found. AI-assisted (Claude Code).
sebastianspicker commented 2026-11-24 11:04:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sebastianspicker on 2026-11-24T11:02:10Z.


Tested 49df7e1 applied onto main ffe310e (macOS, Rust 1.98.1). Both new tests pass, 5 out of 5 runs, and Windows-target clippy (x86_64-pc-windows-msvc, plain and --all-features) is clean. Three things:

  1. Off Windows, publish is only used by tests, so cargo clippy -p victory-loader --all-targets -- -D warnings fails on Linux and macOS: static NEXT_STAGING is never used and function write_if_changed is never used. cargo test passes because it doesn't deny warnings, but a Linux lint job (like the one in #112) would go red. #[cfg(any(windows, test))] on mod publish; would fix it.
  2. On Windows, I think the second rename can still fail when the first launcher has already loaded the published file with LoadLibraryExW. Replacing a file that's mapped as a loaded DLL is refused, even though its bytes are already correct. I can't run that here. A cheap fallback would be: if the rename fails and path now reads back equal to bytes, remove the staging file and return Ok.
  3. If std::fs::write(&staging, bytes) fails partway (a full disk), the staging file stays behind. The rename branch already removes it, so the write could do the same.

Also, publish.rs isn't rustfmt-clean (two hunks with rustfmt 1.98.1), though main isn't either yet.

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7129569452 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/560#issuecomment-7129569452). Originally posted by [sebastianspicker](https://github.com/sebastianspicker) on 2026-11-24T11:02:10Z. --- Tested `49df7e1` applied onto `main` `ffe310e` (macOS, Rust 1.98.1). Both new tests pass, 5 out of 5 runs, and Windows-target clippy (`x86_64-pc-windows-msvc`, plain and `--all-features`) is clean. Three things: 1. Off Windows, `publish` is only used by tests, so `cargo clippy -p victory-loader --all-targets -- -D warnings` fails on Linux and macOS: `static NEXT_STAGING is never used` and `function write_if_changed is never used`. `cargo test` passes because it doesn't deny warnings, but a Linux lint job (like the one in #112) would go red. `#[cfg(any(windows, test))]` on `mod publish;` would fix it. 2. On Windows, I think the second rename can still fail when the first launcher has already loaded the published file with `LoadLibraryExW`. Replacing a file that's mapped as a loaded DLL is refused, even though its bytes are already correct. I can't run that here. A cheap fallback would be: if the rename fails and `path` now reads back equal to `bytes`, remove the staging file and return `Ok`. 3. If `std::fs::write(&staging, bytes)` fails partway (a full disk), the staging file stays behind. The rename branch already removes it, so the write could do the same. Also, `publish.rs` isn't rustfmt-clean (two hunks with rustfmt 1.98.1), though `main` isn't either yet. AI-assisted.
catminou4 commented 2026-11-24 13:01:39 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T12:44:20Z.

Review: APPROVED


Clean portability fix: write_if_changed moves from windows.rs into a shared publish module, and the staging file is now unique per process+call (.{name}.{pid}.{seq}.tmp) instead of a fixed .tmp sibling. Two runner instances preparing the same title can no longer truncate each other's staging bytes or rename over each other's publish; the final rename stays atomic within the directory and failures clean up the staging file.

The read-compare-write fast path and with_context error reporting are preserved. Unit tests cover both the concurrent-publisher case and the failed-publication cleanup.

Verified locally: test-merge with current main (ffe310e) clean; cargo test -p victory-loader --locked publish (macOS arm64, rustc 1.98.1) → 2 passed / 0 failed (the 3 prepare::tests failures in the full suite are the pre-existing Mach-O-vs-PE platform issue on main, unrelated).

<!-- greyfinch-sync:Marvisak/VIctory:review:6039401989 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/560#pullrequestreview-6039401989). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T12:44:20Z. **Review:** APPROVED --- Clean portability fix: `write_if_changed` moves from `windows.rs` into a shared `publish` module, and the staging file is now unique per process+call (`.{name}.{pid}.{seq}.tmp`) instead of a fixed `.tmp` sibling. Two runner instances preparing the same title can no longer truncate each other's staging bytes or rename over each other's publish; the final rename stays atomic within the directory and failures clean up the staging file. The read-compare-write fast path and `with_context` error reporting are preserved. Unit tests cover both the concurrent-publisher case and the failed-publication cleanup. Verified locally: test-merge with current main (`ffe310e`) clean; `cargo test -p victory-loader --locked publish` (macOS arm64, rustc 1.98.1) → **2 passed / 0 failed** (the 3 `prepare::tests` failures in the full suite are the pre-existing Mach-O-vs-PE platform issue on main, unrelated).
upstream-sync closed this pull request 2026-11-25 01:04:14 +00:00
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!560
No description provided.