Skip to content

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

Merged
Marvisak merged 1 commit into
Marvisak:mainfrom
Quat3rnion:victory-image-publication
Nov 25, 2026
Merged

Marvisak merged 1 commit into
Marvisak:mainfrom
Quat3rnion:victory-image-publication

Conversation

@Quat3rnion

Copy link
Copy Markdown
Contributor

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.

@mercuryVM mercuryVM 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.

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).

mercuryVM added a commit to mercuryVM/VIctory that referenced this pull request Nov 24, 2026
…writer files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sebastianspicker

Copy link
Copy Markdown

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 Build: Linux workspace, contributor setup and CI #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 catminou4 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.

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).

write_if_changed used a shared <hash>.tmp file, so two concurrent cold launches of the same image could truncate each other's staging bytes or fail the rename after the other had published. Move publication into a portable module that stages under a unique pid/sequence name and removes it on failure. Two hermetic tests cover concurrent publishers and a failed rename.
@Quat3rnion
Quat3rnion force-pushed the victory-image-publication branch from 49df7e1 to 1aac20a Compare November 24, 2026 14:11
Yaekai pushed a commit to Yaekai/VIctory that referenced this pull request Nov 24, 2026
yourmomsbasement pushed a commit to yourmomsbasement/VIctory_Dev that referenced this pull request Nov 24, 2026
Merges Marvisak#188 Marvisak#213 Marvisak#214 Marvisak#219 Marvisak#221 Marvisak#311 Marvisak#324 Marvisak#363 Marvisak#406 Marvisak#454 Marvisak#529 Marvisak#560 Marvisak#708 Marvisak#937
Marvisak#941 Marvisak#963 Marvisak#1111 Marvisak#1159 Marvisak#1304 Marvisak#1306 onto main (ffe310e), each head unchanged,
no conflicts.

One change of mine: the long-format import descriptor code Marvisak#963 adds nests
`if size == 0` in an `if let`, which clippy::collapsible_if rejects under
-D warnings; it is now one `if let ... && size == 0` (clippy --fix, no
change of behaviour).

cargo clippy --workspace --all-targets --locked -- -D warnings, with and
without --all-features, is clean and cargo test --workspace --locked passes
(388 passed, 7 ignored; main has 342 passed, 6 ignored).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 24, 2026
@Marvisak
Marvisak merged commit 40f5553 into Marvisak:main Nov 25, 2026
1 check passed
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.

5 participants