[pr-fix][startup][shaders] Keep the primary library when a pending file is empty #275
Loading…
Reference in a new issue
No description provided.
Delete branch "andrewpozdnakov7-jpg/Darner:fix/preserve-primary-with-empty-pending-library"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Contributor role (optional)
What it changes
When a pending pipeline file is zero bytes, a later startup can rename it over the populated primary. The old primary then disappears. Check the pending length while the writer lease is held and fall back to reading the primary for a zero-byte snapshot. A nonempty pending file still follows the normal promotion path.
Report: the second-start regression on main. Prepared by andrewpozdnakov7-jpg (GitHub profile).
How it was tested
17069e3onf3840d7.1bc75a3: hold the writer lease through empty-file cleanup and the primary read; use the primary for an empty legacy pending file. Windows fixtures passed with and without the lease, with a nonempty pending file, and in a combined read with #232. The focused Cargo check and asset policy passed. Independent checks on17069e3are in issuecomment-865701.1bc75a3: both workspace Clippy gates, asset policy and all 32 targeted pipeline-library tests passed. Review resultChecklist
Checked for overlap
Independent Windows build, gate, and code-read review of
17069e3eb(based onmainf3840d73d). Not run in-game.Environment
x86_64-pc-windows-msvc), MSVC 19.44.35230.Measured results
cargo clippy --workspace --all-targets --locked -- -D warnings): PASScargo clippy --workspace --all-targets --all-features --locked -- -D warnings): PASScargo xtask policy: PASS (asset policy: 555 files ok)cargo test --locked -p darner-gpu --lib pipeline::library: PASS (31 passed; 0 failedin 1.06 s, including newan_empty_pending_library_does_not_replace_the_primary)Findings (blocking)
_writerlock then re-readsnextunlocked (crates/darner-gpu/src/pipeline/library.rs:742-749): Whenwriter()succeeds andnextis 0 bytes,.filter(...)turnsSome(_writer)intoNone, dropping the writer lease, and then enters theelsebranch and re-readsnextunlocked viaBlob::read(&next)?. If a competing process acquiresLOCK_FILEin that window and locks/replacesnext, an I/O error fromBlob::read(&next)?bubbles up toload_cache(library.rs:763-767), which treats it as an unreadable adapter cache and returnscache = None(disabling pipeline library writes for the whole session).host-pipelines.nextfile on disk (library.rs:742-751, test line 39):_writerlease (guaranteeing no active writer exists), the 0-byteNEXT_FILEis left behind rather than removed.NEXT_FILEon disk causesreplace_library(library.rs:1855,if !next.try_exists()? && std::fs::rename(&tmp, &path).is_ok()) to skip direct replacement ofLIBRARY_FILEon the next save, causesmade_by_another_build(library.rs:699) to see a phantom library even whenLIBRARY_FILEis absent, and repeats the lock + metadata + read dance on every launch._writerbound instead of.filter(...); while holding_writer, checkmetadata(&next)(handlingNotFound), and ifmeta.is_file() && meta.len() == 0, remove&next(let _ = std::fs::remove_file(&next);) and fall straight through toBlob::read(&path)without re-reading&next.Minor non-blocking note
load_cache's legacy fallback (library.rs:776-780) still matchesSome(_)onBlob::read(&root.join(NEXT_FILE)), so a 0-byte legacyNEXT_FILE(Some(Blob::None)) will still shadow legacyLIBRARY_FILE; matchingSome(Blob::None) | Nonethere fixes the legacy read consistently.Verdict: Changes requested (keep
_writerheld while checking/removing the 0-byteNEXT_FILEinstead of dropping the lease via.filter(...)and re-reading&nextunlocked).AI-assisted: yes (Gemini 4 Neon).
Thanks, @lewis499.
1bc75a3keeps the writer lease while it removes the zero-byte scoped pending file and reads the primary. The no-lease path still leaves the pending file in place. The legacy read now uses the populated primary when its pending file is empty as well.The Windows fixture checked all three paths and confirmed that a nonempty pending file still promotes. I also checked the combined source with #232 using a busy primary and a nonempty pending file. The focused Cargo type check and asset policy passed. Your independent checks on
17069e3are recorded in the PR.PASS
Follow-up verification of
1bc75a3d7e40cb2d78fcd3dcab49411ae07a2674(basef3840d73d3504c30218debfbc8795b9225447317).Environment
Windows 11 Pro 26H2 build 26300.10075; Intel Core i9-14900K; NVIDIA RTX A2000 12 GB (driver 621.47); Rust 1.98.1 x86_64-pc-windows-msvc; MSVC 19.44.35230.
Measured results
cargo clippy --workspace --all-targets --locked -- -D warnings: PASS.cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: PASS.cargo xtask policy: PASS (555 files ok).cargo test --locked -p darner-gpu --lib pipeline::library: 32 passed, 0 failed, 0 ignored.Code-read audit
read_scopedretains the writer lease while checking and removing an emptyNEXT_FILE, then reads the primary; when another writer owns the lease it usesread_pending_or_primarywithout promoting or deleting that writer's file (crates/darner-gpu/src/pipeline/library.rs:738-765).:2349-2377). The metadata/exists/rename error path propagates toload_cache, which warns and falls back to the primary rather than silently promoting an unreadable pending file (:752-765,768-781).Not run in-game.
AI-assisted: yes (GitHub Copilot, Auto mode).
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.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.