Skip to content

Reap foreground job-control process groups - #192

Merged
austinywang merged 2 commits into
mainfrom
issue-9573-descendant-reap
Aug 9, 2026
Merged

austinywang merged 2 commits into
mainfrom
issue-9573-descendant-reap

Conversation

@austinywang

@austinywang austinywang commented Aug 8, 2026 •

Copy link
Copy Markdown

Summary

  • capture the PTY foreground process-group id before subprocess teardown
  • signal and probe the session-leader and distinct foreground groups under one shared deadline
  • add a regression with a SIGHUP-resistant foreground job group

Verification

  • red regression on babe426: foreground group remained alive
  • green on 47e9bd4: zig build test -Dtest-filter="subprocess stop"
  • universal ReleaseFast GhosttyKit archive validated and published

cmux issue: manaflow-ai/cmux#9573


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Reap foreground job-control process groups when stopping a subprocess so foreground jobs don’t linger after the terminal closes. Fixes SIGHUP-resistant foreground groups remaining alive (see cmux issue ghostty-org#9573).

  • Bug Fixes
    • Capture the PTY’s foreground process-group id before teardown.
    • Send SIGHUP then SIGKILL to both the primary and distinct foreground groups under a shared deadline.
    • Handle direct-child reaping and transient missing-group windows; ignore expected EPERM from killpg on Darwin.
    • Add a regression test that kills a SIGHUP-resistant foreground group.

Written for commit 47e9bd4. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved terminal process shutdown to reliably terminate child processes and their descendants.
    • Added handling for processes running in separate foreground terminal groups.
    • Made shutdown more resilient when processes exit or temporarily become unavailable.
    • Improved reporting of process groups involved during terminal cleanup.

@coderabbitai

coderabbitai Bot commented Aug 8, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5edd8197-583d-4064-8e6b-b5f4a67b999d

📥 Commits

Reviewing files that changed from the base of the PR and between c0de068 and 47e9bd4.

📒 Files selected for processing (1)
  • src/termio/Exec.zig

📝 Walkthrough

Walkthrough

The POSIX subprocess teardown now detects the terminal foreground process group, coordinates SIGHUP and SIGKILL handling for two groups, preserves direct-child fallback behavior, and adds regression coverage for concurrently reaped leaders.

Changes

POSIX subprocess teardown

Layer / File(s) Summary
Detect and pass foreground group
src/termio/Exec.zig
The PTY foreground process-group ID is read through ioctl. Timeout-aware termination passes this ID and persistent process-group state into POSIX shutdown.
Coordinate multi-group shutdown
src/termio/Exec.zig
Shutdown tracks the primary and foreground groups independently, retries transient group absence, shares SIGHUP/SIGKILL deadlines, and reports both group IDs with the direct-child ID.
Validate descendant termination
src/termio/Exec.zig
A POSIX regression test covers a concurrently reaped session leader and a distinct terminal foreground process group.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SubprocessStop as Subprocess stopping
  participant Pty as PTY
  participant CommandTermination as POSIX command termination
  participant ProcessGroups as Primary and foreground groups

  SubprocessStop->>Pty: Read foreground process-group ID
  Pty-->>SubprocessStop: Return group ID
  SubprocessStop->>CommandTermination: Start timeout-aware shutdown
  CommandTermination->>ProcessGroups: Send SIGHUP and probe both groups
  ProcessGroups-->>CommandTermination: Return group status
  CommandTermination->>ProcessGroups: Send SIGKILL after shared deadline
Loading

Suggested reviewers: mitchellh, rockorager

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: reaping foreground job-control process groups during subprocess teardown.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch issue-9573-descendant-reap

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@austinywang
austinywang merged commit f66cfbd into main Aug 9, 2026
156 checks passed
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.

1 participant