Handle loader publication rename races #1539

Closed
Gauss999 wants to merge 3 commits from upstream-pr/1539 into main
Gauss999 commented 2026-11-28 21:23:43 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Gauss999 on 2026-11-28T21:23:43Z.


Summary

  • Handle Windows loader publication rename races when another publisher wins: accept the existing destination only when its bytes exactly match the file being published.
  • Preserve the original rename error when the destination is missing or different, remove staging files on failure, and keep write-then-rename atomicity.
  • Add a small injection helper for deterministic loader race tests without new dependencies or cross-crate changes.
  • Conflict-resolution note: upstream main now contains the cache-side race handling and its Windows regression test. That file was adopted unchanged, leaving this PR scoped to crates/victory-loader/src/publish.rs.

Tests

  • Added loader regressions for matching destination bytes, mismatched destination bytes, and a missing destination; all verify staging cleanup and error handling.
  • The previous two-commit revision was built and tested externally on Windows: Clippy passed for victory-loader and victory-pipeline with and without all features, and the reported library test runs passed 49 + 9 tests.
  • The merge resolution was made through the GitHub web UI; no local build or tests were run on the resulting head db24ab7. CI is awaiting maintainer approval.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5544706195 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1539). Originally posted by [Gauss999](https://github.com/Gauss999) on 2026-11-28T21:23:43Z. --- ## Summary - Handle Windows loader publication rename races when another publisher wins: accept the existing destination only when its bytes exactly match the file being published. - Preserve the original rename error when the destination is missing or different, remove staging files on failure, and keep write-then-rename atomicity. - Add a small injection helper for deterministic loader race tests without new dependencies or cross-crate changes. - Conflict-resolution note: upstream `main` now contains the cache-side race handling and its Windows regression test. That file was adopted unchanged, leaving this PR scoped to `crates/victory-loader/src/publish.rs`. ## Tests - Added loader regressions for matching destination bytes, mismatched destination bytes, and a missing destination; all verify staging cleanup and error handling. - The previous two-commit revision was built and tested externally on Windows: Clippy passed for `victory-loader` and `victory-pipeline` with and without all features, and the reported library test runs passed 49 + 9 tests. - The merge resolution was made through the GitHub web UI; no local build or tests were run on the resulting head `db24ab7`. CI is awaiting maintainer approval.
babuakhil commented 2026-11-28 22:03:30 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by babuakhil on 2026-11-28T22:03:30Z.


Built and tested this on Windows, since it hadn't been run yet: Windows 11, Rust 1.98.1 (pinned), applied on current main (d4b5d51); both commits cherry-pick cleanly.

  • cargo clippy -p victory-loader -p victory-pipeline --all-targets --locked -- -D warnings, with and without --all-features: pass
  • the five new tests pass; cargo test -p victory-loader -p victory-pipeline --lib --locked: 49 + 9 passed, 5 of 5 runs
  • xtask policy fails only on lower.rs's size, which is already on main (#1429)

The race is real on Windows, and this fixes it. I stressed Cache::get_or_convert from a throwaway integration test (not part of this PR): 300 rounds, each with 16 threads publishing the same new entry at once while 4 threads open the destination with share_mode(FILE_SHARE_READ) (no FILE_SHARE_DELETE, as a scanner or a mapping reader would) and hold it for 200 µs. Each round also checks that no staging file is left and that the published bytes are right.

calls failed
main, run 1 4800 1570, all Access is denied. (os error 5)
main, run 2 4800 1664, same
this PR, run 1 4800 0
this PR, run 2 4800 0

With readers using std::fs::read (which shares delete), main had no failures either (0 of 14,400), so the failure needs a reader that doesn't share delete. No staging files were left on either side, and the published bytes were right every round.

The loader's write_if_changed is pub(crate), so I only covered it through this PR's unit tests, not the stress.

One design note, not a blocker: the cache accepts any regular file at the destination after a failed rename, while the loader requires its exact bytes. That seems right given the key is a content hash; the PR says readers validate on decode, which I didn't check. Happy to share the stress test if it's useful.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7246465964 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1539#issuecomment-7246465964). Originally posted by [babuakhil](https://github.com/babuakhil) on 2026-11-28T22:03:30Z. --- Built and tested this on Windows, since it hadn't been run yet: Windows 11, Rust 1.98.1 (pinned), applied on current `main` (`d4b5d51`); both commits cherry-pick cleanly. - `cargo clippy -p victory-loader -p victory-pipeline --all-targets --locked -- -D warnings`, with and without `--all-features`: pass - the five new tests pass; `cargo test -p victory-loader -p victory-pipeline --lib --locked`: 49 + 9 passed, 5 of 5 runs - `xtask policy` fails only on `lower.rs`'s size, which is already on `main` (#1429) **The race is real on Windows, and this fixes it.** I stressed `Cache::get_or_convert` from a throwaway integration test (not part of this PR): 300 rounds, each with 16 threads publishing the same new entry at once while 4 threads open the destination with `share_mode(FILE_SHARE_READ)` (no `FILE_SHARE_DELETE`, as a scanner or a mapping reader would) and hold it for 200 µs. Each round also checks that no staging file is left and that the published bytes are right. | | calls | failed | |---|---:|---:| | `main`, run 1 | 4800 | 1570, all `Access is denied. (os error 5)` | | `main`, run 2 | 4800 | 1664, same | | this PR, run 1 | 4800 | 0 | | this PR, run 2 | 4800 | 0 | With readers using `std::fs::read` (which shares delete), `main` had no failures either (0 of 14,400), so the failure needs a reader that doesn't share delete. No staging files were left on either side, and the published bytes were right every round. The loader's `write_if_changed` is `pub(crate)`, so I only covered it through this PR's unit tests, not the stress. One design note, not a blocker: the cache accepts any regular file at the destination after a failed rename, while the loader requires its exact bytes. That seems right given the key is a content hash; the PR says readers validate on decode, which I didn't check. Happy to share the stress test if it's useful.
trustno1-coder commented 2026-11-29 08:28:15 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-11-29T08:28:15Z.


Thank you! An earlier version of this pull request was merged into main with its original commits and is part of v2026.11.29.01, where you are credited. GitHub does not show it as merged because new commits were pushed here after that merge. It stays open so those newer commits can be looked at next.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7253124987 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1539#issuecomment-7253124987). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-11-29T08:28:15Z. --- Thank you! An earlier version of this pull request was merged into main with its original commits and is part of [v2026.11.29.01](https://github.com/trustno1-coder/VIctory-NVIDIA/releases/tag/v2026.11.29.01), where you are credited. GitHub does not show it as merged because new commits were pushed here after that merge. It stays open so those newer commits can be looked at next.
Gauss999 commented 2026-11-29 18:34:09 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Gauss999 on 2026-11-29T18:34:09Z.


Closing this after auditing the current heads: there is no residual behaviour left in this PR. The diff of crates/victory-loader/src/publish.rs against the current upstream/main is empty — the original commits are integrated upstream (0c07d4ac, part of v2026.11.29.01, with authorship credit as noted above), and the branch only carries the merge commit db24ab7e on top. Nothing further to review here; thanks for keeping the credit intact.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7260585861 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/1539#issuecomment-7260585861). Originally posted by [Gauss999](https://github.com/Gauss999) on 2026-11-29T18:34:09Z. --- Closing this after auditing the current heads: there is no residual behaviour left in this PR. The diff of crates/victory-loader/src/publish.rs against the current upstream/main is empty — the original commits are integrated upstream (0c07d4ac, part of v2026.11.29.01, with authorship credit as noted above), and the branch only carries the merge commit db24ab7e on top. Nothing further to review here; thanks for keeping the credit intact.

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
trustno1-coder/VIctory-NVIDIA!1539
No description provided.