Skip to content

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

Open
markankamaransheogarat-sys wants to merge 2 commits into
ProjectLeonida:mainfrom
markankamaransheogarat-sys:ubiq/spirv-tool-tree-cleanup
Open

markankamaransheogarat-sys wants to merge 2 commits into
ProjectLeonida:mainfrom
markankamaransheogarat-sys:ubiq/spirv-tool-tree-cleanup

Conversation

@markankamaransheogarat-sys

Copy link
Copy Markdown
Contributor

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

@tiguan26

Copy link
Copy Markdown
Contributor

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

@PierreEbele

Copy link
Copy Markdown
Contributor

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

@tiguan26

Copy link
Copy Markdown
Contributor

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

@markankamaransheogarat-sys

Copy link
Copy Markdown
Contributor Author

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

@tiguan26 tiguan26 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving 317b04f. 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 (d1dff79) 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).

@DadaCap

DadaCap commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this! Cleaning up spirv-as/spirv-val children and leftover .spirv-*.tmp files after an aborted build is useful.

During maintainer testing (local, 2026-11-28) (head 317b04f, merged on main b1619e0 / 6dfca64, Windows 11, Python tests via pytest/unittest) we found:

To get this merged:

AI-assisted (Claude Code), posted for DadaCap (maintainer).

@github-actions github-actions Bot added the needs rebase Conflicts with the base branch: rebase it on main label Nov 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs rebase Conflicts with the base branch: rebase it on main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants