GPU: sweep cut pipeline-cache staging files #2508

Open
Ingenioeren wants to merge 2 commits from upstream-pr/2510 into main
Ingenioeren commented 2026-11-25 15:03:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Ingenioeren on 2026-11-25T15:03:31Z.


What

use_pipeline_cache() in crates/victory-gpu/src/pipeline/library.rs now sweeps stale staging files. Only regular files named exactly {host-pipelines.bin,early-pipelines.txt,prebuilt-pipelines.txt}.tmp-<digits>-<digits> are removed. This process's go at once, because none of its writes has started yet. Other processes' go once untouched for 10 minutes, because the folder is shared and nothing stops a second instance from writing in it.

The earlier version also added a lock to save(). Triage pointed out that #2328 (opened earlier) makes the same change and has tests for it, so that half is dropped here. This PR is now only the sweep.

Why

Since #1660, each write stages in a unique <file>.tmp-<pid>-<n>. A write cut by an exit (the exit save's early return, host_gpu_failed, a crash exit) leaves that file for good: no later run reuses the name, and nothing swept the folder. #2328 makes the normal exit wait for a running save, but crash and host_gpu_failed exits can still cut a write, so a sweep is needed either way.

On #2129: it also removes staging files at load, but decides by checking whether the writing process is still running. This version uses only the file name and age, so it needs no process query and also covers a reused pid. Either approach closes the gap; I'm happy to defer to whichever you prefer.

How tested

  • New pipeline::library::tests::stale_staging_files_are_swept. It checks that own-pid and old foreign staging files are removed for all three cache files, and that a recent foreign one, the cache files themselves, near-miss names (.tmp-7, .tmp-7-x, other.bin.tmp-7-0) and a directory are kept. With the sweep disabled it fails (host-pipelines.bin.tmp-7-0 swept); with the fix it passes.
  • Rebased on current main. cargo test --locked --offline -p victory-gpu: 196 passed, 0 failed, 1 ignored.
  • cargo clippy --locked --offline -p victory-gpu --all-targets: no warnings.
  • cargo run -p xtask -- policy --staged: asset policy: 1 files ok.

Not tested: no game run.

Part of #2496 (the other half is #2328).

