GPU: pipeline library saves run one at a time #2328

Open
github-bot wants to merge 2 commits from github-bot/gh-2328 into main AGit
Owner

@⁠denkencar-sketch on GitHub · 2026-11-25 10:42 UTC · original
denkencar-sketch:fix/plib-001 → main · +60 −0 · 1 files · 2 commits · open

Summary

The worker's pipeline library save and the shutdown's could interleave their files: an older blob over a newer one, or beside another save's prebuilt list. Saves now run one at a time. A second commit makes the periodic save, which workers call after every pipeline, leave it to the save running instead of waiting (shutdown's save still waits).

Testing

Tests a_save_waits_for_the_save_running and a_periodic_save_does_not_wait_for_the_save_running fail without the lock and without try_lock respectively, and pass with this change. The wait in the first test is timing-based.

cargo test --workspace --locked passes apart from known flakes: modules::dstorage::tests::a_page_list_filled_after_its_request_starts fails now and then on main too, and so does a parallel-run flake in victory-gpu's lib tests (watch:: and descriptor::host:: tests, 2 of 40 runs on pristine main).

A skipped periodic save leaves its dirty marks for the next save. It touches save() like #2326 and #2327 do and conflicts with them only in adjacent test blocks in library.rs. Not tried: a run in the game.

AI-assisted.

**@⁠denkencar-sketch** on GitHub · 2026-11-25 10:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2328) `denkencar-sketch:fix/plib-001` → `main` · +60 −0 · 1 files · 2 commits · open ## Summary The worker's pipeline library save and the shutdown's could interleave their files: an older blob over a newer one, or beside another save's prebuilt list. Saves now run one at a time. A second commit makes the periodic save, which workers call after every pipeline, leave it to the save running instead of waiting (shutdown's save still waits). ## Testing Tests `a_save_waits_for_the_save_running` and `a_periodic_save_does_not_wait_for_the_save_running` fail without the lock and without `try_lock` respectively, and pass with this change. The wait in the first test is timing-based. `cargo test --workspace --locked` passes apart from known flakes: `modules::dstorage::tests::a_page_list_filled_after_its_request_starts` fails now and then on `main` too, and so does a parallel-run flake in `victory-gpu`'s lib tests (`watch::` and `descriptor::host::` tests, 2 of 40 runs on pristine `main`). A skipped periodic save leaves its dirty marks for the next save. It touches `save()` like #2326 and #2327 do and conflicts with them only in adjacent test blocks in `library.rs`. Not tried: a run in the game. AI-assisted.
The worker's save and the shutdown's could interleave their files: an older
blob over a newer, or beside another's prebuilt list.
The workers call it after every pipeline; waiting for the files of another
save would stall them. Shutdown's save still waits.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:02:27 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:20 UTC · original · edited 2026-11-26 03:24 UTC

Automated triage for the maintainers.

Verdict: merge candidate. Thanks for the rebase. At a662de9, pipeline::library::save (crates/victory-gpu/src/pipeline/library.rs) holds a SAVING mutex from the LAST check to the last file write. Shutdown's save(true) waits for it, and a worker's save(false) returns at once when another save is running.

The race is real on main. Serialize runs under the library state lock, but the three write_atomically calls run after that lock is released. Two saves can therefore finish their files in the wrong order, leaving an older blob or a prebuilt list beside the wrong bytes. A skipped periodic save leaves added/USED_CHANGED set, so the next save picks the changes up. The two tests check the waiting and non-waiting cases. The first relies on a 300 ms sleep, which is acceptable for a negative check.

CI: passing (check). Merges cleanly.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/2328#issuecomment-7166700142) · edited 2026-11-26 03:24 UTC <!-- victory-triage v1 head=a662de92591345f983324ffef25365d7b5bf8a46 verdict=merge-candidate at=2026-11-26T03:24:53Z --> Automated triage for the maintainers. **Verdict: merge candidate.** Thanks for the rebase. At `a662de9`, `pipeline::library::save` (`crates/victory-gpu/src/pipeline/library.rs`) holds a `SAVING` mutex from the `LAST` check to the last file write. Shutdown's `save(true)` waits for it, and a worker's `save(false)` returns at once when another save is running. The race is real on `main`. `Serialize` runs under the library state lock, but the three `write_atomically` calls run after that lock is released. Two saves can therefore finish their files in the wrong order, leaving an older blob or a prebuilt list beside the wrong bytes. A skipped periodic save leaves `added`/`USED_CHANGED` set, so the next save picks the changes up. The two tests check the waiting and non-waiting cases. The first relies on a 300 ms sleep, which is acceptable for a negative check. CI: passing (`check`). Merges cleanly. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 10:54 UTC · original · reviewed

