Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/great-sheep-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"roo-cline": patch
---

More robust process killing
89 changes: 89 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@
"pkce-challenge": "^4.1.0",
"posthog-node": "^4.7.0",
"pretty-bytes": "^6.1.1",
"ps-tree": "^1.2.0",
"puppeteer-chromium-resolver": "^23.0.0",
"puppeteer-core": "^23.4.0",
"reconnecting-eventsource": "^1.6.4",
Expand Down Expand Up @@ -449,6 +450,7 @@
"@types/node": "20.x",
"@types/node-cache": "^4.1.3",
"@types/node-ipc": "^9.2.3",
"@types/ps-tree": "^1.1.6",
"@types/string-similarity": "^4.0.2",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typescript-eslint/parser": "^7.11.0",
Expand Down
1 change: 1 addition & 0 deletions src/core/tools/executeCommandTool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export async function executeCommand(
completed = true
},
onShellExecutionStarted: (pid: number | undefined) => {
console.log(`[executeCommand] onShellExecutionStarted: ${pid}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider replacing console.log with a structured logging solution (or using an existing logger) to adhere to our structured logging standards.

This comment was generated because it violated a code review rule: mrule_OR1S8PRRHcvbdFib.

const status: CommandExecutionStatus = { executionId, status: "started", pid, command }
clineProvider?.postMessageToWebview({ type: "commandExecutionStatus", text: JSON.stringify(status) })
},
Expand Down
39 changes: 35 additions & 4 deletions src/integrations/terminal/ExecaTerminalProcess.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { execa, ExecaError } from "execa"
import psTree from "ps-tree"
import process from "process"

import type { RooTerminal } from "./types"
import { BaseTerminalProcess } from "./BaseTerminalProcess"

export class ExecaTerminalProcess extends BaseTerminalProcess {
private terminalRef: WeakRef<RooTerminal>
private controller?: AbortController
private aborted = false
private pid?: number

constructor(terminal: RooTerminal) {
super()
Expand All @@ -30,18 +32,17 @@ export class ExecaTerminalProcess extends BaseTerminalProcess {

public override async run(command: string) {
this.command = command
this.controller = new AbortController()

try {
this.isHot = true

const subprocess = execa({
shell: true,
cwd: this.terminal.getCurrentWorkingDirectory(),
cancelSignal: this.controller.signal,
all: true,
})`${command}`

this.pid = subprocess.pid
const stream = subprocess.iterable({ from: "all", preserveNewlines: true })
this.terminal.setActiveStream(stream, subprocess.pid)

Expand Down Expand Up @@ -116,7 +117,37 @@ export class ExecaTerminalProcess extends BaseTerminalProcess {

public override abort() {
this.aborted = true
this.controller?.abort()

if (this.pid) {
psTree(this.pid, async (err, children) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider wrapping the psTree callback in a promise (or using a promise‐based helper) so you can await the termination of child processes. Also, review the use of SIGINT—if processes stubbornly persist, escalating to SIGTERM or SIGKILL might be warranted.

This comment was generated because it violated a code review rule: mrule_OR1S8PRRHcvbdFib.

if (!err) {
const pids = children.map((p) => parseInt(p.PID))

for (const pid of pids) {
try {
process.kill(pid, "SIGINT")
} catch (e) {
console.warn(
`[ExecaTerminalProcess] Failed to send SIGINT to child PID ${pid}: ${e instanceof Error ? e.message : String(e)}`,
)
// Optionally try SIGTERM or SIGKILL on failure, depending on desired behavior.
}
}
} else {
console.error(
`[ExecaTerminalProcess] Failed to get process tree for PID ${this.pid}: ${err.message}`,
)
}
})

try {
process.kill(this.pid, "SIGINT")
} catch (e) {
console.warn(
`[ExecaTerminalProcess] Failed to send SIGINT to main PID ${this.pid}: ${e instanceof Error ? e.message : String(e)}`,
)
}
}
}

public override hasUnretrievedOutput() {
Expand Down