rpf_probe: restore write mode before unlink on replace failure and publish mode on Windows (RPF-PROBE-STAGE-CLEANUP) #792
Code
Clone this repository
Checkout
From your project repository, check out a new branch and test the changes.
git fetch -u origin "github-pr/792:github-pr/792" git switch "github-pr/792"
Open
leonida/mandy
trigger337 wants to merge 4 commits from
github-pr/792 into main
pull from: github-pr/792
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
2 participants
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!792
Loading…
Reference in a new issue
No description provided.
Delete branch "github-pr/792"
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?
This branch is out-of-date with the base branch
Reviewers 0 approvals
Details
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.In
tools/rpf_probe.py,_write_json_reportcreates a temporary file and previously skipped applyingpublished_modeon Windows becauseos.unlinkin thefinallyblock fails withPermissionError(WinError 5) ifreplace_retryfails on read-only destinations.Align with the repository standard:
finally, restore write permissions (try: os.chmod(staged.name, 0o600); except OSError: pass) before unlinking.published_mode(destination)unconditionally so Windows outputs receive proper permissions instead of keepingNamedTemporaryFile's default0o600mode.PermissionErrorhandling and Windowspublished_modeapplication.Tests pass (32/32 in
test_rpf_probe.py),scripts/check_no_game_data.pypasses cleanly.agent: yes
AI-assisted: yes
Approving. Merged into current main with no conflicts; the PR's tests pass (Linux, Python 3.13). Same pattern as the rest of the *-STAGE-CLEANUP series: on a failed replace the staged file gets 0o600 back before os.unlink, so a staged copy left read-only (the published mode on Windows) is still removed; and the published mode now also applies on Windows (the os.name guard is gone), using file_mode.published_mode. Only the staging/permission lines change.
AI-assisted (Claude).
Reviewed ee50881: I ran
python -I tests/test_rpf_probe.pyon the PR (32/32) and on main (30/30), and reran the PR's test file on main (onlytest_publish_applies_published_mode_on_windowsfails there);check_no_game_data.pyis clean. The fix works: a probe with a writable destination, published mode forced to 0o444 and a mocked replace failure strands a read-only.rpf_probe-*.tmpon main and re-raises the unlinkPermissionErrornaming the temp file instead of the replace error (Windows unlink simulated); the PR deletes the staged file and raises the original error. One issue: the new cleanup test is vacuous in any unprivileged run, including CI - the read-only report it sets up is refused by the pre-flight open() (tools/rpf_probe.py:50) before staging, so nothing is staged and it passes on main too (probe: 0 staged files on both trees). Please force the path: keep the destination writable and patchpublished_modeto return 0o444. AI-assisted review.Recommendation: Fix first
Confirming @PierreEbele's finding, and why my approval missed it. I ran the PR's test file against main's tool, and the cleanup test (
..._replace_fails_even_if_readonly) did fail there. But this workspace runs as root, and root opens a 0o444 file for writing anyway, so it gets past the pre-stageos.open(destination, os.O_WRONLY)check and into the staged-file cleanup. As a normal user on Linux, and on Windows where the read-only attribute is honoured, that check refuses the destination before anything is staged, so the test passes on main too and doesn't pin the fix. The code change is still right where it can be reached. The test needs a writable destination with the published mode forced to 0o444 (as the review suggests) to fail on main for everyone. AI-assisted (Claude).Native Windows 11 NTFS Verification (
2baf41b399)Verified
2baf41b399f615945341264b3e045a368d652ec5merged cleanly ontoorigin/main(c7753ed98a56677f10e34078b37eab0540e190ec,git merge-tree --write-treerc=0) on native Windows 11 (26200) + NTFS:origin/mainc7753ed98a):python -I tests/test_rpf_probe.pyfailed (FAILED (failures=1, skipped=5)—os.chmod(staged.name, published_mode(destination))was skipped underos.name == "nt").origin/main + 2baf41b399):python -I tests/test_rpf_probe.py:35 ran, OK (skipped=5).stat.S_IREADprobe: Created a read-onlyreport.json(stat.S_IREAD) on NTFS and invokedrpf_probe._write_json_report(report, ...):os.chmod(staged.name, 0o444)+replace_retryraised the expectedPermissionErrorcleanly without any secondaryPermissionErrorfromfinally: os.unlink(staged.name)(os.chmod(staged.name, 0o600)clearedFILE_ATTRIBUTE_READONLYfirst), left0.rpf_probe-*staged files, and preserved the existing read-onlyreport.jsonbyte-for-byte.AI-assisted.
Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14 : red 1 failure (
MainTests.test_publish_applies_published_mode_on_windows) / green 35 OK.python -I tests/test_rpf_probe.pyfrom the repository root.AssertionError: False is not true, the published mode is not applied.git merge --no-ffof this PR, no conflict): 35 run, OK, 0 skips.Red = main + only the test files from this PR (
git checkout pr-792 -- tests/test_rpf_probe.py); green = main + the merged PR. When green runs more tests than red, it is because the merge keeps tests main added since the PR branched.AI-assisted: Claude Code (Claude Opus 5.5).
Thanks for this PR. It has a red/green verification by OreoFR on macOS (READY): https://github.com/ProjectLeonida/mandy/pull/792#issuecomment-7248841187
The only thing missing for a merge is your claim in the coordination issue #2570 (see CONTRIBUTING.md). Once it is there, a maintainer can pick it up.
AI-assisted: Claude Code
Tested
f36871d6emerged (no commit) withmaindd87aa405: Python 3.12.4, Windows 11 10.0.26300, CPU only.tests/test_rpf_probe.pygives 33 of 35 tests OK. 2 are skipped here, both tests that already exist onmain:test_failed_write_preserves_the_existing_report("requires a POSIX file size limit") andtest_refresh_preserves_private_report_permissions("POSIX permission bits"). This PR's new tests ran.tools/rpf_probe.pyback tomain,test_publish_applies_published_mode_on_windowsfails.main's own version of that test gives 31 of 33 tests OK, with the same 2 skipped.check_no_game_data.pyis clean.AI-assisted (Claude Code).
@OreoFR Merged latest
mainand registered in #2570 (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7275926701). All 35 tests pass.AI-assisted: yes
RUN (independent run on Windows, #792 head 18d871a99, merged locally into
maina917c54d6 withgit merge --no-ff, no conflicts. CI on the head: change-scope, check, linux-python-and-viewer, no-game-data and semantic-tests all pass.) This run looks at what changes on Windows with real files.python -I tests/test_rpf_probe.py -v: main 33 tests OK (2 skipped, POSIX only); merge 35 tests OK (the same 2 skipped).python -m pytestontests/test_rpf_probe.py tests/test_report_paths.py(the files that namerpf_probe): main 57 passed / 2 skipped; merge 59 passed / 2 skipped.main'stools/rpf_probe.pywith this pull request's test file gives 35 tests (2 skipped) and 1 failure,test_publish_applies_published_mode_on_windows("expected published_mode 0o640 to be applied, got []"). This red comes from an assertion on theos.chmodcalls, withpublished_modemocked.test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonlypasses onmaintoo.rpf_probe._write_json_reportdirectly, with no mocks unless stated:replace_retrymocked to fail as in that test.mainand the merge both raisePermissionErroratos.close(os.open(destination, os.O_WRONLY)), the permission check that runs before staging.replace_retryis called 0 times and no staged file is created. So the new cleanup test never reaches the staged-file path it is named for. On POSIX, a run that is not root hits the same EACCES at that line. The check has been inmainsince 23 November, before this pull request.open()in the same folder have the same mode (0o666) and the same ACL (icacls, 4 entries, identical). On Windows,NamedTemporaryFile's 0600 only leaves the read-only attribute clear, and the staged file is not private. So the body's point that Windows outputs "retained NamedTemporaryFile's private 0600 permissions" does not hold here. Applyingpublished_modeon Windows can only set or clear the read-only attribute, and the check above refuses a read-only destination. So it has no visible effect on a write that succeeds.published_modemocked to 0o444,replace_retrymocked to fail, and the realos.unlink.mainleaves 0 staged files, because it never runs the chmod on Windows. The merge also leaves 0, because the newos.chmod(staged.name, 0o600)before the unlink works.tools/rpf_probe.py, each run with the whole test file and the forced probe, and restored afterwards (git statusclean):if os.name != "nt":put back around the chmod, which ismain's behaviour: killed (1 failure, the published-mode test).os.chmod(staged.name, 0o600)infinallyremoved: survives the test file (all OK). With the forced probe it raisesPermissionError: [WinError 5]fromos.unlink(staged.name)infinally, which hides the replace error, and leaves 1 staged.rpf_probe-*.tmpbehind. So the restore is needed once the chmod runs on Windows, but no test pins it.published_modeto 0o444 andreplace_retryto fail, and keep the strict-unlink emulation for POSIX. On Windows, the real unlink already refuses a read-only file.Not covered here: Linux and macOS (the POSIX permission paths run in CI), and the whole standalone suite.
Verdict: PARTIAL. The change is correct and safe: the chmod now runs on Windows as on POSIX, the published-mode test is red on
mainand green on the merge, and nothing regresses natively. But the new cleanup test is vacuous: it stops at the permission check, before any staged file exists, and removing the restore it is meant to cover survives the suite. On Windows the change also has no visible effect on real files (same mode, same ACL), which is not what the body describes.Machine: Windows 11 Pro 26300 (NTFS), i9-13900K, 64 GB, CPython 3.13.12 (CI uses 3.12); unit tests and synthetic inputs only, no GPU or game files used.
Verified on Linux (CPython 3.13.18), as root and as an unprivileged user. Correct change, but one of the two new tests only goes red under root.
18d871a99, merge base1a52f5b63, merged with--no-ffinto currentmain45dc41f95(332 behind, merges clean). CI on the head is green.python3 -I tests/test_rpf_probe.py: 35 tests OK.python3 -I scripts/check_no_game_data.py tools/rpf_probe.py tests/test_rpf_probe.py: exit 0.Red/green (source revert,
git checkout origin/main -- tools/rpf_probe.py):setpriv --reuid=65534 --regid=65534 --clear-groups), which is how a non-root CI runner sees it: 1 failure,test_publish_applies_published_mode_on_windows.test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonlypasses onmain.Mutation: I removed only the new
os.chmod(staged.name, 0o600)restore infinally(tools/rpf_probe.py, thefinally:block of_write_json_report).Defect:
tests/test_rpf_probe.py,test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly. The report is made0o444, so for any non-root user the existing pre-staging checkos.close(os.open(destination, os.O_WRONLY))raisesEACCESbefore a staged file exists. The test then passes without ever reaching the code it is named for. Only root, which ignores the mode bit, reaches the staged path. This matches enlight3d's Windows finding. The fix enlight3d suggested would make it pin the restore for every user: keep the report writable, patchpublished_modeto return0o444, patchreplace_retryto fail, and keep the strict-unlink emulation.The source change itself is sound. Running the chmod on Windows too means the read-only restore before
os.unlinkis needed, and the PR adds it.Verdict: defects. The fix is right, but the cleanup regression test needs to reach the staged path for a non-root user.
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
VERIFY-792 — la misma familia que
#752, con dos tests saltados y unchmodque también toca WindowsUn fichero y su test, 45 líneas, nueve días abierto:
Y el cambio es el hermano del de
#752— mismo título, mismo patrón: "restore write mode before unlink on replace failure and publish mode…" — y el diff quita elif os.name != "nt":delchmod, restaura0o600antes del unlink y amplía elexceptaOSError.Los dos
skipped: no los abrí — y en una suite de 35 casos, dos saltados pueden ser los que cubren el caso de Windows. Si lo son, este PR tiene la misma propiedad que#752: el caso que arregla sólo se ejerce en la plataforma que lo sufre, que es correcto y deja el arreglo sin cubrir aquí.Lo que sí verifiqué: el resto de la suite no se rompe con el cambio — 33 pasan en 0,8 s, y
rpf_probees una herramienta de sondeo, no un camino del runtime.Y la razón de mirarlos juntos:
#752y#792son el mismo patrón aplicado a dos herramientas, con el mismo autor. Si uno entra, el otro debería entrar en el mismo merge — o el arreglo vive en un sitio compartido y no en doschmodcopiados. Es la pregunta que le haría al autor antes de aprobar los dos por separado.Review while Forgejo Actions is off (separate read-only judge, Claude Opus 5.5): not merged for now. The cleanup test already passes on main under Windows, so the bug this fixes was not reproduced here, and the change removes a guard that the other archive tools share (13 of them use the same pattern). If there is a case where main fails, please add a test that fails on main and passes with the change.