Skip to content

glb_writer: retry a replace hit by a sharing violation; test ab_control_flow's metadata filters (#425, #441 follow-ups) - #728

Merged
ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
kotorvr:fix/review-followups-425-441
Nov 22, 2026
Merged

ItsNotRexed merged 2 commits into
ItsNotRexed:mainfrom
kotorvr:fix/review-followups-425-441

Conversation

@kotorvr

@kotorvr kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

Follow-ups to review points on two merged PRs. Claimed in #634 (comment), new item.

#425 (thanks @SourNuht): glb_writer.write_glb on Windows. The docstring says overlapping writers all publish complete files, but on Windows os.replace onto the same destination raises PermissionError (a sharing violation) while another writer is replacing it. In the #425 review, 8 threads × 40 writes to one path failed 43–152 of 320 calls. Now _replace retries only PermissionError, only on Windows, with a short backoff (about 1.3 s in total). A hold that lasts longer still raises and leaves the old file in place. Other errors are raised at once, as before. The docstring says so.

#441 (thanks @ToxicmaggotRP): tests/test_ab_control_flow.py. The stage, binding and feature filters in supported_pixel_shaders were never reached: the rejected index entries had no disassembly or SPIR-V, so the file check dropped them first. Also, only dispatch-side instability was tested. This PR changes tests only, not tools/ab_control_flow.py. A new test gives every rejected entry valid files, so only its metadata can drop it. Another covers structured-side instability, including a form that times out on only one run.

The #422 point (stale docs/models.md) is left out: #650 rewrote that file, and the pin itself is tracked as BUILD-101.

Tested on Windows 11, Python 3.13 (no GPU needed):

  • python -I tests/test_glb_atomic.py: 9 OK (4 new). The new thread test fails on main with dozens of PermissionErrors and passed 8/8 runs with the fix.
  • python -I tests/test_glb_writer.py, tests/test_world_build.py: OK.
  • python -I tests/test_ab_control_flow.py: OK. I removed each of the stage, binding and feature filters and the structured-instability check from tools/ab_control_flow.py in turn. Each removal fails a test.
  • python -m compileall -q make_game.py tools tests: OK.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

…ol_flow's metadata filters

Follow-ups to review points on two merged PRs.

ItsNotRexed#425 (@SourNuht): write_glb said overlapping writers all publish complete
files, but on Windows os.replace onto the same destination raises
PermissionError while another writer is replacing it. 8 threads x 40 writes
to one path failed 43-152 of 320 calls. A replace that hits PermissionError is
now retried with a short backoff (about 1.3 s in total), Windows only; a lasting
hold still raises and leaves the old file. Other errors are not retried.

