Skip to content

fix(kernel): interrupt IPython subprocess groups - #1030

Closed
lucasrgt wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
lucasrgt:fix/kernel-process-groups
Closed

fix(kernel): interrupt IPython subprocess groups#1030
lucasrgt wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
lucasrgt:fix/kernel-process-groups

Conversation

@lucasrgt

@lucasrgt lucasrgt commented Aug 9, 2026

Copy link
Copy Markdown

Summary

Fixes interrupted IPython cells that stay busy until a subprocess naturally exits.

Prime Agent currently launches direct and forked kernels inside the daemon process group. ipykernel deliberately forwards interrupt_request to descendants only when the kernel is its process-group leader; otherwise it signals the kernel PID alone. Commands such as os.system()/subprocess.wait() can therefore leave their child running while the kernel stays occupied for minutes.

Changes

  • launch direct Unix kernels with detached: true so each kernel owns a session/process group
  • call setsid() in forkserver kernel children before starting ipykernel
  • signal the isolated process group during dispose/restart and abandoned-fork cleanup, preventing orphan descendants
  • add real-kernel regression coverage for both direct and forkserver launch paths

Windows retains the existing behavior.

Validation

  • npm run check
  • focused goal/kernel tests: 53/53 passed
  • new Linux real-kernel regression: direct and forkserver paths both pass; after abort, the next cell executes immediately

The regression test launches a sleeping subprocess, aborts the cell, verifies kernel PID == PGID, and proves a follow-up cell completes instead of raising KernelBusyAfterInterruptError.

Note

Fix interrupt handling in IPython kernels to signal full process groups

  • On non-Windows, directly spawned kernels are started with detached: true so they become process-group leaders; forked kernels call os.setsid() for the same effect.
  • Termination and interrupt signals now target the kernel's Unix process group (negative PID) rather than just the kernel PID, ensuring child processes spawned during cell execution are also interrupted.
  • Adds killIsolatedKernelProcessGroup in index.ts and terminateForkedKernel in fork-server.ts with fallback to direct PID signaling when the group is not yet established.
  • Adds integration tests in kernel-process-group.test.ts (skipped on Windows) that verify interrupts reach descendant processes and the kernel remains usable afterward.
  • Behavioral Change: kernels that previously ignored interrupts or left child processes running after abort will now receive SIGTERM/SIGINT across the whole process group.

Macroscope summarized 8dcfff8.

@sethkarten

Copy link
Copy Markdown
Contributor

Thank you for the report and proposed work. This root cause is now covered by maintainer-owned stacked PR #1162, authored independently from upstream/main.

We did not inspect or reuse this PR's diff, branch, commits, implementation code, or tests; its public description/comments were used only as a bug report. To keep one review surface, this PR is superseded by #1162 and is being closed.

The complete review stack is #1158#1165. It is being left unmerged for human review after CI and review-bot findings are cleared.

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