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

Closed
IlyassRS3 wants to merge 1 commit from upstream-pr/1686 into main
IlyassRS3 commented 2026-11-25 08:10:58 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by IlyassRS3 on 2026-11-25T08:10:58Z.


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
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5487595512 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1686). Originally posted by [IlyassRS3](https://github.com/IlyassRS3) on 2026-11-25T08:10:58Z. --- 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] commented 2026-11-25 08:11:06 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T08:11:06Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6053933664 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1686#pullrequestreview-6053933664). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/apps/copilot-pull-request-reviewer) on 2026-11-25T08:11:06Z. **Review:** COMMENTED --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T02:50:46Z.


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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7232630942 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1686#issuecomment-7232630942). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T02:50:46Z. --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T21:08:03Z.


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)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7245795721 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1686#issuecomment-7245795721). Originally posted by [MoonEyes](https://github.com/MoonEyes) on 2026-11-28T21:08:03Z. --- 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 commented 2026-12-01 11:54:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T11:54:26Z.

Review: CHANGES_REQUESTED


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

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130738087 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1686#pullrequestreview-6130738087). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:54:26Z. **Review:** CHANGES_REQUESTED --- 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 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by aslan2142 on 2026-12-01T17:23:56Z.


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.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7319235437 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/1686#issuecomment-7319235437). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T17:23:56Z. --- 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.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
ProjectLeonida/mandy!1686
No description provided.