Skip to content

Improve terminal server teardown behavior.#12205

Open
vorporeal wants to merge 1 commit into
masterfrom
david/improved-terminal-server-teardown
Open

Improve terminal server teardown behavior.#12205
vorporeal wants to merge 1 commit into
masterfrom
david/improved-terminal-server-teardown

Conversation

@vorporeal
Copy link
Copy Markdown
Contributor

@vorporeal vorporeal commented Jun 4, 2026

Description

Fix terminal-server teardown so Warp does not leave server-owned PTY shell process groups running after application shutdown.

This adds an explicit terminal-server shutdown request/response, terminates PTY process groups with SIGHUP followed by a bounded SIGKILL fallback, and reuses the same group-aware cleanup when terminating individual children. It also stops pane PTY event loops before tearing down the terminal server so normal shutdown does not produce redundant socket writes or misleading EOF logs.

Note

note from dstern: i was seeing (terminal session) shell processes leaking, and impacting performance of my system. i asked agent mode to do a little investigation, it pointed out that we don't have a terribly robust teardown strategy for the terminal server. while i'm not entirely sure whether this will fix the cause, improving this can't hurt.

Linked Issue

N/A

Testing

  • Ran cargo fmt --manifest-path /Users/david/src/warp/Cargo.toml --package warp
  • Ran cargo nextest run --manifest-path /Users/david/src/warp/Cargo.toml -p warp -E 'test(terminate_child_signals_the_entire_pty_process_group) | test(terminate_child_escalates_when_a_descendant_ignores_sighup_after_the_shell_exits) | test(terminate_all_escalates_when_a_pty_process_group_ignores_sighup)'
  • Ran cargo check --manifest-path /Users/david/src/warp/Cargo.toml -p warp --lib
  • Ran git diff --check
  • Manually tested application startup and shutdown twice with ./script/run

Agent Mode

CHANGELOG-BUG-FIX: Prevent terminal shell processes from being left running after Warp shuts down.

Co-Authored-By: Oz oz-agent@warp.dev

@cla-bot cla-bot Bot added the cla-signed label Jun 4, 2026
Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@vorporeal
Copy link
Copy Markdown
Contributor Author

/oz-review

@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented Jun 4, 2026

@vorporeal

I'm re-reviewing this pull request in response to a review request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR adds a terminal-server shutdown request/response path, stops PTY event loops before terminal-server teardown, and updates hosted PTY cleanup to signal entire process groups with a bounded SIGKILL fallback. It also adds targeted Unix tests for process-group termination and escalation behavior.

Concerns

  • No blocking correctness concerns found in the changed lines.
  • No security findings found in the supplemental security pass.
  • No approved or repository spec context was available for implementation drift review.
  • The behavioral change is a non-visual lifecycle cleanup; the PR includes targeted process-group tests and manual startup/shutdown testing, so screenshots or video would not add meaningful evidence for this review.

Verdict

Found: 0 critical, 0 important, 0 suggestions

Approve

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

@vorporeal vorporeal marked this pull request as ready for review June 4, 2026 18:46
@oz-for-oss
Copy link
Copy Markdown
Contributor

oz-for-oss Bot commented Jun 4, 2026

@vorporeal

I'm starting a first review of this pull request.

You can view the conversation on Warp.

I completed the review and no human review was requested for this pull request.

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

Copy link
Copy Markdown
Contributor

@oz-for-oss oz-for-oss Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overview

This PR adds a graceful terminal-server shutdown protocol, group-aware SIGHUP/SIGKILL cleanup for server-owned PTYs, and shutdown ordering changes so PTY event loops stop before the terminal server is torn down.

Concerns

  • The new cleanup still loses the PTY process group once the shell leader has already exited and been reaped by the terminal server, so descendants can remain unsignaled during later pane or app shutdown; see the inline comment.
  • No approved spec context was provided. This is non-visual teardown behavior, so screenshots or recordings would not add meaningful evidence.

Verdict

Found: 0 critical, 1 important, 0 suggestions

Request changes

Comment /oz-review on this pull request to retrigger a review (up to 3 times on the same pull request).

Powered by Oz

/// while descendants remain in that group, so this keeps checking group
/// liveness throughout a grace period and sends `SIGKILL` to survivors.
fn terminate_child(&mut self, pid: u32) -> Result<()> {
if !self.0.contains_key(&pid) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ [IMPORTANT] Returning here means cleanup is skipped after terminated_children() has reaped and removed the shell leader, but descendants can still be alive in that PTY process group; keep tracking known pgids until the group is gone and run the group-aware cleanup for already-exited children too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant