semantic tests: stop POSIX worker helpers when a test times out #2201

Closed
EdenBendheim wants to merge 2 commits from upstream-pr/2201 into main
EdenBendheim commented 2026-11-26 05:27:19 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by EdenBendheim on 2026-11-26T05:27:19Z.


Claimed in the coordination issue as: SEMANTIC-RUNNER-POSIX-CHILD-TIMEOUT (claim)

On POSIX, a timed-out test could leave a helper holding its output pipes open. The parallel runner killed the worker and then waited for the helper to close the pipe. A 0.3-second timeout in a synthetic fixture returned after 3.13 seconds.

Timed workers now get their own process group. The timeout handler stops that group so pipe collection can finish. Untimed workers keep the caller's process group. Helpers that explicitly detach from the timed group are outside the cleanup boundary.

Depends on: #2073, #2114 (textual conflicts at the worker launch sites). All three changes can be implemented independently. The second PR to land will need to reconcile the launch arguments. Simulated merges with #2071 and #2135 were clean.

Three synthetic timeout cases reproduced the failure on main a73a57e13, including a worker that had already exited. With the fix, the parallel 0.3-second probe completed in about 0.35 seconds. All 28 runner tests passed on macOS, including checks for untimed serial and parallel worker process groups. Compile, diff and changed-file game-data checks passed.

GPUs tested: n/a. All tests used synthetic inputs.

