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 1 commit into
ProjectLeonida:mainfrom
markankamaransheogarat-sys:ubiq/spirv-tool-tree-cleanup
Open

markankamaransheogarat-sys wants to merge 1 commit 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
@markankamaransheogarat-sys

Copy link
Copy Markdown
Contributor Author

@DadaCap Rebased onto current main and addressed your feedback:

@github-actions github-actions Bot removed the needs rebase Conflicts with the base branch: rebase it on main label Nov 28, 2026
@zmasi

zmasi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Independent verification on Windows 11 (10.0.26200, x64) with f0ae5d3414 merged onto origin/main (e66c65b950, 0 merge conflicts; git merge-tree with #2367 also exits 0 with 0 conflicts), tested under both Python 3.12.10 and Python 3.14.5:

  • Review follow-up check:
    • _run_spirv_tool() in tools/rdna2spirv.py is untouched relative to origin/main (no _run_tool wrapper, avoiding any conflict with #2367 and keeping subprocess.run patch points intact).
  • Red (origin/main + #909 tests/test_make_game_translate_cleanup.py):
    • python -I tests/test_make_game_translate_cleanup.py: Ran 7 tests, FAILED (failures=3) on both Python 3.12.10 and Python 3.14.5.
  • Green (f0ae5d3414 merged onto origin/main):
    • python -I tests/test_make_game_translate_cleanup.py: Ran 7 tests, OK on Python 3.12.10 (0.21 s) and Python 3.14.5 (10.82 s), including test_main_registers_sigterm_handler_that_exits (signal.SIGTERM is defined on Windows Python).
    • python -I tests/test_rdna2spirv_cli.py: Ran 36 tests, OK (skipped=2) on Python 3.12.10 (7.34 s) and Python 3.14.5 (8.27 s) — all 6 tests that failed on the earlier _run_tool revision pass cleanly.
    • python -I tests/test_make_game_platform.py: Ran 48 tests, OK (skipped=4) on Python 3.12.10 (11.40 s) and Python 3.14.5 (12.93 s).
  • Non-blocking note: in tools/rdna2spirv.py (if shard is None: _clean_stale_spirv_temps(a.out)), single-file CLI invocations (rdna2spirv.py file.s --out dir, where single_file is true and shard is None) also sweep .spirv-*.tmp in a.out; make_game.py always passes --shard, so this only affects external callers running concurrent unsharded single-file translations into the same --out folder.
  • Hygiene: git diff --check, python -I -m compileall -q, python -I scripts/check_no_game_data.py, python -I tests/test_ci_registration.py (18/18), and python -I tests/test_text_write_line_endings.py (3/3) all exited 0.

AI-assisted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants