leonida_tui: terminate only the timed-out child in pump_process (TUI-PUMP-PROCESS-TIMEOUT) #1305

Closed
ambroseautomation wants to merge 1 commit from upstream-pr/1305 into main
ambroseautomation commented 2026-11-24 21:37:29 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by ambroseautomation on 2026-11-24T21:37:29Z.


Summary

Coordination item: TUI-PUMP-PROCESS-TIMEOUT (reported by @jtoucas-DIMO in #14).

Problem & Root Cause

In tools/leonida_tui.py, pump_process() waits up to 0.5s for proc to exit after its stdout reaches EOF. On subprocess.TimeoutExpired, it called kill_live_processes(), which iterates over the global _live_procs set and kills every monitored subprocess (and clears _live_procs), terminating unrelated parallel workers (such as concurrent shader shards or overlapped build stages) whenever one child lingers after closing stdout.

Implementation

  • Extracted _terminate_process(proc) from kill_live_processes() in tools/leonida_tui.py (preserving Windows taskkill /F /T /PID tree termination and POSIX terminate() → wait(1.0) → kill() fallback).
  • Updated pump_process() to call _terminate_process(proc) on post-EOF subprocess.TimeoutExpired instead of kill_live_processes(), so only the timed-out child is terminated and later unregistered in finally, while sibling live processes remain running and registered.
  • Added PumpProcessTimeoutTest in tests/test_leonida_tui.py covering both POSIX (terminate()) and Windows (taskkill /F /T /PID) paths with a registered sibling process.

Tests Run

Environment: Windows 11 Pro 64-bit, Python 3.12.10, synthetic FakeProc fixtures only (no game data).

  • python -I -m py_compile tools/leonida_tui.py tests/test_leonida_tui.py — PASS
  • python -I tests/test_leonida_tui.py -v — 27/27 PASS (including 2 new tests in PumpProcessTimeoutTest)
  • pytest tests/test_leonida_tui.py tests/test_text_write_line_endings.py -v — 30/30 PASS
  • python -I scripts/check_no_game_data.py tools/leonida_tui.py tests/test_leonida_tui.py — PASS

Disclosure

AI-assisted: yes

<!-- greyfinch-sync:ubiquitarianism/leonida:issue:5480755791 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1305). Originally posted by [ambroseautomation](https://github.com/ambroseautomation) on 2026-11-24T21:37:29Z. --- ## Summary Coordination item: `TUI-PUMP-PROCESS-TIMEOUT` (reported by `@jtoucas-DIMO` in #14). ### Problem & Root Cause In `tools/leonida_tui.py`, `pump_process()` waits up to `0.5s` for `proc` to exit after its `stdout` reaches EOF. On `subprocess.TimeoutExpired`, it called `kill_live_processes()`, which iterates over the global `_live_procs` set and kills **every** monitored subprocess (and clears `_live_procs`), terminating unrelated parallel workers (such as concurrent shader shards or overlapped build stages) whenever one child lingers after closing stdout. ### Implementation - Extracted `_terminate_process(proc)` from `kill_live_processes()` in `tools/leonida_tui.py` (preserving Windows `taskkill /F /T /PID` tree termination and POSIX `terminate()` → `wait(1.0)` → `kill()` fallback). - Updated `pump_process()` to call `_terminate_process(proc)` on post-EOF `subprocess.TimeoutExpired` instead of `kill_live_processes()`, so only the timed-out child is terminated and later unregistered in `finally`, while sibling live processes remain running and registered. - Added `PumpProcessTimeoutTest` in `tests/test_leonida_tui.py` covering both POSIX (`terminate()`) and Windows (`taskkill /F /T /PID`) paths with a registered sibling process. ## Tests Run Environment: Windows 11 Pro 64-bit, Python 3.12.10, synthetic `FakeProc` fixtures only (no game data). - `python -I -m py_compile tools/leonida_tui.py tests/test_leonida_tui.py` — PASS - `python -I tests/test_leonida_tui.py -v` — 27/27 PASS (including 2 new tests in `PumpProcessTimeoutTest`) - `pytest tests/test_leonida_tui.py tests/test_text_write_line_endings.py -v` — 30/30 PASS - `python -I scripts/check_no_game_data.py tools/leonida_tui.py tests/test_leonida_tui.py` — PASS ## Disclosure AI-assisted: yes
nicoco23 commented 2026-11-24 22:07:16 +00:00 (Migrated from github.com)

Imported from ubiquitarianism/leonida. Originally posted by nicoco23 on 2026-11-24T22:07:16Z.

Review: APPROVED


Reviewed the diff and ran the tests: python -I tests/test_leonida_tui.py -v on Windows 11, Python 3.12, 27 tests, OK.

The fix is the right scope: on the post-EOF TimeoutExpired, pump_process() now terminates only that child instead of calling kill_live_processes(), which killed every registered process.

Nits, none blocking:

  • In PumpProcessTimeoutTest, assertNotIn(hung, leonida_tui._live_procs) passes trivially if hung was never registered, so it does not show that the timed-out process is unregistered afterwards. Registering it first, then asserting after pump_process returns, would make it meaningful.
  • On Windows the taskkill return code is ignored and there is no proc.kill() fallback if taskkill fails.
  • On POSIX, terminate() only reaches the direct child, not its children. That was already the case before this change.

NOT AI-assisted review

<!-- greyfinch-sync:ubiquitarianism/leonida:review:6048169152 --> Imported from [ubiquitarianism/leonida](https://github.com/ubiquitarianism/leonida/pull/1305#pullrequestreview-6048169152). Originally posted by [nicoco23](https://github.com/nicoco23) on 2026-11-24T22:07:16Z. **Review:** APPROVED --- Reviewed the diff and ran the tests: `python -I tests/test_leonida_tui.py -v` on Windows 11, Python 3.12, 27 tests, OK. The fix is the right scope: on the post-EOF TimeoutExpired, pump_process() now terminates only that child instead of calling kill_live_processes(), which killed every registered process. Nits, none blocking: - In PumpProcessTimeoutTest, assertNotIn(hung, leonida_tui._live_procs) passes trivially if `hung` was never registered, so it does not show that the timed-out process is unregistered afterwards. Registering it first, then asserting after pump_process returns, would make it meaningful. - On Windows the taskkill return code is ignored and there is no proc.kill() fallback if taskkill fails. - On POSIX, terminate() only reaches the direct child, not its children. That was already the case before this change. NOT AI-assisted review

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!1305
No description provided.