D3D12-LOADER-PUBLISH-CONCURRENT-RENAME: tolerate Windows AccessDenied when destination already matches #2675
No reviewers
No assignees
Labels
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
No project
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
No due date set.
Reference
leonida/mandy!2675
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/d3d12-loader-publish-concurrent-rename"
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?
Pull request successfully merged and closed
Claimed in #2570 as
D3D12-LOADER-PUBLISH-CONCURRENT-RENAME(#issuecomment-7261851356).What and why
In
d3d12/crates/leonida-loader/src/publish.rs,write_if_changed(path, bytes)stages into a per-process/per-call temp file and publishes viastd::fs::rename(&staging, path). On Windows, if a peer runner has already mapped/openedpath(e.g. withoutFILE_SHARE_DELETE),std::fs::renamefails withERROR_ACCESS_DENIED(os error 5/PermissionDenied) even whenpathalready holds the exactbytesbeing published.This change extracts
publish_staging(), cleans up&staging, and returnsOk(())whenstd::fs::renamefails andstd::fs::read(path)already equalsbytes, while still returningErrwhen the destination is missing or holds different bytes.Verification (Red -> Green)
Hardware / OS: native Windows 11 Pro (
10.0.26200), AMD Ryzen 7 7800X3D, Rust1.98.rename_denied_succeeds_when_destination_already_matches_bytesfailed deterministically withOs { code: 5, kind: PermissionDenied, message: "Access is denied." }.main40e7fe69d):cargo test -p leonida-loader --lib publish::tests—4 passed; 0 failed(75/75fullleonida-loader --libPASS).python -I scripts/check_no_game_data.py d3d12/crates/leonida-loader/src/publish.rs— PASS.AI-assisted: Antigravity (Gemini 4 Neon)
Static review: no blocker found.
publish_stagingkeeps the original rename error unless the destination already contains exactlybytes, which is the correct idempotent outcome.Optional follow-up: the claim mentions concurrent writers, while the tests simulate a locked destination rather than two publishers racing. A small barrier-synchronized multi-writer stress test would strengthen coverage, but I do not see it as a merge blocker.
I did not execute the Rust tests locally. AI-assisted: yes.
Independent Windows verification of
d29dfbc49onmain497bdd039(clean merge,0f93f4573). Native Windows 11, MSVC x64, Rust 1.98.1,cargo test -p leonida-loader --lib.main+ this PR's two tests, withpublish_stagingholdingmain's unchanged rename-or-error step (the function doesn't exist onmain).rename_denied_succeeds_when_destination_already_matches_bytesfails withOs { code: 5, kind: PermissionDenied }; the different-bytes test passes, as it should either way.main+ this PR. All 4publish::testspass; whole crate 83 passed, 0 failed (main: 81 + these two).On imShangLi's follow-up (a share-mode lock vs. what a peer really holds), two local probes on the merged tree (not part of the PR), each with
same= destination already holds the bytes being published:fs::renamepublish_staging(same)publish_staging(different)LoadLibraryExWLOAD_LIBRARY_AS_IMAGE_RESOURCEon a copied system DLL, no handle left open, nothing run)Ok, staging removedCreateFileMappingW+MapViewOfFile, file opened with share read+delete, handle closed)OkOk(replaced)So the case the PR is for is real without any share-mode lock: a published file that another runner has loaded as an image can't be replaced, and the PR turns that into success exactly when the bytes already match. A file only mapped as data is replaced normally, so nothing changes there.
GPUs tested: n/a (CPU/file-system tests). AI-assisted: yes.
Independent three-process publication test under Wine for
d29dfbc4. I used GitHub’s mergeb1bde49eand its based367675c, with Windows x64 MSVC-target Rust 1.98.1 on Wine 11.22 (CachyOS x86-64).I tested the public
write_if_changedentry point. The only local change in both builds is the same checkpoint just after the staging write, before the rename. Three distinct processes write to the same initially absent destination. The controller verifies all three PID-specific staging files and their payloads before letting the first writer publish. It holds the winning file open withFILE_SHARE_READ(no delete sharing), then lets the two other writers continue. One staged the same bytes and the other staged different bytes.MEASURED (6 rounds per revision)
PermissionDenied(OS error 5)Ok(())PermissionDenied(OS error 5)PermissionDenied(OS error 5)In all 12 rounds the first writer succeeded, its bytes survived while the handle was held, no staging files remained after the writers exited, and a different-byte publication succeeded after the handle closed. A second agent recomputed the counts from the raw logs. Synthetic CPU-only test, AI-assisted.
Merged on head
d29dfbc49. @Kal0s-design ran the red/green on this head (Windows 11, Rust 1.98.1); @merzleckeier checked three concurrent publishers under Wine on this head. CPU and file-system tests, no GPU. CI was green on this head and no test was run by the merger.Merged by MoonEyes. AI-assisted: yes (Claude Code).