Pipeline library saves run one at a time (SAVING mutex, try_lock for periodic, blocking for shutdown). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Same cluster; prevents blob/prebuilt interleaving.

**@⁠catminou4** on GitHub · 2026-11-25 10:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2328#pullrequestreview-6056245243) · **reviewed** Pipeline library saves run one at a time (SAVING mutex, try_lock for periodic, blocking for shutdown). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Same cluster; prevents blob/prebuilt interleaving.
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 11:42 UTC · original · approved these changes

Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090:

  • Serializing pipeline library saves while letting periodic saves skip when a save is already running avoids concurrent write races cleanly.
  • cargo test -p victory-gpu pipeline::library::tests: 10/10 passed (including a_periodic_save_does_not_wait_for_the_save_running and a_save_waits_for_the_save_running).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-25 11:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2328#pullrequestreview-6056966596) · **approved these changes** Verified against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090: - Serializing pipeline library saves while letting periodic saves skip when a save is already running avoids concurrent write races cleanly. - `cargo test -p victory-gpu pipeline::library::tests`: 10/10 passed (including `a_periodic_save_does_not_wait_for_the_save_running` and `a_save_waits_for_the_save_running`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 16:38 UTC · original · approved these changes

Reviewed a662de92591345f983324ffef25365d7b5bf8a46 (merged cleanly onto 63bcca43c6a00a758510398fa43096ce7e4f7df0) and verified on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, VICTORY_D3D12_DEBUG=1).

The SAVING guard covers the full save sequence (early list, prebuilt list, and library blob) with consistent lock ordering (SAVING -> LAST -> state -> USED -> WRITING), keeping periodic saves non-blocking on contention while shutdown waits for an active save to finish.

Non-blocking notes for coordination / follow-up:

  • #2803 already extends LAST with the same blocking/try_lock policy over the save window (so if both land, keeping a single outer lock avoids stacking two save mutexes), and #2327 handles dirty-state restoration if a file replacement fails after clearing marks.
  • Replacing the 300 ms sleep in a_save_waits_for_the_save_running with an explicit synchronization point (keeping a timeout only as a watchdog) would make the concurrency tests immune to scheduler jitter.

Verification

  • cargo run -p xtask -- policy (191 files ok), cargo clippy (default & --all-features) clean, new lines rustfmt-clean.
  • victory-gpu pipeline::library:: with VICTORY_D3D12_DEBUG=1: 13/13 passed on both RTX 5090 and WARP (at both PR head and merged onto 63bcca43).
**@⁠fuzeofficlal** on GitHub · 2026-11-26 16:38 UTC · [original](https://github.com/Marvisak/VIctory/pull/2328#pullrequestreview-6077676245) · **approved these changes** Reviewed `a662de92591345f983324ffef25365d7b5bf8a46` (merged cleanly onto `63bcca43c6a00a758510398fa43096ce7e4f7df0`) and verified on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, `VICTORY_D3D12_DEBUG=1`). The `SAVING` guard covers the full save sequence (early list, prebuilt list, and library blob) with consistent lock ordering (`SAVING` -> `LAST` -> `state` -> `USED` -> `WRITING`), keeping periodic saves non-blocking on contention while shutdown waits for an active save to finish. Non-blocking notes for coordination / follow-up: - `#2803` already extends `LAST` with the same blocking/`try_lock` policy over the save window (so if both land, keeping a single outer lock avoids stacking two save mutexes), and `#2327` handles dirty-state restoration if a file replacement fails after clearing marks. - Replacing the 300 ms sleep in `a_save_waits_for_the_save_running` with an explicit synchronization point (keeping a timeout only as a watchdog) would make the concurrency tests immune to scheduler jitter. ### Verification - `cargo run -p xtask -- policy` (`191 files ok`), `cargo clippy` (default & `--all-features`) clean, new lines `rustfmt`-clean. - `victory-gpu` `pipeline::library::` with `VICTORY_D3D12_DEBUG=1`: **13/13 passed** on both RTX 5090 and WARP (at both PR head and merged onto `63bcca43`).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2328/head:github-bot/gh-2328'
git switch 'github-bot/gh-2328'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2328'
git switch 'github-bot/gh-2328'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2328'
git switch 'github-bot/gh-2328'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2328'
git switch 'main'
git merge --squash 'github-bot/gh-2328'
git switch 'main'
git merge --ff-only 'github-bot/gh-2328'
git switch 'main'
git merge 'github-bot/gh-2328'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2328
No description provided.