AI assistance: prepared with Claude Code, reviewed by Ingenioeren.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:5493872311 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2510). Originally posted by [Ingenioeren](https://github.com/Ingenioeren) on 2026-11-25T15:03:31Z. --- ## What `use_pipeline_cache()` in `crates/victory-gpu/src/pipeline/library.rs` now sweeps stale staging files. Only regular files named exactly `{host-pipelines.bin,early-pipelines.txt,prebuilt-pipelines.txt}.tmp-<digits>-<digits>` are removed. This process's go at once, because none of its writes has started yet. Other processes' go once untouched for 10 minutes, because the folder is shared and nothing stops a second instance from writing in it. The earlier version also added a lock to `save()`. Triage pointed out that #2328 (opened earlier) makes the same change and has tests for it, so that half is dropped here. This PR is now only the sweep. ## Why Since #1660, each write stages in a unique `<file>.tmp-<pid>-<n>`. A write cut by an exit (the exit save's early return, `host_gpu_failed`, a crash exit) leaves that file for good: no later run reuses the name, and nothing swept the folder. #2328 makes the normal exit wait for a running save, but crash and `host_gpu_failed` exits can still cut a write, so a sweep is needed either way. On #2129: it also removes staging files at load, but decides by checking whether the writing process is still running. This version uses only the file name and age, so it needs no process query and also covers a reused pid. Either approach closes the gap; I'm happy to defer to whichever you prefer. ## How tested - New `pipeline::library::tests::stale_staging_files_are_swept`. It checks that own-pid and old foreign staging files are removed for all three cache files, and that a recent foreign one, the cache files themselves, near-miss names (`.tmp-7`, `.tmp-7-x`, `other.bin.tmp-7-0`) and a directory are kept. With the sweep disabled it fails (`host-pipelines.bin.tmp-7-0 swept`); with the fix it passes. - Rebased on current `main`. `cargo test --locked --offline -p victory-gpu`: 196 passed, 0 failed, 1 ignored. - `cargo clippy --locked --offline -p victory-gpu --all-targets`: no warnings. - `cargo run -p xtask -- policy --staged`: `asset policy: 1 files ok`. Not tested: no game run. Part of #2496 (the other half is #2328). AI assistance: prepared with Claude Code, reviewed by Ingenioeren. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Marvisak commented 2026-11-25 16:09:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T16:00:23Z.


Automated triage for the maintainers.

Merge candidate.

Changed since the last review (new head 1b6a079): the save() lock that duplicated #2328 is gone. The PR is now only the staging-file sweep in crates/victory-gpu/src/pipeline/library.rs. At startup, use_pipeline_cache calls sweep_staging, which removes leftover temporary files from interrupted cache writes.

  • It removes only files named <cache file>.tmp-<pid>-<n>, matching the names write_atomically creates in main. staging_pid requires both numbers to be all digits.
  • It removes this process's own staging files at once. Another process's files are removed only after 10 minutes untouched, since a running instance may still be writing them.
  • Directories and other files are left alone.

stale_staging_files_are_swept covers the name matching, the age rule and the directory case. tempfile is already a dev-dependency.

On your reply: thanks, this is the reduced version that was asked for. #2129 also clears staging files at load, by checking whether the writing process is still running, so the maintainer will pick one of the two.

CI: check passing.


Generated by Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167508319 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2510#issuecomment-7167508319). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T16:00:23Z. --- <!-- victory-triage v1 head=1b6a0795161ead0e1b6bd5f87b4a32d8ce6b6947 verdict=merge-candidate at=2026-11-25T16:44:54Z --> Automated triage for the maintainers. **Merge candidate.** Changed since the last review (new head `1b6a079`): the `save()` lock that duplicated #2328 is gone. The PR is now only the staging-file sweep in `crates/victory-gpu/src/pipeline/library.rs`. At startup, `use_pipeline_cache` calls `sweep_staging`, which removes leftover temporary files from interrupted cache writes. - It removes only files named `<cache file>.tmp-<pid>-<n>`, matching the names `write_atomically` creates in main. `staging_pid` requires both numbers to be all digits. - It removes this process's own staging files at once. Another process's files are removed only after 10 minutes untouched, since a running instance may still be writing them. - Directories and other files are left alone. `stale_staging_files_are_swept` covers the name matching, the age rule and the directory case. `tempfile` is already a dev-dependency. On your reply: thanks, this is the reduced version that was asked for. #2129 also clears staging files at load, by checking whether the writing process is still running, so the maintainer will pick one of the two. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Ingenioeren commented 2026-11-25 16:09:46 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Ingenioeren on 2026-11-25T16:05:19Z.


Thanks for the triage. I dropped the save() lock, since #2328 already covers it. The PR is now only the staging-file sweep, rebased on current main (1b6a079). I also changed "Fixes #2496" to "Part of #2496" and added a note to the description comparing this with #2129.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167582629 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2510#issuecomment-7167582629). Originally posted by [Ingenioeren](https://github.com/Ingenioeren) on 2026-11-25T16:05:19Z. --- Thanks for the triage. I dropped the `save()` lock, since #2328 already covers it. The PR is now only the staging-file sweep, rebased on current `main` (1b6a079). I also changed "Fixes #2496" to "Part of #2496" and added a note to the description comparing this with #2129.
futurepro62 commented 2026-11-26 02:06:54 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-26T01:09:30Z.


Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head 1b6a079 (on its base 67e8ae1).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), dxil.dll from Windows SDK 10.0.26100 (the loader's default), debug.
  • cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 774 passed, 0 failed, 9 ignored.
  • The new tests ran and passed: stale_staging_files_are_swept.
  • --skip leaves out tests that fail on main 63bcca4 on this card too, not because of this PR: heap_direct_texture_reads_mark_their_heap_index ends the victory-shader test process with 0xc0000005 (#2571), so without the skip the rest of that crate never reports; dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views and the two stride_tests hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); gathers_at_a_level_match_the_hardware fails on lane 0 (#1744).

Not tested

  • AMD (the tests take the default adapter), a release build, the title (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7179490772 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2510#issuecomment-7179490772). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-26T01:09:30Z. --- Full-suite run on NVIDIA, since this PR has no test report yet. Tested exact head `1b6a079` (on its base `67e8ae1`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (pinned), `dxil.dll` from Windows SDK 10.0.26100 (the loader's default), debug. - `cargo build --workspace --locked`, then `cargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware`: **774 passed, 0 failed, 9 ignored**. - The new tests ran and passed: `stale_staging_files_are_swept`. - `--skip` leaves out tests that fail on main `63bcca4` on this card too, not because of this PR: `heap_direct_texture_reads_mark_their_heap_index` ends the `victory-shader` test process with `0xc0000005` (#2571), so without the skip the rest of that crate never reports; `dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views` and the two `stride_tests` hit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317); `gathers_at_a_level_match_the_hardware` fails on lane 0 (#1744). **Not tested** - AMD (the tests take the default adapter), a release build, the title (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
fuzeofficlal commented 2026-11-26 18:42:37 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T18:42:37Z.

Review: APPROVED


Reviewed and verified 1b6a0795161ead0e1b6bd5f87b4a32d8ce6b6947 merged onto main (63bcca43) on Windows 11 x64 (cargo test -p xtask --locked policy::tests::repository_passes_policy: 1 passed, 191 files ok; cargo clippy --locked -p victory-gpu --all-targets -- -D warnings: clean; cargo test --locked -p victory-gpu --lib pipeline::library::: 12 passed, 0 failed, including stale_staging_files_are_swept).

sweep_staging and staging_pid (crates/victory-gpu/src/pipeline/library.rs:59-87) cleanly restrict cleanup to immediate regular <cache-file>.tmp-<pid>-<n> staging files and ignore locked-file/directory errors so live reads and saves continue unaffected.

Two minor non-blocking notes:

  • use_pipeline_cache (library.rs:46-49) runs sweep_staging before DIR.set(dir); guarding the sweep with DIR.get().is_none() would ensure a repeated call cannot sweep an active staging file of the current pid without waiting STAGING_KEPT.
  • rustfmt --edition 2024 --check flags the single-line else { return }; and else { continue }; at library.rs:60, 63.
<!-- greyfinch-sync:Marvisak/VIctory:review:6079109521 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2510#pullrequestreview-6079109521). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T18:42:37Z. **Review:** APPROVED --- Reviewed and verified `1b6a0795161ead0e1b6bd5f87b4a32d8ce6b6947` merged onto `main` (`63bcca43`) on Windows 11 x64 (`cargo test -p xtask --locked policy::tests::repository_passes_policy`: `1 passed`, `191 files ok`; `cargo clippy --locked -p victory-gpu --all-targets -- -D warnings`: clean; `cargo test --locked -p victory-gpu --lib pipeline::library::`: `12 passed, 0 failed`, including `stale_staging_files_are_swept`). `sweep_staging` and `staging_pid` (`crates/victory-gpu/src/pipeline/library.rs:59-87`) cleanly restrict cleanup to immediate regular `<cache-file>.tmp-<pid>-<n>` staging files and ignore locked-file/directory errors so live reads and saves continue unaffected. Two minor non-blocking notes: - `use_pipeline_cache` (`library.rs:46-49`) runs `sweep_staging` before `DIR.set(dir)`; guarding the sweep with `DIR.get().is_none()` would ensure a repeated call cannot sweep an active staging file of the current `pid` without waiting `STAGING_KEPT`. - `rustfmt --edition 2024 --check` flags the single-line `else { return };` and `else { continue };` at `library.rs:60, 63`.
Ingenioeren commented 2026-11-26 18:48:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Ingenioeren on 2026-11-26T18:48:30Z.


Thanks for the review. Commit c5d6577 moves the staging sweep inside DIR.get_or_init. Only the winning initializer sweeps, and the cache path is published after it finishes. I also expanded the new single-line let else statements.

A Windows temp-directory probe reproduced the reported behavior on the previous head. A second initialization removed a same-process staging file. With this change, the initial sweep still removed the cut write, and both a live staging file and a file in a later ignored directory survived. All 12 pipeline-library tests passed with the PR applied to 63bcca4. Clippy with warnings denied and the staged asset policy passed.

AI-assisted verification with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7200874046 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2510#issuecomment-7200874046). Originally posted by [Ingenioeren](https://github.com/Ingenioeren) on 2026-11-26T18:48:30Z. --- Thanks for the review. Commit `c5d6577` moves the staging sweep inside `DIR.get_or_init`. Only the winning initializer sweeps, and the cache path is published after it finishes. I also expanded the new single-line `let else` statements. A Windows temp-directory probe reproduced the reported behavior on the previous head. A second initialization removed a same-process staging file. With this change, the initial sweep still removed the cut write, and both a live staging file and a file in a later ignored directory survived. All 12 pipeline-library tests passed with the PR applied to `63bcca4`. Clippy with warnings denied and the staged asset policy passed. AI-assisted verification with OpenAI Codex.
Dukestar69 commented 2026-11-26 18:50:15 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T18:50:15Z.

Review: APPROVED


LGTM — verified on Windows against origin/main (63bcca4).

  • Sweeping <file>.tmp-<pid>-<n> regular staging files for the three pipeline cache files (immediately for the current PID, after 10 minutes for other PIDs) cleans up leftovers from interrupted atomic writes without risking active writers or unrelated files/directories.
  • cargo test -p victory-gpu --lib pipeline::library:: -- --test-threads=1: 12 passed, 0 failed (including stale_staging_files_are_swept).
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6079174064 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2510#pullrequestreview-6079174064). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T18:50:15Z. **Review:** APPROVED --- LGTM — verified on Windows against `origin/main` (`63bcca4`). - Sweeping `<file>.tmp-<pid>-<n>` regular staging files for the three pipeline cache files (immediately for the current PID, after 10 minutes for other PIDs) cleans up leftovers from interrupted atomic writes without risking active writers or unrelated files/directories. - `cargo test -p victory-gpu --lib pipeline::library:: -- --test-threads=1`: 12 passed, 0 failed (including `stale_staging_files_are_swept`). - `cargo clippy -p victory-gpu --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2510:upstream-pr/2510'
git switch 'upstream-pr/2510'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2510'
git switch 'upstream-pr/2510'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2510'
git switch 'upstream-pr/2510'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2510'
git switch 'main'
git merge --squash 'upstream-pr/2510'
git switch 'main'
git merge --ff-only 'upstream-pr/2510'
git switch 'main'
git merge 'upstream-pr/2510'
git push origin 'main'
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!2508
No description provided.