[PR #1686] translate_pipeline_compute: harden index parsing, published .spv mode, and worker cleanup #1700

Open
opened 2026-11-26 20:22:09 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1686
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/translate-pipeline-compute-io-and-worker


📝 Commits (1)

  • 6f2fd66 translate_pipeline_compute: harden index parsing, published .spv mode, and worker cleanup

📊 Changes

2 files changed (+191 additions, -27 deletions)

View changed files

📝 scripts/translate_pipeline_compute.py (+63 -27)
📝 tests/test_translate_pipeline_compute.py (+128 -0)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1686 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/translate-pipeline-compute-io-and-worker` --- ### 📝 Commits (1) - [`6f2fd66`](https://github.com/ubiquitarianism/leonida/commit/6f2fd66a88a3a313e651ec9497136517aa21884b) translate_pipeline_compute: harden index parsing, published .spv mode, and worker cleanup ### 📊 Changes **2 files changed** (+191 additions, -27 deletions) <details> <summary>View changed files</summary> 📝 `scripts/translate_pipeline_compute.py` (+63 -27) 📝 `tests/test_translate_pipeline_compute.py` (+128 -0) </details> ### 📄 Description 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` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1700
No description provided.