Skip to content

fix(pty): only force-kill processes in the terminal's own Linux session - #27422

Merged
OrcaWin merged 1 commit into
mainfrom
OrcaWin/fix-27337-pts-session-kill
Oct 11, 2026
Merged

OrcaWin merged 1 commit into
mainfrom
OrcaWin/fix-27337-pts-session-kill

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​110 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​106
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​43 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​39

ELI5

When you force-close a terminal on Linux, Orca also kills the programs that were running inside it. It found them by the terminal's number, like pts/6. A Docker container has its own private set of terminal numbers, and it can also have a pts/6. If that container ran as your user, closing Orca's pts/6 killed the container's programs too. Now Orca also checks that each program belongs to the terminal's own login session before it kills it.

What Changed

  • Before: on Linux, force-killing an Orca terminal sent SIGKILL to every process group whose controlling terminal number matched the shell's. Same-uid services inside containers that happened to use the same pts number died too: the issue reports 117 unrelated kills in four days.
  • After: on Linux, Orca reads each candidate's session id from /proc/<pid>/stat (field 6). It only signals processes whose session id equals the terminal shell's pid. The node-pty shell is always the leader of its own session. If the shell's session can't be read, or the shell doesn't lead its session, Orca uses the existing fallback and kills only the shell itself. Candidates whose session can't be read are skipped.
  • The same filter covers the stop/continue sweep (signalPosixPtyProcessGroups), which uses the same selection.
  • macOS is unchanged: it has no per-container terminal numbering, and it never reads /proc. The kill escalation (graceful first, then forced) and its ordering are also unchanged.

Why

On Linux, a controlling terminal belongs to exactly one session, and every member of that session shares it. So inside Orca's own namespace, "has this tty" and "is in the shell's session" pick out the same processes. The session check only removes look-alikes from other devpts instances, so legitimate processes are never dropped. The session id read from /proc is translated into Orca's PID namespace, so a container's session shows up with a different id and can't collide.

Alternatives considered:

  • A child cgroup per terminal with cgroup.kill: stronger, and it would also catch processes that detached with setsid(). But it is a much larger change and depends on cgroup v2 and delegation. That belongs with Hand-typed agent sessions (claude/codex in a plain shell) leak their process tree on tab close #16714.
  • Adding a sid column to ps: this depends on what each ps variant supports (procps, BusyBox, toybox). If one rejected the column, the whole sweep would fail. Reading /proc works the same on every Linux system.

Processes that detached on purpose with setsid(): these are intentionally still not killed. setsid() drops the controlling terminal, so those processes were never in the tty-based list either. This PR doesn't change that, and #16714 tracks it.

Linked Issue

Fixes #27337

Visual Proof

N/A. This is process-selection logic with no UI change.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • New unit tests in src/main/pty/posix-pty-process-groups.test.ts use /proc/<pid>/stat fixtures through a mocked readFileSync, so no real processes are signalled. They use the issue's layout: an Orca shell and two "container" sessions on the same pts/6. They cover:

    • force-kill signals only the shell's own groups;
    • the stop sweep is filtered the same way;
    • a candidate whose session can't be read is excluded;
    • the root-only fallback runs when the shell's session is unreadable or the shell isn't a session leader;
    • macOS still selects by tty alone and never reads /proc;
    • the session-id parser handles a command name that contains spaces and ).
  • The new tests fail without the fix: 6 of 48 fail.

  • The existing real-PTY integration test (posix-pty-process-groups.integration.test.ts) runs the actual /proc path on the Linux CI runner.

  • Local runs: pnpm tc, pnpm lint, oxlint, and pnpm run check:code-quality:changed all pass, as do the focused pty, terminal-teardown and daemon-subprocess test suites.

Review

P0/P1 review: a self-review plus an independent model reviewer, run read-only.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Linux-only behaviour change; macOS and Windows are untouched.
  • On SSH hosts, the daemon on the execution host runs this same code, so remote Linux hosts get the same protection.
  • WSL and BusyBox: /proc/<pid>/stat is standard there.
  • Cost: one small /proc read per process on that terminal, only when a force kill happens.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

Container devpts instances reuse pts numbers, so selecting kill targets by
tty alone could SIGKILL same-uid processes in other namespaces. On Linux,
require each candidate's /proc session id to equal the PTY shell's pid.

Fixes #27337
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a6b83a3f-d4ef-4be3-9e02-face51c8de00

📥 Commits

Reviewing files that changed from the base of the PR and between e8b3981 and 8edd266.


📒 Files selected for processing (2)
  • src/main/pty/posix-pty-process-groups.test.ts
  • src/main/pty/posix-pty-process-groups.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.



📝 Walkthrough

Walkthrough

Linux process-group discovery can read session IDs from /proc/<pid>/stat. When a session-ID reader is supplied, discovery requires the root process to lead its session and selects only same-session processes on its terminal. Linux signaling supplies the proc reader by default. Other platforms retain terminal-based selection, and Windows retains its existing fallback. Tests cover parsing, filtering, fallback behavior, and macOS selection.


Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 8edd2

This change narrows which Linux processes are signaled when a terminal is force-killed, so unrelated processes are no longer hit. Unreadable or unexpected session data falls back to killing only the shell. No actionable merge-blocking risk was found.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely summarizes the main Linux PTY process-selection fix.
Description check Passed The description is complete and covers the required sections, including the user impact, implementation, rationale, linked issue, testing, platform considerations, and checklist. It provides sufficien…
Linked Issues check Passed Issue #27337 requires Linux terminal force-kill to signal only processes in the terminal session. The production change reads session ID field 6 from /proc/<pid>/stat, requires the root session ID t…
Out of Scope Changes check Passed The pull request changes only src/main/pty/posix-pty-process-groups.ts and its test file. The production changes implement session filtering for issue #27337. The tests directly verify the new behav…

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@OrcaWin
OrcaWin merged commit 2d5e9b6 into main Oct 11, 2026
54 of 56 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.

Linux: terminal force-kill SIGKILLs same-uid processes in containers that reuse the terminal's pts number

1 participant