Skip to content

fix(ipython): terminate %%bash subprocesses on interrupt - #861

Closed
Akashmdshetty wants to merge 2 commits into
PrimeIntellect-ai:mainfrom
Akashmdshetty:fix/issue-849-ipython-interrupt
Closed

fix(ipython): terminate %%bash subprocesses on interrupt#861
Akashmdshetty wants to merge 2 commits into
PrimeIntellect-ai:mainfrom
Akashmdshetty:fix/issue-849-ipython-interrupt

Conversation

@Akashmdshetty

@Akashmdshetty Akashmdshetty commented Aug 7, 2026

Copy link
Copy Markdown

Summary

This PR fixes an issue where interrupting a %%bash/%%script cell returns control to the agent but leaves child subprocesses running indefinitely.

Changes

  • Ensure subprocesses spawned by %%bash/%%script execute in their own process group.
  • Clean up the entire process group when a KeyboardInterrupt occurs.
  • Preserve existing IPython behavior by wrapping the existing script magic implementation.
  • Add regression tests covering the interrupt behavior.

Motivation

Previously, interrupting long-running %%bash cells could leave orphaned subprocesses running after the tool call was abandoned, requiring manual cleanup.

Closes #849

Note

Fix %%bash cell interrupts to terminate subprocess groups in IPython

  • Patches ScriptMagics.shebang in the IPython bootstrap to wrap subprocess.Popen, creating a new process group for child processes spawned during shebang cell execution.
  • On KeyboardInterrupt, sends SIGINT then SIGKILL to the entire child process group (POSIX) or uses taskkill (Windows), ensuring %%bash and similar cells stop reliably.
  • Also updates the abort timeout in KernelManager to re-attempt interrupt() before calling forceAbort() if the same execution is still active.
  • The bootstrap patch is wrapped in try/except to be best-effort and avoid breaking the kernel on failure.

Macroscope summarized cbf0eb5.

@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.

@sethkarten sethkarten closed this Aug 10, 2026
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.

Esc/interrupt leaves %%bash subprocesses running forever: forceAbort resolves the tool call after 1s but never reaches the cell's grandchildren

2 participants