Skip to content

GPU: sweep cut pipeline-cache staging files - #2510

Open
Ingenioeren wants to merge 2 commits into
Marvisak:mainfrom
Ingenioeren:fix/2496-pipeline-staging-sweep
Open

Ingenioeren wants to merge 2 commits into
Marvisak:mainfrom
Ingenioeren:fix/2496-pipeline-staging-sweep

Conversation

@Ingenioeren

@Ingenioeren Ingenioeren commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@Ingenioeren
Ingenioeren force-pushed the fix/2496-pipeline-staging-sweep branch from 6638591 to 433ec5b Compare November 25, 2026 16:04
Since Marvisak#1660 each cache write stages in `<file>.tmp-<pid>-<n>`, and a write
cut by an exit (TerminateProcess) leaves that file for good: no later run
reuses the name and nothing removed it.

`use_pipeline_cache()` sweeps the staging files of the three cache files:
this process's at once, other processes' after 10 minutes untouched (the
folder is shared and nothing stops a second instance). Only regular files
named exactly `<cache file>.tmp-<digits>-<digits>` go.

Part of Marvisak#2496: its other half (an exit save that waits for a running
one) is Marvisak#2328.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Ingenioeren
Ingenioeren force-pushed the fix/2496-pipeline-staging-sweep branch from 433ec5b to 1b6a079 Compare November 25, 2026 16:04
@Ingenioeren Ingenioeren changed the title GPU: sweep cut pipeline-cache staging files; an exit save waits for a running one GPU: sweep cut pipeline-cache staging files Nov 25, 2026
@Ingenioeren

Copy link
Copy Markdown
Contributor Author

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.

Bebrik229 pushed a commit to Bebrik229/VIctory that referenced this pull request Nov 25, 2026
github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
@futurepro62

Copy link
Copy Markdown

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

Tested

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.

BastienRodz added a commit to BastienRodz/VIctory that referenced this pull request Nov 26, 2026

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

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

Copy link
Copy Markdown
Contributor Author

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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants