translate_pipeline_compute: harden index parsing, published .spv mode, and worker cleanup #1686

Closed
leonida/mandy
quietfold wants to merge 0 commits from fix/translate-pipeline-compute-io-and-worker into main

Pull request closed

This pull request cannot be reopened because the branch was deleted.

quietfold commented 2026-11-25 08:10:58 +00:00

Item ID: TRANSLATE-PIPELINE-COMPUTE-IO-AND-WORKER (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156665714)

Summary

  • Input index validation (scripts/translate_pipeline_compute.py):
    • Extracted load_compute_names(index_path) supporting UTF-8 BOM (utf-8-sig), validating JSON list/dict structure and stage/file types, rejecting empty-stem ".dxbc" filenames and path separators (/ and \), and reporting errors via ap.error() instead of raw tracebacks.
    • Validate tools and index.json before mutating process priority (os.setpriority) or RLIMIT_AS (resource.setrlimit), and accept argv=None in main().
    • Include args.compact_spirv explicitly in cache settings.
  • Published .spv permissions & cache directory creation:
    • Ensure out / ".compute-cache" is created with parents=True, exist_ok=True in both build_one() and build().
    • Apply file_mode.published_mode() before replacing published .spv files so they do not inherit 0o600 permissions from tempfile.TemporaryDirectory.
  • Forked worker lifecycle in build():
    • When the parent worker raises an exception (including KeyboardInterrupt), send SIGTERM to the forked child before os.waitpid(pid, 0) and do not raise "second translation worker failed" inside finally, preventing the child's exit status from masking the parent exception.
  • Cross-platform POSIX unit tests (tests/test_translate_pipeline_compute.py):
    • Added ComputePipelineUnitTests (runs on macOS & Linux without requiring spirv-as/spirv-val) covering BOM & malformed index.json, build_one() cache creation + published_mode, parent-exception preservation + SIGTERM/waitpid cleanup vs child-only failure, and upfront validation before setrlimit/setpriority.

Checklist & Verification

  • AI-assisted: yes
  • Game data included: none (python3 -I scripts/check_no_game_data.py scripts/translate_pipeline_compute.py tests/test_translate_pipeline_compute.py passed)
  • GPUs tested: none (hostless macOS POSIX unit test run; Linux SPIRV-Tools integration test skipped cleanly)
  • Tests run:
    • python3 -W error -I tests/test_translate_pipeline_compute.py -v: Ran 5 tests ... OK (skipped=1)
    • Mutation test (ComputePipelineUnitTests against unpatched main scripts/translate_pipeline_compute.py): Ran 4 tests ... FAILED (errors=4)
    • python3 -m compileall -q make_game.py tools tests scripts: passed
    • python3 -I tests/test_text_write_line_endings.py: Ran 3 tests ... OK
Item ID: `TRANSLATE-PIPELINE-COMPUTE-IO-AND-WORKER` (claimed in https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7156665714) ## Summary - **Input index validation (`scripts/translate_pipeline_compute.py`)**: - Extracted `load_compute_names(index_path)` supporting UTF-8 BOM (`utf-8-sig`), validating JSON list/dict structure and `stage`/`file` types, rejecting empty-stem `".dxbc"` filenames and path separators (`/` and `\`), and reporting errors via `ap.error()` instead of raw tracebacks. - Validate tools and `index.json` before mutating process priority (`os.setpriority`) or `RLIMIT_AS` (`resource.setrlimit`), and accept `argv=None` in `main()`. - Include `args.compact_spirv` explicitly in cache `settings`. - **Published `.spv` permissions & cache directory creation**: - Ensure `out / ".compute-cache"` is created with `parents=True, exist_ok=True` in both `build_one()` and `build()`. - Apply `file_mode.published_mode()` before replacing published `.spv` files so they do not inherit `0o600` permissions from `tempfile.TemporaryDirectory`. - **Forked worker lifecycle in `build()`**: - When the parent worker raises an exception (including `KeyboardInterrupt`), send `SIGTERM` to the forked child before `os.waitpid(pid, 0)` and do not raise `"second translation worker failed"` inside `finally`, preventing the child's exit status from masking the parent exception. - **Cross-platform POSIX unit tests (`tests/test_translate_pipeline_compute.py`)**: - Added `ComputePipelineUnitTests` (runs on macOS & Linux without requiring `spirv-as`/`spirv-val`) covering BOM & malformed `index.json`, `build_one()` cache creation + `published_mode`, parent-exception preservation + `SIGTERM`/`waitpid` cleanup vs child-only failure, and upfront validation before `setrlimit`/`setpriority`. ## Checklist & Verification - **AI-assisted**: yes - **Game data included**: none (`python3 -I scripts/check_no_game_data.py scripts/translate_pipeline_compute.py tests/test_translate_pipeline_compute.py` passed) - **GPUs tested**: none (hostless macOS POSIX unit test run; Linux SPIRV-Tools integration test skipped cleanly) - **Tests run**: - `python3 -W error -I tests/test_translate_pipeline_compute.py -v`: `Ran 5 tests ... OK (skipped=1)` - Mutation test (`ComputePipelineUnitTests` against unpatched `main` `scripts/translate_pipeline_compute.py`): `Ran 4 tests ... FAILED (errors=4)` - `python3 -m compileall -q make_game.py tools tests scripts`: passed - `python3 -I tests/test_text_write_line_endings.py`: `Ran 3 tests ... OK`
copilot-pull-request-reviewer[bot] reviewed 2026-11-25 08:11:06 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MoonEyes commented 2026-11-28 02:50:46 +00:00

Hi @IlyassRS3, thanks for this pull request. It currently conflicts with main (conflicting file(s): scripts/translate_pipeline_compute.py, tests/test_translate_pipeline_compute.py), so it carries the needs rebase label. CONTRIBUTING.md asks authors to rebase their branch on main; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.

AI-assisted (Claude Code, Claude Opus 5.5).

Hi @IlyassRS3, thanks for this pull request. It currently conflicts with `main` (conflicting file(s): `scripts/translate_pipeline_compute.py`, `tests/test_translate_pipeline_compute.py`), so it carries the `needs rebase` label. CONTRIBUTING.md asks authors to rebase their branch on `main`; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here. AI-assisted (Claude Code, Claude Opus 5.5).
MoonEyes commented 2026-11-28 21:08:03 +00:00

Main has since rewritten scripts/translate_pipeline_compute.py (Options/recipe, the Windows worker, output_lock, replace_retry), so the guards of this PR (load_compute_names, published_mode, SIGTERM handling) no longer apply where they were written. Could you merge main into this branch and port them onto the current script? Once that is done we will run the red/green tests and merge it.

AI-assisted (Claude Code, Claude Opus 5.5)

Main has since rewritten scripts/translate_pipeline_compute.py (Options/recipe, the Windows worker, output_lock, replace_retry), so the guards of this PR (load_compute_names, published_mode, SIGTERM handling) no longer apply where they were written. Could you merge main into this branch and port them onto the current script? Once that is done we will run the red/green tests and merge it. AI-assisted (Claude Code, Claude Opus 5.5)
aslan2142 reviewed 2026-12-01 11:54:26 +00:00
aslan2142 left a comment
No description provided.
Reviewed against current `main`: `scripts/translate_pipeline_compute.py` has been substantially rewritten on `main` (new `Options`/recipe structure, Windows worker, `output_lock`, `replace_retry`), so this branch conflicts heavily and has failing CI. Please re-baseline onto current `main` keeping only the hardening checks still missing there and re-run CI. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 17:23:56 +00:00

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, d3d12/, or general docs), please feel free to reopen it.

Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (`d3d12/`) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools, `d3d12/`, or general docs), please feel free to reopen it.
Sign in to join this conversation.
No description provided.