rdna2spirv: isolate and clean up index staging files (SHADER-INDEX-ATOMIC) #558

Manually merged
github merged 3 commits from gh-pr/558/head into gh-pr/558/base 2026-11-26 09:08:31 +00:00
Owner

@⁠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 UTC

Claimed in the coordination issue as: SHADER-INDEX-ATOMIC — #14

What and why

write_index used 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).

  • All six new tests fail against the original writer and pass with this change.
  • 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.
  • Full semantic suite with SPIRV-Tools v2026.4 available: 465 files, 6,103 tests, 0 files failed (532 s, 8 jobs).
  • compileall, make_game.py --help, no-game-data scan of both changed files and git 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

  • Based on current main at task start; GitHub mergeability checked before opening.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption, including in logs or reports.
  • No translator rule added, so no contract table change needed.
**@⁠JiyouProt** on GitHub · 2026-11-24 08:04 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/558) `JiyouProt:codex/shader-index-atomic` → `main` · +155 −7 · 5 files · 3 commits · merged 2026-11-24 09:50 UTC Claimed in the coordination issue as: SHADER-INDEX-ATOMIC — https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14 ### What and why `write_index` used 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 ece4ba5b31ebc6f345c8e29eae1261f2f780057a (current when this task started). - All six new tests fail against the original writer and pass with this change. - `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. - Full semantic suite with SPIRV-Tools v2026.4 available: **465 files, 6,103 tests, 0 files failed** (532 s, 8 jobs). - compileall, `make_game.py --help`, no-game-data scan of both changed files and `git 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 - [x] Based on current main at task start; GitHub mergeability checked before opening. - [x] One topic; follow-up work goes in a new pull request. - [x] No game data, keys or decryption, including in logs or reports. - [x] No translator rule added, so no contract table change needed.
Address review of #558: include file_mode.py in CMake shader dependencies,
make_game translation source digests, and both Runtime workflow path filters.
AI-assisted with Codex.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:08:29 +00:00
github manually merged commit e4dc13b079 into gh-pr/558/base 2026-11-26 09:08:31 +00:00
Author
Owner

@⁠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.

**@⁠JiyouProt** on GitHub · 2026-11-24 08:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/558#issuecomment-7126017183) 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.
Author
Owner

@⁠Dezmonius on GitHub · 2026-11-24 08:23 UTC · original

Independent Windows check at 62c061e against 1c93c86, 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 outside index.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).

**@⁠Dezmonius** on GitHub · 2026-11-24 08:23 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/558#issuecomment-7126080889) Independent Windows check at `62c061e` against `1c93c86`, 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 outside `index.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).
Author
Owner

@⁠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.

**@⁠sodove** on GitHub · 2026-11-24 08:24 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/558#issuecomment-7126100916) 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.
Author
Owner

@⁠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).

**@⁠QemmHD** on GitHub · 2026-11-24 09:27 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/558#issuecomment-7127438235) 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).
Author
Owner

@⁠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 62c061e before 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 main d7576d5 in 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.

**@⁠JiyouProt** on GitHub · 2026-11-24 09:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/558#issuecomment-7127650395) @⁠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 62c061e before 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 main d7576d5 in 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.
Author
Owner

@⁠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 e4dc13b on main d7576d5 (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).

**@⁠QemmHD** on GitHub · 2026-11-24 09:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/558#issuecomment-7127963493) 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 e4dc13b on main d7576d5 (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).
This discussion has been locked. Commenting is limited to contributors.
No description provided.