AI-assisted: yes. Created with gpt-6.2-astra in Codex.

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5504545557 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2201). Originally posted by [EdenBendheim](https://github.com/EdenBendheim) on 2026-11-26T05:27:19Z. --- Claimed in the coordination issue as: SEMANTIC-RUNNER-POSIX-CHILD-TIMEOUT ([claim](https://github.com/ubiquitarianism/leonida/issues/1608#issuecomment-7183431216)) On POSIX, a timed-out test could leave a helper holding its output pipes open. The parallel runner killed the worker and then waited for the helper to close the pipe. A 0.3-second timeout in a synthetic fixture returned after 3.13 seconds. Timed workers now get their own process group. The timeout handler stops that group so pipe collection can finish. Untimed workers keep the caller's process group. Helpers that explicitly detach from the timed group are outside the cleanup boundary. Depends on: #2073, #2114 (textual conflicts at the worker launch sites). All three changes can be implemented independently. The second PR to land will need to reconcile the launch arguments. Simulated merges with #2071 and #2135 were clean. Three synthetic timeout cases reproduced the failure on main `a73a57e13`, including a worker that had already exited. With the fix, the parallel 0.3-second probe completed in about 0.35 seconds. All 28 runner tests passed on macOS, including checks for untimed serial and parallel worker process groups. Compile, diff and changed-file game-data checks passed. GPUs tested: n/a. All tests used synthetic inputs. AI-assisted: yes. Created with gpt-6.2-astra in Codex.
lixonik commented 2026-11-26 06:13:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T06:13:04Z.

Review: COMMENTED


Both new POSIX tests passed on Ubuntu 22.04 under WSL. I checked one remaining pipe-lifetime case separately. AI-assisted.

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6069345015 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2201#pullrequestreview-6069345015). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T06:13:04Z. **Review:** COMMENTED --- Both new POSIX tests passed on Ubuntu 22.04 under WSL. I checked one remaining pipe-lifetime case separately. AI-assisted.
lixonik commented 2026-11-26 06:13:04 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by lixonik on 2026-11-26T06:13:04Z.

Code review location: scripts/run_semantic_tests.py; line 84

@@ -65,6 +77,13 @@ def _kill_process_tree(proc):
                            stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
         except OSError:
             pass
+    elif os.name == "posix" and getattr(proc, "_semantic_owns_group", False):
+        # A launcher can exit while a helper still owns a copy of its output pipe. The session's group ID is
+        # the original worker PID even after the launcher exits.
+        try:
+            os.killpg(proc.pid, signal.SIGKILL)

[P3] Bound the pipe drain after sending the group kill. A helper that deliberately starts its own session can inherit the worker's stdout and stderr. The helper is outside the stated kill scope, but the second, unbounded proc.communicate() still waits for its pipes. A synthetic parallel worker with a detached helper that sleeps 2.5 s took 2.66 s to return for --timeout 0.5. A long-lived helper can hold the runner open indefinitely. Could the timeout path give the pipes a bounded drain without terminating the detached helper?

<!-- greyfinch-sync:ubiquitarianism/leonida:review-comment:4704534160 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2201#discussion_r4704534160). Originally posted by [lixonik](https://github.com/lixonik) on 2026-11-26T06:13:04Z. **Code review location:** `scripts/run_semantic_tests.py`; line 84 ~~~~diff @@ -65,6 +77,13 @@ def _kill_process_tree(proc): stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) except OSError: pass + elif os.name == "posix" and getattr(proc, "_semantic_owns_group", False): + # A launcher can exit while a helper still owns a copy of its output pipe. The session's group ID is + # the original worker PID even after the launcher exits. + try: + os.killpg(proc.pid, signal.SIGKILL) ~~~~ --- [P3] Bound the pipe drain after sending the group kill. A helper that deliberately starts its own session can inherit the worker's stdout and stderr. The helper is outside the stated kill scope, but the second, unbounded `proc.communicate()` still waits for its pipes. A synthetic parallel worker with a detached helper that sleeps 2.5 s took 2.66 s to return for `--timeout 0.5`. A long-lived helper can hold the runner open indefinitely. Could the timeout path give the pipes a bounded drain without terminating the detached helper?
Tauwni commented 2026-11-26 09:25:49 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by Tauwni on 2026-11-26T09:25:49Z.


Tested db8d971c9 on an Apple M3 (macOS 26.5.1, Python 3.15, Homebrew), against main a73a57e13. Synthetic inputs only.

  • tests/test_run_semantic_tests.py: 28/28 pass on this head (26/26 on main).
  • Reproduction with a throwaway suite of two files. One is test_hang.py, which starts python -c "time.sleep(3)" with Popen and then sleeps 60 s. The other is a passing test. Command: scripts/run_semantic_tests.py -j 2 --timeout 0.3 <dir>.
exit wall time
main 1 3.11 s (waits for the helper's pipe)
this PR 1 0.36 s

So on macOS too, the timeout now returns at the timeout instead of when the helper exits.

AI-assisted (Claude Code). No game data.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7187976588 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2201#issuecomment-7187976588). Originally posted by [Tauwni](https://github.com/Tauwni) on 2026-11-26T09:25:49Z. --- Tested `db8d971c9` on an Apple M3 (macOS 26.5.1, Python 3.15, Homebrew), against `main` `a73a57e13`. Synthetic inputs only. - `tests/test_run_semantic_tests.py`: 28/28 pass on this head (26/26 on `main`). - Reproduction with a throwaway suite of two files. One is `test_hang.py`, which starts `python -c "time.sleep(3)"` with `Popen` and then sleeps 60 s. The other is a passing test. Command: `scripts/run_semantic_tests.py -j 2 --timeout 0.3 <dir>`. | | exit | wall time | |---|---|---| | `main` | 1 | 3.11 s (waits for the helper's pipe) | | this PR | 1 | 0.36 s | So on macOS too, the timeout now returns at the timeout instead of when the helper exits. AI-assisted (Claude Code). No game data.
DeadlyChirp commented 2026-11-26 10:50:26 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DeadlyChirp on 2026-11-26T10:50:26Z.


Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main.

  • tests/test_run_semantic_tests.py: 25 passed, 3 skipped, 33 subtests passed. The 2 new tests skip on Windows as intended ("POSIX worker process groups"); nothing else changed on this platform (main: 25 passed, 1 skipped).

(AI-assisted test run; output checked by hand.)

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7189906937 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/2201#issuecomment-7189906937). Originally posted by [DeadlyChirp](https://github.com/DeadlyChirp) on 2026-11-26T10:50:26Z. --- Tested on Windows 11, Python 3.12.10, with this PR merged onto current upstream main. - `tests/test_run_semantic_tests.py`: 25 passed, 3 skipped, 33 subtests passed. The 2 new tests skip on Windows as intended ("POSIX worker process groups"); nothing else changed on this platform (main: 25 passed, 1 skipped). (AI-assisted test run; output checked by hand.)
DadaCap commented 2026-11-28 07:21:18 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T07:21:18Z.


Thanks for this! Killing the whole process group on a POSIX timeout stops helper processes from holding the runner's pipes open.

During maintainer testing (local, 2026-11-28) (head db8d971c9, merged on main b1619e0a3 / 6dfca6428, Windows 11, Python tests via pytest/unittest) we found:

  • Review finding: it conflicts with #1437, #2071 and #2073 in scripts/run_semantic_tests.py. After the rebase, run_discover (from #1437) must call _start_test_process, or -j 1 --timeout silently loses the fix.

To get this merged:

  • Rebase after #1437, #2071 and #2073 land.
  • Route run_discover through _start_test_process.

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

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7235880475 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2201#issuecomment-7235880475). Originally posted by [DadaCap](https://github.com/DadaCap) on 2026-11-28T07:21:18Z. --- Thanks for this! Killing the whole process group on a POSIX timeout stops helper processes from holding the runner's pipes open. During maintainer testing (local, 2026-11-28) (head db8d971c9, merged on main b1619e0a3 / 6dfca6428, Windows 11, Python tests via pytest/unittest) we found: - Review finding: it conflicts with #1437, #2071 and #2073 in `scripts/run_semantic_tests.py`. After the rebase, `run_discover` (from #1437) must call `_start_test_process`, or `-j 1 --timeout` silently loses the fix. To get this merged: - Rebase after #1437, #2071 and #2073 land. - Route `run_discover` through `_start_test_process`. _AI-assisted (Claude Code), posted for DadaCap (maintainer)._
TheGeogeo commented 2026-11-28 22:16:45 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by TheGeogeo on 2026-11-28T22:16:45Z.


Duplicate check (diff reading only, no build): not a duplicate of #2073. They are two different fixes in scripts/run_semantic_tests.py:

  • #2073 closes a race between Ctrl+C cancellation and a worker still inside Popen: the registration is refused once cancelled, on every platform.
  • #2201 runs timed workers in their own session on POSIX and kills the whole group on timeout. It does not change the behaviour on Windows.

They conflict textually (git merge-tree: scripts/run_semantic_tests.py), as this PR's Depends on: #2073 says. Suggest keeping both: #2073 first after its rebase (needs rebase), then this one rebased on it.

AI-assisted (Claude Code).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7246623039 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2201#issuecomment-7246623039). Originally posted by [TheGeogeo](https://github.com/TheGeogeo) on 2026-11-28T22:16:45Z. --- Duplicate check (diff reading only, no build): not a duplicate of #2073. They are two different fixes in `scripts/run_semantic_tests.py`: - #2073 closes a race between Ctrl+C cancellation and a worker still inside `Popen`: the registration is refused once cancelled, on every platform. - #2201 runs timed workers in their own session on POSIX and kills the whole group on timeout. It does not change the behaviour on Windows. They conflict textually (`git merge-tree`: `scripts/run_semantic_tests.py`), as this PR's `Depends on: #2073` says. Suggest keeping both: #2073 first after its rebase (`needs rebase`), then this one rebased on it. AI-assisted (Claude Code).
aslan2142 commented 2026-12-01 11:56:26 +00:00 (Migrated from github.com)

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

Review: CHANGES_REQUESTED


Reviewed against current main: the POSIX process-group timeout cleanup in scripts/run_semantic_tests.py:21-88 looks solid, but this branch conflicts with main, has failing CI, and carries unrelated tools/bcpack_tool.py and tests/test_bcpack_tool.py hunks that are already on main. Please rebase onto current main keeping only the run_semantic_tests changes and re-run CI.

(AI-assisted review.)

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6130773918 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2201#pullrequestreview-6130773918). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T11:56:26Z. **Review:** CHANGES_REQUESTED --- Reviewed against current `main`: the POSIX process-group timeout cleanup in `scripts/run_semantic_tests.py:21-88` looks solid, but this branch conflicts with `main`, has failing CI, and carries unrelated `tools/bcpack_tool.py` and `tests/test_bcpack_tool.py` hunks that are already on `main`. Please rebase onto current `main` keeping only the `run_semantic_tests` changes and re-run CI. *(AI-assisted review.)*
aslan2142 commented 2026-12-01 17:25:34 +00:00 (Migrated from github.com)

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


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:7319278685 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/pull/2201#issuecomment-7319278685). Originally posted by [aslan2142](https://github.com/aslan2142) on 2026-12-01T17:25:34Z. --- 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!2201
No description provided.