summaryrefslogtreecommitdiffhomepage
path: root/packages
diff options
context:
space:
mode:
authorAiden Cline <[email protected]>2025-10-15 13:01:54 -0500
committerGitHub <[email protected]>2025-10-15 13:01:54 -0500
commit278ffb9a4e7f99c7546ec8150b195d6e49476f3a (patch)
treedf7c2d77bf5cfe10ee6982f8f657d6a3a7cf0ebb /packages
parentb2ff4be4c6990bbad2576a13c13dba83245c89e0 (diff)
downloadopencode-278ffb9a4e7f99c7546ec8150b195d6e49476f3a.tar.gz
opencode-278ffb9a4e7f99c7546ec8150b195d6e49476f3a.zip
fix: spawns hanging (#3192)
Diffstat (limited to 'packages')
-rw-r--r--packages/opencode/src/tool/bash.ts26
1 files changed, 19 insertions, 7 deletions
diff --git a/packages/opencode/src/tool/bash.ts b/packages/opencode/src/tool/bash.ts
index d4e8ce85a..af1610d56 100644
--- a/packages/opencode/src/tool/bash.ts
+++ b/packages/opencode/src/tool/bash.ts
@@ -145,14 +145,26 @@ export const BashTool = Tool.define("bash", {
})
}
- const process = spawn(params.command, {
+ const proc = spawn(params.command, {
shell: true,
cwd: Instance.directory,
signal: ctx.abort,
stdio: ["ignore", "pipe", "pipe"],
timeout,
+ detached: process.platform !== "win32",
})
+ if (!ctx.abort.aborted) {
+ ctx.abort.addEventListener("abort", () => {
+ if (!proc.pid) return
+ if (process.platform === "win32") {
+ proc.kill()
+ return
+ }
+ process.kill(-proc.pid)
+ })
+ }
+
let output = ""
// Initialize metadata with empty output
@@ -163,7 +175,7 @@ export const BashTool = Tool.define("bash", {
},
})
- process.stdout?.on("data", (chunk) => {
+ proc.stdout?.on("data", (chunk) => {
output += chunk.toString()
ctx.metadata({
metadata: {
@@ -173,7 +185,7 @@ export const BashTool = Tool.define("bash", {
})
})
- process.stderr?.on("data", (chunk) => {
+ proc.stderr?.on("data", (chunk) => {
output += chunk.toString()
ctx.metadata({
metadata: {
@@ -184,7 +196,7 @@ export const BashTool = Tool.define("bash", {
})
await new Promise<void>((resolve) => {
- process.on("close", () => {
+ proc.on("close", () => {
resolve()
})
})
@@ -192,7 +204,7 @@ export const BashTool = Tool.define("bash", {
ctx.metadata({
metadata: {
output: output,
- exit: process.exitCode,
+ exit: proc.exitCode,
description: params.description,
},
})
@@ -202,7 +214,7 @@ export const BashTool = Tool.define("bash", {
output += "\n\n(Output was truncated due to length limit)"
}
- if (process.signalCode === "SIGTERM" && params.timeout) {
+ if (proc.signalCode === "SIGTERM" && params.timeout) {
output += `\n\n(Command timed out after ${timeout} ms)`
}
@@ -210,7 +222,7 @@ export const BashTool = Tool.define("bash", {
title: params.command,
metadata: {
output,
- exit: process.exitCode,
+ exit: proc.exitCode,
description: params.description,
},
output,