Skip to content

fix(code-run): terminate descendant processes - #800

Draft
Whxuan0701 wants to merge 1 commit into
lsdefine:mainfrom
Whxuan0701:fix/code-run-process-tree
Draft

fix(code-run): terminate descendant processes#800
Whxuan0701 wants to merge 1 commit into
lsdefine:mainfrom
Whxuan0701:fix/code-run-process-tree

Conversation

@Whxuan0701

@Whxuan0701 Whxuan0701 commented Sep 8, 2026

Copy link
Copy Markdown

Closes #797

What

  • Starts each POSIX code_run in its own session and terminates the process group on stop/timeout.
  • Tracks Windows descendants with a Job Object, with taskkill /T /F as a fallback when job assignment is unavailable.
  • Uses a bounded graceful-then-forceful stop on POSIX and retains the existing result/status contract.
  • Adds regression tests in which a delayed child side effect must not occur after manual stop or timeout.

Why

The previous process.kill() only terminated the direct child. A command could report [Stopped] or [Timeout Error] while grandchildren continued running, retained resources, or modified files later.

Validation

  • Parent baseline f6e5657: delayed child canary still appears after timeout.
  • macOS 14.6.1: frontends/tests/test_code_run_process_tree.py — 2 passed.
  • Python 3.10.20, 3.12.13, and 3.13.14 focused tests passed.
  • Full non-release frontend suite: 242 passed.
  • Release qualification suite: 35 passed.
  • python -m py_compile ga.py and git diff --check passed.

Boundary

The POSIX behavior was exercised on macOS. The Windows Job Object path was syntax-checked and is covered structurally by the same implementation, but I did not have a Windows host for an end-to-end descendant canary run; Windows CI feedback is welcome while this remains a draft.

Review note

The Windows Popen-to-Job assignment has an unavoidable short creation window with the stdlib API. A child that forks and exits before assignment can escape the job. If maintainers need a strict Windows guarantee, I suggest following up with suspended process creation plus assignment before resume; I kept that lower-level change out of this focused patch.

@Whxuan0701

Copy link
Copy Markdown
Author

Implementation and regression tests are ready in this draft. The POSIX process-group path was exercised on macOS 14.6.1; the Windows Job Object path is included but awaits Windows CI/maintainer validation.

@Whxuan0701
Whxuan0701 force-pushed the fix/code-run-process-tree branch from 709769f to c489fc1 Compare September 8, 2026 09:29
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.

code_run stop/timeout leaves descendant processes running

1 participant