SPIRV-TOOL-TREE-CLEANUP: rdna2spirv, make_game: terminate spirv-as/val children on abort and sweep stale .spirv-*.tmp #909

Open
github-bot wants to merge 2 commits from github-bot/gh-909 into main AGit
Owner

@⁠markankamaransheogarat-sys on GitHub · 2026-11-24 15:09 UTC · original
markankamaransheogarat-sys:ubiq/spirv-tool-tree-cleanup → main · +175 −2 · 3 files · 2 commits · open

Summary

  • Replace subprocess.run in _run_spirv_tool() with _run_tool() using Popen + terminate()/kill() on BaseException (SIGINT/SIGTERM) so orphaned spirv-as/spirv-val children are cleaned up.
  • Install a SIGTERM handler in rdna2spirv.main() and sweep leftover .spirv-*.tmp staging files on make_game.translate() abort and after rdna2spirv merge/single-run completion.

Verification

  • python3 -I tests/test_make_game_translate_cleanup.py: 7/7 passed.

AI-assisted: yes (synthetic tests only, no game files).

**@⁠markankamaransheogarat-sys** on GitHub · 2026-11-24 15:09 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/909) `markankamaransheogarat-sys:ubiq/spirv-tool-tree-cleanup` → `main` · +175 −2 · 3 files · 2 commits · open ### Summary - Replace `subprocess.run` in `_run_spirv_tool()` with `_run_tool()` using `Popen` + `terminate()`/`kill()` on `BaseException` (SIGINT/SIGTERM) so orphaned `spirv-as`/`spirv-val` children are cleaned up. - Install a `SIGTERM` handler in `rdna2spirv.main()` and sweep leftover `.spirv-*.tmp` staging files on `make_game.translate()` abort and after `rdna2spirv` merge/single-run completion. ### Verification - `python3 -I tests/test_make_game_translate_cleanup.py`: 7/7 passed. AI-assisted: yes (synthetic tests only, no game files).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:27:37 +00:00
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-25 19:19 UTC · original

Tested this merged into current main (9f9a7c5). The translator suite and tests/test_make_game_translate_cleanup.py pass, but 6 tests in tests/test_rdna2spirv_cli.py that pass on main fail with this PR: lines 465 and 486 (None != 2: a missing spirv-as/spirv-val no longer exits 2), 510 twice ('INVALID: synthetic rejection' not printed), and 559 (the real module is written instead of b'new module').

The cause: those tests patch subprocess.run to fake a missing tool or a rejection. _run_tool now starts the tool with subprocess.Popen, so the patches no longer apply and the real spirv-as/spirv-val run instead. You could have the tests patch _run_spirv_tool (or subprocess.Popen), or keep subprocess.run and handle the interrupt around it. subprocess.run already kills the child on an exception during communicate(), so the SIGTERM handler alone may give you most of this.

A smaller point: _run_spirv_tool now keeps only input/text/cwd and silently drops any other keyword. Today's callers pass only those plus capture_output (always true here), so nothing breaks, but a future timeout= or env= would be ignored without warning.

AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-25 19:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/909#issuecomment-7172135115) Tested this merged into current main (9f9a7c5). The translator suite and `tests/test_make_game_translate_cleanup.py` pass, but 6 tests in `tests/test_rdna2spirv_cli.py` that pass on main fail with this PR: lines 465 and 486 (`None != 2`: a missing spirv-as/spirv-val no longer exits 2), 510 twice (`'INVALID: synthetic rejection'` not printed), and 559 (the real module is written instead of `b'new module'`). The cause: those tests patch `subprocess.run` to fake a missing tool or a rejection. `_run_tool` now starts the tool with `subprocess.Popen`, so the patches no longer apply and the real spirv-as/spirv-val run instead. You could have the tests patch `_run_spirv_tool` (or `subprocess.Popen`), or keep `subprocess.run` and handle the interrupt around it. `subprocess.run` already kills the child on an exception during `communicate()`, so the SIGTERM handler alone may give you most of this. A smaller point: `_run_spirv_tool` now keeps only `input`/`text`/`cwd` and silently drops any other keyword. Today's callers pass only those plus `capture_output` (always true here), so nothing breaks, but a future `timeout=` or `env=` would be ignored without warning. AI-assisted (Claude).
Author
Owner

@⁠PierreEbele on GitHub · 2026-11-25 21:17 UTC · original

Reviewed 60f6dc7: external spirv-as/val invocations now run through run_tool, which terminates and reaps the child on interrupt; SIGTERM becomes a graceful SystemExit(143); make_game's abort path and rdna2spirv's merge/non-shard tails sweep stale .spirv-*.tmp. Run on arm64 Linux without SPIRV-Tools: the 7-test file passes on this branch and its 4 new tests fail on main exactly at the new behavior; related suites (gpu_python_assembler, the make_game* family, pipeline_batches, an alu_add translator subset) pass on the PR and on a materialized merge into current main; a deterministic SIGTERM-inside-the-staging-window probe shows main dying by signal (-15) with a stranded .spirv-*.tmp in --out while this branch exits 143 with the staging file removed. No findings; minor notes: _run_spirv_tool ignores kwargs beyond input/text/cwd (worth a comment for future callers) and the sweep helper exists in two copies. AI-assisted review.

Recommendation: Merge

