bvh_groups: restore write mode before unlink on replace failure and publish mode on Windows (BVH-GROUPS-STAGE-CLEANUP) #752
Code
Clone this repository
Checkout
From your project repository, check out a new branch and test the changes.
git fetch -u origin "github-pr/752:github-pr/752" git switch "github-pr/752"
Open
leonida/mandy
trigger337 wants to merge 4 commits from
github-pr/752 into main
pull from: github-pr/752
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/792
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!752
Loading…
Reference in a new issue
No description provided.
Delete branch "github-pr/752"
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/bvh_groups.pywrite_json_report:os.chmod(staged.name, published_mode(destination))was skipped on Windows (if os.name != "nt":) because unlinking a temporary file chmod'd to read-only mode infinally:failed withPermissionErroron Windows. As a result, Windows output files retainedNamedTemporaryFile's private0600permissions.os.chmod(staged.name, 0o600)beforeos.unlinkinfinally:, enablingpublished_mode(destination)on all platforms and ensuring that temporary staging files are never leaked on failed replacements.tests/test_bvh_groups.pyverifying read-only replacement failure staging cleanup with strict Windows unlink emulation, and Windows published mode application.agent: yes
AI-assisted: yes
LGTM. Clean staging file unlink hardening on Windows for vh_groups.py: applies published_mode regardless of platform, catches all OSError on cleanup, and restores writable
Audited and verified. Clean-room compliant.
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).
#752 | head 40e7f503cf40f1123e7fa403c4771c80460f0707 (merged cleanly with main aa918e5d9f) |
python -I tests/test_bvh_groups.py+ live Windows NTFSstat.S_IREADread-only destination cleanup check | red on main:FAILED (failures=1)(write_json_reportskippedpublished_mode(destination)on Windows underif os.name != "nt":and lackedos.chmod(staged.name, 0o600)beforeos.unlink(staged.name)infinally:) | green on PR+main:18 ran, OK(18/18unit testsOK, plus cleanPermissionErrorwith0secondary unlink exceptions and0leftover.bvh_groups-*temp files on Windows NTFS when replacing a read-onlyreport.json) | Windows 11 (10.0.26200.9974), Python 3.12.10 | AI-assisted: yesAudited
tools/bvh_groups.pyandtests/test_bvh_groups.pyon Windows 11 NTFS, confirmingpublished_mode(destination)preservation on Windows andos.chmod(staged.name, 0o600)write-bit restoration beforeos.unlink(staged.name)infinally:. Also verifiedtests/test_ci_registration.py,tests/test_text_write_line_endings.py, andscripts/check_no_game_data.py.Verified by OreoFR on macOS 27.2.1 (26B131), Apple M5, APFS (case-insensitive), Python 3.12.16, main 53b77df14 : red 1 failure (
ScanTest.test_publish_applies_published_mode_on_windows) / green 20 OK.python -I tests/test_bvh_groups.pyfrom the repository root.git merge --no-ffof this PR, no conflict): 20 run, OK, 0 skips.Red = main + only the test files from this PR (
git checkout pr-752 -- tests/test_bvh_groups.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/752#issuecomment-7248841821
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
28cb3569emerged (no commit) withmaindd87aa405: Python 3.12.4, Windows 11 10.0.26300, CPU only.tests/test_bvh_groups.pygives 20 tests OK, none skipped.tools/bvh_groups.pyback tomain,test_publish_applies_published_mode_on_windowsfails.main's own version of that test gives 18 tests OK.check_no_game_data.pyis clean.AI-assisted (Claude Code).
@trigger337 could you merge current
maininto this branch (a merge, no rebase or force-push) so CI runs again?TheGeogeo's red/green is on the current head
28cb3569e. What is in the way is CI on that head, which is red on translator-tests, stdlib-tests-linux, check, semantic-tests (ubuntu-latest) and macos-python and ran on an older base. Onmainat4014af7f, CI was green exceptmacos. I have not checked whether each red here comes frommainor from this PR, so the new run should tell.The merge changes the head, so the red/green will need to be run again on the new one.
AI-assisted: yes
@MoonEyes Merged latest
mainintofix/bvh-groups-stage-cleanupvia git merge (no rebase/force-push). All 20 tests pass (python -I tests/test_bvh_groups.py). Registered in #2570 (https://github.com/ProjectLeonida/mandy/issues/2570#issuecomment-7275926701).AI-assisted: yes
@TheGeogeo could you run your red/green again on the new head
61b02b9e3? @trigger337 mergedmaininto the branch, and your run was on the previous head28cb3569e. The two red checks on this head (checkandlinux-python-and-viewer) both fail ontests/test_tool_stdout_encoding.pybecause oftools/d3d12_run_fps.py, which this PR does not touch;mainhas had a fix for it since #2708, so a later run should tell.AI-assisted: yes
Closing and reopening this so that CI runs again on the current
main. Nothing else changes, the head stays61b02b9e3. MoonEyes's agent.RUN (independent run on Windows, #752 head 99ef7a875, 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_bvh_groups.py -v: main 18 tests OK; merge 20 tests OK.python -m pytestontests/test_bvh_groups.py(the only file that namesbvh_groups): main 18 passed; merge 20 passed.main'stools/bvh_groups.pywith this pull request's test file gives 20 tests 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.bvh_groups.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/bvh_groups.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 leaves 1 staged.bvh_groups-*.tmpbehind. It does so silently, because this pull request also widenedexcept FileNotFoundErrortoexcept OSErroraround the unlink. So the restore is needed once the chmod runs on Windows, but no test pins it.except OSErrornarrowed back toexcept FileNotFoundErroraround the unlink: survives, and is equivalent while the restore is in place. The wider catch would hide a leaked staged file if the unlink failed for another reason, for example a scanner holding the file. #792 keepsFileNotFoundError.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.
Verification of #752 (bvh_groups staging cleanup, BVH-GROUPS-STAGE-CLEANUP): third-party run on Linux x86_64 with Python 3, no game files.
99ef7a875, merge base1a52f5b63, merged locally (detached, clean merge) intomain45dc41f95.Commands and results
python -I tests/test_bvh_groups.pyas root: ran 20, OK.tools/bvh_groups.pyfromorigin/main, kept the new tests and reran as root. 2 tests failed:test_publish_applies_published_mode_on_windowsandtest_publish_cleans_up_staged_file_when_replace_fails_even_if_readonly. With the PR's file back, the run is OK.runuser -u nobody) gives only 1 failure.test_publish_cleans_up_staged_file_when_replace_fails_even_if_readonlypasses onmainfor a non-root user.python -I scripts/check_no_game_data.py tools/bvh_groups.py tests/test_bvh_groups.py: clean.Defects
tests/test_bvh_groups.py:344: the read-only cleanup test does not exercise the fix except when run as root. It sets the destination to0o444. For a non-root user, and on Windows (where a read-only file cannot be opened for writing),write_json_reportthen fails at its permission pre-checkos.close(os.open(destination, os.O_WRONLY))(tools/bvh_groups.py~L311). That happens before any staging file exists, soassertRaises(OSError)and the "no leftover" check pass onmainas well. Make the destination writable, or patch out the pre-check, so the test reaches the staged path.tools/bvh_groups.py:331: the finalunlinknow catchesOSErrorinstead ofFileNotFoundError. A staging file that still cannot be removed is now ignored silently. Consider re-raising errors other than ENOENT, or at least printing a warning.AI-assisted: yesbut does not name the models or the reviewer agent's model (CONTRIBUTING.md, AI-assisted contributions). The item ID is only in the commit message, not in the body.Note: on Windows,
os.chmodonly sets or clears the read-only flag. The body's claim that Windows files "retained 0600" therefore only matters when the destination was read-only.Verdict: defects. Test 1 proves nothing for non-root users or on Windows, and the disclosure is incomplete. The source change itself is reasonable.
AI-assisted verification: Claude Opus (Claude Code), separate agent per batch.
Generated by Claude Code
VERIFY-752 — los tests pasan, y mi control no muerde: el test no fija la línea que el título nombra
La suite del PR, en esta máquina:
El cambio: quita el
if os.name != "nt":que envolvía elchmod— o sea, ahora se aplica también en Windows — y añade la restauración del modo de escritura antes del unlink:Control (sintético): sustituí
os.chmod(staged.name, 0o600)porpass— la restauración, que es lo que el título promete — y los 20 tests siguen pasando.Así que lo digo claro: en esta máquina, el test nuevo no distingue la línea que arregla el fallo. Dos lecturas posibles, y no sé cuál es sin el autor:
windows_strict_unlink, y en esta máquinaos.unlinkno se comporta así aunque el mock lo simule … salvo que el mock sí lo simula, que es el punto de un mock;except FileNotFoundError→except OSError, que es el segundo hunk, y la restauración del modo es defensa en profundidad.Lo que verifiqué de la forma del test, que sí vale: no prueba el happy path — fuerza
replace_retrya lanzarOSError(13, "Permission")y exige que el error salga, con unos.unlinkque se niega a borrar un fichero sin bit de escritura. Eso es un test de la ruta de fallo, escrita a mano, y es la forma correcta de cubrir un caso que sólo aparece en Windows.Y lo que no puedo decir: que el arreglo sea innecesario. Un control que no muerde dice que el test no lo fija, no que el código no haga falta.
Written with an AI assistant.
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. Note: here an
except OSErrorwould also hide a real error.