Skip to content

D3D12-PIPELINE-CACHE-CONCURRENT-PUBLISH: tolerate Windows AccessDenied on concurrent cache publish - #2674

Merged
MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
bobcatchris:fix/d3d12-pipeline-cache-concurrent-publish
Nov 30, 2026
Merged

MoonEyes merged 1 commit into
ProjectLeonida:mainfrom
bobcatchris:fix/d3d12-pipeline-cache-concurrent-publish

Conversation

@bobcatchris

@bobcatchris bobcatchris commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Claimed in #2570 as D3D12-PIPELINE-CACHE-CONCURRENT-PUBLISH (#issuecomment-7261030254).

What and why

In d3d12/crates/leonida-pipeline/src/cache.rs, get_or_convert() stages a converted asset into a temporary file and publishes it via std::fs::rename(&tmp, &path). On Windows, when another thread/process concurrently publishes or holds &path open without FILE_SHARE_DELETE, std::fs::rename fails with ERROR_ACCESS_DENIED (os error 5 / ErrorKind::PermissionDenied). Currently get_or_convert() removes &tmp and propagates that error even though &path is already published on disk.

This change cleans up &tmp and returns Ok(path) whenever std::fs::rename(&tmp, &path) fails and path.is_file() is already true (a peer won the race), while continuing to propagate errors when &path is not present as a file on disk.

Verification (Red -> Green)

Hardware / OS: native Windows 11 Pro (10.0.26200), AMD Ryzen 7 7800X3D, Rust 1.98.

  • Red (before fix): concurrent_publish_while_reader_holds_destination_succeeds_and_cleans_staging failed with Os { code: 5, kind: PermissionDenied, message: "Access is denied." }.
  • Green (after fix, rebased onto main 40e7fe69d):
    • cargo test -p leonida-pipeline --lib — 8 passed; 0 failed.
    • python -I scripts/check_no_game_data.py d3d12/crates/leonida-pipeline/src/cache.rs — PASS.

AI-assisted: Antigravity (Gemini 4 Neon)

@ecox982745

Copy link
Copy Markdown
Contributor

Independent Windows cache publication test. I used 59399dad8 on 40e7fe69d (clean merge tree 113838f6c), Windows 11 build 26300 with MSVC and Rust 1.98.1. All eight tests on the exact PR tree passed.

I added a local probe with eight real writer threads per round. All eight first miss the key. One publishes, and a reader opens that hit with FILE_SHARE_READ only before seven waiting writers resume. Across ten rounds, main returned Windows error 5 to all 70 followers. The PR returned the published path to all 70 followers. Both arms left the expected bytes and exactly one file in the shard directory. The PR probe plus its existing suite passed 9/9. Synthetic temporary files, CPU only.

One diff/description mismatch: the recovery guard currently accepts any rename error when path.is_file() is true. The PR description names PermissionDenied and AlreadyExists. The probe verifies the error-5 case.

AI-assisted with OpenAI Codex (GPT-6.2 Sol).

@bobcatchris

Copy link
Copy Markdown
Contributor Author

Thanks for the independent 8-writer probe and for catching the description mismatch, @ecox982745! Updated the PR description to accurately reflect that the guard recovers on any rename error when path.is_file() is already true (keeping the verified commit 59399dad8 unchanged).

AI-assisted: Antigravity (Gemini 4 Neon)

@bobcatchris
bobcatchris force-pushed the fix/d3d12-pipeline-cache-concurrent-publish branch from 59399da to be2a1ab Compare November 30, 2026 11:20
@merzleckeier

Copy link
Copy Markdown
Contributor

Cross-process publication and retry on the current head

MEASURED. I tested be2a1ab0f on main 1d4949d58 (merge tree 527f01df2). Rust 1.98.1, x86_64-pc-windows-msvc via cargo-xwin, Wine 11.22 on CachyOS. The fixture starts two independent Windows writer processes and waits for both to enter the converter after missing the same cache key. The first publishes through Cache::get_or_convert. The controller opens its output with FILE_SHARE_READ before releasing the second process.

Case main PR
Reader stays open Second writer returned OS error 5 in all 15 rounds Second writer returned the published path in all 15 rounds
Reader is closed before the second writer continues Returned the path in all 15 rounds Returned the path in all 15 rounds
A directory occupies the final key after the miss OS error 5 in all 15 rounds, then successful retry and subsequent cache hit Same result in all 15 rounds

The open reader saw the expected 32,768 bytes before and after the second writer's attempt. The cache shard contained exactly one entry after every publish attempt and retry. In the directory case the failed attempt left only the directory entry, and retry after removing it left just the expected file. A further lookup reused that file without calling the converter again. Stock leonida-pipeline --lib tests passed 7 on main and 8 on the PR.

Scope: synthetic temporary files and Windows file-sharing semantics under Wine. AI-assisted: Codex (GPT-6.2 Sol).

@OreoFR

OreoFR commented Nov 30, 2026

Copy link
Copy Markdown
Collaborator

RUN - native Windows red/green (Verified by OreoFR) - Intel Core Ultra 7 155H, Windows 11 Pro 10.0.26300, CPU only.

  • Base: main afb511541; green = main + this PR at be2a1ab0f (git merge --no-ff, clean, merge tree 7b88c0b8d).
  • Red: same main, cache.rs taken from the PR with only the fix hunk (the match on std::fs::rename) put back to main's one-line rename; the new test is kept as is.
  • Toolchain: rustc 1.98.1 (48a229cea 2026-09-01), x86_64-pc-windows-msvc, pinned by d3d12/rust-toolchain.toml. Native Windows, not Wine.
  • Command (from d3d12/, one worktree and one target/ per arm): cargo test -p leonida-pipeline

Result: PASS

Arm lib tests failed
main afb511541 7 passed 0
red (main code + new test) 7 passed 1
green (main + PR) 8 passed 0
  • Red fails as the PR describes, on native Windows file sharing: concurrent_publish_while_reader_holds_destination_succeeds_and_cleans_staging panics at cache.rs:287 on unwrap() with os error 5 (access denied): the rename over a destination held open with FILE_SHARE_READ only is refused.
  • Green: the same test passes. It returns the published path, reads back RACE, and leaves exactly one file in the shard directory, with no .tmp-* left over. The 7 existing tests pass on all three arms. There are 0 doc-tests.
  • This matches merzleckeier's Wine run (error 5 on main, path returned with the PR) and the author's native red. It is now confirmed natively on a second machine.

Not covered:

  • Only the in-process test was run here. I did not re-run the two-process fixture or the 8-writer probe natively.
  • I did not test a rename that fails while path.is_file() is true for a reason other than a racing publisher. The guard accepts any rename error in that case, as the updated description says.
  • No game run: this path is the pipeline cache, and the test uses synthetic temporary files only.

This run was AI-assisted (Claude Code, oreofr-agent).

@ecox982745

Copy link
Copy Markdown
Contributor

Native Windows cross-process verification. I checked be2a1ab0f merged with ad36782c6 (tree abdf3818b), on Windows 11 build 26300 with Rust 1.98.1 MSVC release. This complements the Wine process check and the native single-process regression above.

Two separate publisher processes entered the converter after missing the same key. Each case ran 12 times per tree.

Case Base With PR
Reader holds the published file with FILE_SHARE_READ only Second publisher received OS error 5 in all 12 runs Second publisher returned the published path in all 12 runs
Reader closed before the second publisher resumed All 12 succeeded All 12 succeeded
A directory occupied the target after the miss Error propagated, then retry succeeded after the directory was removed Same result in all 12 runs

The published output always matched all 32,768 expected bytes. In the directory case the shard contained just the directory after the failed attempt. In all cases it contained just the published file after success, and the next lookup returned it without converting again. Stock library tests passed 7/7 on the base and 8/8 with the PR. Synthetic file I/O only. AI-assisted with OpenAI Codex (GPT-6.2 Sol).

@MoonEyes

Copy link
Copy Markdown
Collaborator

RUN · VERIFY-2674-RTX4060 · by MoonEyes (another person than the author) on head be2a1ab0f, with #2674 (be2a1ab0f) and #2656 (02de3303a) merged into main 8f41d7d01. Windows 11 Pro 26300, RTX 4060 8 GB, -SeriesS -FrameGen 2, diag build.

  • cargo test -p leonida-pipeline --locked: 8 passed; cargo test -p leonida --locked: 46 passed; 0 failed.
  • Game: two runs of 480 s, the person walking in the world from 345 s. The first after a full translation (846 s before the title, little of it steady) is not counted; the second, warm: the steady world after 151 s, about 450 s of it, about 52 m walked, no device loss, no unhandled exception, the process alive at the end. PASS for the gate of 300 s. The picture was not looked at; no frame rate is claimed.

AI-assisted (Claude Code).

@MoonEyes

Copy link
Copy Markdown
Collaborator

Merging. Head be2a1ab0f merges cleanly with main 8f41d7d01 and does not force a rebase of #2566. Run in the game of 450 s steady (RTX 4060, with both pull requests, no device loss) on this head; cargo tests green; checked by two other people. Merged by MoonEyes.

AI-assisted (Claude Code).

@MoonEyes
MoonEyes merged commit 51dbc5b into ProjectLeonida:main Nov 30, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants