rdna2spirv: isolate and clean up index staging files (SHADER-INDEX-ATOMIC) #558
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!558
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/558/head"
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?
@JiyouProt on GitHub · 2026-11-24 08:04 UTC · original
JiyouProt:codex/shader-index-atomic→main· +155 −7 · 5 files · 3 commits · merged 2026-11-24 09:50 UTCClaimed in the coordination issue as: SHADER-INDEX-ATOMIC — #14
What and why
write_indexused the fixed sibling<index>.tmp. An existing file at that name was overwritten, a directory at that name blocked a valid write, and concurrent writers could replace or remove each other's staging file. Failed writes also left partial staging files behind.Use a unique temporary file in the destination directory, close it before publishing through the existing Windows-aware
replace_retry, and remove it if serialization, fsync or replacement fails (including interruption). Keep fsync, sorted JSON, LF output and atomic replacement. Temporary names do not match the shard-merge glob. No shader translation rule changes.Six synthetic regression tests reproduce the old behavior and cover an unrelated .tmp file/directory, serialization/fsync/replace failures, interruption and overlapping writers. The overlap test also checks that the shard glob sees only complete indexes.
Tested
Windows, Python 3.14.3, based on main
ece4ba5b31(current when this task started).python -I tests/test_rdna2spirv_index_write.py: 6 passed.python -I tests/test_rdna2spirv_merge.py: 30 passed.python -I tests/test_text_write_line_endings.py: 3 passed.make_game.py --help, no-game-data scan of both changed files andgit diff --check: passed.GPUs tested: n/a — index file publication only; fixtures are synthetic dictionaries. No game files needed or used.
AI-assisted: yes, with Codex.
Checklist
@JiyouProt on GitHub · 2026-11-24 08:20 UTC · original
Portability follow-up in
62c061e: the unique temporary file must not impose its private 0600 permissions on the published index. On POSIX, use the existing file_mode.published_mode helper before replacement; this preserves an existing destination mode or the directory/umask default for a new file, without changing the process umask. Permission lookup/chmod failures retain the old index and clean up staging. Windows retains its existing behavior.Validation: index writer 9 tests (8 passed, 1 POSIX-only skip on this Windows host); shard merge 30 passed; LF writers 3 passed; compile and no-game-data checks passed. Both new portable permission tests fail without this addition. The full 6,103-test run reported above was before this mode-only addition; no translation rules changed.
The same portability fix is included in #344 at 6164357: verifier 65 tests (62 passed, 3 platform skips) and shared file_mode tests 5 (3 passed, 2 POSIX-only skips). Both PRs remain ready for review. AI-assisted.
@Dezmonius on GitHub · 2026-11-24 08:23 UTC · original
Independent Windows check at
62c061eagainst1c93c86, CPython 3.14.7: 8 index-writer tests passed (1 POSIX-only skip), 30 shard-merge tests passed, and 3 LF-output tests passed.I also checked publication with two separate Python processes writing different synthetic JSON payloads to the same destination. A barrier held both processes immediately before the real rename. On main, both staged to the same path: the first publisher wrote the second process's payload, and the second publisher failed with
FileNotFoundError. On the PR, the staging paths were distinct and outsideindex.part*.json; readers saw the existing complete index until the first release, then each complete new payload as its process published. Both processes exited 0.With a real Win32 destination handle that omitted
FILE_SHARE_DELETE, publication succeeded after the handle was released. Holding the handle past a shortened retry budget produced WinError 5: the original index stayed intact in both versions, and only the PR removed the staging file. These checks use the actual filesystem and replace path, with a barrier and shorter retry budget in the probe only.CPU-only synthetic JSON. AI-assisted (Codex).
@sodove on GitHub · 2026-11-24 08:24 UTC · original
At
62c061e, the POSIX permission case passed on Ubuntu under WSL, Python 3.14.4. All 9 index writer tests passed there, including the real permission bits for an existing index and a new file.I also confirmed the Windows behavior above with three independent processes on Python 3.12. Main used one staging path. The first process published the third process's content and the other two failed. With the PR, all three processes published their own complete indexes in release order. The native sharing conflict and retry-expiry cleanup checks also agreed with the report above. Synthetic JSON. AI-assisted.
@QemmHD on GitHub · 2026-11-24 09:27 UTC · original
Thanks, the unique staging file is a good fix, and its tests pass on Windows (index_write 2 passed / 10 failed on main -> 8 passed). One thing before it can merge: rdna2spirv.py now imports tools/file_mode.py, so that file also needs listing in runtime/cmake/translator_deps.cmake, in make_game.py's translation sources, and in the tools paths of .github/workflows/runtime.yml. Without those, test_cmake_translator_deps, test_shader_stage_resume and test_runtime_paths fail on the merge (565 -> 562 passed, 3 failed). Happy to re-test after a push.
AI-assisted (Claude Code, Claude Opus 5.5).
@JiyouProt on GitHub · 2026-11-24 09:36 UTC · original
@QemmHD Thanks for catching the missing dependency registration. Fixed in
e4dc13b: tools/file_mode.py is now in runtime/cmake/translator_deps.cmake, make_game.py TRANSLATION_SOURCES, and both push/pull_request tools path filters in .github/workflows/runtime.yml.I reproduced all three failures on
62c061ebefore the change. After it, test_cmake_translator_deps (5), test_shader_stage_resume (46) and test_runtime_paths (5) all pass: 56/56. I also applied the complete PR cleanly to current maind7576d5in a separate checkout; the same 56 tests pass there, along with the index writer tests (8 passed, 1 POSIX-only skip on Windows).On the PR branch, index writer: 8 passed/1 skipped; shard merge: 30 passed; file_mode: 3 passed/2 POSIX-only skips; LF writers: 3 passed. No-game-data and diff whitespace checks pass. Windows/Python 3.14.3, CMake available, synthetic inputs only. No translation behavior change in this follow-up. AI-assisted with Codex.
@QemmHD on GitHub · 2026-11-24 09:50 UTC · original
Merging. Why merged: each rdna2spirv index write now uses its own staging file and cleans it up, so parallel translations can't clobber each other's index; and, after review, the new tools/file_mode.py is registered as a translator input (translator_deps.cmake, make_game.py's translation sources, runtime.yml paths).
Why it's good: re-tested at
e4dc13bon maind7576d5(Windows 11, RTX 4070 SUPER): the new index-write tests go from 2 passed / 10 failed on main to 8 passed; the translator-input tests stay 56/56; the full repo-consistency set is 565 passed / 0 failed; compileall clean. Thanks @JiyouProt for the quick fix.AI-assisted (Claude Code, Claude Opus 5.5).