Loader: stage each prepared image under its own name, then publish #1446

Closed
CwWwWwW wants to merge 1 commit from upstream-pr/1446 into main
CwWwWwW commented 2026-11-27 08:39:27 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-27T08:39:27Z.


Problem

victory-loader's write_if_changed staged every prepared title image in one deterministic .tmp file next to its target. Two victory processes loading the same title from the same cache folder stage the same name: one truncates the other's staging file and the first rename takes it away, so the other's rename fails with ENOENT - a second instance cannot start - and a loader can map a partly written image. Prepared copies are content-addressed (victory-image-<hash16>.dll), so the racing copies hold the same bytes.

Fix

Stage each process and call under its own name (<pid>.<serial>.tmp), rename into place, treat "the target is already published with these bytes" (another process won the race) as success, and remove the staging file on every path including write and rename failures.

Regression test

windows::tests::concurrent_preparations_publish_a_complete_image runs eight preparations of a 1 MiB image under one path: on the old code one fails renaming (ENOENT); with the change all publish, the path holds the complete bytes and no .tmp is left.

Verification

  • cargo test -p victory-loader --lib --locked: 29 passed, 0 failed
  • cargo clippy -p victory-loader --all-targets --locked -- -D warnings: clean
  • one file changed: crates/victory-loader/src/windows.rs (+61/-5)

Implemented independently from the target tree; no external code was copied.

The PR's Clippy check fails on main already: at 9a9091d cargo clippy --workspace --all-targets fails in victory-shader (wave64_after_loop.rs precedence, valu_tests.rs simplifiable/negated partial-ord comparisons); open PR #1440 fixes exactly those lints. This diff touches none of those files, and the touched crate's own tests and clippy are clean locally.

<!-- greyfinch-sync:fxceless/victory-fork:issue:5523689755 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1446). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-27T08:39:27Z. --- ## Problem `victory-loader`'s `write_if_changed` staged every prepared title image in one deterministic `.tmp` file next to its target. Two victory processes loading the same title from the same cache folder stage the same name: one truncates the other's staging file and the first rename takes it away, so the other's rename fails with `ENOENT` - a second instance cannot start - and a loader can map a partly written image. Prepared copies are content-addressed (`victory-image-<hash16>.dll`), so the racing copies hold the same bytes. ## Fix Stage each process and call under its own name (`<pid>.<serial>.tmp`), rename into place, treat "the target is already published with these bytes" (another process won the race) as success, and remove the staging file on every path including write and rename failures. ## Regression test `windows::tests::concurrent_preparations_publish_a_complete_image` runs eight preparations of a 1 MiB image under one path: on the old code one fails renaming (`ENOENT`); with the change all publish, the path holds the complete bytes and no `.tmp` is left. ## Verification - `cargo test -p victory-loader --lib --locked`: 29 passed, 0 failed - `cargo clippy -p victory-loader --all-targets --locked -- -D warnings`: clean - one file changed: `crates/victory-loader/src/windows.rs` (+61/-5) Implemented independently from the target tree; no external code was copied. The PR's Clippy check fails on main already: at 9a9091d `cargo clippy --workspace --all-targets` fails in `victory-shader` (wave64_after_loop.rs precedence, valu_tests.rs simplifiable/negated partial-ord comparisons); open PR #1440 fixes exactly those lints. This diff touches none of those files, and the touched crate's own tests and clippy are clean locally.
CwWwWwW commented 2026-11-27 16:21:30 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by CwWwWwW on 2026-11-27T16:21:30Z.


Superseded on the VIctory-NVIDIA tree that replaced main: the loader already stages prepared images in per-writer files and publishes with an atomic rename, with tests (crates/victory-loader/src/publish.rs; windows.rs uses it). Closing; the branch cannot be rebased onto the new tree meaningfully.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7223164707 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1446#issuecomment-7223164707). Originally posted by [CwWwWwW](https://github.com/CwWwWwW) on 2026-11-27T16:21:30Z. --- Superseded on the VIctory-NVIDIA tree that replaced main: the loader already stages prepared images in per-writer files and publishes with an atomic rename, with tests (crates/victory-loader/src/publish.rs; windows.rs uses it). Closing; the branch cannot be rebased onto the new tree meaningfully.

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
fxceless/victory-fork!1446
No description provided.