Repository navigation
fix(pty): only force-kill processes in the terminal's own Linux session - #27422
Conversation
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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Priority: ➖ Normal Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to 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 |
|
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 apts/6. If that container ran as your user, closing Orca'spts/6killed 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
/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.signalPosixPtyProcessGroups), which uses the same selection./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
/procis translated into Orca's PID namespace, so a container's session shows up with a different id and can't collide.Alternatives considered:
cgroup.kill: stronger, and it would also catch processes that detached withsetsid(). 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.sidcolumn tops: this depends on what eachpsvariant supports (procps, BusyBox, toybox). If one rejected the column, the whole sweep would fail. Reading/procworks 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.tsuse/proc/<pid>/statfixtures through a mockedreadFileSync, so no real processes are signalled. They use the issue's layout: an Orca shell and two "container" sessions on the samepts/6. They cover:/proc;).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/procpath on the Linux CI runner.Local runs:
pnpm tc,pnpm lint,oxlint, andpnpm run check:code-quality:changedall 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
Notes
/proc/<pid>/statis standard there./procread per process on that terminal, only when a force kill happens.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)