ItsNotRexed#441 (@ToxicmaggotRP): the stage, binding and feature filters were never
reached by the tests (the rejected entries had no files, so they dropped out
earlier), and only dispatch-side instability was tested. Tests only; each of
those filters now fails a test when removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The staging file comes from NamedTemporaryFile, which creates it 0600, so
every GLB written since ItsNotRexed#425 has been owner-only on Linux. The staging file
now gets the replaced file's mode, or 0666 minus the umask for a new one,
before the replace. Same issue @VictorJulianiR found in rtti_scan (ItsNotRexed#750).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Added 18c8092: the published GLB now keeps the replaced file's permission bits, or 0666 minus the umask for a new file. Before this, NamedTemporaryFile's 0600 staging file made every GLB owner-only on Linux, which has been on main since #425. @VictorJulianiR found the same issue in rtti_scan on #750. New tests: a POSIX-only mode test (0644 under umask 022, a replaced 0640 stays 0640) and a Windows-safe writability test. test_glb_atomic.py 10 OK and 1 skipped (the POSIX test) on Windows 11, Python 3.13; test_glb_writer.py and test_world_build.py OK.

AI-assisted (Claude Code).

@Pierre-Kookis

Copy link
Copy Markdown

Checked #728 (7410f5d) on Windows 11, Python 3.13.14:

  • pytest tests/test_ab_control_flow.py: 20 passed (8 subtests); pytest tests/test_glb_atomic.py: 9 passed; compileall: OK
  • Code read (a second model, read-only, and checked by hand). One small remark: _replace() at tools/glb_writer.py:855 retries on any PermissionError, not only the sharing violation the comment above it describes (winerror == 32). A permanent denial, for example writing over a read-only .glb (winerror == 5), now waits about 1.3 s before it raises. Re-raising at once unless getattr(exc, 'winerror', None) == 32 would keep the retry for the case it was written for. The tests don't tell the two apart. Retry bounds, temp-file cleanup and atomicity look fine.

(AI-assisted review, no game files.)

ItsNotRexed added a commit that referenced this pull request Nov 22, 2026
@quackottu

Copy link
Copy Markdown
Contributor

Reviewed and tested 18c8092 on Windows 11 Pro (26300), Python 3.12.10: pass

  • python -I tests/test_glb_atomic.py: 11 tests OK (1 POSIX-only skipped), including test_threads_writing_one_file_all_publish (8 threads x 40 writes, no PermissionError)
  • python -I tests/test_ab_control_flow.py: 20 tests OK

Code read: the retry is limited to PermissionError on nt, gives len(_REPLACE_DELAYS) + 1 attempts and leaves the old file in place on a lasting hold, as the tests pin. One thing for POSIX: _output_mode reads the umask with os.umask(0) / os.umask(mask), which is process-wide and not thread-safe. Two threads publishing a GLB that doesn't exist yet can interleave as A umask(0) -> 022, B umask(0) -> 0, A umask(022), B umask(0), which leaves the process umask at 0 and gives B mode 0666. It only happens for a new file under concurrent writers, so it's minor, but a module-level lock around the two calls (or reading the umask once at import) would close it.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 18c8092 on Linux (WSL2 Ubuntu), Python 3.12, CPU only: pass, with the same concern as #750

  • pytest tests/test_glb_atomic.py tests/test_ab_control_flow.py: 30 passed, 1 skipped (the Windows-only case)
  • Negative control: with tools/glb_writer.py from main, test_published_glb_keeps_permission_bits fails (384 != 420).
  • The retry and the ab_control_flow tests the description covers are already on main. What's new is _output_mode plus os.chmod(tmp_path, ...).
  • It toggles os.umask(0) as rtti_scan: keep the old report when a write fails; mark mad denormals as not modelled (#658, #627, #645 follow-ups) #750 does. write_glb is called from overlapping threads, so that process-wide change can race with other file creation. Reading the umask once at import would avoid it.

@ItsNotRexed
ItsNotRexed merged commit 19073af into ItsNotRexed:main Nov 22, 2026
8 of 9 checks passed
@kotorvr

kotorvr commented Nov 22, 2026

Copy link
Copy Markdown
Contributor Author

Thanks @kapitche. Correction to my description: what this PR added on top of main was the os.chmod of the staging file to the old file's mode (or a new file's). The description didn't say so. The umask flip you found is being fixed in #866 (quackottu). A probe-file variant that never calls os.umask and covers rtti_scan too is offered there. AI-assisted.

quackottu pushed a commit to quackottu/Leonida that referenced this pull request Nov 22, 2026
…the umask

glb_writer._output_mode and rtti_scan._report_mode read the umask with
os.umask(0) then os.umask(mask). The umask is process-wide, so any thread
creating a file in that window got mask 0. A probe file created with mode
0666 gives the same bits (and honours a directory's default ACL) without
changing anything. Raised by kapitche on ItsNotRexed#750 and ItsNotRexed#728.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
quackottu pushed a commit to quackottu/Leonida that referenced this pull request Nov 22, 2026
…the umask

glb_writer._output_mode and rtti_scan._report_mode read the umask with
os.umask(0) then os.umask(mask). The umask is process-wide, so any thread
creating a file in that window got mask 0. A probe file created with mode
0666 gives the same bits (and honours a directory's default ACL) without
changing anything. Raised by kapitche on ItsNotRexed#750 and ItsNotRexed#728.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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