Skip to content

run_semantic_tests: stop active subprocesses and cancel queued modules on interrupt (SEMANTIC-RUNNER-INTERRUPT) - #1936

Merged
aslan2142 merged 2 commits into
ProjectLeonida:mainfrom
abnalstlll-byte:feat/semantic-runner-interrupt
Nov 25, 2026
Merged

aslan2142 merged 2 commits into
ProjectLeonida:mainfrom
abnalstlll-byte:feat/semantic-runner-interrupt

Conversation

@abnalstlll-byte

Copy link
Copy Markdown
Contributor

Summary

In scripts/run_semantic_tests.py, catch KeyboardInterrupt during both parallel module execution and serial test execution, cancelling queued test modules via pool.shutdown(wait=False, cancel_futures=True) and terminating active child subprocesses so that no orphaned zombie processes or queued modules run after Ctrl+C.

Changes

  • Active Subprocess Tracking: Track active child subprocesses in _active_processes with a thread-safe lock; register before execution and unregister upon completion.
  • Immediate Termination: On KeyboardInterrupt (or BaseException), invoke _terminate_active_processes() which terminates and kills registered child processes and cleans up immediately.
  • Future Cancellation: Empty remaining queued futures from ThreadPoolExecutor with pool.shutdown(wait=False, cancel_futures=True) and cancel all uncompleted futures so no pending tests run.
  • Responsive Wait Loop: In parallel execution, poll with concurrent.futures.wait(pending, timeout=0.2, return_when=FIRST_COMPLETED) to ensure sub-second signal delivery across Windows and POSIX.
  • Serial Mode: In -j 1 mode, run discover subprocess with responsive proc.wait(timeout=0.2) polling and clean interrupt termination.
  • Exit Code & Output: Return exit code 130 and output 'interrupted' to sys.stderr without printing a false success summary.
  • Regressions: Add parallel cancellation, serial interrupt, direct process termination, and POSIX signal regression tests in tests/test_run_semantic_tests.py.

Item: SEMANTIC-RUNNER-INTERRUPT

AI-assisted (Claude Code)

…s on interrupt (SEMANTIC-RUNNER-INTERRUPT)

Catch KeyboardInterrupt in run_semantic_tests.py, cancelling queued test modules via pool.shutdown(wait=False, cancel_futures=True) and terminating active child subprocesses so that no orphaned zombie processes or queued modules run after Ctrl+C. In serial mode (-j 1), terminate the discover subprocess on interrupt.

Return exit code 130 and output 'interrupted' to stderr without printing a false success summary.

Adds regression and lifecycle tests in tests/test_run_semantic_tests.py.

AI-assisted (Claude Code)
…d increase sleep margin (SEMANTIC-RUNNER-INTERRUPT)

- On Windows, terminate child processes using taskkill /F /T /PID to ensure
  launcher processes (e.g. venv python.exe wrappers) terminate all child workers.
- Increase synthetic sleep duration in tests from 5s to 10s and timeout margin to
  eliminate timing flakiness under high machine load.

AI-assisted (Claude Code).
@abnalstlll-byte

Copy link
Copy Markdown
Contributor Author

Updated in commit \30a2a1862\ (cc @Zalthor re verification feedback):

  1. Windows process tree termination:
    • Added _kill_process_tree\ using \ askkill /F /T /PID\ on Windows. This guarantees that if Python is invoked via a launcher/wrapper (such as \�env\Scripts\python.exe\ or Windows sandbox wrappers), the entire descendant process tree (including the worker interpreter) is forcefully terminated immediately rather than leaving orphaned child processes running.
  2. Test robustness under load:
    • Increased synthetic sleep duration in \ est_parallel_interrupt_stops_active_processes_and_cancels_queued_jobs\ and \ est_serial_interrupt_returns_130_and_prints_interrupted\ from 5 s to 10 s and relaxed elapsed ceiling to 5.0 s (with trigger wait up to 8.0 s).
    • This prevents machine load during Python interpreter startup from racing against the sleep interval while still definitively asserting that interruption completes in ~0.2 s–0.8 s (well below 5 s).
    • Verified 26/26 tests pass on Windows.

AI-assisted (Claude Code).

@aslan2142
aslan2142 merged commit e48ff03 into ProjectLeonida:main Nov 25, 2026
2 of 5 checks passed
@aslan2142

Copy link
Copy Markdown
Collaborator

Merged, thanks! The new tests pass here (26/26), and on main the test file stops on an uncaught KeyboardInterrupt. The Windows paths are guarded (taskkill under os.name == "nt", the killpg test skipped off POSIX).

AI-assisted (Claude Code, Claude Opus 5.5).

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.

2 participants