mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-29 11:02:12 +03:00
fix(exec): close stdin for non-pty runs
This commit is contained in:
@@ -362,6 +362,22 @@ export async function runExecProcess(opts: {
|
|||||||
let stdin: SessionStdin | undefined;
|
let stdin: SessionStdin | undefined;
|
||||||
const execCommand = opts.execCommand ?? opts.command;
|
const execCommand = opts.execCommand ?? opts.command;
|
||||||
|
|
||||||
|
// `exec` does not currently accept tool-provided stdin content. For non-PTY runs,
|
||||||
|
// keeping stdin open can cause commands like `wc -l` (or safeBins-hardened segments)
|
||||||
|
// to block forever waiting for input, leading to accidental backgrounding.
|
||||||
|
// For interactive flows, callers should use `pty: true` (stdin kept open).
|
||||||
|
const maybeCloseNonPtyStdin = () => {
|
||||||
|
if (opts.usePty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// Signal EOF immediately so stdin-only commands can terminate.
|
||||||
|
child?.stdin?.end();
|
||||||
|
} catch {
|
||||||
|
// ignore stdin close errors
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
if (opts.sandbox) {
|
if (opts.sandbox) {
|
||||||
const { child: spawned } = await spawnWithFallback({
|
const { child: spawned } = await spawnWithFallback({
|
||||||
argv: [
|
argv: [
|
||||||
@@ -396,6 +412,7 @@ export async function runExecProcess(opts: {
|
|||||||
});
|
});
|
||||||
child = spawned as ChildProcessWithoutNullStreams;
|
child = spawned as ChildProcessWithoutNullStreams;
|
||||||
stdin = child.stdin;
|
stdin = child.stdin;
|
||||||
|
maybeCloseNonPtyStdin();
|
||||||
} else if (opts.usePty) {
|
} else if (opts.usePty) {
|
||||||
const { shell, args: shellArgs } = getShellConfig();
|
const { shell, args: shellArgs } = getShellConfig();
|
||||||
try {
|
try {
|
||||||
@@ -489,6 +506,7 @@ export async function runExecProcess(opts: {
|
|||||||
});
|
});
|
||||||
child = spawned as ChildProcessWithoutNullStreams;
|
child = spawned as ChildProcessWithoutNullStreams;
|
||||||
stdin = child.stdin;
|
stdin = child.stdin;
|
||||||
|
maybeCloseNonPtyStdin();
|
||||||
}
|
}
|
||||||
|
|
||||||
const session = {
|
const session = {
|
||||||
|
|||||||
Reference in New Issue
Block a user