**@⁠PierreEbele** on GitHub · 2026-11-25 21:17 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/909#issuecomment-7174884359) Reviewed 60f6dc7: external spirv-as/val invocations now run through _run_tool, which terminates and reaps the child on interrupt; SIGTERM becomes a graceful SystemExit(143); make_game's abort path and rdna2spirv's merge/non-shard tails sweep stale .spirv-*.tmp. Run on arm64 Linux without SPIRV-Tools: the 7-test file passes on this branch and its 4 new tests fail on main exactly at the new behavior; related suites (gpu_python_assembler, the make_game_* family, pipeline_batches, an alu_add translator subset) pass on the PR and on a materialized merge into current main; a deterministic SIGTERM-inside-the-staging-window probe shows main dying by signal (-15) with a stranded .spirv-*.tmp in --out while this branch exits 143 with the staging file removed. No findings; minor notes: _run_spirv_tool ignores kwargs beyond input/text/cwd (worth a comment for future callers) and the sweep helper exists in two copies. AI-assisted review. **Recommendation:** Merge
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-25 21:36 UTC · original

Rechecked the current head 60f6dc7 merged into today's main: tests/test_make_game_translate_cleanup.py passes, but the same 6 tests in tests/test_rdna2spirv_cli.py still fail (6 failed, 38 passed, 1 skipped), and all of them pass on main. The cause is unchanged: those tests patch subprocess.run, and the tool now starts through subprocess.Popen, so the fake missing tool or rejection never reaches it. Either update those tests to patch the new entry point, or keep subprocess.run (it already kills and reaps the child when communicate() is interrupted) and add just the SIGTERM handler and the temp sweep. AI-assisted (Claude).

**@⁠tiguan26** on GitHub · 2026-11-25 21:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/909#issuecomment-7175292413) Rechecked the current head 60f6dc7 merged into today's main: `tests/test_make_game_translate_cleanup.py` passes, but the same 6 tests in `tests/test_rdna2spirv_cli.py` still fail (6 failed, 38 passed, 1 skipped), and all of them pass on main. The cause is unchanged: those tests patch `subprocess.run`, and the tool now starts through `subprocess.Popen`, so the fake missing tool or rejection never reaches it. Either update those tests to patch the new entry point, or keep `subprocess.run` (it already kills and reaps the child when `communicate()` is interrupted) and add just the SIGTERM handler and the temp sweep. AI-assisted (Claude).
Author
Owner

@⁠markankamaransheogarat-sys on GitHub · 2026-11-26 08:29 UTC · original

@⁠tiguan26 Thanks for catching that! Rebased onto main and updated _run_spirv_tool in tools/rdna2spirv.py to delegate to subprocess.run whenever it is patched (while keeping _run_tool with timeout/env forwarding for process-tree cleanup). Both tests/test_rdna2spirv_cli.py and tests/test_make_game_translate_cleanup.py now pass together ().

**@⁠markankamaransheogarat-sys** on GitHub · 2026-11-26 08:29 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/909#issuecomment-7186662276) @⁠tiguan26 Thanks for catching that! Rebased onto `main` and updated `_run_spirv_tool` in `tools/rdna2spirv.py` to delegate to `subprocess.run` whenever it is patched (while keeping `_run_tool` with `timeout`/`env` forwarding for process-tree cleanup). Both `tests/test_rdna2spirv_cli.py` and `tests/test_make_game_translate_cleanup.py` now pass together ().
Author
Owner

@⁠tiguan26 on GitHub · 2026-11-27 01:06 UTC · original · approved these changes

Approving 317b04f3d. Thanks for the fix: _run_spirv_tool now leaves a patched subprocess.run in charge, and _run_tool forwards timeout/env.

Merged into current main (d1dff7949) with no conflicts, then on Linux, Python 3.13:

  • tests/test_rdna2spirv_cli.py and tests/test_make_game_translate_cleanup.py in one process (the case that failed before): 42 passed, 1 skipped.
  • The other tests that touch these helpers (test_make_game_argparse, _empty_translation, _wave64, _resume, _translator_flags, test_run_gpu_tests_python_assembler): 154 passed, 1 skipped, the same on main.
  • Full translator suite (run_semantic_tests.py tests/semantic): 6,374 tests; the 8 failures (7 in test_fspx_dot4_op_sel_disasm, plus test_int32_to_f64) fail identically on main.

Every call site passes only input/capture_output/text/cwd, which _run_tool handles. AI-assisted (Claude Code).

**@⁠tiguan26** on GitHub · 2026-11-27 01:06 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/909#pullrequestreview-6082158050) · **approved these changes** Approving 317b04f3d. Thanks for the fix: `_run_spirv_tool` now leaves a patched `subprocess.run` in charge, and `_run_tool` forwards `timeout`/`env`. Merged into current main (d1dff7949) with no conflicts, then on Linux, Python 3.13: - `tests/test_rdna2spirv_cli.py` and `tests/test_make_game_translate_cleanup.py` in **one** process (the case that failed before): 42 passed, 1 skipped. - The other tests that touch these helpers (`test_make_game_argparse`, `_empty_translation`, `_wave64`, `_resume`, `_translator_flags`, `test_run_gpu_tests_python_assembler`): 154 passed, 1 skipped, the same on main. - Full translator suite (`run_semantic_tests.py tests/semantic`): 6,374 tests; the 8 failures (7 in `test_fspx_dot4_op_sel_disasm`, plus `test_int32_to_f64`) fail identically on main. Every call site passes only `input`/`capture_output`/`text`/`cwd`, which `_run_tool` handles. AI-assisted (Claude Code).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/909/head:github-bot/gh-909'
git switch 'github-bot/gh-909'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-909'
git switch 'github-bot/gh-909'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-909'
git switch 'github-bot/gh-909'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-909'
git switch 'main'
git merge --squash 'github-bot/gh-909'
git switch 'main'
git merge --ff-only 'github-bot/gh-909'
git switch 'main'
git merge 'github-bot/gh-909'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.